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

Remove suggested_url validation from feedback model #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ GEM
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.1)
google-protobuf (3.25.1-aarch64-linux)
google-protobuf (3.25.1-x86_64-darwin)
google-protobuf (3.25.1-x86_64-linux)
googleapis-common-protos-types (1.10.0)
google-protobuf (~> 3.18)
Expand Down Expand Up @@ -228,6 +229,8 @@ GEM
nio4r (2.6.1)
nokogiri (1.15.5-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
null_logger (0.0.1)
Expand Down Expand Up @@ -607,6 +610,7 @@ GEM

PLATFORMS
aarch64-linux
x86_64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
2 changes: 0 additions & 2 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class Feedback
include ActiveModel::Model
include ActiveModel::Validations

validates :suggested_url, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), allow_blank: true, message: "must be a valid URL" }

attr_accessor :search_query, :result_ratings, :suggested_url, :comments, :user_id

def result_ratings_attributes=(attributes)
Expand Down
58 changes: 20 additions & 38 deletions spec/system/feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,27 @@
expect(page).to have_content("Thank you for your feedback")
end

scenario "submitting feedback with a suggested URL and comments" do
perform_search

# Allows the user to give a suggested URL
fill_in "URL for the best possible result", with: "https://www.gov.uk/"

# Allows the user to give comments
fill_in "Your comments about these results", with: "Looking good!"

click_on "Submit feedback"

expect(bigquery_table).to have_received(:insert).with(
hash_including(
{
comments: "Looking good!",
suggested_url: "https://www.gov.uk/",
},
),
)
end

scenario "submitting feedback with an invalid suggested URL fails but doesn't lose input" do
perform_search

fill_in "URL for the best possible result", with: "bad url"
within(all(".search-results__ranking")[1]) { choose "Good" }
click_on "Submit feedback"

# Doesn't send the data to Bigquery
expect(bigquery_table).not_to have_received(:insert)

# Shows an error message
expect(page).to have_content("URL for the best possible result must be a valid URL")

# Doesn't lose the input
within(all(".search-results__ranking")[1]) do
expect(page).to have_checked_field("Good")
["http://www.gov.uk", "https://www.gov.uk/", "/relative_url"].each do |suggested_url|
scenario `submitting feedback with a valid suggested URL (#{suggested_url}) and comments` do
perform_search

# Allows the user to give a suggested URL
fill_in "URL for the best possible result", with: suggested_url

# Allows the user to give comments
fill_in "Your comments about these results", with: "Looking good!"

click_on "Submit feedback"

expect(bigquery_table).to have_received(:insert).with(
hash_including(
{
comments: "Looking good!",
suggested_url:,
},
),
)
end
expect(page).to have_field("URL for the best possible result", with: "bad url")
end

scenario "submitting feedback includes user ID" do
Expand Down