Thanks for the suggestion, Ignacio, but that request is still assumed to be
a request against the TitlesController:
it "Authenticated user must see Titles index" do
get '/dev/set_current_user?login=me%40nowhere.com'
get :index
it { must render_template(:index) }
end
TitlesController
0001 Authenticated user must see Titles index
ERROR
No route matches {:controller=>"titles",
:action=>"/dev/set_current_user?login=me%40nowhere.com"}
STDERR:
Tim
On Wednesday, May 1, 2013 7:58:59 AM UTC-4, Tim Griffin wrote:
>
> Hi all;
>
> Being one of those RonR/Hoboists learning a lot of testing *after* having
> written the application (>cough<), I'm experiencing a little
> head-scratching about testing a controller other than the UsersController.
>
> Could anyone enlighten me as to how to properly test a controller in Hobo
> that requires a user to be logged in?
>
> For example, with a TitlesController, the #index action in my application
> is only available to an authenticated user. So, I want to test as follows:
>
> describe "TitlesController" do
>
> it "Authenticated user must see Titles index" do
> # User needs to be logged in. How?
>
> get :index
> it { must render_template(:index) }
> it { must respond_with(:success) }
> end
>
> end
>
> But, anything I do inside the it..do..end block works with the context of
> the TitlesController.
>
> So, even if I do this:
>
> it "Authenticated user must see Titles index" do
> post :login, :controller => :users, :login => "m<[email protected]>
> [email protected]", :password => "Test123"
> get :index
>
> or
>
> it "Authenticated user must see Titles index" do
> post "http://localhost:3000/login", :login => "n<[email protected]>
> [email protected]", :password => "Test123"
> get :index
>
>
> the post directives pretty much get garbled thinking that the login post
> is for the TitlesController:
>
> 0001 Authenticated user must see Titles index
> ERROR
> No route matches {:login=>"[email protected]", :password=>"Test123",
> :controller=>"titles", :action=>"http://localhost:3000/login"}
>
>
> So, what's the best way to get the user authenticated within a specific
> controller test?
>
> I know I can do this:
>
> it "Authenticated user must see Titles index" do
> session = ActionDispatch::Integration::Session.new(Rails.application)
> session.post ('http://localhost:3000/login'), :login => "
> [email protected]", :password => "Test123"
> session.get('http://localhost:3000/titles')
> titles_html = session.response.body
> assert(titles_html ... )
> end
>
>
> But, is building my own session in each test the only way to circumvent
> the assumed context of the TitlesController for a login?
>
> Many thanks,
> Tim
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.