aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin_user_controller_spec.rb17
-rw-r--r--spec/controllers/user_controller_spec.rb37
-rw-r--r--spec/helpers/link_to_helper_spec.rb6
3 files changed, 56 insertions, 4 deletions
diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb
index 65ecbc37d..60ac6969d 100644
--- a/spec/controllers/admin_user_controller_spec.rb
+++ b/spec/controllers/admin_user_controller_spec.rb
@@ -2,7 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminUserController, "when administering users" do
integrate_views
- before { basic_auth_login @request }
+ before do
+ basic_auth_login @request
+ end
it "shows the index/list page" do
get :index
@@ -16,6 +18,19 @@ describe AdminUserController, "when administering users" do
it "shows a user" do
get :show, :id => users(:bob_smith_user)
end
+
+ it "logs in as another user" do
+ get :login_as, :id => users(:bob_smith_user).id
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'confirm', :email_token => post_redirect.email_token)
+ end
+ it "logs in as another user when already logged in as an admin" do
+ session[:user_id] = users(:admin_user).id
+ get :login_as, :id => users(:bob_smith_user).id
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'confirm', :email_token => post_redirect.email_token)
+ session[:user_id].should be_nil
+ end
end
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index fbe33c529..40649b6e1 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -190,6 +190,43 @@ describe UserController, "when signing in" do
ActionController::Routing::Routes.filters = old_filters
end
+ it "should keep you logged in if you click a confirmation link and are already logged in as an admin" do
+ old_filters = ActionController::Routing::Routes.filters
+ ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
+
+ get :signin, :r => "/list"
+ post_redirect = get_last_postredirect
+
+ post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' },
+ :token => post_redirect.token
+ }
+ response.should send_email
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body =~ /(http:\/\/.*(\/c\/(.*)))/
+ mail_url = $1
+ mail_path = $2
+ mail_token = $3
+
+ # check is right confirmation URL
+ mail_token.should == post_redirect.email_token
+ params_from(:get, mail_path).should == { :controller => 'user', :action => 'confirm', :email_token => mail_token }
+
+ # Log in as an admin
+ session[:user_id] = users(:admin_user).id
+
+ # Get the confirmation URL, and check we’re still Joe
+ get :confirm, :email_token => post_redirect.email_token
+ session[:user_id].should == users(:admin_user).id
+
+ # And the redirect should still work, of course
+ response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1)
+
+ ActionController::Routing::Routes.filters = old_filters
+ end
+
end
describe UserController, "when signing up" do
diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb
index 3fa91a8f8..f11f2b5bb 100644
--- a/spec/helpers/link_to_helper_spec.rb
+++ b/spec/helpers/link_to_helper_spec.rb
@@ -28,13 +28,13 @@ describe LinkToHelper do
describe "when appending something to a URL" do
it 'should append to things without query strings' do
- main_url('/a', '.json').should == 'http://test.localdomain/a.json'
+ main_url('/a', '.json').should == 'http://test.host/a.json'
end
it 'should append to things with query strings' do
- main_url('/a?z=1', '.json').should == 'http://test.localdomain/a.json?z=1'
+ main_url('/a?z=1', '.json').should == 'http://test.host/a.json?z=1'
end
it 'should fail silently with invalid URLs' do
- main_url('/a?z=9%', '.json').should == 'http://test.localdomain/a?z=9%'
+ main_url('/a?z=9%', '.json').should == 'http://test.host/a?z=9%'
end
end