From 24bbaa5afac5ce27c351e3b460be1b0182446ba1 Mon Sep 17 00:00:00 2001 From: Robin Houston Date: Thu, 26 Jan 2012 23:21:12 +0000 Subject: Refactor test code so new test data can be added Previously many of the tests made assumptions about the global structure of the test data set: the total number of requests, for example, or the names of all public bodies. This makes it difficult to add to the test data. This change is intended to make the test data easier to extend by eliminating such global assumptions. --- spec/controllers/user_controller_spec.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'spec/controllers/user_controller_spec.rb') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index a90fa18df..81d3ff2e5 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -46,16 +46,19 @@ describe UserController, "when showing a user" do it "should search the user's contributions" do get :show, :url_name => "bob_smith" - assigns[:xapian_requests].results.count.should == 3 + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(:conditions => "user_id = #{users(:bob_smith_user).id}") + get :show, :url_name => "bob_smith", :user_query => "money" - assigns[:xapian_requests].results.count.should == 1 + assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should == [info_requests(:naughty_chicken_request)] end -# Error handling not quite good enough for this yet -# it "should not show unconfirmed users" do -# get :show, :url_name => "silly_emnameem" -# assigns[:display_users].should == [ users(:silly_name_user) ] -# end + it "should not show unconfirmed users" do + begin + get :show, :url_name => "unconfirmed_user" + rescue => e + end + e.should be_an_instance_of(ActiveRecord::RecordNotFound) + end end -- cgit v1.2.3