I'm following a Hanami tutorial and I can't work out what's going wrong in this test:
describe Web::Controllers::Books::Create do
let(:action) { Web::Controllers::Books::Create.new }
let(:params) { Hash[book: { title: 'Confident Ruby', author: 'Avdi Grimm' }] }
it 'creates a new book' do
action.call(params)
action.book.id.wont_be_nil
action.book.title.must_equal params[:book][:title]
end
end
rake test
results in a failure because "Confident Ruby" does not equal nil.
I can puts params[:book]
after the action.call
, but sure enough params[:book][:title]
is nil
. I've tried to access title
via other means but can't seem to manage it. It does seem though that params[:book][:title]
should be correct.
However, when I use params[:book]['title']
, it appears to work. If I try to create a params hash in IRB, params[:book][:title]
works, and params[:book]['title']
doesn't, so I remain confused.
I have upgraded to Ruby 2.3.0, but still experience the same behaviour.
params[:book].has_key?(:title)
is false
, params[:book].has_key?('title')
is true
. Cross-referencing with the documentation on how to access hash elements, I just don't get it.
What is happening here?