aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin_request_controller_spec.rb4
-rw-r--r--spec/controllers/general_controller_spec.rb40
-rw-r--r--spec/controllers/public_body_controller_spec.rb18
-rw-r--r--spec/controllers/request_controller_spec.rb59
-rw-r--r--spec/controllers/request_game_controller_spec.rb2
-rw-r--r--spec/controllers/track_controller_spec.rb6
-rw-r--r--spec/controllers/user_controller_spec.rb10
7 files changed, 87 insertions, 52 deletions
diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb
index 6d3c955bb..5e6f6c2a5 100644
--- a/spec/controllers/admin_request_controller_spec.rb
+++ b/spec/controllers/admin_request_controller_spec.rb
@@ -6,7 +6,7 @@ describe AdminRequestController, "when administering requests" do
before { basic_auth_login @request }
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
@old_filters = ActionController::Routing::Routes.filters
ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
@@ -53,7 +53,7 @@ describe AdminRequestController, "when administering the holding pen" do
fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
basic_auth_login @request
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
@old_filters = ActionController::Routing::Routes.filters
ActionController::Routing::Routes.filters = RoutingFilter::Chain.new
end
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index b067707de..9a5421a78 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -34,7 +34,7 @@ describe GeneralController, "when searching" do
]
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -111,23 +111,33 @@ describe GeneralController, "when searching" do
describe 'when constructing the list of recent requests' do
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
it 'should list the newest successful request first' do
- # Make sure the newest is listed first even if an older one has an even newer comment:
+ # Make sure the newest is listed first even if an older one
+ # has a newer comment or was reclassified more recently:
# https://github.com/sebbacon/alaveteli/issues/370
+ #
+ # This is a deliberate behaviour change, in that the
+ # previous behaviour (showing more-recently-reclassified
+ # requests first) was intentional.
get :frontpage
assigns[:request_events].first.info_request.should == info_requests(:another_boring_request)
end
+
+ it 'should coalesce duplicate requests' do
+ get :frontpage
+ assigns[:request_events].map(&:info_request).select{|x|x.url_title =~ /^spam/}.length.should == 1
+ end
end
describe 'when using xapian search' do
# rebuild xapian index after fixtures loaded
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -158,21 +168,31 @@ describe GeneralController, "when searching" do
it "should filter results based on end of URL being 'all'" do
get :search, :combined => ['"bob"', "all"]
- assigns[:xapian_requests].results.size.should == 2
- assigns[:xapian_users].results.size.should == 1
- assigns[:xapian_bodies].results.size.should == 0
+ assigns[:xapian_requests].results.map{|x| x[:model]}.should =~ [
+ info_request_events(:useless_outgoing_message_event),
+ info_request_events(:silly_outgoing_message_event),
+ info_request_events(:useful_incoming_message_event),
+ info_request_events(:another_useful_incoming_message_event),
+ ]
+ assigns[:xapian_users].results.map{|x| x[:model]}.should == [users(:bob_smith_user)]
+ assigns[:xapian_bodies].results.should == []
end
it "should filter results based on end of URL being 'users'" do
get :search, :combined => ['"bob"', "users"]
assigns[:xapian_requests].should == nil
- assigns[:xapian_users].results.size.should == 1
+ assigns[:xapian_users].results.map{|x| x[:model]}.should == [users(:bob_smith_user)]
assigns[:xapian_bodies].should == nil
end
it "should filter results based on end of URL being 'requests'" do
get :search, :combined => ['"bob"', "requests"]
- assigns[:xapian_requests].results.size.should == 2
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [
+ info_request_events(:useless_outgoing_message_event),
+ info_request_events(:silly_outgoing_message_event),
+ info_request_events(:useful_incoming_message_event),
+ info_request_events(:another_useful_incoming_message_event),
+ ]
assigns[:xapian_users].should == nil
assigns[:xapian_bodies].should == nil
end
@@ -181,7 +201,7 @@ describe GeneralController, "when searching" do
get :search, :combined => ['"quango"', "bodies"]
assigns[:xapian_requests].should == nil
assigns[:xapian_users].should == nil
- assigns[:xapian_bodies].results.size.should == 1
+ assigns[:xapian_bodies].results.map{|x|x[:model]}.should == [public_bodies(:geraldine_public_body)]
end
it "should show help when searching for nothing" do
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index bd4e625ca..4d27ea3f5 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -7,7 +7,7 @@ describe PublicBodyController, "when showing a body" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -153,7 +153,6 @@ describe PublicBodyController, "when listing bodies" do
get :list
response.should render_template('list')
assigns[:public_bodies].should =~ PublicBody.all(:conditions => "id <> #{PublicBody.internal_admin_body.id}")
-
end
it "should list a machine tagged thing, should get it in both ways" do
@@ -199,6 +198,11 @@ describe PublicBodyController, "when doing type ahead searches" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
integrate_views
+
+ before(:each) do
+ load_raw_emails_data
+ rebuild_xapian_index
+ end
it "should return nothing for the empty query string" do
get :search_typeahead, :query => ""
@@ -217,16 +221,16 @@ describe PublicBodyController, "when doing type ahead searches" do
it "should return all requests matching any of the given keywords" do
get :search_typeahead, :query => "Geraldine Humpadinking"
response.should render_template('public_body/_search_ahead')
- assigns[:xapian_requests].results.size.should == 2
- assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name
- assigns[:xapian_requests].results[1][:model].name.should == public_bodies(:geraldine_public_body).name
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [
+ public_bodies(:humpadink_public_body),
+ public_bodies(:geraldine_public_body),
+ ]
end
it "should return requests matching the given keywords in any of their locales" do
get :search_typeahead, :query => "baguette" # part of the spanish notes
response.should render_template('public_body/_search_ahead')
- assigns[:xapian_requests].results.size.should == 1
- assigns[:xapian_requests].results[0][:model].name.should == public_bodies(:humpadink_public_body).name
+ assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [public_bodies(:humpadink_public_body)]
end
it "should not return matches for short words" do
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index bae1f32e7..77652b26d 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -7,7 +7,7 @@ describe RequestController, "when listing recent requests" do
fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -125,7 +125,7 @@ describe RequestController, "when showing one request" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should be successful" do
@@ -209,7 +209,8 @@ describe RequestController, "when showing one request" do
it "should download attachments" do
ir = info_requests(:fancy_dog_request)
- ir.incoming_messages.each { |x| x.parse_raw_email! }
+ ir.incoming_messages.each { |x| x.parse_raw_email!(true) }
+
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
response.content_type.should == "text/html"
size_before = assigns[:info_request_events].size
@@ -221,11 +222,11 @@ describe RequestController, "when showing one request" do
(assigns[:info_request_events].size - size_before).should == 1
ir.reload
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt']
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/Second hello/)
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt']
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :file_name => ['hello.txt'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/First hello/)
end
@@ -321,7 +322,7 @@ describe RequestController, "when showing one request" do
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
lambda {
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2,
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2,
:file_name => ['http://trying.to.hack']
}.should raise_error(ActiveRecord::RecordNotFound)
end
@@ -335,12 +336,16 @@ describe RequestController, "when showing one request" do
censor_rule.last_edit_editor = "unknown"
censor_rule.last_edit_comment = "none"
ir.censor_rules << censor_rule
+
+ begin
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
-
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt']
- response.content_type.should == "text/plain"
- response.should have_text(/xxxxxx hello/)
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt'], :skip_cache => 1
+ response.content_type.should == "text/plain"
+ response.should have_text(/xxxxxx hello/)
+ ensure
+ ir.censor_rules.clear
+ end
end
it "should censor with rules on the user (rather than the request)" do
@@ -441,7 +446,7 @@ describe RequestController, "when changing prominence of a request" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should not show hidden requests" do
@@ -507,11 +512,11 @@ describe RequestController, "when changing prominence of a request" do
ir.save!
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :skip_cache => 1
response.content_type.should == "text/html"
response.should_not have_text(/Second hello/)
response.should render_template('request/hidden')
- get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3
+ get :get_attachment, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 3, :skip_cache => 1
response.content_type.should == "text/html"
response.should_not have_text(/First hello/)
response.should render_template('request/hidden')
@@ -755,7 +760,7 @@ describe RequestController, "when viewing an individual response for reply/follo
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should ask for login if you are logged in as wrong person" do
@@ -805,7 +810,7 @@ describe RequestController, "when classifying an information request" do
@dog_request = info_requests(:fancy_dog_request)
@dog_request.stub!(:is_old_unclassified?).and_return(false)
InfoRequest.stub!(:find).and_return(@dog_request)
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
def post_status(status)
@@ -1142,7 +1147,7 @@ describe RequestController, "when sending a followup message" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should require login" do
@@ -1225,7 +1230,7 @@ describe RequestController, "sending overdue request alerts" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should send an overdue alert mail to creators of overdue requests" do
@@ -1313,7 +1318,7 @@ describe RequestController, "sending unclassified new response reminder alerts"
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should send an alert" do
@@ -1343,7 +1348,7 @@ describe RequestController, "clarification required alerts" do
integrate_views
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should send an alert" do
@@ -1397,7 +1402,7 @@ describe RequestController, "comment alerts" do
integrate_views
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should send an alert (once and once only)" do
@@ -1472,7 +1477,7 @@ describe RequestController, "when viewing comments" do
integrate_views
fixtures :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should link to the user who submitted it" do
@@ -1584,7 +1589,7 @@ describe RequestController, "when showing JSON version for API" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should return data in JSON form" do
@@ -1621,9 +1626,11 @@ describe RequestController, "when doing type ahead searches" do
it "should return all requests matching any of the given keywords" do
get :search_typeahead, :q => "money dog"
response.should render_template('request/_search_ahead.rhtml')
- assigns[:xapian_requests].results.size.should == 2
- assigns[:xapian_requests].results[0][:model].title.should == info_requests(:fancy_dog_request).title
- assigns[:xapian_requests].results[1][:model].title.should == info_requests(:naughty_chicken_request).title
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
+ info_requests(:fancy_dog_request),
+ info_requests(:naughty_chicken_request),
+ info_requests(:another_boring_request),
+ ]
end
it "should not return matches for short words" do
diff --git a/spec/controllers/request_game_controller_spec.rb b/spec/controllers/request_game_controller_spec.rb
index cc0808ef3..1383554a1 100644
--- a/spec/controllers/request_game_controller_spec.rb
+++ b/spec/controllers/request_game_controller_spec.rb
@@ -4,7 +4,7 @@ describe RequestGameController, "when playing the game" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things # all needed as integrating views
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
end
it "should show the game homepage" do
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index ad4d651cb..509aa6725 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -40,7 +40,7 @@ describe TrackController, "when sending alerts for a track" do
include LinkToHelper # for main_url
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -118,7 +118,7 @@ describe TrackController, "when viewing RSS feed for a track" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -144,7 +144,7 @@ describe TrackController, "when viewing JSON version of a track feed" do
fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 81d3ff2e5..4e14aeaa3 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -10,7 +10,7 @@ describe UserController, "when showing a user" do
integrate_views
fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
before(:each) do
- load_raw_emails_data(raw_emails)
+ load_raw_emails_data
rebuild_xapian_index
end
@@ -46,10 +46,14 @@ 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.map{|x|x[:model].info_request}.should =~ InfoRequest.all(:conditions => "user_id = #{users(:bob_smith_user).id}")
+ 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.map{|x|x[:model].info_request}.should == [info_requests(:naughty_chicken_request)]
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
+ info_requests(:naughty_chicken_request),
+ info_requests(:another_boring_request),
+ ]
end
it "should not show unconfirmed users" do