From 56682530f3305f924c1adcfaaf1451805d55e588 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Thu, 20 Jun 2024 07:40:02 -0500 Subject: [PATCH] Rails 5 fix announcement service (#326) * Updated tests to get announcements_controller working Changes: 1) Rails 4 -> 5, parameters no longer inherit from HashWithIndifferentAccess 2) response.json no longer is valid in Rails 5. response's class in Rails 4 is ActionController::TestResponse in Rails 5, response's class is ActionDispatch::TestResponse 3) Starting Rails 5, responses will default to 204s unless specified otherwise. And status of 204 will return response.content_type as nil * update .json method responses in test no longer an instance of ActionController::TestResponses * update typo * update comment * ActionController::TestResponse injerits from ActionDispatch::TestResponse in Rails 4. Rails 5 test responses are instances of ActionDispatch::TestResponse * update talk_service update_resource to_h --- app/services/concerns/talk_service.rb | 2 +- spec/support/shared_examples_for_services.rb | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/services/concerns/talk_service.rb b/app/services/concerns/talk_service.rb index 4aade0c7..0f2915ad 100644 --- a/app/services/concerns/talk_service.rb +++ b/app/services/concerns/talk_service.rb @@ -33,7 +33,7 @@ def find_resource end def update_resource - resource.assign_attributes unrooted_params + resource.assign_attributes unrooted_params.to_h rescue ArgumentError => e reraise_enum_errors e rescue NameError => e diff --git a/spec/support/shared_examples_for_services.rb b/spec/support/shared_examples_for_services.rb index e738ee5c..8302c2d9 100644 --- a/spec/support/shared_examples_for_services.rb +++ b/spec/support/shared_examples_for_services.rb @@ -69,7 +69,7 @@ describe '#unrooted_params' do let(:create_params){ { resource.table_name => { foo: 1 } } } - subject{ service.unrooted_params } + subject{ service.unrooted_params.to_h } it{ is_expected.to include 'foo' => 1 } it 'should permit the params' do @@ -98,19 +98,13 @@ end it 'should set the user id' do - expect{ - service.set_user - }.to change{ - service.unrooted_params[:user_id] - }.from(nil).to current_user.id + service.set_user + expect(service.unrooted_params[:user_id]).to eq(current_user.id) end it 'should accept a block' do - expect{ - service.set_user{ unrooted_params[:foo] = 123 } - }.to change{ - service.unrooted_params[:foo] - }.from(nil).to 123 + service.set_user{ unrooted_params[:foo] = 123 } + expect(service.unrooted_params[:foo]).to eq(123) end end end