Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surveys: add a handler for the URL we sent in the letters #152

Merged
merged 3 commits into from
May 10, 2021

Conversation

freesteph
Copy link
Contributor

No description provided.

@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 09:10 Inactive
@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 09:18 Inactive
Copy link
Member

@pixeltrix pixeltrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept is 👍🏻

@@ -142,7 +142,11 @@
end
end

Given('I see the summary {string} with') do |summary, table|
When('I open a survey link for UPRN {int}') do |uprn|
visit root_path + "?uprn=#{uprn}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use visit "/?uprn=#{uprn}" - I prefer to avoid url helpers in tests so that bugs in routing don't get masked.

Scenario: Alex opens a survey link
Given a building exists with UPRN 777
When I open a survey link for UPRN 777
Then the page contains "Your details"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a scenario for failure as well

</div>
</div>
</div>
<% end %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is the right component here - should probably use a notification banner:

alphagov/govuk-design-system-backlog#46 (comment)

building = Building.find_by(uprn: params[:uprn])

if building.nil?
redirect_to root_path, alert: I18n.t("errors.unknown_uprn", uprn: params[:uprn])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we not use flash.now rather than redirecting?


@survey = Survey::Record.find_or_create_by(
building_id: building.id,
session_id: session.id.to_s,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the to_s necessary?

return
end

@survey = Survey::Record.find_or_create_by(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create the record through the building and avoid having to set building_id:

begin
  survey = building.find_or_create_by!(session_id: session.id)
rescue ActiveRecord::RecordNotUnique
  retry
end

redirect_to goto_url("ownership")

The rescue is to handle any race conditions.

stage: "ownership"
)

redirect_to survey_path(@survey, format: "html")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why the format is needed but we can use goto_url instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting an UnknownFormatError but I can't seem to reproduce that anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it happens in the Cucumber tests, presumably because it's a headless browser?

@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 14:22 Inactive
@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 14:25 Inactive
@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 14:26 Inactive
@freesteph freesteph temporarily deployed to southwark-bsp-pr-152 May 10, 2021 14:27 Inactive
@freesteph freesteph merged commit 25a71a6 into main May 10, 2021
@freesteph freesteph deleted the fix/survey-links branch May 10, 2021 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants