Hello everyone!
My name is Paweł and i’m writing my first Hanami app
So far so good, but i run into following 2 issues with tests for my controller and view.
First one, i have a route for form for nested resource, like /albums/:id/photos
In the template with list of photos i want to add link to new photo for album, using album_id from routing, from current URL
<a href="<%= routes.new_album_photo_path(params[:album_id]) %>">New photo</a>
This works in feature specs and in the application itself, however in view spec if fails:
Failure/Error: let(:rendered) { view.render }
NameError:
undefined local variable or method `params' for #<Hanami::View::Rendering::Scope:0x000055fbb93e6a10>
I have made a workaround for this in the test like this
before do
def view.params
{ album_id: 1 }
end
end
However, maybe someone will have other idea? I was thinking about using expose
for this, but given that it works, and only tests fails, i decided for now that i prefer to hack tests, not logic WDYT?
Second issue is also related to params
, but this time in controller.
I wanted to use params[:album_id]
for creating associated photo, like:
@photo = PhotosRepository.new.create(params[:photo].merge(album_id: params[:album_id]))
This also works everywhere other than controller spec, where i get:
Failure/Error: action.call(params)
Hanami::Model::NotNullConstraintViolationError:
SQLite3::ConstraintException: NOT NULL constraint failed: photo.album_id
regardless of the fact, that i have params in the test defined:
let(:params) { Hash[album_id: @album.id, photo: { name: 'Photo1' }] }
Any ideas for this maybe also?