From 6b790cc3291018bfe41c88e1ae88c1d9a0c650f1 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 3 Feb 2012 18:41:47 +0000 Subject: Eliminate trailing spaces in test names Really, what was that about? --- spec/controllers/request_controller_spec.rb | 4 ++-- spec/controllers/track_controller_spec.rb | 2 +- spec/controllers/user_controller_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 25dce3f22..1211e03bb 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -300,7 +300,7 @@ describe RequestController, "when showing one request" do }.should raise_error(ActiveRecord::RecordNotFound) end - it "should generate valid HTML verson of PDF attachments " do + it "should generate valid HTML verson of PDF attachments" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-pdf-attachment.email', ir.incoming_email) ir.reload @@ -309,7 +309,7 @@ describe RequestController, "when showing one request" do response.should have_text(/Walberswick Parish Council/) end - it "should not cause a reparsing of the raw email, even when the result would be a 404 " do + it "should not cause a reparsing of the raw email, even when the result would be a 404" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) ir.reload diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 38a447640..ee974dedd 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -25,7 +25,7 @@ describe TrackController, "when making a new track on a request" do response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) end - it "should save the track and redirect if you are logged in " do + it "should save the track and redirect if you are logged in" do session[:user_id] = @user.id @track_thing.should_receive(:save!) get :track_request, :url_title => @ir.url_title, :feed => 'track' diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 1a701ad43..fbe33c529 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -233,7 +233,7 @@ describe UserController, "when signing up" do deliveries[0].body.should include("No revelaremos su dirección de correo") end - it "should send special 'already signed up' mail if you fill the form in with existing registered email " do + it "should send special 'already signed up' mail if you fill the form in with existing registered email" do post :signup, { :user_signup => { :email => 'silly@localhost', :name => 'New Person', :password => 'sillypassword', :password_confirmation => 'sillypassword' } } -- cgit v1.2.3 From 8584824006b987fb260636fe65ff525f3b2acf52 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 3 Feb 2012 22:13:40 +0000 Subject: Test should not depend on nondeterministic order Issue #409 seems to be another problem of the same type as #408, though with the important difference that the bug in this case is in the test suite rather than the code under test. RequestMailer sends alert emails warning of overdue requests. However it does not specify the order that these messages are sent in, but runs over the overdue requests in whatever order they are returned by a database query (that does not have an order by clause). Therefore it is not safe for the test code to assume that the alert mails will have been sent in a particular order: just as with #408 it seems that they were *usually* sent in the order assumed by the test code, but occasionally not -- which would result in sporadic test failures. Closes #409. --- spec/controllers/request_controller_spec.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1211e03bb..9018f76fe 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -1319,9 +1319,10 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 2 - mail = deliveries[1] + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + mail = chicken_mails[0] + mail.body.should =~ /promptly, as normally/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email @@ -1347,9 +1348,10 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 2 - mail = deliveries[1] + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + mail = chicken_mails[0] + mail.body.should =~ /promptly, as normally/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email end @@ -1372,9 +1374,10 @@ describe RequestController, "sending overdue request alerts" do RequestMailer.alert_overdue_requests - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 2 - mail = deliveries[1] + chicken_mails = ActionMailer::Base.deliveries.select{|x| x.body =~ /chickens/} + chicken_mails.size.should == 1 + mail = chicken_mails[0] + mail.body.should =~ /required by law/ mail.to_addrs.first.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email -- cgit v1.2.3 From ead0b3bcc458cec61c8d1d157a17d82e393c5434 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Fri, 3 Feb 2012 22:36:54 +0000 Subject: Return 404 for /feed/user/no_such_user Fixes #407. --- spec/controllers/track_controller_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index ee974dedd..0dc5db607 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -134,6 +134,11 @@ describe TrackController, "when viewing RSS feed for a track" do assigns[:xapian_object].results[2][:model].should == info_request_events(:useless_outgoing_message_event) # created_at 2007-10-14 10:41:12.686264 end + it "should return NotFound for a non-existent user" do + lambda { + get :track_user, :feed => 'feed', :url_name => "there_is_no_such_user" + }.should raise_error(ActiveRecord::RecordNotFound) + end end describe TrackController, "when viewing JSON version of a track feed" do -- cgit v1.2.3 From 3b6e5a692b852a88f55b21a7210f60a6f7cfc24b Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Mon, 6 Feb 2012 14:48:12 +0000 Subject: Let admin users use auto-login URLs Don't change logged-in user from an admin when visiting a auto-login URL. Closes #306. --- spec/controllers/admin_user_controller_spec.rb | 17 +++++++++++- spec/controllers/user_controller_spec.rb | 37 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'spec/controllers') 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 -- cgit v1.2.3 From 0f541e0cf80ba1135a2ae0ae34d53c7917dec23c Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Mon, 6 Feb 2012 15:14:01 +0000 Subject: =?UTF-8?q?Don=E2=80=99t=20index=20unconfirmed=20users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #415. --- spec/controllers/general_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index 7fc019c64..81f4ed6d5 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -198,6 +198,22 @@ describe GeneralController, "when searching" do assigns[:query].should be_nil end + it "should not show unconfirmed users" do + get :search, :combined => ["unconfirmed", "users"] + response.should render_template('search') + assigns[:xapian_users].results.map{|x|x[:model]}.should == [] + end + + it "should show newly-confirmed users" do + u = users(:unconfirmed_user) + u.email_confirmed = true + u.save! + update_xapian_index + + get :search, :combined => ["unconfirmed", "users"] + response.should render_template('search') + assigns[:xapian_users].results.map{|x|x[:model]}.should == [u] + end end -- cgit v1.2.3