From 3d5b5ae1dbef7f942fcc521368f05c98aa9c0579 Mon Sep 17 00:00:00 2001 From: Alexander Griffen Date: Mon, 20 Nov 2023 11:07:27 +0000 Subject: [PATCH] WIP: url title permutations --- app/controllers/reports_controller.rb | 2 +- app/controllers/widget_votes_controller.rb | 2 +- app/controllers/widgets_controller.rb | 2 +- app/views/comment/_single_comment.html.erb | 2 +- app/views/reports/new.html.erb | 2 +- app/views/request/_act.html.erb | 2 +- app/views/request/_after_actions.html.erb | 2 +- .../request/_incoming_correspondence.html.erb | 2 +- .../request/_outgoing_correspondence.html.erb | 2 +- app/views/widgets/new.html.erb | 4 +- app/views/widgets/show.html.erb | 2 +- config/routes.rb | 2 +- .../widget_votes_controller_spec.rb | 18 +++---- spec/controllers/widgets_controller_spec.rb | 48 +++++++++---------- spec/integration/reports_controller_spec.rb | 4 +- 15 files changed, 48 insertions(+), 48 deletions(-) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 9913f6f7211..57cc7fea098 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -51,7 +51,7 @@ def new def set_info_request @info_request = InfoRequest .not_embargoed - .find_by_url_title!(params[:request_id]) + .find_by_url_title!(params[:url_title])) end def set_comment diff --git a/app/controllers/widget_votes_controller.rb b/app/controllers/widget_votes_controller.rb index cf04d0f63c2..df3c6c1b311 100644 --- a/app/controllers/widget_votes_controller.rb +++ b/app/controllers/widget_votes_controller.rb @@ -38,7 +38,7 @@ def check_widget_config end def find_info_request - @info_request = InfoRequest.not_embargoed.find(params[:request_id]) + @info_request = InfoRequest.not_embargoed.find_by(url_title: params[:url_title]) end def check_prominence diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb index b2c801b4755..3ce63730ca0 100644 --- a/app/controllers/widgets_controller.rb +++ b/app/controllers/widgets_controller.rb @@ -43,7 +43,7 @@ def check_widget_config end def find_info_request - @info_request = InfoRequest.find(params[:request_id]) + @info_request = InfoRequest.find_by(url_title: params[:url_title]) end def check_prominence diff --git a/app/views/comment/_single_comment.html.erb b/app/views/comment/_single_comment.html.erb index 286e6c9eaa8..c7b034a9118 100644 --- a/app/views/comment/_single_comment.html.erb +++ b/app/views/comment/_single_comment.html.erb @@ -35,7 +35,7 @@ <% link_to_this_url = comment_url(comment) %> <% report_path = - new_request_report_path(request_id: @info_request.url_title, + new_report_path(url_title: @info_request.url_title, comment_id: comment.id) %> <%= render partial: 'request/correspondence_footer', diff --git a/app/views/reports/new.html.erb b/app/views/reports/new.html.erb index 0f52a0d6ceb..520bb2ba2e0 100644 --- a/app/views/reports/new.html.erb +++ b/app/views/reports/new.html.erb @@ -11,7 +11,7 @@

<%= _("Why specifically do you consider this request unsuitable?") %>

- <%= form_tag request_report_path(:request_id => @info_request.url_title) do %> + <%= form_tag report_path(:url_title => @info_request.url_title) do %>

<%= select_tag :reason, options_for_select(@report_reasons, @reason), :prompt => _("Choose a reason") %> diff --git a/app/views/request/_act.html.erb b/app/views/request/_act.html.erb index a055c6148a3..f0c53cdb8a7 100644 --- a/app/views/request/_act.html.erb +++ b/app/views/request/_act.html.erb @@ -44,7 +44,7 @@ <% if AlaveteliConfiguration::enable_widgets %>

<% end %> diff --git a/app/views/request/_after_actions.html.erb b/app/views/request/_after_actions.html.erb index a1522cd9af4..18893fea387 100644 --- a/app/views/request/_after_actions.html.erb +++ b/app/views/request/_after_actions.html.erb @@ -61,7 +61,7 @@ <% else %>
  • - <%= link_to _("Report this request"), new_request_report_path(:request_id => info_request.url_title) %> + <%= link_to _("Report this request"), new_report_path(:url_title => info_request.url_title) %> <%= link_to _("Help"), help_about_path(:anchor => "reporting") %>
  • diff --git a/app/views/request/_incoming_correspondence.html.erb b/app/views/request/_incoming_correspondence.html.erb index ade5c8a466c..b5ecbdeaeaf 100644 --- a/app/views/request/_incoming_correspondence.html.erb +++ b/app/views/request/_incoming_correspondence.html.erb @@ -37,7 +37,7 @@ <% link_to_this_url = incoming_message_url(incoming_message) %> <% report_path = - new_request_report_path(request_id: @info_request.url_title, + new_report_path(url_title: @info_request.url_title, incoming_message_id: incoming_message.id) %> <%= render partial: 'request/correspondence_footer', diff --git a/app/views/request/_outgoing_correspondence.html.erb b/app/views/request/_outgoing_correspondence.html.erb index 43e0fbdc4ae..773aa676a68 100644 --- a/app/views/request/_outgoing_correspondence.html.erb +++ b/app/views/request/_outgoing_correspondence.html.erb @@ -46,7 +46,7 @@ <% link_to_this_url = outgoing_message_url(outgoing_message) %> <% report_path = - new_request_report_path(request_id: @info_request.url_title, + new_report_path(url_title: @info_request.url_title, outgoing_message_id: outgoing_message.id) %> <%= render partial: 'request/correspondence_footer', diff --git a/app/views/widgets/new.html.erb b/app/views/widgets/new.html.erb index 0d24d2ff664..836c9b124ac 100644 --- a/app/views/widgets/new.html.erb +++ b/app/views/widgets/new.html.erb @@ -4,12 +4,12 @@ <%= _("To add a widget for {{info_request_title}}, copy and paste " \ "the following code to your web page:", :info_request_title => @info_request.title) %> - +

    <%= _("The widget will look like this:") %>
    - +

    diff --git a/app/views/widgets/show.html.erb b/app/views/widgets/show.html.erb index d0a1207720b..084a35d6a30 100644 --- a/app/views/widgets/show.html.erb +++ b/app/views/widgets/show.html.erb @@ -57,7 +57,7 @@ <%= _('I also want to know!') %> <% end %> <% else %> - <%= form_tag request_widget_votes_url(@info_request), + <%= form_tag widget_votes_url(url_title: @info_request.url_title), :method => 'post', :target => '_top' do %> <%= submit_tag _('I also want to know!'), :class => 'alaveteli-widget__bottom__action alaveteli-widget__button--create-vote', diff --git a/config/routes.rb b/config/routes.rb index 0889f08be84..db6e17baf4c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -228,7 +228,7 @@ def matches?(request) end get '/health_checks' => redirect('/health/checks') - resources :request, :only => [] do + scope path: 'request/:url_title' do resource :report, :only => [:new, :create] resource :widget, :only => [:new, :show] resources :widget_votes, :only => [:create] diff --git a/spec/controllers/widget_votes_controller_spec.rb b/spec/controllers/widget_votes_controller_spec.rb index 0c57d77b917..3527d466f3c 100644 --- a/spec/controllers/widget_votes_controller_spec.rb +++ b/spec/controllers/widget_votes_controller_spec.rb @@ -12,12 +12,12 @@ end it 'should find the info request' do - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(assigns[:info_request]).to eq(info_request) end it 'should redirect to the track path for the info request' do - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } track_thing = TrackThing.create_track_for_request(info_request) expect(response).to redirect_to(do_track_path(track_thing)) end @@ -26,7 +26,7 @@ it 'sets a tracking cookie' do allow(SecureRandom).to receive(:hex).and_return(mock_cookie) - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(cookies[:widget_vote]).to eq(mock_cookie) end @@ -36,7 +36,7 @@ widget_votes. where(cookie: mock_cookie) - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(votes.size).to eq(1) end @@ -47,7 +47,7 @@ it 'retains the existing tracking cookie' do request.cookies['widget_vote'] = mock_cookie - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(cookies[:widget_vote]).to eq(mock_cookie) end @@ -57,7 +57,7 @@ widget_votes. where(cookie: mock_cookie) - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(votes.size).to eq(1) end @@ -69,7 +69,7 @@ it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } }.to raise_error(ActiveRecord::RecordNotFound) end @@ -80,7 +80,7 @@ it 'should return a 403' do info_request.prominence = 'hidden' info_request.save! - post :create, params: { request_id: info_request.id } + post :create, params: { url_title: info_request.url_title } expect(response.code).to eq("403") end @@ -91,7 +91,7 @@ it 'should raise an ActiveRecord::RecordNotFound error' do embargoed_request = FactoryBot.create(:embargoed_request) expect { - post :create, params: { request_id: embargoed_request.id } + post :create, params: { url_title: embargoed_request.url_title } }.to raise_error ActiveRecord::RecordNotFound end end diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index d942d9ff7aa..c44ec7e67d8 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -12,22 +12,22 @@ end it 'should render the widget template' do - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(response).to render_template('show') end it 'should find the info request' do - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:info_request]).to eq(@info_request) end it 'should create a track thing for the request' do - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:track_thing].info_request).to eq(@info_request) end it 'should assign the request status' do - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:status]).to eq(@info_request.calculate_status) end @@ -44,7 +44,7 @@ @info_request.widget_votes.create(cookie: SecureRandom.hex(10)) end - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } # Count should be 5 # 1 for the request's owning user @@ -55,18 +55,18 @@ it 'sets user_owns_request to true if the user owns the request' do sign_in @info_request.user - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:user_owns_request]).to be true end it 'sets user_owns_request to false if the user does not own the request' do sign_in FactoryBot.create(:user) - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:user_owns_request]).to be false end it 'should not send an x-frame-options header' do - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(response.headers["X-Frame-Options"]).to be_nil end @@ -74,7 +74,7 @@ it 'will not find existing tracks' do request.cookies['widget_vote'] = mock_cookie - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_track]).to be_nil end @@ -83,14 +83,14 @@ info_request: @info_request, cookie: mock_cookie) request.cookies['widget_vote'] = vote.cookie - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be true end it 'will not find any existing votes if none exist' do WidgetVote.delete_all request.cookies['widget_vote'] = mock_cookie - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be false end @@ -100,13 +100,13 @@ it 'will not find existing tracks' do request.cookies['widget_vote'] = nil - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_track]).to be_nil end it 'will not find any existing votes' do request.cookies['widget_vote'] = nil - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be false end @@ -122,7 +122,7 @@ track.save! sign_in user - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_track]).to eq(track) end @@ -136,7 +136,7 @@ user = FactoryBot.create(:user) sign_in user - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_track]).to be_nil end @@ -149,7 +149,7 @@ sign_in @info_request.user request.cookies['widget_vote'] = mock_cookie - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be true end @@ -160,7 +160,7 @@ sign_in @info_request.user request.cookies['widget_vote'] = mock_cookie - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be false end @@ -172,7 +172,7 @@ it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } }.to raise_error(ActiveRecord::RecordNotFound) end @@ -183,7 +183,7 @@ it 'should return a 403' do @info_request.prominence = 'hidden' @info_request.save! - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(response.code).to eq("403") end @@ -193,7 +193,7 @@ cookie: mock_cookie) sign_in @info_request.user - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(assigns[:existing_vote]).to be false end @@ -210,12 +210,12 @@ end it 'should render the create widget template' do - get :new, params: { request_id: @info_request.id } + get :new, params: { url_title: @info_request.url_title } expect(response).to render_template('new') end it 'should find the info request' do - get :new, params: { request_id: @info_request.id } + get :new, params: { url_title: @info_request.url_title } expect(assigns[:info_request]).to eq(@info_request) end @@ -224,7 +224,7 @@ it 'raises ActiveRecord::RecordNotFound' do allow(AlaveteliConfiguration).to receive(:enable_widgets).and_return(false) expect { - get :new, params: { request_id: @info_request.id } + get :new, params: { url_title: @info_request.url_title } }.to raise_error(ActiveRecord::RecordNotFound) end @@ -235,7 +235,7 @@ it 'should return a 403' do @info_request.prominence = 'hidden' @info_request.save! - get :show, params: { request_id: @info_request.id } + get :show, params: { url_title: @info_request.url_title } expect(response.code).to eq("403") end diff --git a/spec/integration/reports_controller_spec.rb b/spec/integration/reports_controller_spec.rb index 959a306f400..02b5df319de 100644 --- a/spec/integration/reports_controller_spec.rb +++ b/spec/integration/reports_controller_spec.rb @@ -12,14 +12,14 @@ describe 'when not logged in' do it "should redirect to the login page" do - visit new_request_report_path(request_id: request.url_title, + visit new_report_path(url_title: request.url_title, comment_id: comment.id) expect(page).to have_content "create an account or sign in" end it "should not lose the comment_id post login" do - visit new_request_report_path(request_id: request.url_title, + visit new_report_path(url_title: request.url_title, comment_id: comment.id) fill_in :user_signin_email, with: user.email