aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/public_body_controller_spec.rb5
-rw-r--r--spec/controllers/request_controller_spec.rb105
-rw-r--r--spec/controllers/track_controller_spec.rb3
3 files changed, 87 insertions, 26 deletions
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 38e874469..7b2876aff 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -62,6 +62,11 @@ describe PublicBodyController, "when showing a body" do
RoutingFilter.active = true
end
+ it "should remember the filter (view) setting on redirecting" do
+ get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
+ response.should redirect_to show_public_body_successful_url(:url_name => "etgq")
+ end
+
it "should redirect to newest name if you use historic name of public body in URL" do
get :show, :url_name => "hdink", :view => 'all'
response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh")
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 842b4e47c..396182f00 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -337,12 +337,12 @@ describe RequestController, "when showing one request" do
it 'should not show the describe state form' do
make_request
- response.should_not have_selector('div.describe_state_form')
+ response.should_not have_tag('div.describe_state_form')
end
it 'should not ask the user to use the describe state form' do
make_request
- response.should_not have_selector('p#request_status', :content => "answer the question above")
+ response.should_not have_tag('p#request_status', :text => /answer the question above/)
end
end
@@ -1251,8 +1251,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should redirect to the request page' do
- post :describe_state, :id => @external_request.id,
- :submitted_describe_state => 1
+ post :describe_state, :id => @external_request.id
response.should redirect_to(:action => 'show',
:controller => 'request',
:url_title => @external_request.url_title)
@@ -1272,8 +1271,7 @@ describe RequestController, "when classifying an information request" do
def post_status(status)
post :describe_state, :incoming_message => { :described_state => status },
:id => @dog_request.id,
- :last_info_request_event_id => @dog_request.last_event_id_needing_description,
- :submitted_describe_state => 1
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
end
it "should require login" do
@@ -1283,6 +1281,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should ask whether the request is old and unclassified' do
+ session[:user_id] = users(:silly_name_user).id
@dog_request.should_receive(:is_old_unclassified?)
post_status('rejected')
end
@@ -1322,7 +1321,7 @@ describe RequestController, "when classifying an information request" do
it 'should classify the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', users(:silly_name_user), nil)
post_status('rejected')
end
@@ -1350,6 +1349,26 @@ describe RequestController, "when classifying an information request" do
flash[:notice].should == 'Thank you for updating this request!'
end
+ context "playing the classification game" do
+ before :each do
+ session[:request_game] = true
+ end
+
+ it "should continue the game after classifying a request" do
+ post_status("rejected")
+ flash[:notice].should =~ /There are some more requests below for you to classify/
+ response.should redirect_to categorise_play_url
+ end
+ end
+
+ it "should send a mail from the user who changed the state to requires_admin" do
+ post :describe_state, :incoming_message => { :described_state => "requires_admin", :message => "a message" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.from_addrs.first.to_s.should == users(:silly_name_user).name_and_email
+ end
end
end
@@ -1365,7 +1384,7 @@ describe RequestController, "when classifying an information request" do
it 'should update the status of the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil)
post_status('rejected')
end
@@ -1418,7 +1437,7 @@ describe RequestController, "when classifying an information request" do
it 'should update the status of the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
- @dog_request.should_receive(:set_described_state).with('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected', @admin_user, nil)
post_status('rejected')
end
@@ -1453,6 +1472,22 @@ describe RequestController, "when classifying an information request" do
@dog_request.stub!(:each).and_return([@dog_request])
end
+ it "should let you know when you forget to select a status" do
+ post :describe_state, :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ flash[:error].should == _("Please choose whether or not you got some of the information that you wanted.")
+ end
+
+ it "should not change the status if the request has changed while viewing it" do
+ @dog_request.stub!(:last_event_id_needing_description).and_return(2)
+
+ post :describe_state, :incoming_message => { :described_state => "rejected" },
+ :id => @dog_request.id, :last_info_request_event_id => 1
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
+ flash[:error].should =~ /The request has been updated since you originally loaded this page/
+ end
+
it "should successfully classify response if logged in as user controlling request" do
post_status('rejected')
response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
@@ -1473,22 +1508,34 @@ describe RequestController, "when classifying an information request" do
post_status('rejected')
end
- it "should send email when classified as requires_admin" do
- post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1
- response.should redirect_to(:controller => 'help', :action => 'contact')
+ it "should go to the page asking for more information when classified as requires_admin" do
+ post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to describe_state_message_url(:url_title => @dog_request.url_title, :described_state => "requires_admin")
@dog_request.reload
- @dog_request.awaiting_description.should == false
- @dog_request.described_state.should == 'requires_admin'
- @dog_request.get_last_response_event.calculated_state.should == 'requires_admin'
+ @dog_request.described_state.should_not == 'requires_admin'
+
+ ActionMailer::Base.deliveries.should be_empty
+ end
+
+ context "message is included when classifying as requires_admin" do
+ it "should send an email including the message" do
+ post :describe_state,
+ :incoming_message => {
+ :described_state => "requires_admin",
+ :message => "Something weird happened" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- mail = deliveries[0]
- mail.body.should =~ /as needing admin/
- mail.from_addrs.first.to_s.should == @request_owner.email
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /as needing admin/
+ mail.body.should =~ /Something weird happened/
+ end
end
+
it 'should say it is showing advice as to what to do next' do
post_status('rejected')
flash[:notice].should match(/Here is what to do now/)
@@ -1598,12 +1645,22 @@ describe RequestController, "when classifying an information request" do
expect_redirect('internal_review', request_url)
end
- it 'should redirect to the "help general url" when status is updated to "requires admin"' do
- expect_redirect('requires_admin', "help/contact")
+ it 'should redirect to the "request url" when status is updated to "requires admin"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'requires_admin',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
end
- it 'should redirect to the "help general url" when status is updated to "error message"' do
- expect_redirect('error_message', "help/contact")
+ it 'should redirect to the "request url" when status is updated to "error message"' do
+ post :describe_state, :incoming_message => {
+ :described_state => 'error_message',
+ :message => "A message" },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description
+ response.should redirect_to show_request_url(:url_title => @dog_request.url_title)
end
it 'should redirect to the "respond to last url url" when status is updated to "user_withdrawn"' do
diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb
index 8d9d7637b..e9501b1ed 100644
--- a/spec/controllers/track_controller_spec.rb
+++ b/spec/controllers/track_controller_spec.rb
@@ -57,7 +57,6 @@ end
describe TrackController, "when sending alerts for a track" do
render_views
- include LinkToHelper # for main_url
before(:each) do
load_raw_emails_data
@@ -104,7 +103,7 @@ describe TrackController, "when sending alerts for a track" do
# Given we can't click the link, check the token is right instead
post_redirect = PostRedirect.find_by_email_token(mail_token)
- expected_url = main_url("/user/" + users(:silly_name_user).url_name + "#email_subscriptions") # XXX can't call URL making functions here, what is correct way to do this?
+ expected_url = show_user_url(:url_name => users(:silly_name_user).url_name, :anchor => "email_subscriptions")
post_redirect.uri.should == expected_url
# Check nothing more is delivered if we try again