Closed PikachuEXE closed 9 years ago
Is that url_for
in a cell or in the spec example?
It's in cell template like desktop.haml
Ok! And it works in production?
That's weird, I have that all the time and it works..... both in rpsec and dev/prod.
I tried that in dev, not on production yet
And in dev the url_for
gets rendered, right? Have I mentioned how much I hate Rails' way of "injecting" url helpers?
Now I start writing helper with extend self
without including them
Not the best but still better than including everything?
Need to use module_eval
and extend self
though, sometimes has bug as well with this approach.
Does your url_for
stuff work in the browser, no rspec?
Yes it does
Maybe I should stub params
?
Ah, because you didn't set a host and have to specify :only_path
.
I already have :only_path
(see top comment)
I got it working by stubbing params in spec
before
allow(controller).to receive(:params) do
{controller: :home, action: :index}
end
end
Ah... I know what is the problem. In a real environment we get this kind of data from parent_controller
(passed into SongCell.new(parent_controller, ..)
. This is missing here apparently.
I guess the available action here is to add some note about testing for
cells using parent_controller
(which includes params
and other I don't know what).
Edit: Off from work now~
This will be more straight-forward in Cells 4.0, I want to entirely get rid of the parent_controller
dependency, so rspec and dev/prod render calls will be identical.
I still don't understand why params
is used in url_for
, but this might be some Rails bullshit.
I use url_for(params.merge({only_path: true, locale: locale}))
which contains params
:3
rails 4.2 beta released Start bombing them after the stable 4.2 is released!
Is setting the controller dependency using ::controller
supposed to fix this? Because I've tried testing some cells with RSpec, where the template is rendering some Kaminari helper which is calling url_for
, and it still doesn't seem like the params
are filled in properly (self.params
called from within the template returns an empty hash), so I'm still stuck with stubbing out #params
on controller
The ::controller
method simply creates an empty controller instance. The problem lies in Kaminari, it should never use a global variable like params
, but unfortunately, it does.
right. I see
+1 for adding only_path: true
when running testing rspec.
It will only gives "No route matches" error
For now I use