aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/request_controller_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r--spec/controllers/request_controller_spec.rb140
1 files changed, 105 insertions, 35 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index a77d1ac27..3b58df869 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
@@ -39,6 +39,7 @@ describe RequestController, "when listing recent requests" do
from info_request_events later_events
where later_events.created_at > info_request_events.created_at
and later_events.info_request_id = info_request_events.info_request_id
+ and later_events.described_state is not null
)
and info_request_events.described_state in ('successful', 'partially_successful')
)")
@@ -124,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
@@ -208,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
@@ -219,10 +221,12 @@ describe RequestController, "when showing one request" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
(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
@@ -318,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
@@ -332,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
-
- 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/)
+
+ begin
+ 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'], :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
@@ -350,12 +358,16 @@ describe RequestController, "when showing one request" do
censor_rule.last_edit_comment = "none"
ir.user.censor_rules << censor_rule
- receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
- ir.reload
+ begin
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
+ ir.reload
- 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/)
+ 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.user.censor_rules.clear
+ end
end
it "should censor attachment names" do
@@ -386,9 +398,12 @@ describe RequestController, "when showing one request" do
censor_rule.last_edit_editor = "unknown"
censor_rule.last_edit_comment = "none"
ir.censor_rules << censor_rule
-
- get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
- response.body.should have_tag("p.attachment strong", /goodbye.txt/m)
+ begin
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
+ response.body.should have_tag("p.attachment strong", /goodbye.txt/m)
+ ensure
+ ir.censor_rules.clear
+ end
end
it "should make a zipfile available, which has a different URL when it changes" do
@@ -431,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
@@ -497,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')
@@ -687,6 +702,58 @@ describe RequestController, "when creating a new request" do
response.should redirect_to(:action => 'show', :url_title => ir2.url_title)
end
+
+ it 'should respect the rate limit' do
+ # Try to create three requests in succession.
+ # (The limit set in config/test.yml is two.)
+ session[:user_id] = users(:robin_user)
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "What is the answer to the ultimate question?", :tag_string => "" },
+ :outgoing_message => { :body => "Please supply the answer from your files." },
+ :submitted_new_request => 1, :preview => 0
+ response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
+
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "Why did the chicken cross the road?", :tag_string => "" },
+ :outgoing_message => { :body => "Please send me all the relevant documents you hold." },
+ :submitted_new_request => 1, :preview => 0
+ response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "What's black and white and red all over?", :tag_string => "" },
+ :outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." },
+ :submitted_new_request => 1, :preview => 0
+ response.should render_template('user/rate_limited')
+ end
+
+ it 'should ignore the rate limit for specified users' do
+ # Try to create three requests in succession.
+ # (The limit set in config/test.yml is two.)
+ session[:user_id] = users(:robin_user)
+ users(:robin_user).no_limit = true
+ users(:robin_user).save!
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "What is the answer to the ultimate question?", :tag_string => "" },
+ :outgoing_message => { :body => "Please supply the answer from your files." },
+ :submitted_new_request => 1, :preview => 0
+ response.should redirect_to(:action => 'show', :url_title => 'what_is_the_answer_to_the_ultima')
+
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "Why did the chicken cross the road?", :tag_string => "" },
+ :outgoing_message => { :body => "Please send me all the relevant documents you hold." },
+ :submitted_new_request => 1, :preview => 0
+ response.should redirect_to(:action => 'show', :url_title => 'why_did_the_chicken_cross_the_ro')
+
+ post :new, :info_request => { :public_body_id => @body.id,
+ :title => "What's black and white and red all over?", :tag_string => "" },
+ :outgoing_message => { :body => "Please send all minutes of meetings and email records that address this question." },
+ :submitted_new_request => 1, :preview => 0
+ response.should redirect_to(:action => 'show', :url_title => 'whats_black_and_white_and_red_al')
+ end
end
@@ -732,6 +799,7 @@ describe RequestController, "when making a new request" do
it "should fail if user is banned" do
@user.stub!(:can_file_requests?).and_return(false)
+ @user.stub!(:exceeded_limit?).and_return(false)
@user.should_receive(:can_fail_html).and_return('FAIL!')
session[:user_id] = @user.id
get :new, :public_body_id => @body.id
@@ -745,7 +813,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
@@ -795,7 +863,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)
@@ -1132,7 +1200,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
@@ -1215,7 +1283,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
@@ -1303,7 +1371,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
@@ -1333,7 +1401,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
@@ -1387,7 +1455,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
@@ -1462,7 +1530,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
@@ -1574,7 +1642,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
@@ -1611,9 +1679,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