diff --git a/README.md b/README.md index cb9680db..8cc605a8 100644 --- a/README.md +++ b/README.md @@ -72,12 +72,15 @@ Some resources ([User](app/models/user.rb), [Subject](app/models/subject.rb)) ar ## Setting Up Rails-next Using the gem https://github.com/clio/ten_years_rails to help with the upgrade path https://www.youtube.com/watch?v=6aCfc0DkSFo -### Using docker-compose for env setup +### Using docker-compose-rails-next for env setup ``` docker-compose -f docker-compose-rails-next.yml build docker-compose -f docker-compose-rails-next.yml run --service-ports --rm talkapi bash + +## To run bash in test env +docker-compose -f docker-compose-rails-next.yml run --service-ports --rm -e RAILS_ENV=test talkapi bash ``` ### Install the gems via next diff --git a/app/services/concerns/talk_service.rb b/app/services/concerns/talk_service.rb index be15ff26..4aade0c7 100644 --- a/app/services/concerns/talk_service.rb +++ b/app/services/concerns/talk_service.rb @@ -101,7 +101,15 @@ def permitted_params end def rooted_params - permitted_params.slice model_class.table_name + # Parameters in Rails 5+ behave differently, because they no longer inherit from HashWithIndifferentAccess + # methods like slice will behave differently in Rails 4 than Rails 5 + # In Rails 5, we will need to first to apply to_h and then slice. + # TODO: Can Remove version comparison once Prod is on Rails 5+ + if Rails.version.starts_with?('4.2') + permitted_params.slice model_class.table_name + else + permitted_params.to_h.slice model_class.table_name + end end def unrooted_params diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb index 53d68ee0..542f10c0 100644 --- a/spec/support/api_helpers.rb +++ b/spec/support/api_helpers.rb @@ -1,4 +1,4 @@ -class ActionController::TestResponse +class ActionDispatch::TestResponse def json @_json ||= JSON.parse(body).with_indifferent_access end diff --git a/spec/support/shared_examples_for_controller_actions.rb b/spec/support/shared_examples_for_controller_actions.rb index 695f36ad..c064bc25 100644 --- a/spec/support/shared_examples_for_controller_actions.rb +++ b/spec/support/shared_examples_for_controller_actions.rb @@ -18,7 +18,8 @@ end it 'should be json' do - expect(response.content_type).to eql 'application/json' + # starting from Rails 5+, if responding with 204, content-type of response is set by Rails as nil + expect(response.content_type).to eql 'application/json' unless response.status == 204 end it 'should be an object' do @@ -47,7 +48,7 @@ let!(:banned_ip){ create :user_ip_ban } before(:each) do allow(subject).to receive(:current_user).and_return user - allow(subject.request).to receive(:remote_ip).and_return '1.2.3.4' + request.env['REMOTE_ADDR'] = '1.2.3.4' send_request end diff --git a/spec/support/shared_examples_for_schedulable.rb b/spec/support/shared_examples_for_schedulable.rb index f4f151e9..c1ad2086 100644 --- a/spec/support/shared_examples_for_schedulable.rb +++ b/spec/support/shared_examples_for_schedulable.rb @@ -3,7 +3,7 @@ it 'gets queued on enqueued_times' do enqueued_times.each do |enqueued_time| - # update to formatted_enqueue_time when updating sidekiq-cron to 1.9+ (sidekiq 7 support) + # TODO: Once on sidekiq-cron v1.9 can updated method to "formatted_enqueue_time" job_enqueue_time = Time.at(job.formated_enqueue_time.to_f).utc expect(job_enqueue_time).to eq(enqueued_time) end