Skip to content

Commit 74010eb

Browse files
authored
Merge pull request #88 from fastruby/IIRR-41
[IIRR-41] Preserve filters when cloning archived puzzle
2 parents 35d9fef + b10e67e commit 74010eb

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

app/controllers/puzzles/clones_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ def create
44
cloned_puzzle = original_puzzle.clone_puzzle
55

66
if cloned_puzzle.persisted?
7-
redirect_to puzzles_path, notice: "Puzzle cloned. You can now edit the new puzzle."
7+
redirect_back fallback_location: puzzles_path, notice: "Puzzle cloned. You can now edit the new puzzle."
88
else
9-
redirect_to puzzles_path, alert: "Failed to clone puzzle."
9+
redirect_back fallback_location: puzzles_path, alert: "Failed to clone puzzle."
1010
end
1111
end
1212
end

test/controllers/puzzles/clones_controller_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class Puzzles::ClonesControllerTest < ActionDispatch::IntegrationTest
2222
assert_equal "pending", cloned.state
2323
end
2424

25+
test "redirects back to referer to preserve filters" do
26+
original = puzzles(:one)
27+
referer = puzzles_path(hide_cloned_puzzles: true, low_success_rate: true)
28+
29+
sign_in
30+
post puzzle_clone_path(original), headers: { "HTTP_REFERER" => referer }
31+
32+
assert_redirected_to referer
33+
end
34+
2535
test "does not allow unauthenticated users to create a clone" do
2636
original = puzzles(:one)
2737

0 commit comments

Comments
 (0)