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.rb96
1 files changed, 83 insertions, 13 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index f3084af12..aa3027c00 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -216,7 +216,28 @@ describe RequestController, "when showing one request" do
response.body.should have_tag("p.attachment strong", /goodbye.txt/m)
end
-
+ it "should make a zipfile available, which has a different URL when it changes" do
+ ir = info_requests(:fancy_dog_request)
+ session[:user_id] = ir.user.id # bob_smith_user
+ receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email)
+ title = 'why_do_you_have_such_a_fancy_dog'
+ get :download_entire_request, :url_title => title
+ assigns[:url_path].should have_text(/#{title}.zip$/)
+ old_path = assigns[:url_path]
+ response.location.should have_text(/#{assigns[:url_path]}$/)
+ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", old_path)) { |zipfile|
+ zipfile.count.should == 2
+ }
+ receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email)
+ get :download_entire_request, :url_title => title
+ assigns[:url_path].should have_text(/#{title}.zip$/)
+ response.location.should have_text(/#{assigns[:url_path]}/)
+ assigns[:url_path].should_not == old_path
+ zipfile = Zip::ZipFile.open(File.join(File.dirname(__FILE__), "../../cache/zips", assigns[:url_path])) { |zipfile|
+ zipfile.count.should == 4
+zipfile.entries.each {|x| puts x.name}
+ }
+ end
end
end
@@ -349,7 +370,20 @@ describe RequestController, "when creating a new request" do
response.should render_template('new')
end
+ it "should redirect to sign in page when input is good and nobody is logged in" do
+ params = { :info_request => { :public_body_id => @body.id,
+ :title => "Why is your quango called Geraldine?", :tag_string => "" },
+ :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
+ :submitted_new_request => 1, :preview => 0
+ }
+ post :new, params
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others
+ end
+
it "should show preview when input is good" do
+ session[:user_id] = @user.id
post :new, { :info_request => { :public_body_id => @body.id,
:title => "Why is your quango called Geraldine?", :tag_string => "" },
:outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
@@ -367,18 +401,6 @@ describe RequestController, "when creating a new request" do
response.should render_template('new')
end
- it "should redirect to sign in page when input is good and nobody is logged in" do
- params = { :info_request => { :public_body_id => @body.id,
- :title => "Why is your quango called Geraldine?", :tag_string => "" },
- :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." },
- :submitted_new_request => 1, :preview => 0
- }
- post :new, params
- post_redirect = PostRedirect.get_last_post_redirect
- response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
- # post_redirect.post_params.should == params # XXX get this working. there's a : vs '' problem amongst others
- end
-
it "should create the request and outgoing message, and send the outgoing message by email, and redirect to request page when input is good and somebody is logged in" do
session[:user_id] = @user.id
post :new, :info_request => { :public_body_id => @body.id,
@@ -450,6 +472,7 @@ describe RequestController, "when making a new request" do
@user.stub!(:get_undescribed_requests).and_return([])
@user.stub!(:can_leave_requests_undescribed?).and_return(false)
@user.stub!(:can_file_requests?).and_return(true)
+ @user.stub!(:locale).and_return("en")
User.stub!(:find).and_return(@user)
@body = mock_model(PublicBody, :id => 314, :eir_only? => false, :is_requestable? => true, :name => "Test Quango")
@@ -510,6 +533,22 @@ describe RequestController, "when viewing an individual response for reply/follo
response.should render_template('show_response')
end
+ it "should offer the opportunity to reply to the main address" do
+ session[:user_id] = users(:bob_smith_user).id
+ get :show_response, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message)
+ response.body.should have_tag("div#other_recipients ul li", /the main FOI contact address for/)
+ end
+
+ it "should offer an opportunity to reply to another address" do
+ session[:user_id] = users(:bob_smith_user).id
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = "anybody"
+ ir.save!
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "Frob <frob@bonce.com>")
+ get :show_response, :id => ir.id, :incoming_message_id => incoming_messages(:useless_incoming_message)
+ response.body.should have_tag("div#other_recipients ul li", /Frob/)
+ end
+
it "should not show individual responses if request hidden, even if request owner" do
ir = info_requests(:fancy_dog_request)
ir.prominence = 'hidden'
@@ -1319,5 +1358,36 @@ describe RequestController, "when showing JSON version for API" do
end
+describe RequestController, "when doing type ahead searches" do
+ fixtures :info_requests, :info_request_events, :public_bodies, :public_body_translations, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments
+
+ it "should return nothing for the empty query string" do
+ get :search_typeahead, :q => ""
+ response.should render_template('request/_search_ahead.rhtml')
+ assigns[:xapian_requests].results.size.should == 0
+ end
+
+ it "should return a request matching the given keyword, but not users with a matching description" do
+ get :search_typeahead, :q => "chicken"
+ response.should render_template('request/_search_ahead.rhtml')
+ assigns[:xapian_requests].results.size.should == 1
+ assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title
+ end
+
+ 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
+ end
+
+ it "should return partial matches" do
+ get :search_typeahead, :q => "chick" # 'chick' for 'chicken'
+ response.should render_template('request/_search_ahead.rhtml')
+ assigns[:xapian_requests].results.size.should == 1
+ assigns[:xapian_requests].results[0][:model].title.should == info_requests(:naughty_chicken_request).title
+ end
+end