aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/request_controller_spec.rb
diff options
context:
space:
mode:
authorfrancis <francis>2008-01-09 17:47:31 +0000
committerfrancis <francis>2008-01-09 17:47:31 +0000
commitc660cd2855c33fbe079b80ad644caf8964d23c65 (patch)
treed82efc0730b179251c160407d9fc40bf51078dcb /spec/controllers/request_controller_spec.rb
parent9b6eacca5079625a97493df32edc4fa09e979bff (diff)
Test code for classifying responses.
Diffstat (limited to 'spec/controllers/request_controller_spec.rb')
-rw-r--r--spec/controllers/request_controller_spec.rb55
1 files changed, 49 insertions, 6 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 94892081c..1e20ca8ab 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -114,12 +114,7 @@ describe RequestController, "when creating a new request" do
:submitted_new_request => 1
}
post :new, params
- # XXX yeuch - no other easy way of getting the token so we can check
- # the redirect URL, as it is by definition opaque to the controller
- # apart from in the place that it redirects to.
- post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1")
- post_redirects.size.should == 1
- post_redirect = post_redirects[0]
+ 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
@@ -148,6 +143,54 @@ describe RequestController, "when creating a new request" do
end
end
+describe RequestController, "when viewing an individual response" do
+ integrate_views
+ fixtures :info_requests, :public_bodies, :users, :incoming_messages, :outgoing_messages # all needed as integrating views
+
+ it "should require login if not logged in" do
+ get :classify, :incoming_message_id => 1
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ it "should say you are the wrong user if logged in as wrong user" do
+ session[:user_id] = users(:silly_name_user).id
+ get :classify, :incoming_message_id => 1
+ response.should render_template('user/wrong_user')
+ end
+
+ it "should show classification page if logged in as user controlling request" do
+ session[:user_id] = users(:bob_smith_user).id
+ get :classify, :incoming_message_id => 1
+ response.should render_template('classify')
+ end
+end
+
+describe RequestController, "when classifying an individual response" do
+ integrate_views
+ fixtures :info_requests, :public_bodies, :users, :incoming_messages, :outgoing_messages # all needed as integrating views
+
+ it "should require login" do
+ post :classify, :incoming_message => { :contains_information => true }, :incoming_message_id => incoming_messages(:useless_incoming_message)
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ it "should not classify response if logged in as wrong user" do
+ session[:user_id] = users(:silly_name_user).id
+ post :classify, :incoming_message => { :contains_information => true }, :incoming_message_id => incoming_messages(:useless_incoming_message)
+ response.should render_template('user/wrong_user')
+ end
+
+ it "should successfully classify response if logged in as user controlling request" do
+ incoming_messages(:useless_incoming_message).user_classified.should == false
+ session[:user_id] = users(:bob_smith_user).id
+ post :classify, :incoming_message => { :contains_information => true }, :incoming_message_id => incoming_messages(:useless_incoming_message)
+ response.should redirect_to(:controller => 'request', :action => 'show', :id => info_requests(:fancy_dog_request))
+ incoming_messages(:useless_incoming_message).reload
+ incoming_messages(:useless_incoming_message).user_classified.should == true
+ end
+end