diff options
-rw-r--r-- | app/controllers/request_controller.rb | 52 | ||||
-rw-r--r-- | app/models/user.rb | 11 | ||||
-rw-r--r-- | app/views/request/_after_actions.rhtml | 28 | ||||
-rw-r--r-- | app/views/request/_describe_state.rhtml | 34 | ||||
-rw-r--r-- | app/views/request/_sidebar.rhtml | 36 | ||||
-rw-r--r-- | app/views/request/show.rhtml | 67 | ||||
-rw-r--r-- | public/stylesheets/main.css | 5 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 132 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 12 | ||||
-rw-r--r-- | spec/views/request/_after_actions.rhtml_spec.rb | 61 | ||||
-rw-r--r-- | spec/views/request/_describe_state.rhtml_spec.rb | 49 | ||||
-rw-r--r-- | spec/views/request/show.rhtml_spec.rb | 111 |
12 files changed, 479 insertions, 119 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index d0c12dc28..ae4f3a229 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: request_controller.rb,v 1.154 2009-04-03 14:22:02 louise Exp $ +# $Id: request_controller.rb,v 1.155 2009-04-07 10:32:54 louise Exp $ class RequestController < ApplicationController @@ -24,16 +24,21 @@ class RequestController < ApplicationController @info_request_events = @info_request.info_request_events @status = @info_request.calculate_status @collapse_quotes = params[:unfold] ? false : true - @update_status = params[:update_status] ? true : false - @is_owning_user = !authenticated_user.nil? && (authenticated_user.id == @info_request.user_id || authenticated_user.owns_every_request?) + @update_status = params[:update_status] ? true : false + @is_owning_user = @info_request.is_owning_user?(authenticated_user) + + if @update_status + return if !@is_owning_user && !authenticated_as_user?(@info_request.user, + :web => "To update the status of this FOI request", + :email => "Then you can update the status of your request to " + @info_request.public_body.name + ".", + :email_subject => "Update the status of your request to " + @info_request.public_body.name + ) + end + @events_needing_description = @info_request.events_needing_description - last_event = @events_needing_description[-1] - @last_info_request_event_id = last_event.nil? ? 0 : last_event.id + @last_info_request_event_id = @info_request.last_event_id_needing_description @new_responses_count = @events_needing_description.select {|i| i.event_type == 'response'}.size - # special case that an admin user can edit requires_admin requests - @requires_admin_describe = (InfoRequest.requires_admin_states.include?(@info_request.described_state)) && !authenticated_user.nil? && authenticated_user.requires_admin_power? - # Sidebar stuff limit = 3 # ... requests that have similar imporant terms @@ -240,23 +245,9 @@ class RequestController < ApplicationController return end - # special case that an admin user can edit requires_admin requests - @requires_admin_describe = (InfoRequest.requires_admin_states.include?(@info_request.described_state)) && !authenticated_user.nil? && authenticated_user.requires_admin_power? - - if !@info_request.awaiting_description && !@requires_admin_describe - flash[:notice] = "The status of this request is up to date." - if !params[:submitted_describe_state].nil? - flash[:notice] = "The status of this request was made up to date elsewhere while you were filling in the form." - end - redirect_to request_url(@info_request) - return - end - - @collapse_quotes = params[:unfold] ? false : true + @is_owning_user = @info_request.is_owning_user?(authenticated_user) @events_needing_description = @info_request.events_needing_description - last_event = @events_needing_description[-1] - @last_info_request_event_id = last_event.nil? ? 0 : last_event.id - @is_owning_user = !authenticated_user.nil? && (authenticated_user.id == @info_request.user_id || authenticated_user.owns_every_request?) + @last_info_request_event_id = @info_request.last_event_id_needing_description @new_responses_count = @events_needing_description.select {|i| i.event_type == 'response'}.size # Check authenticated, and parameters set. We check is_owning_user @@ -284,6 +275,12 @@ class RequestController < ApplicationController # Make the state change @info_request.set_described_state(params[:incoming_message][:described_state]) + + if User.owns_every_request?(authenticated_user) + flash[:notice] = '<p>The request status has been updated</p>' + redirect_to request_url(@info_request) + return + end # Display appropriate next page (e.g. help for complaint etc.) if @info_request.calculate_status == 'waiting_response' @@ -316,7 +313,7 @@ class RequestController < ApplicationController redirect_to unhappy_url(@info_request) elsif @info_request.calculate_status == 'waiting_clarification' flash[:notice] = "Please write your follow up message containing the necessary clarifications below." - redirect_to show_response_url(:id => @info_request.id, :incoming_message_id => @events_needing_description[-1].params[:incoming_message_id]) + redirect_to respond_to_last_url(@info_request) elsif @info_request.calculate_status == 'gone_postal' redirect_to respond_to_last_url(@info_request) + "?gone_postal=1" elsif @info_request.calculate_status == 'internal_review' @@ -328,6 +325,9 @@ class RequestController < ApplicationController elsif @info_request.calculate_status == 'requires_admin' flash[:notice] = "Please use the form below to tell us more." redirect_to help_general_url(:action => 'contact') + elsif @info_request.calculate_status == 'user_withdrawn' + flash[:notice] = "Thanks for letting us know that you've withdrawn your request. Please add an annotation below to let other people know why you withdrew it." + redirect_to request_url(@info_request) else raise "unknown calculate_status " + @info_request.calculate_status end @@ -366,7 +366,7 @@ class RequestController < ApplicationController set_last_request(@info_request) @collapse_quotes = params[:unfold] ? false : true - @is_owning_user = !authenticated_user.nil? && (authenticated_user.id == @info_request.user_id || authenticated_user.owns_every_request?) + @is_owning_user = @info_request.is_owning_user?(authenticated_user) @gone_postal = params[:gone_postal] ? true : false if !@is_owning_user @gone_postal = false diff --git a/app/models/user.rb b/app/models/user.rb index be27e8f95..c281d7f18 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,7 +23,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.86 2009-04-06 09:30:26 louise Exp $ +# $Id: user.rb,v 1.87 2009-04-07 10:32:54 louise Exp $ require 'digest/sha1' @@ -60,6 +60,7 @@ class User < ActiveRecord::Base # format it here as no datetime support in Xapian's value ranges return self.created_at.strftime("%Y%m%d%H%M%S") end + def variety "user" end @@ -210,13 +211,9 @@ class User < ActiveRecord::Base def owns_every_request? self.admin_level == 'super' end - # Can the user edit status of requires_admin requests from main website? - def requires_admin_power? - self.admin_level == 'super' - end - def self.requires_admin_power?(user) - !user.nil? && user.requires_admin_power? + def self.owns_every_request?(user) + !user.nil? && user.owns_every_request? end # Does the user get "(admin)" links on each page on the main site? diff --git a/app/views/request/_after_actions.rhtml b/app/views/request/_after_actions.rhtml new file mode 100644 index 000000000..aa6411453 --- /dev/null +++ b/app/views/request/_after_actions.rhtml @@ -0,0 +1,28 @@ +<div id="after_actions"> + + <h2>Things to do with this request</h2> + + <div id="anyone_actions"> + <%= link_to "Add an annotation", new_comment_url(:url_title => @info_request.url_title) %> (to help + the requester or others) + </div> + + <div id="owner_actions"> + <strong><%=h @info_request.user.name %> only:</strong> + <% if @last_response.nil? %> + <%= link_to "Send follow up to " + RequestMailer.name_for_followup(@info_request, @last_response), show_response_no_followup_url(:id => @info_request.id, :incoming_message_id => nil) + "#followup" %> + <% else %> + <%= link_to "Reply to " + RequestMailer.name_for_followup(@info_request, @last_response), show_response_url(:id => @info_request.id, :incoming_message_id => @last_response.id) + "#followup" %> + <% end %> + | + <%= link_to "Update the status of this request", request_url(@info_request, :update_status => 1) %> + | + <%= link_to "Request an internal review", show_response_no_followup_url(:id => @info_request.id, :incoming_message_id => nil) + "?internal_review=1#followup" %> + </div> + + <div id="public_body_actions"> + <strong><%=h @info_request.public_body.name %> only:</strong> + <%= link_to "Respond to request", upload_response_url(:url_title => @info_request.url_title) %> + </div> + +</div>
\ No newline at end of file diff --git a/app/views/request/_describe_state.rhtml b/app/views/request/_describe_state.rhtml index d6e24c453..8b3ac2cf3 100644 --- a/app/views/request/_describe_state.rhtml +++ b/app/views/request/_describe_state.rhtml @@ -1,4 +1,5 @@ -<% if @is_owning_user || @requires_admin_describe %> +<% if @is_owning_user %> + <% form_for(:incoming_message, @info_request, :url => describe_state_url(:id => @info_request.id)) do |f| %> <h2>What best describes the status of this request now?</h2> @@ -25,6 +26,13 @@ </div> <% end %> + <% if @update_status && @info_request.described_state != 'internal_review' %> + <div> + <%= radio_button "incoming_message", "described_state", "internal_review", :id => 'internal_review' + id_suffix %> + <label for="internal_review<%=id_suffix%>">I'm waiting for an <strong>internal review</strong> response</label> + </div> + <% end %> + <div> <%= radio_button "incoming_message", "described_state", "gone_postal", :id => 'gone_postal' + id_suffix %> <label for="gone_postal<%=id_suffix%>">They are going to reply <strong>by post</strong></label> @@ -61,14 +69,22 @@ I've received an <strong>error message</strong> </label> </div> -<!-- <div> - <%= radio_button "incoming_message", "described_state", "requires_admin", :id => 'requires_admin' + id_suffix %> - <label for="requires_admin<%=id_suffix%>"> - <strong>None</strong> of the above - </label> - </div> --> - - + <% if @update_status %> + <div> + <%= radio_button "incoming_message", "described_state", "requires_admin", :id => 'requires_admin' + id_suffix %> + <label for="error_message<%=id_suffix%>"> + This request <strong>requires administrator attention</strong> + </label> + </div> + + <div> + <%= radio_button "incoming_message", "described_state", "user_withdrawn", :id => 'user_withdrawn' + id_suffix %> + <label for="user_withdrawn<%=id_suffix%>"> + I would like to <strong>withdraw this request</strong> + </label> + </div> + <% end %> + <hr> <p> diff --git a/app/views/request/_sidebar.rhtml b/app/views/request/_sidebar.rhtml new file mode 100644 index 000000000..0cb9207d8 --- /dev/null +++ b/app/views/request/_sidebar.rhtml @@ -0,0 +1,36 @@ +<div id="request_sidebar"> + <h2>Track this request</h2> + <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => @info_request.user == @user, :location => 'sidebar' } %> + + <h2>Act on what you've learnt</h2> + <div class="act_link"> + <%= link_to '<img src="/images/writetothem.png" alt="" class="rss">', "http://www.writetothem.com"%> + <%= link_to 'Write to your politician', "http://www.writetothem.com"%> + </div> + <div class="act_link"> + <%= link_to '<img src="/images/pledgebank.png" alt="" class="rss">', "http://www.pledgebank.com"%> + <%= link_to 'Pledge with others', "http://www.pledgebank.com"%> + </div> + <div class="act_link"> + <%= link_to '<img src="/images/petitions.png" alt="" class="rss">', "http://petitions.number10.gov.uk"%> + <%= link_to 'Petition the PM', "http://petitions.number10.gov.uk"%> + </div> + <div class="act_link"> + <%= link_to '<img src="/images/wordpress.png" alt="" class="rss">', "http://wordpress.com/"%> + <%= link_to 'Start your own blog', "http://wordpress.com/"%> + </div> + + <% if !@xapian_similar.nil? && @xapian_similar.results.size > 0 %> + <h2>Similar requests</h2> + <% for result in @xapian_similar.results %> + <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> + <% end %> + <% if @xapian_similar_more %> + <p><%= link_to "More similar requests", request_similar_url(@info_request) %></p> + <% end %> + <!-- Important terms: <%= @xapian_similar.important_terms.join(" ") %> --> + <% end %> + + <p><a href="/help/about#commercial">Are you the owner of + any commercial copyright on this page?</a></p> +</div>
\ No newline at end of file diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml index b86b92800..fa9c8f4a7 100644 --- a/app/views/request/show.rhtml +++ b/app/views/request/show.rhtml @@ -1,48 +1,12 @@ <% @title = h(@info_request.title) %> -<% if @info_request.awaiting_description || @requires_admin_describe %> +<% if @update_status || @info_request.awaiting_description %> <div class="describe_state_form" id="describe_state_form_1"> <%= render :partial => 'describe_state', :locals => { :id_suffix => "1" } %> </div> <% end %> -<div id="request_sidebar"> - <h2>Track this request</h2> - <%= render :partial => 'track/tracking_links', :locals => { :track_thing => @track_thing, :own_request => @info_request.user == @user, :location => 'sidebar' } %> - - <h2>Act on what you've learnt</h2> - <div class="act_link"> - <%= link_to '<img src="/images/writetothem.png" alt="" class="rss">', "http://www.writetothem.com"%> - <%= link_to 'Write to your politician', "http://www.writetothem.com"%> - </div> - <div class="act_link"> - <%= link_to '<img src="/images/pledgebank.png" alt="" class="rss">', "http://www.pledgebank.com"%> - <%= link_to 'Pledge with others', "http://www.pledgebank.com"%> - </div> - <div class="act_link"> - <%= link_to '<img src="/images/petitions.png" alt="" class="rss">', "http://petitions.number10.gov.uk"%> - <%= link_to 'Petition the PM', "http://petitions.number10.gov.uk"%> - </div> - <div class="act_link"> - <%= link_to '<img src="/images/wordpress.png" alt="" class="rss">', "http://wordpress.com/"%> - <%= link_to 'Start your own blog', "http://wordpress.com/"%> - </div> - - <% if !@xapian_similar.nil? && @xapian_similar.results.size > 0 %> - <h2>Similar requests</h2> - <% for result in @xapian_similar.results %> - <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> - <% end %> - <% if @xapian_similar_more %> - <p><%= link_to "More similar requests", request_similar_url(@info_request) %></p> - <% end %> - <!-- Important terms: <%= @xapian_similar.important_terms.join(" ") %> --> - <% end %> - - <p><a href="/help/about#commercial">Are you the owner of - any commercial copyright on this page?</a></p> -</div> - +<%= render :partial => 'sidebar' %> <div id="request_main"> <h1><%=@title%></h1> @@ -98,7 +62,7 @@ <% if @is_owning_user %> <%=h @info_request.public_body.name %> is <strong>waiting for your clarification</strong>. Please - <%= link_to "send a follow up message", show_response_url(:id => @info_request.id, :incoming_message_id => @info_request.get_last_response.id) + "#followup" %>. + <%= link_to "send a follow up message", respond_to_last_url(@info_request) + '#followup' %>. <% else %> The request is <strong>waiting for clarification</strong>. If you are @@ -133,29 +97,6 @@ </div> <% end %> - <div id="after_actions"> - <h2>Things to do with this request</h2> - - <p> - <%= link_to "Add an annotation", new_comment_url(:url_title => @info_request.url_title) %> (to help - the requester or others) - </p> - - <p> - <strong><%=h @info_request.user.name %> only:</strong> - <% if @last_response.nil? %> - <%= link_to "Send follow up to " + RequestMailer.name_for_followup(@info_request, @last_response), show_response_no_followup_url(:id => @info_request.id, :incoming_message_id => nil) + "#followup" %> - <% else %> - <%= link_to "Reply to " + RequestMailer.name_for_followup(@info_request, @last_response), show_response_url(:id => @info_request.id, :incoming_message_id => @last_response.id) + "#followup" %> - <% end %> - | - <%= link_to "Request an internal review", show_response_no_followup_url(:id => @info_request.id, :incoming_message_id => nil) + "?internal_review=1#followup" %> - - <br> - - <strong><%=h @info_request.public_body.name %> only:</strong> - <%= link_to "Respond to request", upload_response_url(:url_title => @info_request.url_title) %> - </p> - </div> + <%= render :partial => 'after_actions' %> </div> diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 3fe389f2e..d9ccd7224 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -720,6 +720,11 @@ div#after_actions width: 37em; } +div#anyone_actions +{ + margin-bottom: 1em; +} + /* id starts with... */ div[id|="outgoing"] { } div[id|="outgoing"] p { font-size: 0.95em;} diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 856b4c804..950682ca7 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -300,30 +300,68 @@ describe RequestController, "when viewing an individual response for reply/follo end end -describe RequestController, "when classifying an individual response" do - integrate_views +describe RequestController, "when classifying an information request" do + fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views + def post_rejected_status + post :describe_state, :incoming_message => { :described_state => "rejected" }, + :id => info_requests(:fancy_dog_request).id, + :last_info_request_event_id => info_request_events(:silly_comment_event).id, + :submitted_describe_state => 1 + end + it "should require login" do - post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1 + post_rejected_status 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 + it "should not classify the reqest if logged in as the wrong user" do session[:user_id] = users(:silly_name_user).id - post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1 + post_rejected_status response.should render_template('user/wrong_user') end + + describe 'when logged in as an admin user' do + + before do + @admin_user = users(:admin_user) + session[:user_id] = @admin_user.id + @dog_request = info_requests(:fancy_dog_request) + InfoRequest.stub!(:find).and_return(@dog_request) + end + + it 'should update the status of the request if the request requires admin' do + @dog_request.stub!(:calculate_status).and_return('rejected') + @dog_request.should_receive(:set_described_state).with('rejected') + post_rejected_status + end + + it 'should show the message "The request status has been updated"' do + post_rejected_status + flash[:notice].should == '<p>The request status has been updated</p>' + end + + it 'should redirect to the page that shows the request' do + post_rejected_status + response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title) + end + end + it "should successfully classify response if logged in as user controlling request" do info_requests(:fancy_dog_request).awaiting_description.should == true session[:user_id] = users(:bob_smith_user).id - post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:silly_comment_event).id, :submitted_describe_state => 1 + post :describe_state, :incoming_message => { :described_state => "rejected" }, + :id => info_requests(:fancy_dog_request).id, + :last_info_request_event_id => info_request_events(:silly_comment_event).id, + :submitted_describe_state => 1 response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => info_requests(:fancy_dog_request).url_title) info_requests(:fancy_dog_request).reload info_requests(:fancy_dog_request).awaiting_description.should == false info_requests(:fancy_dog_request).described_state.should == 'rejected' + info_requests(:fancy_dog_request).get_last_response_event.should == info_request_events(:useless_incoming_message_event) info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'rejected' end @@ -344,6 +382,88 @@ describe RequestController, "when classifying an individual response" do mail.body.should =~ /as needing admin/ mail.from_addrs.to_s.should == users(:bob_smith_user).name_and_email end + + describe 'when redirecting after a successful status update by the request owner' do + + before do + @request_owner = users(:bob_smith_user) + session[:user_id] = @request_owner.id + @dog_request = info_requests(:fancy_dog_request) + InfoRequest.stub!(:find).and_return(@dog_request) + end + + 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 + end + + def expect_redirect(status, redirect_path) + post_status(status) + response.should redirect_to("http://test.host/#{redirect_path}") + end + + it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is not overdue' do + @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date+1) + expect_redirect("waiting_response", "request/#{@dog_request.url_title}") + flash[:notice].should match(/should get a response/) + end + + it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do + @dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1) + expect_redirect('waiting_response', "request/#{@dog_request.url_title}") + flash[:notice].should match(/should have got a response/) + end + + it 'should redirect to the "request url" when status is updated to "not held"' do + expect_redirect('not_held', "request/#{@dog_request.url_title}") + end + + it 'should redirect to the "request url" when status is updated to "successful"' do + expect_redirect('successful', "request/#{@dog_request.url_title}") + end + + it 'should redirect to the "unhappy url" when status is updated to "rejected"' do + expect_redirect('rejected', "help/unhappy/#{@dog_request.url_title}") + end + + it 'should redirect to the "unhappy url" when status is updated to "partially successful"' do + expect_redirect('partially_successful', "help/unhappy/#{@dog_request.url_title}") + end + + it 'should redirect to the "response url" when status is updated to "waiting clarification" and there is a last response' do + incoming_message = mock_model(IncomingMessage) + @dog_request.stub!(:get_last_response).and_return(incoming_message) + expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response/#{incoming_message.id}") + end + + it 'should redirect to the "response no followup url" when status is updated to "waiting clarification" and there are no events needing description' do + @dog_request.stub!(:get_last_response).and_return(nil) + expect_redirect('waiting_clarification', "request/#{@dog_request.id}/response") + end + + it 'should redirect to the "respond to last url" when status is updated to "gone postal"' do + expect_redirect('gone_postal', "request/#{@dog_request.id}/response/1?gone_postal=1") + end + + it 'should redirect to the "request url" when status is updated to "internal review"' do + expect_redirect('internal_review', "request/#{@dog_request.url_title}") + end + + it 'should redirect to the "help general url" when status is updated to "requires admin"' do + expect_redirect('requires_admin', "help/contact") + end + + it 'should redirect to the "help general url" when status is updated to "error message"' do + expect_redirect('error_message', "help/contact") + end + + it 'should redirect to the "request url" when status is updated to "user_withdrawn"' do + expect_redirect('user_withdrawn', "request/#{@dog_request.url_title}") + end + + end end describe RequestController, "when sending a followup message" do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 5b7b08a7d..dc14feff9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -103,24 +103,24 @@ describe User, "when checking abilities" do end -describe User, 'when asked if a user has the ability to edit "requires admin" requests' do +describe User, 'when asked if a user owns every request' do before do @mock_user = mock_model(User) end it 'should return false if no user is passed' do - User.requires_admin_power?(nil).should be_false + User.owns_every_request?(nil).should be_false end it 'should return true if the user has "requires admin" power' do - @mock_user.stub!(:requires_admin_power?).and_return true - User.requires_admin_power?(@mock_user).should be_true + @mock_user.stub!(:owns_every_request?).and_return true + User.owns_every_request?(@mock_user).should be_true end it 'should return false if the user does not have "requires admin" power' do - @mock_user.stub!(:requires_admin_power?).and_return false - User.requires_admin_power?(@mock_user).should be_false + @mock_user.stub!(:owns_every_request?).and_return false + User.owns_every_request?(@mock_user).should be_false end end diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.rhtml_spec.rb new file mode 100644 index 000000000..7893d2e49 --- /dev/null +++ b/spec/views/request/_after_actions.rhtml_spec.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'when displaying actions that can be taken with regard to a request' do + + before do + @mock_body = mock_model(PublicBody, :name => 'test public body', + :url_name => 'test_public_body') + @mock_user = mock_model(User, :name => 'test user', + :url_name => 'test_user') + @mock_request = mock_model(InfoRequest, :title => 'test request', + :user => @mock_user, + :public_body => @mock_body, + :url_title => 'test_request') + assigns[:info_request] = @mock_request + end + + def do_render + render :partial => 'request/after_actions' + end + + def expect_owner_link(text) + do_render + response.should have_tag('div#owner_actions') do + with_tag('a', :text => text) + end + end + + it 'should display a link for the request owner to update the status of the request' do + expect_owner_link('Update the status of this request') + end + + it 'should display a link for the request owner to request a review' do + expect_owner_link('Request an internal review') + end + + describe 'when there is no last response' do + + before do + assigns[:last_response] = nil + end + + it 'should display a link for the request owner to send a follow up' do + expect_owner_link('Send follow up to test public body') + end + + end + + describe 'when there is a last response' do + + before do + assigns[:last_response] = mock_model(IncomingMessage, + :valid_to_reply_to? => false) + end + + it 'should display a link for the request owner to reply to the last response' do + expect_owner_link('Reply to test public body') + end + + end + +end
\ No newline at end of file diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.rhtml_spec.rb index 306f70060..ebb1d5a91 100644 --- a/spec/views/request/_describe_state.rhtml_spec.rb +++ b/spec/views/request/_describe_state.rhtml_spec.rb @@ -6,6 +6,11 @@ describe 'when showing the form for describing the state of a request' do do_render response.should have_tag("input[type=radio][value=#{value}]") end + + def expect_no_radio_button(value) + do_render + response.should_not have_tag("input[type=radio][value=#{value}]") + end def do_render render :partial => 'request/describe_state', :locals => {:id_suffix => '1'} @@ -17,17 +22,22 @@ describe 'when showing the form for describing the state of a request' do assigns[:info_request] = @mock_request end - describe 'if showing the form to a regular user' do + describe 'if the user is a regular user' do before do assigns[:is_owning_user] = false end + it 'should not show the form' do + do_render + response.should_not have_tag('form') + end + it 'should give a link to login' do do_render response.should have_tag('a', :text => 'sign in') end - + end describe 'if showing the form to the user owning the request' do @@ -49,7 +59,31 @@ describe 'when showing the form for describing the state of a request' do it 'should show a radio button to set the status to "waiting clarification"' do expect_radio_button('waiting_clarification') end + + it 'should not show a radio button to set the status to "internal_review"' do + expect_no_radio_button('internal_review') + end + + end + describe 'when the user has asked to update the status of the request' do + + before do + assigns[:update_status] = true + end + + it 'should show a radio button to set the status to "internal_review"' do + expect_radio_button('internal_review') + end + + it 'should show a radio button to set the status to "requires_admin"' do + expect_radio_button('requires_admin') + end + + it 'should show a radio button to set the status to "user_withdrawn"' do + expect_radio_button('user_withdrawn') + end + end describe 'when the request is in internal review' do @@ -68,6 +102,9 @@ describe 'when showing the form for describing the state of a request' do end end + + describe 'when request is awaiting a description and the user has not asked to update the status' do + end it 'should show a radio button to set the status to "gone postal"' do expect_radio_button('gone_postal') @@ -93,5 +130,13 @@ describe 'when showing the form for describing the state of a request' do expect_radio_button('error_message') end + it 'should not show a radio button to set the status to "requires_admin"' do + expect_no_radio_button('requires_admin') + end + + it 'should not show a radio button to set the status to "user_withdrawn"' do + expect_no_radio_button('user_withdrawn') + end + end end
\ No newline at end of file diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb new file mode 100644 index 000000000..f4222e354 --- /dev/null +++ b/spec/views/request/show.rhtml_spec.rb @@ -0,0 +1,111 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'when viewing an information request' do + + before do + @mock_body = mock_model(PublicBody, :name => 'test body', + :url_name => 'test_body') + @mock_user = mock_model(User, :name => 'test user', + :url_name => 'test_user') + @mock_request = mock_model(InfoRequest, :title => 'test request', + :awaiting_description => false, + :law_used_with_a => '', + :public_body => @mock_body, + :user => @mock_user, + :calculate_status => 'waiting_response', + :date_response_required_by => Date.today) + end + + def do_render + assigns[:info_request] = @mock_request + assigns[:info_request_events] = [] + assigns[:status] = @mock_request.calculate_status + template.stub!(:render) + render 'request/show' + end + + it 'should show the sidebar' do + template.should_receive(:render).with(:partial => 'sidebar') + do_render + end + + it 'should show the actions people can take' do + template.should_receive(:render).with(:partial => 'after_actions') + do_render + end + + describe 'when a status update has been requested' do + + before do + assigns[:update_status] = true + end + + it 'should show the first form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_1") + end + + end + + describe 'when it is awaiting a description' do + + before do + @mock_request.stub!(:awaiting_description).and_return(true) + end + + it 'should show the first form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_1") + end + + it 'should show the second form for describing the state of the request' do + do_render + response.should have_tag("div.describe_state_form#describe_state_form_2") + end + + end + + describe 'when the user is the request owner' do + + before do + assigns[:is_owning_user] = true + end + + describe 'when the request status is "waiting clarification"' do + + before do + @mock_request.stub!(:calculate_status).and_return('waiting_clarification') + end + + describe 'when there is a last response' do + + before do + @mock_response = mock_model(IncomingMessage) + @mock_request.stub!(:get_last_response).and_return(@mock_response) + end + + it 'should show a link to follow up the last response with clarification' do + do_render + expected_url = "http://test.host/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" + puts response.body + response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + end + + end + + describe 'when there is no last response' do + + before do + @mock_request.stub!(:get_last_response).and_return(nil) + end + + it 'should show a link to follow up the request without reference to a specific response' do + do_render + expected_url = "http://test.host/request/#{@mock_request.id}/response#followup" + response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + end + end + end + + end +end
\ No newline at end of file |