-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3d0d65
commit 16daef0
Showing
3 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
module TalksHelper | ||
def normalize_back_to(back_to) | ||
return nil if back_to.blank? | ||
|
||
uri = URI.parse(back_to) | ||
params = Rack::Utils.parse_query(uri.query.to_s).except("infinite_count", "format", "page") | ||
uri.query = params.present? ? params.to_query : nil | ||
uri.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "test_helper" | ||
|
||
class TalksHelperTest < ActionView::TestCase | ||
test "normalize_back_to removes infinite_count and format params" do | ||
assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails") | ||
assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=1") | ||
assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&format=turbo_stream") | ||
assert_equal "talks_url?page=2", normalize_back_to("talks_url?format=turbo_stream&page=2") | ||
assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=1&format=turbo_stream") | ||
assert_equal "talks_url?s=rails", normalize_back_to("talks_url?s=rails&infinite_count=111&format=turbo_stream") | ||
end | ||
|
||
test "normalize_back_to handles empty params" do | ||
assert_equal "talks_url", normalize_back_to("talks_url") | ||
end | ||
|
||
test "normalize_back_to preserves other params" do | ||
result = normalize_back_to("talks_url?topic=ruby&speaker=john&infinite_count=1") | ||
assert_equal ["speaker=john", "topic=ruby"].sort, URI.parse(result).query.split("&").sort | ||
end | ||
end |