Skip to content
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: 2 additions & 2 deletions app/controllers/puzzles/clones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ def create
cloned_puzzle = original_puzzle.clone_puzzle

if cloned_puzzle.persisted?
redirect_to puzzles_path, notice: "Puzzle cloned. You can now edit the new puzzle."
redirect_back fallback_location: puzzles_path, notice: "Puzzle cloned. You can now edit the new puzzle."
else
redirect_to puzzles_path, alert: "Failed to clone puzzle."
redirect_back fallback_location: puzzles_path, alert: "Failed to clone puzzle."
end
end
end
10 changes: 10 additions & 0 deletions test/controllers/puzzles/clones_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class Puzzles::ClonesControllerTest < ActionDispatch::IntegrationTest
assert_equal "pending", cloned.state
end

test "redirects back to referer to preserve filters" do
original = puzzles(:one)
referer = puzzles_path(hide_cloned_puzzles: true, low_success_rate: true)

sign_in
post puzzle_clone_path(original), headers: { "HTTP_REFERER" => referer }

assert_redirected_to referer
end

test "does not allow unauthenticated users to create a clone" do
original = puzzles(:one)

Expand Down