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.rb68
1 files changed, 44 insertions, 24 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 7b24e88d7..530e9b2c3 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -156,12 +156,18 @@ describe RequestController, "when changing things that appear on the request pag
ir.public_body.save!
PurgeRequest.all().map{|x| x.model_id}.should =~ ir.public_body.info_requests.map{|x| x.id}
end
- it "should purge the downstream cache when the user details are changed" do
+ it "should purge the downstream cache when the user name is changed" do
ir = info_requests(:fancy_dog_request)
ir.user.name = "Something new"
ir.user.save!
PurgeRequest.all().map{|x| x.model_id}.should =~ ir.user.info_requests.map{|x| x.id}
end
+ it "should not purge the downstream cache when non-visible user details are changed" do
+ ir = info_requests(:fancy_dog_request)
+ ir.user.hashed_password = "some old hash"
+ ir.user.save!
+ PurgeRequest.all().count.should == 0
+ end
it "should purge the downstream cache when censor rules have changed" do
# XXX really, CensorRules should execute expiry logic as part
# of the after_save of the model. Currently this is part of
@@ -187,6 +193,7 @@ describe RequestController, "when changing things that appear on the request pag
end
describe RequestController, "when showing one request" do
+ integrate_views
before(:each) do
load_raw_emails_data
@@ -203,6 +210,12 @@ describe RequestController, "when showing one request" do
response.should render_template('show')
end
+ it "should show the request" do
+ get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
+ response.should be_success
+ response.body.should include("Why do you have such a fancy dog?")
+ end
+
it "should assign the request" do
get :show, :url_title => 'why_do_you_have_such_a_fancy_dog'
assigns[:info_request].should == info_requests(:fancy_dog_request)
@@ -290,6 +303,7 @@ describe RequestController, "when showing one request" do
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'], :skip_cache => 1
response.content_type.should == "text/plain"
response.should have_text(/First hello/)
@@ -418,15 +432,6 @@ describe RequestController, "when showing one request" do
response.should have_text(/an unusual sort of file/)
end
- it "should apply a content-disposition header" do
- ir = info_requests(:fancy_dog_request)
- receive_incoming_mail('incoming-request-attachment-unknown-extension.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.qwglhm'], :skip_cache => 1
- response.headers.should include("Content-Disposition")
- response.headers["Content-Disposition"].should include('hello.qwglhm')
- end
-
it "should not download attachments with wrong file name" do
ir = info_requests(:fancy_dog_request)
receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
@@ -1845,23 +1850,29 @@ describe RequestController, "when showing similar requests" do
end
-describe RequestController, "when reporting a request" do
- integrate_views
-
+describe RequestController, "when reporting a request when not logged in" do
it "should only allow logged-in users to report requests" do
get :report_request, :url_title => info_requests(:badger_request).url_title
post_redirect = PostRedirect.get_last_post_redirect
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
+end
+
+describe RequestController, "when reporting a request (logged in)" do
+ integrate_views
+ before do
+ @user = users(:robin_user)
+ session[:user_id] = @user.id
+ end
+
it "should mark a request as having been reported" do
ir = info_requests(:badger_request)
title = ir.url_title
get :show, :url_title => title
assigns[:info_request].attention_requested.should == false
- session[:user_id] = users(:bob_smith_user).id
- get :report_request, :url_title => title
+ post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
get :show, :url_title => title
@@ -1873,18 +1884,16 @@ describe RequestController, "when reporting a request" do
it "should not allow a request to be reported twice" do
title = info_requests(:badger_request).url_title
- session[:user_id] = users(:bob_smith_user).id
- get :report_request, :url_title => title
+ post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
-
get :show, :url_title => title
+ response.should be_success
response.body.should include("has been reported")
- session[:user_id] = users(:bob_smith_user).id
- get :report_request, :url_title => title
+ post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
-
get :show, :url_title => title
+ response.should be_success
response.body.should include("has already been reported")
end
@@ -1893,19 +1902,30 @@ describe RequestController, "when reporting a request" do
get :show, :url_title => title
response.body.should include("Offensive?")
- session[:user_id] = users(:bob_smith_user).id
- get :report_request, :url_title => title
+ post :report_request, :url_title => title
response.should redirect_to(:action => :show, :url_title => title)
get :show, :url_title => title
response.body.should_not include("Offensive?")
response.body.should include("This request has been reported")
+
info_requests(:badger_request).set_described_state("successful")
get :show, :url_title => title
response.body.should_not include("This request has been reported")
- response.body.should include("The site administrators have reviewed this request")
+ response.body.should =~ (/the site administrators.*have not hidden it/)
end
+ it "should send an email from the reporter to admins" do
+ ir = info_requests(:badger_request)
+ title = ir.url_title
+ post :report_request, :url_title => title
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should =~ /attention_requested/
+ mail.from.should include(@user.email)
+ mail.body.should include(@user.name)
+ end
end