diff options
Diffstat (limited to 'spec/views')
-rw-r--r-- | spec/views/public_body/show.html.erb_spec.rb (renamed from spec/views/public_body/show.rhtml_spec.rb) | 67 | ||||
-rw-r--r-- | spec/views/reports/new.erb_spec.rb | 29 | ||||
-rw-r--r-- | spec/views/request/_after_actions.html.erb_spec.rb (renamed from spec/views/request/_after_actions.rhtml_spec.rb) | 74 | ||||
-rw-r--r-- | spec/views/request/_describe_state.html.erb_spec.rb (renamed from spec/views/request/_describe_state.rhtml_spec.rb) | 28 | ||||
-rw-r--r-- | spec/views/request/list.rhtml_spec.rb | 51 | ||||
-rw-r--r-- | spec/views/request/show.html.erb_spec.rb | 110 | ||||
-rw-r--r-- | spec/views/request/show.rhtml_spec.rb | 128 | ||||
-rw-r--r-- | spec/views/request_game/play.html.erb_spec.rb (renamed from spec/views/request_game/play.rhtml_spec.rb) | 14 |
8 files changed, 216 insertions, 285 deletions
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.html.erb_spec.rb index b68b3f43b..0559fc8ef 100644 --- a/spec/views/public_body/show.rhtml_spec.rb +++ b/spec/views/public_body/show.html.erb_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) -describe "when viewing a body" do +describe "public_body/show" do before do @pb = mock_model(PublicBody, :name => 'Test Quango', @@ -17,64 +17,57 @@ describe "when viewing a body" do @pb.stub!(:is_requestable?).and_return(true) @pb.stub!(:has_notes?).and_return(false) @pb.stub!(:has_tag?).and_return(false) - @xap = mock_model(ActsAsXapian::Search, :matches_estimated => 2) + @xap = mock(ActsAsXapian::Search, :matches_estimated => 2) @xap.stub!(:results).and_return([ { :model => mock_event }, { :model => mock_event } ]) - assigns[:public_body] = @pb - assigns[:track_thing] = mock_model(TrackThing, - :track_type => 'public_body_updates', :public_body => @pb, :params => {}) - assigns[:xapian_requests] = @xap - assigns[:page] = 1 - assigns[:per_page] = 10 - # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template - request.env["REQUEST_URI"] = "" + assign(:public_body, @pb) + assign(:track_thing, mock_model(TrackThing, + :track_type => 'public_body_updates', :public_body => @pb, :params => {})) + assign(:xapian_requests, @xap) + assign(:page, 1) + assign(:per_page, 10) end it "should be successful" do - render "public_body/show" - response.should be_success - end - - it "should be valid HTML" do - render "public_body/show" - validate_as_body response.body + render + controller.response.should be_success end it "should show the body's name" do - render "public_body/show" - response.should have_tag("h1", "Test Quango") + render + response.should have_selector('h1', :content => "Test Quango") end it "should tell total number of requests" do - render "public_body/show" - response.should include_text("4 Freedom of Information requests") + render + response.should match "4 Freedom of Information requests" end it "should cope with no results" do @pb.stub!(:info_requests).and_return([]) - render "public_body/show" - response.should have_tag("p", /Nobody has made any Freedom of Information requests/m) + render + response.should have_selector('p', :content => "Nobody has made any Freedom of Information requests") end it "should cope with Xapian being down" do - assigns[:xapian_requests] = nil - render "public_body/show" - response.should have_tag("p", /The search index is currently offline/m) + assign(:xapian_requests, nil) + render + response.should match "The search index is currently offline" end it "should link to Charity Commission site if we have numbers to do so" do @pb.stub!(:has_tag?).and_return(true) @pb.stub!(:get_tag_values).and_return(['98765', '12345']) - render "public_body/show" - response.should have_tag("div#header_right") do - with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=98765$/) + render + response.should have_selector("div#header_right") do + have_selector "a", :href => /charity-commission.gov.uk.*RegisteredCharityNumber=98765$/ end - response.should have_tag("div#header_right") do - with_tag("a[href*=?]", /charity-commission.gov.uk.*RegisteredCharityNumber=12345$/) + response.should have_selector("div#header_right") do + have_selector "a", :href => /www.charity-commission.gov.uk.*RegisteredCharityNumber=12345$/ end end @@ -82,17 +75,17 @@ describe "when viewing a body" do @pb.stub!(:has_tag?).and_return(true) @pb.stub!(:get_tag_values).and_return(['SC1234']) - render "public_body/show" - response.should have_tag("div#header_right") do - with_tag("a[href*=?]", /www.oscr.org.uk.*id=SC1234$/) + render + response.should have_selector("div#header_right") do + have_selector "a", :href => /www.oscr.org.uk.*id=SC1234$/ end end it "should not link to Charity Commission site if we don't have number" do - render "public_body/show" - response.should have_tag("div#header_right") do - without_tag("a[href*=?]", /charity-commission.gov.uk/) + render + response.should have_selector("div#header_right") do + have_selector "a", :href => /charity-commission.gov.uk/ end end diff --git a/spec/views/reports/new.erb_spec.rb b/spec/views/reports/new.erb_spec.rb new file mode 100644 index 000000000..66b738261 --- /dev/null +++ b/spec/views/reports/new.erb_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) + +describe 'reports/new.html.erb' do + let(:info_request) { mock_model(InfoRequest, :url_title => "foo", :report_reasons => ["Weird"]) } + before :each do + assign(:info_request, info_request) + end + + it "should show a form" do + render + rendered.should have_selector("form") + end + + context "request has already been reported" do + before :each do + info_request.stub!(:attention_requested).and_return(true) + end + + it "should not show a form" do + render + rendered.should_not have_selector("form") + end + + it "should say it's already been reported" do + render + rendered.should contain("This request has already been reported") + end + end +end diff --git a/spec/views/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.html.erb_spec.rb index 548990c9f..833323d68 100644 --- a/spec/views/request/_after_actions.rhtml_spec.rb +++ b/spec/views/request/_after_actions.html.erb_spec.rb @@ -15,51 +15,27 @@ describe 'when displaying actions that can be taken with regard to a request' do :comments_allowed? => true, :url_title => 'test_request', :all_can_view? => true) - assigns[:info_request] = @mock_request - end - - def do_render - render :partial => 'request/after_actions' - end - - def expect_owner_div - do_render - response.should have_tag('div#owner_actions'){ yield } - end - - def expect_anyone_div - do_render - response.should have_tag('div#anyone_actions'){ yield } - end - - def expect_owner_link(text) - expect_owner_div{ with_tag('a', :text => text) } - end - - def expect_no_owner_link(text) - expect_owner_div{ without_tag('a', :text => text) } - end - - def expect_anyone_link(text) - expect_anyone_div{ with_tag('a', :text => text) } - end - - def expect_no_anyone_link(text) - expect_anyone_div{ without_tag('a', :text => text) } + assign :info_request, @mock_request end describe 'if the request is old and unclassified' do before do - assigns[:old_unclassified] = true + assign :old_unclassified, true end it 'should not display a link for the request owner to update the status of the request' do - expect_no_owner_link('Update the status of this request') + render :partial => 'request/after_actions' + response.should have_selector('div#owner_actions') do |div| + div.should_not have_selector('a', :content => 'Update the status of this request') + end end it 'should display a link for anyone to update the status of the request' do - expect_anyone_link('Update the status of this request') + render :partial => 'request/after_actions' + response.should have_selector('div#anyone_actions') do |div| + div.should have_selector('a', :content => 'Update the status of this request') + end end end @@ -67,35 +43,37 @@ describe 'when displaying actions that can be taken with regard to a request' do describe 'if the request is not old and unclassified' do before do - assigns[:old_unclassified] = false + assign :old_unclassified, false 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') + render :partial => 'request/after_actions' + response.should have_selector('div#owner_actions') do |div| + div.should have_selector('a', :content => 'Update the status of this request') + end end it 'should not display a link for anyone to update the status of the request' do - expect_no_anyone_link('Update the status of this request') + render :partial => 'request/after_actions' + response.should have_selector('div#anyone_actions') do |div| + div.should_not have_selector('a', :content => 'Update the status of this request') + end end end it 'should display a link for the request owner to request a review' do - expect_owner_link('Request an internal review') - end - - describe 'if the request is viewable by all' do - - it 'should display the link to download the entire request' do - expect_anyone_link('Download a zip file of all correspondence') + render :partial => 'request/after_actions' + response.should have_selector('div#owner_actions') do |div| + div.should have_selector('a', :content => 'Request an internal review') end end - describe 'if the request is not viewable by all' do - it 'should not display the link to download the entire request' do - @mock_request.stub!(:all_can_view?).and_return(false) - expect_no_anyone_link('Download a zip file of all correspondence') + it 'should display the link to download the entire request' do + render :partial => 'request/after_actions' + response.should have_selector('div#anyone_actions') do |div| + div.should have_selector('a', :content => 'Download a zip file of all correspondence') end end diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.html.erb_spec.rb index 18778d5d2..88dea53c5 100644 --- a/spec/views/request/_describe_state.rhtml_spec.rb +++ b/spec/views/request/_describe_state.html.erb_spec.rb @@ -4,12 +4,12 @@ describe 'when showing the form for describing the state of a request' do def expect_radio_button(value) do_render - response.should have_tag("input[type=radio][value=#{value}]") + response.should have_selector('input', :type => 'radio', :value => value) end def expect_no_radio_button(value) do_render - response.should_not have_tag("input[type=radio][value=#{value}]") + response.should_not have_selector('input', :type => 'radio', :value => value) end def do_render @@ -24,25 +24,25 @@ describe 'when showing the form for describing the state of a request' do :user_name => @mock_user.name, :is_external? => false ) - assigns[:info_request] = @mock_request + assign :info_request, @mock_request end describe 'if the user is a regular user (not the request owner)' do before do - assigns[:is_owning_user] = false + assign :is_owning_user, false end describe 'if the request is not old and unclassified' do it 'should not show the form' do do_render - response.should_not have_tag('h2', :text => 'What best describes the status of this request now?') + response.should_not have_selector('h2', :content => 'What best describes the status of this request now?') end it 'should give a link to login' do do_render - response.should have_tag('a', :text => 'sign in') + response.should have_selector('a', :content => 'sign in') end end @@ -50,22 +50,22 @@ describe 'when showing the form for describing the state of a request' do describe 'if the request is old and unclassified' do before do - assigns[:old_unclassified] = true + assign :old_unclassified, true end it 'should not show the form' do do_render - response.should_not have_tag('h2', :text => 'What best describes the status of this request now?') + response.should_not have_selector('h2', :content => 'What best describes the status of this request now?') end it 'should show the form for someone else to classify the request' do do_render - response.should have_tag('h2', :text => /We need your help/) + response.should have_selector('h2', :content => 'We need your help') end it 'should not give a link to login' do do_render - response.should_not have_tag('a', :text => 'sign in') + response.should_not have_selector('a', :content => 'sign in') end end @@ -74,7 +74,7 @@ describe 'when showing the form for describing the state of a request' do describe 'if showing the form to the user owning the request' do before do - assigns[:is_owning_user] = true + assign :is_owning_user, true end describe 'when the request is not in internal review' do @@ -100,7 +100,7 @@ describe 'when showing the form for describing the state of a request' do describe 'when the user has asked to update the status of the request' do before do - assigns[:update_status] = true + assign :update_status, true end it 'should show a radio button to set the status to "internal_review"' do @@ -129,7 +129,7 @@ describe 'when showing the form for describing the state of a request' do it 'should show the text "The review has finished and overall:"' do do_render - response.should have_tag('p', :text => 'The review has finished and overall:') + response.should have_selector('p', :content => 'The review has finished and overall:') end end @@ -170,4 +170,4 @@ describe 'when showing the form for describing the state of a request' do end end -end
\ No newline at end of file +end diff --git a/spec/views/request/list.rhtml_spec.rb b/spec/views/request/list.rhtml_spec.rb deleted file mode 100644 index 137bc359d..000000000 --- a/spec/views/request/list.rhtml_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) - -describe "when listing recent requests" do - - before do - assigns[:page] = 1 - assigns[:per_page] = 10 - # work round a bug in ActionController::TestRequest; allows request.query_string to work in the template - request.env["REQUEST_URI"] = "" - end - - def make_mock_event - return mock_model(InfoRequestEvent, - :info_request => mock_model(InfoRequest, - :title => 'Title', - :url_title => 'title', - :display_status => 'awaiting_response', - :calculate_status => 'awaiting_response', - :public_body => mock_model(PublicBody, :name => 'Test Quango', :url_name => 'testquango'), - :user => mock_model(User, :name => 'Test User', :url_name => 'testuser'), - :is_external? => false - ), - :incoming_message => nil, :is_incoming_message? => false, - :outgoing_message => nil, :is_outgoing_message? => false, - :comment => nil, :is_comment? => false, - :event_type => 'sent', - :created_at => Time.now - 4.days, - :search_text_main => '' - ) - end - - it "should be successful" do - assigns[:list_results] = [ make_mock_event, make_mock_event ] - assigns[:matches_estimated] = 2 - assigns[:show_no_more_than] = 100 - render "request/list" - response.should have_tag("div.request_listing") - response.should_not have_tag("p", /No requests of this sort yet/m) - end - - it "should cope with no results" do - assigns[:list_results] = [ ] - assigns[:matches_estimated] = 0 - assigns[:show_no_more_than] = 0 - render "request/list" - response.should have_tag("p", /No requests of this sort yet/m) - response.should_not have_tag("div.request_listing") - end - -end - diff --git a/spec/views/request/show.html.erb_spec.rb b/spec/views/request/show.html.erb_spec.rb new file mode 100644 index 000000000..6e63b9b43 --- /dev/null +++ b/spec/views/request/show.html.erb_spec.rb @@ -0,0 +1,110 @@ +require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) + +describe 'request/show' do + + before do + @mock_body = mock_model(PublicBody, :name => 'test body', + :url_name => 'test_body', + :is_school? => false) + @mock_user = mock_model(User, :name => 'test user', + :url_name => 'test_user', + :profile_photo => nil) + @mock_request = mock_model(InfoRequest, :title => 'test request', + :awaiting_description => false, + :law_used_with_a => 'A Freedom of Information request', + :law_used_full => 'Freedom of Information', + :public_body => @mock_body, + :user => @mock_user, + :user_name => @mock_user.name, + :is_external? => false, + :calculate_status => 'waiting_response', + :date_response_required_by => Date.today, + :prominence => 'normal', + :comments_allowed? => true, + :all_can_view? => true, + :url_title => 'test_request') + end + + def request_page + assign :info_request, @mock_request + assign :info_request_events, [] + assign :status, @mock_request.calculate_status + render + end + + describe 'when a status update has been requested' do + + before do + assign :update_status, true + end + + it 'should show the first form for describing the state of the request' do + request_page + response.should have_selector("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 + request_page + response.should have_selector("div.describe_state_form#describe_state_form_1") + end + + it 'should show the second form for describing the state of the request' do + request_page + response.should have_selector("div.describe_state_form#describe_state_form_2") + end + + end + + describe 'when the user is the request owner' do + + before do + assign :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_public_response).and_return(@mock_response) + end + + + it 'should show a link to follow up the last response with clarification' do + request_page + expected_url = "/en/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" + response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') + end + + end + + describe 'when there is no last response' do + + before do + @mock_request.stub!(:get_last_public_response).and_return(nil) + end + + + it 'should show a link to follow up the request without reference to a specific response' do + request_page + expected_url = "/en/request/#{@mock_request.id}/response#followup" + response.should have_selector("a", :href => expected_url, :content => 'send a follow up message') + end + end + end + + end +end diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.rhtml_spec.rb deleted file mode 100644 index 4429e9e58..000000000 --- a/spec/views/request/show.rhtml_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) - -describe 'when viewing an information request' do - - before do - @mock_body = mock_model(PublicBody, :name => 'test body', - :url_name => 'test_body', - :is_school? => false) - @mock_user = mock_model(User, :name => 'test user', - :url_name => 'test_user', - :profile_photo => nil) - @mock_request = mock_model(InfoRequest, :title => 'test request', - :awaiting_description => false, - :law_used_with_a => 'A Freedom of Information request', - :law_used_full => 'Freedom of Information', - :public_body => @mock_body, - :user => @mock_user, - :user_name => @mock_user.name, - :is_external? => false, - :calculate_status => 'waiting_response', - :date_response_required_by => Date.today, - :prominence => 'normal') - end - - def request_page - assigns[:info_request] = @mock_request - assigns[:info_request_events] = [] - assigns[:status] = @mock_request.calculate_status - template.stub!(:render_partial) - render 'request/show' - end - - it 'should show the sidebar' do - template.should_receive(:render_partial).with(:partial => 'sidebar', :locals => {}) - request_page - end - - it 'should show the actions people can take' do - template.should_receive(:render_partial).with(:partial => 'after_actions', :locals => {}) - request_page - 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 - request_page - 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 - request_page - 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 - request_page - 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) - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - after do - ActionController::Routing::Routes.filters = @old_filters - end - - - it 'should show a link to follow up the last response with clarification' do - request_page - expected_url = "http://test.host/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" - 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) - @old_filters = ActionController::Routing::Routes.filters - ActionController::Routing::Routes.filters = RoutingFilter::Chain.new - end - after do - ActionController::Routing::Routes.filters = @old_filters - end - - - it 'should show a link to follow up the request without reference to a specific response' do - request_page - 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 diff --git a/spec/views/request_game/play.rhtml_spec.rb b/spec/views/request_game/play.html.erb_spec.rb index 24fb6d75d..b5cf57c23 100644 --- a/spec/views/request_game/play.rhtml_spec.rb +++ b/spec/views/request_game/play.html.erb_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) -describe 'when viewing the request game' do +describe 'request_game/play' do before do @mock_body = mock_model(PublicBody, :name => 'test body', @@ -22,15 +22,15 @@ describe 'when viewing the request game' do :initial_request_text => 'hi there', :display_status => 'Awaiting categorisation', :created_at => Time.now) - assigns[:league_table_28_days] = [] - assigns[:league_table_all_time] = [] - assigns[:requests] = [@mock_request] - assigns[:play_urls] = true + assign :league_table_28_days, [] + assign :league_table_all_time, [] + assign :requests, [@mock_request] + assign :play_urls, true end it 'should show the correct url for a request' do - render "request_game/play" - response.should include_text("/categorise/request/a_test_request") + render + response.should include("/categorise/request/a_test_request") end |