diff --git a/spec/controllers/api_controller_spec.rb b/spec/controllers/api_controller_spec.rb index 41711838e5..8bd305ad7e 100644 --- a/spec/controllers/api_controller_spec.rb +++ b/spec/controllers/api_controller_spec.rb @@ -7,7 +7,9 @@ @number_of_requests = InfoRequest.count @request_data = { 'title' => 'Tell me about your chickens', - 'body' => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n", + 'body' => "Dear Sir,\n\n" \ + "I should like to know about your chickens.\n\n" \ + "Yours in faith,\nBob\n", 'external_url' => 'http://www.example.gov.uk/foi/chickens_23', 'external_user_name' => 'Bob Smith' } @@ -57,7 +59,9 @@ def _create_request request_data = { 'title' => 'Tell me about your chickens', - 'body' => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n", + 'body' => "Dear Sir,\n\n" \ + "I should like to know about your chickens.\n\n" \ + "Yours in faith,\nBob\n", 'external_url' => 'http://www.example.gov.uk/foi/chickens_23', 'external_user_name' => 'Bob Smith' } @@ -82,16 +86,24 @@ def _create_request new_request = InfoRequest.find(response_body['id']) expect(new_request.user_id).to be_nil - expect(new_request.external_user_name).to eq(request_data['external_user_name']) + expect( + new_request.external_user_name + ).to eq(request_data['external_user_name']) expect(new_request.external_url).to eq(request_data['external_url']) expect(new_request.title).to eq(request_data['title']) - expect(new_request.last_event_forming_initial_request.outgoing_message.body).to eq(request_data['body'].strip) + expect( + new_request.last_event_forming_initial_request.outgoing_message.body + ).to eq(request_data['body'].strip) - expect(new_request.public_body_id).to eq(public_bodies(:geraldine_public_body).id) + expect( + new_request.public_body_id + ).to eq(public_bodies(:geraldine_public_body).id) expect(new_request.info_request_events.size).to eq(1) expect(new_request.info_request_events[0].event_type).to eq('sent') - expect(new_request.info_request_events[0].calculated_state).to eq('waiting_response') + expect( + new_request.info_request_events[0].calculated_state + ).to eq('waiting_response') end end @@ -108,7 +120,11 @@ def _create_request # Now add one sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we " \ + "are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely," \ + "\nJohn Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -128,7 +144,9 @@ def _create_request incoming_message = incoming_messages[0] expect(incoming_message.sent_at).to eq(Time.iso8601(sent_at)) - expect(incoming_message.get_main_body_text_folded).to be_equal_modulo_whitespace_to(response_body) + expect( + incoming_message.get_main_body_text_folded + ).to be_equal_modulo_whitespace_to(response_body) end it 'should add a followup to a request' do @@ -178,7 +196,11 @@ def _create_request # Now add one sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we" \ + " are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \ + "Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -212,7 +234,11 @@ def _create_request # Now add one sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we " \ + "are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \ + "Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -290,9 +316,16 @@ def _create_request it 'should return a JSON 404 error for non-existent requests' do request_id = '123459876' - allow(InfoRequest).to receive(:find_by_id).with(request_id).and_return(nil) + allow(InfoRequest). + to receive(:find_by_id). + with(request_id). + and_return(nil) sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we " \ + "are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \ + "Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -304,13 +337,19 @@ def _create_request }.to_json } expect(response.status).to eq(404) - expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(['Could not find request 123459876']) + expect( + ActiveSupport::JSON.decode(response.body)['errors'] + ).to eq(['Could not find request 123459876']) end it 'should return a JSON 403 error if we try to add correspondence to a request we don\'t own' do request_id = info_requests(:naughty_chicken_request).id sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we " \ + "are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \ + "Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -322,7 +361,9 @@ def _create_request }.to_json } expect(response.status).to eq(403) - expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["Request #{request_id} cannot be updated using the API"]) + expect( + ActiveSupport::JSON.decode(response.body)['errors'] + ).to eq(["Request #{request_id} cannot be updated using the API"]) end it 'should not allow files to be attached to a followup' do @@ -343,7 +384,9 @@ def _create_request # Make sure it worked expect(response.status).to eq(500) errors = ActiveSupport::JSON.decode(response.body)['errors'] - expect(errors).to eq(["You cannot attach files to messages in the 'request' direction"]) + expect(errors).to eq( + ["You cannot attach files to messages in the 'request' direction"] + ) end it 'should allow files to be attached to a response' do @@ -356,7 +399,11 @@ def _create_request # Now add one sent_at = '2012-05-28T12:35:39+01:00' - response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n" + response_body = "Thank you for your request for information, which we " \ + "are handling in accordance with the Freedom of Information Act " \ + "2000. You will receive a response within 20 working days or before " \ + "the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \ + "Gandermulch,\nExample Council FOI Officer\n" post :add_correspondence, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -379,7 +426,9 @@ def _create_request incoming_message = incoming_messages[0] expect(incoming_message.sent_at).to eq(Time.iso8601(sent_at)) - expect(incoming_message.get_main_body_text_folded).to be_equal_modulo_whitespace_to(response_body) + expect( + incoming_message.get_main_body_text_folded + ).to be_equal_modulo_whitespace_to(response_body) # Get the attachment attachments = incoming_message.get_attachments_for_display @@ -437,7 +486,9 @@ def _create_request # Check that the error has been raised... expect(response.status).to eq(500) - expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["'random_string' is not a valid request state"]) + expect( + ActiveSupport::JSON.decode(response.body)['errors'] + ).to eq(["'random_string' is not a valid request state"]) # ..and that the status hasn't been updated request = InfoRequest.find_by_id(request_id) @@ -446,7 +497,10 @@ def _create_request it 'should return a JSON 404 error for non-existent requests' do request_id = '123459876' - allow(InfoRequest).to receive(:find_by_id).with(request_id).and_return(nil) + allow(InfoRequest). + to receive(:find_by_id). + with(request_id). + and_return(nil) post :update_state, params: { k: public_bodies(:geraldine_public_body).api_key, @@ -454,7 +508,9 @@ def _create_request } expect(response.status).to eq(404) - expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(['Could not find request 123459876']) + expect( + ActiveSupport::JSON.decode(response.body)['errors'] + ).to eq(['Could not find request 123459876']) end it 'should return a JSON 403 error if we try to add correspondence to a request we don\'t own' do @@ -466,7 +522,9 @@ def _create_request } expect(response.status).to eq(403) - expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["Request #{request_id} cannot be updated using the API"]) + expect( + ActiveSupport::JSON.decode(response.body)['errors'] + ).to eq(["Request #{request_id} cannot be updated using the API"]) end end @@ -519,9 +577,12 @@ def _create_request expect(response).to render_template('api/request_events') expect(assigns[:events].size).to be > 0 assigns[:events].each do |event| - expect(event.info_request.public_body).to eq(public_bodies(:geraldine_public_body)) + expect(event.info_request.public_body). + to eq(public_bodies(:geraldine_public_body)) expect(event.outgoing_message).not_to be_nil - expect(event.event_type).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) } + expect(event.event_type).to satisfy { + |x| %w[sent followup_sent resent followup_resent].include?(x) + } end end @@ -536,14 +597,19 @@ def _create_request expect(response).to be_successful expect(assigns[:events].size).to be > 0 assigns[:events].each do |event| - expect(event.info_request.public_body).to eq(public_bodies(:geraldine_public_body)) + expect(event.info_request.public_body). + to eq(public_bodies(:geraldine_public_body)) expect(event.outgoing_message).not_to be_nil - expect(event.event_type).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) } + expect(event.event_type).to satisfy { + |x| %w[sent followup_sent resent followup_resent].include?(x) + } end expect(assigns[:event_data].size).to eq(assigns[:events].size) assigns[:event_data].each do |event_record| - expect(event_record[:event_type]).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) } + expect(event_record[:event_type]).to satisfy { + |x| %w[sent followup_sent resent followup_resent].include?(x) + } end end diff --git a/spec/controllers/attachments_controller_spec.rb b/spec/controllers/attachments_controller_spec.rb index 61c83a2235..c3800c769b 100644 --- a/spec/controllers/attachments_controller_spec.rb +++ b/spec/controllers/attachments_controller_spec.rb @@ -64,14 +64,15 @@ def show(params = {}) File.delete(key_path) end - # This is a regression test for a bug where URLs of this form were causing 500 errors - # instead of 404s. + # This is a regression test for a bug where URLs of this form were causing + # 500 errors nstead of 404s. # - # (Note that in fact only the integer-prefix of the URL part is used, so there are - # *some* “ugly URLs containing a request id that isn't an integer” that actually return - # a 200 response. The point is that IDs of this sort were triggering an error in the - # error-handling path, causing the wrong sort of error response to be returned in the - # case where the integer prefix referred to the wrong request.) + # (Note that in fact only the integer-prefix of the URL part is used, so + # there are *some* “ugly URLs containing a request id that isn't an integer” + # that actually return a 200 response. The point is that IDs of this sort + # were triggering an error in the error-handling path, causing the wrong + # sort of error response to be returned in the case where the integer prefix + # referred to the wrong request.) # # https://github.com/mysociety/alaveteli/issues/351 it "should return 404 for ugly URLs containing a request id that isn't an integer" do @@ -268,13 +269,17 @@ def show(params = {}) end describe 'GET show_as_html' do - let(:info_request) { FactoryBot.create(:info_request_with_incoming_attachments) } + let(:info_request) { + FactoryBot.create(:info_request_with_incoming_attachments) + } def get_html_attachment(params = {}) - default_params = { incoming_message_id: info_request.incoming_messages.first.id, - id: info_request.id, - part: 2, - file_name: 'interesting.pdf.html' } + default_params = { + incoming_message_id: info_request.incoming_messages.first.id, + id: info_request.id, + part: 2, + file_name: 'interesting.pdf.html' + } get :show_as_html, params: default_params.merge(params) end diff --git a/spec/controllers/classifications_controller_spec.rb b/spec/controllers/classifications_controller_spec.rb index 2f4ef7174c..a269341cca 100644 --- a/spec/controllers/classifications_controller_spec.rb +++ b/spec/controllers/classifications_controller_spec.rb @@ -318,9 +318,11 @@ def post_status(status, message: nil) end it 'should log a status update event' do - expected_params = { user: { gid: info_request.user.to_global_id.to_s }, - old_described_state: 'waiting_response', - described_state: 'rejected' } + expected_params = { + user: { gid: info_request.user.to_global_id.to_s }, + old_described_state: 'waiting_response', + described_state: 'rejected' + } post_status('rejected') last_event = info_request.reload.info_request_events.last expect(last_event.params).to eq expected_params diff --git a/spec/controllers/comment_controller_spec.rb b/spec/controllers/comment_controller_spec.rb index 77624b40a5..da5eb25620 100644 --- a/spec/controllers/comment_controller_spec.rb +++ b/spec/controllers/comment_controller_spec.rb @@ -78,8 +78,9 @@ params: { url_title: info_requests(:naughty_chicken_request).url_title, comment: { - body: "A good question, but why not also ask about nice chickens?" - }, type: 'request', + body: "A good question, but why not also ask about nice chickens?" + }, + type: 'request', submitted_comment: 1, preview: 1 } @@ -87,16 +88,20 @@ end it "should redirect to sign in page when input is good and nobody is logged in" do - params = { url_title: info_requests(:naughty_chicken_request).url_title, - comment: { body: "A good question, but why not also ask about nice chickens?" }, - type: 'request', - submitted_comment: 1, - preview: 0 - } + params = { + url_title: info_requests(:naughty_chicken_request).url_title, + comment: { + body: "A good question, but why not also ask about nice chickens?" + }, + type: 'request', + submitted_comment: 1, + preview: 0 + } post :new, params: params expect(response). to redirect_to(signin_path(token: get_last_post_redirect.token)) - # post_redirect.post_params.should == params # TODO: get this working. there's a : vs '' problem amongst others + # post_redirect.post_params.should == params # TODO: get this working. + # there's a : vs '' problem amongst others end it "should create the comment, and redirect to request page when input is good and somebody is logged in" do @@ -106,7 +111,7 @@ params: { url_title: info_requests(:naughty_chicken_request).url_title, comment: { - body: "A good question, but why not also ask about nice chickens?" + body: "A good question, but why not also ask about nice chickens?" }, type: 'request', submitted_comment: 1, @@ -120,7 +125,11 @@ expect(ActionMailer::Base.deliveries.size).to eq(0) - expect(response).to redirect_to(controller: 'request', action: 'show', url_title: info_requests(:naughty_chicken_request).url_title) + expect(response).to redirect_to( + controller: 'request', + action: 'show', + url_title: info_requests(:naughty_chicken_request).url_title + ) end it 'errors if the same comment is submitted twice' do @@ -161,7 +170,10 @@ end it "should not allow comments if comments are not allowed globally" do - allow(controller).to receive(:feature_enabled?).with(:annotations).and_return(false) + allow(controller). + to receive(:feature_enabled?). + with(:annotations). + and_return(false) sign_in users(:silly_name_user) info_request = info_requests(:fancy_dog_request) @@ -263,8 +275,10 @@ submitted_comment: 1, preview: 0 } - expect(flash[:error]) - .to eq("Sorry, we're currently unable to add your annotation. Please try again later.") + expect(flash[:error]).to eq( + "Sorry, we're currently unable to add your annotation. " \ + "Please try again later." + ) end it 'renders the compose interface' do diff --git a/spec/controllers/concerns/translatable_params_spec.rb b/spec/controllers/concerns/translatable_params_spec.rb index d93dfcea44..0e6bdef147 100644 --- a/spec/controllers/concerns/translatable_params_spec.rb +++ b/spec/controllers/concerns/translatable_params_spec.rb @@ -9,16 +9,28 @@ general_keys: [ :status ] } } it 'whitelists translatable_params' do - params = { name: 'Some name', - status: 'good', - id: 40, - translations_attributes: { en: { locale: 'en', - name: 'Other name', - bad: "value" } } } - expected = { name: 'Some name', - status: 'good', - translations_attributes: { en: { locale: 'en', - name: 'Other name' } } } + params = { + name: 'Some name', + status: 'good', + id: 40, + translations_attributes: { + en: { + locale: 'en', + name: 'Other name', + bad: "value" + } + } + } + expected = { + name: 'Some name', + status: 'good', + translations_attributes: { + en: { + locale: 'en', + name: 'Other name' + } + } + } params = ActionController::Parameters.new(params) expect(translatable_params(params, **keys)). @@ -58,9 +70,15 @@ end it 'allows id in the translation params' do - params = { translations_attributes: { en: { id: 40, - locale: 'en', - name: 'Other name' } } } + params = { + translations_attributes: { + en: { + id: 40, + locale: 'en', + name: 'Other name' + } + } + } expected = ActionController::Parameters.new(params).permit! params = params = ActionController::Parameters.new(params) @@ -70,11 +88,23 @@ end it 'removes a non-whitelisted translation param' do - params = { translations_attributes: { en: { locale: 'en', - name: 'Other name', - bad: "value" } } } - expected = { translations_attributes: { en: { locale: 'en', - name: 'Other name' } } } + params = { + translations_attributes: { + en: { + locale: 'en', + name: 'Other name', + bad: "value" + } + } + } + expected = { + translations_attributes: { + en: { + locale: 'en', + name: 'Other name' + } + } + } params = ActionController::Parameters.new(params) expect( diff --git a/spec/controllers/followups_controller_spec.rb b/spec/controllers/followups_controller_spec.rb index cc7f57f455..b516f39ab7 100644 --- a/spec/controllers/followups_controller_spec.rb +++ b/spec/controllers/followups_controller_spec.rb @@ -4,7 +4,10 @@ render_views let(:request_user) { FactoryBot.create(:user) } - let(:request) { FactoryBot.create(:info_request_with_incoming, user: request_user) } + let(:request) { FactoryBot.create( + :info_request_with_incoming, + user: request_user + ) } let(:message_id) { request.incoming_messages[0].id } let(:pro_user) { FactoryBot.create(:pro_user) } @@ -71,7 +74,8 @@ end it "calls the message a followup if there is an incoming message" do - expected_reason = "To send a follow up message to #{request.public_body.name}" + expected_reason = "To send a follow up message " \ + "to #{request.public_body.name}" get :new, params: { request_id: request.id, incoming_message_id: message_id } expect(get_last_post_redirect.reason_params[:web]).to eq(expected_reason) @@ -539,7 +543,9 @@ def send_request request_id: request.id, incoming_message_id: message_id } - expect(flash[:notice]).to eq('Your follow up message has been sent on its way.') + expect(flash[:notice]).to eq( + 'Your follow up message has been sent on its way.' + ) end it "displays an error if the request has been closed to new responses" do @@ -583,8 +589,10 @@ def send_request it "displays the form with an error message" do expect(response).to render_template('new') - expect(response.body). - to include('You previously submitted that exact follow up message for this request.') + expect(response.body).to include( + 'You previously submitted that exact follow up message for this ' \ + 'request.' + ) end it "only delivers the message once" do diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb index a624d25926..7504372d0d 100644 --- a/spec/controllers/general_controller_spec.rb +++ b/spec/controllers/general_controller_spec.rb @@ -85,7 +85,9 @@ info_request: info_request, described_at: Time.zone.now, search_text_main: 'example text') - xapian_result = double('xapian result', results: [{ model: info_request_event }]) + xapian_result = double( + 'xapian result', results: [{model: info_request_event}] + ) allow(controller).to receive(:perform_search).and_return(xapian_result) end @@ -188,7 +190,10 @@ before do @user = FactoryBot.create(:pro_user) sign_in @user - allow(controller).to receive(:feature_enabled?).with(:alaveteli_pro).and_return(true) + allow(controller). + to receive(:feature_enabled?). + with(:alaveteli_pro). + and_return(true) end it 'should redirect pro users to the pro dashboard' do @@ -211,8 +216,11 @@ end it "should redirect from search query URL to pretty URL" do - post :search_redirect, params: { query: "mouse" } # query hidden in POST parameters - expect(response).to redirect_to(action: 'search', combined: "mouse", view: "all") # URL /search/:query/all + # query hidden in POST parameters + post :search_redirect, params: { query: "mouse" } + # URL /search/:query/all + expect(response). + to redirect_to(action: 'search', combined: "mouse", view: "all") end it "should find info request when searching for '\"fancy dog\"'" do @@ -220,7 +228,9 @@ expect(response).to render_template('search') expect(assigns[:xapian_requests].matches_estimated).to eq(1) expect(assigns[:xapian_requests].results.size).to eq(1) - expect(assigns[:xapian_requests].results[0][:model]).to eq(info_request_events(:useless_outgoing_message_event)) + expect(assigns[:xapian_requests].results[0][:model]).to eq( + info_request_events(:useless_outgoing_message_event) + ) assigns[:xapian_requests].words_to_highlight == %w[fancy dog] end @@ -231,29 +241,34 @@ expect(assigns[:xapian_requests].matches_estimated).to eq(1) expect(assigns[:xapian_requests].results.size).to eq(1) - expect(assigns[:xapian_requests].results[0][:model]).to eq(info_request_events(:useless_incoming_message_event)) + expect(assigns[:xapian_requests].results[0][:model]). + to eq(info_request_events(:useless_incoming_message_event)) expect(assigns[:xapian_bodies].matches_estimated).to eq(1) expect(assigns[:xapian_bodies].results.size).to eq(1) - expect(assigns[:xapian_bodies].results[0][:model]).to eq(public_bodies(:geraldine_public_body)) + expect(assigns[:xapian_bodies].results[0][:model]). + to eq(public_bodies(:geraldine_public_body)) end it "should filter results based on end of URL being 'all'" do get :search, params: { combined: "bob/all" } - expect(assigns[:xapian_requests].results.map { |x| x[:model] }).to match_array([ - info_request_events(:useless_outgoing_message_event), - info_request_events(:silly_outgoing_message_event), - info_request_events(:useful_incoming_message_event), - info_request_events(:another_useful_incoming_message_event) - ]) - expect(assigns[:xapian_users].results.map { |x| x[:model] }).to eq([users(:bob_smith_user)]) + expect(assigns[:xapian_requests].results.map { |x| x[:model] }). + to match_array([ + info_request_events(:useless_outgoing_message_event), + info_request_events(:silly_outgoing_message_event), + info_request_events(:useful_incoming_message_event), + info_request_events(:another_useful_incoming_message_event) + ]) + expect(assigns[:xapian_users].results.map { |x| x[:model] }). + to eq([users(:bob_smith_user)]) expect(assigns[:xapian_bodies].results).to eq([]) end it "should filter results based on end of URL being 'users'" do get :search, params: { combined: "bob/users" } expect(assigns[:xapian_requests]).to eq(nil) - expect(assigns[:xapian_users].results.map { |x| x[:model] }).to eq([users(:bob_smith_user)]) + expect(assigns[:xapian_users].results.map { |x| x[:model] }). + to eq([users(:bob_smith_user)]) expect(assigns[:xapian_bodies]).to eq(nil) end @@ -270,12 +285,13 @@ it "should filter results based on end of URL being 'requests'" do get :search, params: { combined: "bob/requests" } - expect(assigns[:xapian_requests].results.map { |x|x[:model] }).to match_array([ - info_request_events(:useless_outgoing_message_event), - info_request_events(:silly_outgoing_message_event), - info_request_events(:useful_incoming_message_event), - info_request_events(:another_useful_incoming_message_event) - ]) + expect(assigns[:xapian_requests].results.map { |x|x[:model] }). + to match_array([ + info_request_events(:useless_outgoing_message_event), + info_request_events(:silly_outgoing_message_event), + info_request_events(:useful_incoming_message_event), + info_request_events(:another_useful_incoming_message_event) + ]) expect(assigns[:xapian_users]).to eq(nil) expect(assigns[:xapian_bodies]).to eq(nil) end @@ -284,7 +300,9 @@ get :search, params: { combined: "quango/bodies" } expect(assigns[:xapian_requests]).to eq(nil) expect(assigns[:xapian_users]).to eq(nil) - expect(assigns[:xapian_bodies].results.map { |x|x[:model] }).to eq([public_bodies(:geraldine_public_body)]) + expect(assigns[:xapian_bodies].results.map { |x|x[:model] }).to eq( + [public_bodies(:geraldine_public_body)] + ) end it 'should prioritise direct matches of public body names' do @@ -348,7 +366,8 @@ end it 'should pass xapian error messages to flash and redirect to a blank search page' do - error_text = "Your query was not quite right. QueryParserError: Syntax: AND " + error_text = "Your query was not quite right. " \ + "QueryParserError: Syntax: AND " get :search, params: { combined: "test AND" } expect(flash[:error]).to eq(error_text) expect(response).to redirect_to(action: 'search', combined: "") diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index 18810286c3..c1d2c6839c 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -72,7 +72,13 @@ before do # Prepend our fixture templates - fixture_theme_path = File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'theme_one') + fixture_theme_path = File.join( + Rails.root, + 'spec', + 'fixtures', + 'theme_views', + 'theme_one' + ) controller.prepend_view_path fixture_theme_path end diff --git a/spec/controllers/info_request_batch_controller_spec.rb b/spec/controllers/info_request_batch_controller_spec.rb index 408b27346e..b91038e065 100644 --- a/spec/controllers/info_request_batch_controller_spec.rb +++ b/spec/controllers/info_request_batch_controller_spec.rb @@ -34,18 +34,30 @@ describe 'assigning @info_requests' do context 'when the batch has been sent' do let!(:first_request) do - FactoryBot.create(:info_request, info_request_batch: info_request_batch, - public_body: first_public_body) + FactoryBot.create( + :info_request, + info_request_batch: info_request_batch, + public_body: first_public_body + ) end let!(:second_request) do - FactoryBot.create(:info_request, info_request_batch: info_request_batch, - public_body: second_public_body) + FactoryBot.create( + :info_request, + info_request_batch: info_request_batch, + public_body: second_public_body + ) end let!(:hidden_request) do - FactoryBot.create(:hidden_request, info_request_batch: info_request_batch) + FactoryBot.create( + :hidden_request, + info_request_batch: info_request_batch + ) end let!(:backpage_request) do - FactoryBot.create(:backpage_request, info_request_batch: info_request_batch) + FactoryBot.create( + :backpage_request, + info_request_batch: info_request_batch + ) end before do @@ -73,7 +85,12 @@ with_feature_enabled(:alaveteli_pro) do action expect(assigns[:info_requests].sort). - to eq([first_request, second_request, hidden_request, backpage_request]) + to eq([ + first_request, + second_request, + hidden_request, + backpage_request + ]) end end end diff --git a/spec/controllers/track_controller_spec.rb b/spec/controllers/track_controller_spec.rb index 92823a9088..7bfb31d35d 100644 --- a/spec/controllers/track_controller_spec.rb +++ b/spec/controllers/track_controller_spec.rb @@ -53,7 +53,8 @@ it "should save a request track and redirect if you are logged in" do sign_in user - allow(TrackThing).to receive(:create_track_for_request).and_return(track_thing) + allow(TrackThing).to receive(:create_track_for_request). + and_return(track_thing) expect(track_thing).to receive(:save).and_call_original get :track_request, params: { url_title: info_request.url_title, @@ -150,8 +151,7 @@ expect(a[2]['event_type']).to eq('sent') end - it 'should return atom/xml for a feed url without format specified, even if the - requester prefers json' do + it 'should return atom/xml for a feed url without format specified, even if the requester prefers json' do request.env['HTTP_ACCEPT'] = 'application/json,text/xml' track_thing = FactoryBot.create(:request_update_track) get :track_request, params: { @@ -176,7 +176,8 @@ it "should save a search track and redirect to the right place" do sign_in user - allow(TrackThing).to receive(:create_track_for_search_query).and_return(track_thing) + allow(TrackThing).to receive(:create_track_for_search_query). + and_return(track_thing) expect(track_thing).to receive(:save).and_call_original get :track_search_query, params: { query_array: "bob variety:sent", feed: 'track' } @@ -228,7 +229,8 @@ long_track = TrackThing.new(track_type: 'search_query', track_query: "lorem ipsum " * 42) sign_in user - allow(TrackThing).to receive(:create_track_for_search_query).and_return(long_track) + allow(TrackThing).to receive(:create_track_for_search_query). + and_return(long_track) get :track_search_query, params: { query_array: "bob variety:sent", feed: 'track' @@ -254,7 +256,8 @@ sign_in user track_thing = TrackThing.new(track_type: 'public_body_updates', public_body: public_body) - allow(TrackThing).to receive(:create_track_for_public_body).and_return(track_thing) + allow(TrackThing).to receive(:create_track_for_public_body). + and_return(track_thing) expect(track_thing).to receive(:save).and_call_original get :track_public_body, params: { url_name: public_body.url_name, @@ -269,7 +272,8 @@ long_track = TrackThing.new(track_type: 'public_body_updates', public_body: public_body, track_query: "lorem ipsum " * 42) - allow(TrackThing).to receive(:create_track_for_public_body).and_return(long_track) + allow(TrackThing).to receive(:create_track_for_public_body). + and_return(long_track) get :track_public_body, params: { url_name: public_body.url_name, feed: 'track', @@ -315,10 +319,14 @@ it "should save a user track and redirect to the right place" do sign_in user - track_thing = TrackThing.new(track_type: 'user_updates', - tracked_user: target_user, - track_query: "requested_by:#{target_user.url_name}") - allow(TrackThing).to receive(:create_track_for_user).and_return(track_thing) + track_thing = TrackThing.new( + track_type: 'user_updates', + tracked_user: target_user, + track_query: "requested_by:#{target_user.url_name}" + ) + allow(TrackThing). + to receive(:create_track_for_user). + and_return(track_thing) expect(track_thing).to receive(:save).and_call_original get :track_user, params: { url_name: target_user.url_name, feed: 'track' } @@ -330,7 +338,9 @@ long_track = TrackThing.new(track_type: 'user_updates', tracked_user: target_user, track_query: "lorem ipsum " * 42) - allow(TrackThing).to receive(:create_track_for_user).and_return(long_track) + allow(TrackThing). + to receive(:create_track_for_user). + and_return(long_track) get :track_user, params: { url_name: target_user.url_name, feed: 'track' } expect(flash[:error]).to match('too long') @@ -484,7 +494,8 @@ track_type: 'search_query', r: '/' } - expect(flash[:notice]).to eq("You will no longer be emailed updates for those alerts") + expect(flash[:notice]). + to eq("You will no longer be emailed updates for those alerts") end end