Skip to content

Commit

Permalink
Rails 5 fix announcement service (#326)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yuenmichelle1 authored Jun 20, 2024
1 parent 59bc2cc commit 5668253
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/services/concerns/talk_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 5 additions & 11 deletions spec/support/shared_examples_for_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5668253

Please sign in to comment.