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) | 62 | ||||
-rw-r--r-- | spec/views/request/_after_actions.html.erb_spec.rb (renamed from spec/views/request/_after_actions.rhtml_spec.rb) | 71 | ||||
-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.html.erb_spec.rb (renamed from spec/views/request/list.rhtml_spec.rb) | 32 | ||||
-rw-r--r-- | spec/views/request/show.html.erb_spec.rb (renamed from spec/views/request/show.rhtml_spec.rb) | 54 | ||||
-rw-r--r-- | spec/views/request_game/play.html.erb_spec.rb (renamed from spec/views/request_game/play.rhtml_spec.rb) | 14 |
6 files changed, 115 insertions, 146 deletions
diff --git a/spec/views/public_body/show.rhtml_spec.rb b/spec/views/public_body/show.html.erb_spec.rb index 23e92dedd..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,59 +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 + 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 @@ -77,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/request/_after_actions.rhtml_spec.rb b/spec/views/request/_after_actions.html.erb_spec.rb index 548990c9f..ae398f4ce 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,27 +43,39 @@ 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') + 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 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#anyone_actions') do |div| + div.should have_selector('a', :content => 'Download a zip file of all correspondence') + end end end @@ -95,7 +83,10 @@ describe 'when displaying actions that can be taken with regard to a request' 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') + render :partial => 'request/after_actions' + response.should have_selector('div#anyone_actions') do |div| + div.should_not have_selector('a', :content => 'Download a zip file of all correspondence') + end 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.html.erb_spec.rb index 137bc359d..521d946bc 100644 --- a/spec/views/request/list.rhtml_spec.rb +++ b/spec/views/request/list.html.erb_spec.rb @@ -1,12 +1,10 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) -describe "when listing recent requests" do +describe "request/list" 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"] = "" + assign :page, 1 + assign :per_page, 10 end def make_mock_event @@ -30,21 +28,21 @@ describe "when listing recent requests" do 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) + assign :list_results, [ make_mock_event, make_mock_event ] + assign :matches_estimated, 2 + assign :show_no_more_than, 100 + render + response.should have_selector("div.request_listing") + response.should_not have_selector("p", :content => "No requests of this sort yet") 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") + assign :list_results, [ ] + assign :matches_estimated, 0 + assign :show_no_more_than, 0 + render + response.should have_selector("p", :content => "No requests of this sort yet") + response.should_not have_selector("div.request_listing") end end diff --git a/spec/views/request/show.rhtml_spec.rb b/spec/views/request/show.html.erb_spec.rb index a22f29951..4578268b2 100644 --- a/spec/views/request/show.rhtml_spec.rb +++ b/spec/views/request/show.html.erb_spec.rb @@ -1,6 +1,6 @@ require File.expand_path(File.join('..', '..', '..', 'spec_helper'), __FILE__) -describe 'when viewing an information request' do +describe 'request/show' do before do @mock_body = mock_model(PublicBody, :name => 'test body', @@ -19,36 +19,28 @@ describe 'when viewing an information request' do :is_external? => false, :calculate_status => 'waiting_response', :date_response_required_by => Date.today, - :prominence => 'normal') + :prominence => 'normal', + :comments_allowed? => true, + :all_can_view? => true, + :url_title => 'test_request') 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 + 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 - assigns[:update_status] = true + assign :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") + response.should have_selector("div.describe_state_form#describe_state_form_1") end end @@ -61,12 +53,12 @@ describe 'when viewing an information request' do 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") + 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_tag("div.describe_state_form#describe_state_form_2") + response.should have_selector("div.describe_state_form#describe_state_form_2") end end @@ -74,7 +66,7 @@ describe 'when viewing an information request' do describe 'when the user is the request owner' do before do - assigns[:is_owning_user] = true + assign :is_owning_user, true end describe 'when the request status is "waiting clarification"' do @@ -88,18 +80,13 @@ describe 'when viewing an information request' 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 = "/request/#{@mock_request.id}/response/#{@mock_response.id}#followup" - response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + 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 @@ -108,18 +95,13 @@ describe 'when viewing an information request' 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 = "/request/#{@mock_request.id}/response#followup" - response.should have_tag("a[href=#{expected_url}]", :text => 'send a follow up message') + 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 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 |