Skip to content

Commit

Permalink
Fix admin notification with relative URLs
Browse files Browse the repository at this point in the history
The test was passing because it was using the rack driver, but on real
browsers it wasn't generating the expected URL.
  • Loading branch information
javierm committed Mar 31, 2021
1 parent f33d2cc commit d7563be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/admin_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def validate_segment_recipient
def complete_link_url
return unless link.present?

unless self.link[/\Ahttp:\/\//] || self.link[/\Ahttps:\/\//]
unless link =~ /\A(http:\/\/|https:\/\/|\/)/
self.link = "http://#{self.link}"
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/admin_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
expect(admin_notification.link).to eq("http://www.lol.consul.dev")
end

it "does not modify a relative link" do
admin_notification.link = "/proposals"

expect(admin_notification).to be_valid
expect(admin_notification.link).to eq("/proposals")
end

it "does not modify a link with http://" do
admin_notification.link = "http://lol.consul.dev"

Expand Down
2 changes: 1 addition & 1 deletion spec/system/notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
expect(page.current_url).to eq("https://www.external.link.dev/")
end

scenario "With internal link" do
scenario "With internal link", :js do
admin_notification.update!(link: "/stats")

visit notifications_path
Expand Down

0 comments on commit d7563be

Please sign in to comment.