Skip to content

Commit

Permalink
Add support for Rails 8
Browse files Browse the repository at this point in the history
  • Loading branch information
iffyuva committed Nov 21, 2024
1 parent 64bbfd5 commit 6b3bc83
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 104 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Tests

on:
pull_request:
push:
branches:
- master

jobs:
rspec:
runs-on: ubuntu-latest
Expand All @@ -19,6 +22,7 @@ jobs:
- 6.0.0
- 6.1.0
- 7.0.0
- 8.0.0
# https://www.ruby-lang.org/en/downloads/
ruby:
- 2.4.10 # not maintained by ruby team
Expand Down Expand Up @@ -81,6 +85,17 @@ jobs:
ruby: 2.5.9
- rails: 7.0.0
ruby: 2.6.10
# Rails 8 needs ruby >= 3.1.0
- rails: 8.0.0
ruby: 2.4.10
- rails: 8.0.0
ruby: 2.5.9
- rails: 8.0.0
ruby: 2.6.10
- rails: 8.0.0
ruby: 2.7.8
- rails: 8.0.0
ruby: 3.0.6
services:
postgres:
image: postgres:11-alpine
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ source 'https://rubygems.org'

gemspec

gem 'rails', "~> #{ENV['RAILS_VERSION']}"
gem 'rails', '~> 8.0.0'
gem 'pg'
gem 'ostruct'

group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
2 changes: 1 addition & 1 deletion app/models/rapidfire/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Question < ApplicationRecord

validates :survey, :question_text, :presence => true
validate :type_can_change
serialize :validation_rules
serialize :validation_rules, coder: YAML

def self.inherited(child)
child.instance_eval do
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/Gemfile.rails-8.0.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- ruby -*-

source 'https://rubygems.org'

gemspec path: '..'
gem 'rails', '~> 8.0.0'
gem 'ostruct'
6 changes: 3 additions & 3 deletions rapidfire.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ There is breaking delimiter change when upgrading to version 2.0.0.
Please see Readme for more information.
PIM

s.add_dependency 'rails', '>= 3.2.13'
s.add_dependency 'rails', '>= 7.0.0'
s.add_dependency 'active_model_serializers', '~> 0.10.0'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec-rails', '~> 3.6.1'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'shoulda'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_girl_rails'
s.add_development_dependency 'factory_bot_rails'
s.add_development_dependency 'capybara'
s.add_development_dependency 'launchy'
s.add_development_dependency 'minitest'
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/rapidfire/attempts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# any default value.
context 'when no parameters are passed' do
it 'initializes answer builder with empty args' do
survey = FactoryGirl.create(:survey)
survey = FactoryBot.create(:survey)

if Rails::VERSION::MAJOR >= 5
expect {
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
config.whiny_nils = false

# Expands the lines which load the assets
config.assets.debug = true
# config.assets.debug = true
end
2 changes: 1 addition & 1 deletion spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_04_02_174122) do
ActiveRecord::Schema[8.0].define(version: 2023_04_02_174122) do
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down
8 changes: 4 additions & 4 deletions spec/factories/answers_factory.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
FactoryBot.define do
factory :answer, :class => "Rapidfire::Answer" do
attempt { FactoryGirl.create(:attempt) }
question { FactoryGirl.create(:q_long) }
answer_text "hello world"
attempt { FactoryBot.create(:attempt) }
question { FactoryBot.create(:q_long) }
answer_text { "hello world" }
end
end
4 changes: 2 additions & 2 deletions spec/factories/attempts_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryGirl.define do
FactoryBot.define do
factory :attempt, :class => "Rapidfire::Attempt" do
survey { FactoryGirl.create(:survey) }
survey { FactoryBot.create(:survey) }
end
end
14 changes: 7 additions & 7 deletions spec/factories/questions_factory.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FactoryGirl.define do
factory :question do
survey { FactoryGirl.create(:survey) }
question_text "Sample Question"
FactoryBot.define do
factory :question, :class => "Rapidfire::Question" do
survey { FactoryBot.create(:survey) }
question_text { "Sample Question" }

factory :q_checkbox, :class => "Rapidfire::Questions::Checkbox" do
answer_options "hindi\r\ntelugu\r\nkannada\r\n"
answer_options { "hindi\r\ntelugu\r\nkannada\r\n" }
end

factory :q_date, :class => "Rapidfire::Questions::Date" do
Expand All @@ -17,11 +17,11 @@
end

factory :q_radio, :class => "Rapidfire::Questions::Radio" do
answer_options "male\r\nfemale\r\n"
answer_options { "male\r\nfemale\r\n" }
end

factory :q_select, :class => "Rapidfire::Questions::Select" do
answer_options "mac\r\nwindows\r\n"
answer_options { "mac\r\nwindows\r\n" }
end

factory :q_short, :class => "Rapidfire::Questions::Short" do
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/surveys_factory.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
FactoryBot.define do
factory :survey, :class => "Rapidfire::Survey" do
name "Test Survey"
introduction "Please answer all the questions in this survey."
name { "Test Survey" }
introduction { "Please answer all the questions in this survey." }
end
end
4 changes: 2 additions & 2 deletions spec/factories/users_factory.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
name "Test User"
name { "Test User" }
end
end
16 changes: 8 additions & 8 deletions spec/features/rapidfire/answering_questions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe "Surveys" do
let!(:survey) { FactoryGirl.create(:survey, name: "Question Set", introduction: "Some introduction") }
let!(:survey) { FactoryBot.create(:survey, name: "Question Set", introduction: "Some introduction") }

it "displays survey introduction" do
visit rapidfire.new_survey_attempt_path(survey)
Expand All @@ -10,10 +10,10 @@
end

describe "Answering Questions" do
let!(:question1) { FactoryGirl.create(:q_long, survey: survey, question_text: "Long Question", validation_rules: { presence: "1" }) }
let!(:question2) { FactoryGirl.create(:q_short, survey: survey, question_text: "Short Question") }
let!(:question3) { FactoryGirl.create(:q_checkbox, survey: survey, question_text: "Checkbox question") }
let!(:question4) { FactoryGirl.create(:q_checkbox, survey: survey, question_text: "Checkbox question", validation_rules: { presence: "1" }) }
let!(:question1) { FactoryBot.create(:q_long, survey: survey, question_text: "Long Question", validation_rules: { presence: "1" }) }
let!(:question2) { FactoryBot.create(:q_short, survey: survey, question_text: "Short Question") }
let!(:question3) { FactoryBot.create(:q_checkbox, survey: survey, question_text: "Checkbox question") }
let!(:question4) { FactoryBot.create(:q_checkbox, survey: survey, question_text: "Checkbox question", validation_rules: { presence: "1" }) }

before do
visit rapidfire.new_survey_attempt_path(survey)
Expand Down Expand Up @@ -92,7 +92,7 @@
if "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" >= "5.2"
describe "Answering File uploads" do
context "when the question is single file upload" do
let!(:question1) { FactoryGirl.create(:q_file, survey: survey, question_text: "Avatar") }
let!(:question1) { FactoryBot.create(:q_file, survey: survey, question_text: "Avatar") }

it "persistes the file" do
visit rapidfire.new_survey_attempt_path(survey)
Expand All @@ -107,7 +107,7 @@
end

context "when the question is multi file upload" do
let!(:question1) { FactoryGirl.create(:q_multifile, survey: survey, question_text: "Images") }
let!(:question1) { FactoryBot.create(:q_multifile, survey: survey, question_text: "Images") }

it "persistes the file" do
visit rapidfire.new_survey_attempt_path(survey)
Expand All @@ -125,7 +125,7 @@
end

context "when persisting a file fails" do
let!(:question1) { FactoryGirl.create(:q_file, survey: survey, question_text: "Avatar") }
let!(:question1) { FactoryBot.create(:q_file, survey: survey, question_text: "Avatar") }

it "bubbles up the error" do
visit rapidfire.new_survey_attempt_path(survey)
Expand Down
12 changes: 6 additions & 6 deletions spec/features/rapidfire/editing_answers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'spec_helper'

describe "Surveys" do
let(:survey) { FactoryGirl.create(:survey, name: "Question Set") }
let(:question1) { FactoryGirl.create(:q_long, survey: survey, question_text: "Long Question", validation_rules: { presence: "1" }) }
let(:question2) { FactoryGirl.create(:q_short, survey: survey, question_text: "Short Question") }
let(:attempt) { FactoryGirl.create(:attempt, survey: survey) }
let!(:answer1) { FactoryGirl.create(:answer, attempt: attempt, question: question1, answer_text: "Long Answer") }
let!(:answer2) { FactoryGirl.create(:answer, attempt: attempt, question: question2, answer_text: "Short Answer") }
let(:survey) { FactoryBot.create(:survey, name: "Question Set") }
let(:question1) { FactoryBot.create(:q_long, survey: survey, question_text: "Long Question", validation_rules: { presence: "1" }) }
let(:question2) { FactoryBot.create(:q_short, survey: survey, question_text: "Short Question") }
let(:attempt) { FactoryBot.create(:attempt, survey: survey) }
let!(:answer1) { FactoryBot.create(:answer, attempt: attempt, question: question1, answer_text: "Long Answer") }
let!(:answer2) { FactoryBot.create(:answer, attempt: attempt, question: question2, answer_text: "Short Answer") }
before do
visit rapidfire.edit_survey_attempt_path(survey, attempt)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/rapidfire/managing_questions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

describe "Questions" do
let(:survey) { FactoryGirl.create(:survey, name: "Question Set") }
let(:question1) { FactoryGirl.create(:q_long, survey: survey, question_text: "Long Question") }
let(:question2) { FactoryGirl.create(:q_short, survey: survey, question_text: "Short Question") }
let(:survey) { FactoryBot.create(:survey, name: "Question Set") }
let(:question1) { FactoryBot.create(:q_long, survey: survey, question_text: "Long Question") }
let(:question2) { FactoryBot.create(:q_short, survey: survey, question_text: "Short Question") }
before do
[question1, question2]
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/rapidfire/managing_surveys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
include Rapidfire::QuestionSpecHelper
include Rapidfire::AnswerSpecHelper

let(:survey) { FactoryGirl.create(:survey, name: "Question Set") }
let(:question1) { FactoryGirl.create(:q_long, survey: survey, question_text: "Long Question") }
let(:question2) { FactoryGirl.create(:q_short, survey: survey, question_text: "Short Question") }
let(:survey) { FactoryBot.create(:survey, name: "Question Set") }
let(:question1) { FactoryBot.create(:q_long, survey: survey, question_text: "Long Question") }
let(:question2) { FactoryBot.create(:q_short, survey: survey, question_text: "Short Question") }
before do
[question1, question2]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/rapidfire/answer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

describe Rapidfire::Answer do
describe "Validations" do
subject { FactoryGirl.build(:answer) }
subject { FactoryBot.build(:answer) }
it { is_expected.to validate_presence_of(:question) }
it { is_expected.to validate_presence_of(:attempt) }

context "when validations are run" do
let(:answer) { FactoryGirl.build(:answer) }
let(:answer) { FactoryBot.build(:answer) }

it "delegates validation of answer text to question" do
expect(answer.question).to receive(:validate_answer).with(answer).once
Expand Down
6 changes: 3 additions & 3 deletions spec/models/rapidfire/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

describe "#rules" do
let(:question) { FactoryGirl.create(:q_long, validation_rules: validation_rules) }
let(:question) { FactoryBot.create(:q_long, validation_rules: validation_rules) }

context "when there are no validation rules" do
let(:validation_rules) { {} }
Expand All @@ -33,8 +33,8 @@
end

describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_long, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
let(:question) { FactoryBot.create(:q_long, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, answer_text: answer_text) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/rapidfire/questions/checkbox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
end

describe "#options" do
let(:question) { FactoryGirl.create(:q_select) }
let(:question) { FactoryBot.create(:q_select) }

it "returns options" do
expect(question.options).to match_array(["mac", "windows"])
end
end

describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_checkbox, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
let(:question) { FactoryBot.create(:q_checkbox, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, answer_text: answer_text) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/rapidfire/questions/date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe Rapidfire::Questions::Date do
describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_date, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
let(:question) { FactoryBot.create(:q_date, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, answer_text: answer_text) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/rapidfire/questions/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def fixture_file_upload(path, mime_type)

if "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" >= "5.2"
describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_file, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, file: file) }
let(:question) { FactoryBot.create(:q_file, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, file: file) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/rapidfire/questions/multi_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def fixture_file_upload(path, mime_type)

if "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" >= "5.2"
describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_multifile, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, files: files) }
let(:question) { FactoryBot.create(:q_multifile, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, files: files) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/rapidfire/questions/numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe Rapidfire::Questions::Numeric do
describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_numeric, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
let(:question) { FactoryBot.create(:q_numeric, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, answer_text: answer_text) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/rapidfire/questions/select_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
end

describe "#options" do
let(:question) { FactoryGirl.create(:q_select) }
let(:question) { FactoryBot.create(:q_select) }

it "returns options" do
expect(question.options).to match_array(["mac", "windows"])
end
end

describe "validate_answer" do
let(:question) { FactoryGirl.create(:q_select, validation_rules: validation_rules) }
let(:answer) { FactoryGirl.build(:answer, question: question, answer_text: answer_text) }
let(:question) { FactoryBot.create(:q_select, validation_rules: validation_rules) }
let(:answer) { FactoryBot.build(:answer, question: question, answer_text: answer_text) }
before { answer.valid? }

context "when there are no validation rules" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/rapidfire/survey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

describe "factory" do
let(:survey) { FactoryGirl.create(:survey) }
let(:survey) { FactoryBot.create(:survey) }

it "has a name" do
expect(survey.name).to eql("Test Survey")
Expand Down
Loading

0 comments on commit 6b3bc83

Please sign in to comment.