Skip to content

Commit

Permalink
WIP: url title permutations
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-griffen committed Nov 20, 2023
1 parent e6c3333 commit 3d5b5ae
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Check failure on line 54 in app/controllers/reports_controller.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 unexpected token tRPAREN (Using Ruby 3.0 parser; configure using `TargetRubyVersion` parameter, under `AllCops`) Raw Output: app/controllers/reports_controller.rb:54:64: F: Lint/Syntax: unexpected token tRPAREN (Using Ruby 3.0 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
end

def set_comment
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/widget_votes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Check warning on line 41 in app/controllers/widget_votes_controller.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Line is too long. [84/80] (https://rubystyle.guide#max-line-length) Raw Output: app/controllers/widget_votes_controller.rb:41:81: C: Layout/LineLength: Line is too long. [84/80] (https://rubystyle.guide#max-line-length)
end

def check_prominence
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/comment/_single_comment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>
<p><%= _("Why specifically do you consider this request unsuitable?") %></p>

<%= form_tag request_report_path(:request_id => @info_request.url_title) do %>
<%= form_tag report_path(:url_title => @info_request.url_title) do %>
<p>
<label class="form_label" for="reason"><%= _('Reason:') %></label>
<%= select_tag :reason, options_for_select(@report_reasons, @reason), :prompt => _("Choose a reason") %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/request/_act.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<% if AlaveteliConfiguration::enable_widgets %>
<div class="act_link">
<i class="act-link-icon act-link-icon--widget"></i>
<%= link_to _("Create a widget for this request"), new_request_widget_path(info_request) %>
<%= link_to _("Create a widget for this request"), new_widget_path(url_title: info_request.url_title) %>
</div>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/request/_after_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</li>
<% else %>
<li>
<%= link_to _("Report this request"), new_request_report_path(:request_id => info_request.url_title) %><span class="action-menu__info-link">
<%= link_to _("Report this request"), new_report_path(:url_title => info_request.url_title) %><span class="action-menu__info-link">
<%= link_to _("Help"), help_about_path(:anchor => "reporting") %>
</span>
</li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/request/_incoming_correspondence.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/views/request/_outgoing_correspondence.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions app/views/widgets/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<%= _("To add a widget for <b>{{info_request_title}}</b>, copy and paste " \
"the following code to your web page:",
:info_request_title => @info_request.title) %>
<textarea autofocus readonly rows='4' cols='60' id='widgetbox'><iframe src='<%= request_widget_url(@info_request) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe></textarea>
<textarea autofocus readonly rows='4' cols='60' id='widgetbox'><iframe src='<%= widget_url(url_title: @info_request.url_title) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe></textarea>

</p>

<p>
<%= _("The widget will look like this:") %>
<br>
<iframe src='<%= request_widget_url(@info_request) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe>
<iframe src='<%= widget_url(url_title: @info_request.url_title) %>' width='320' height='215' frameborder='0' marginwidth='0' marginheight='0'></iframe>
</p>
2 changes: 1 addition & 1 deletion app/views/widgets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/widget_votes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
48 changes: 24 additions & 24 deletions spec/controllers/widgets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -55,26 +55,26 @@

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

context 'for a non-logged-in user with a tracking cookie' do

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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
Loading

0 comments on commit 3d5b5ae

Please sign in to comment.