]> git.openstreetmap.org Git - rails.git/commitdiff
Replace 'remove this redaction' confirmation and request with Turbo
authorAnton Khorev <tony29@yandex.ru>
Wed, 11 Sep 2024 14:43:37 +0000 (17:43 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 11 Sep 2024 14:43:37 +0000 (17:43 +0300)
app/views/redactions/show.html.erb
test/system/redaction_destroy_test.rb [new file with mode: 0644]

index 5b9749a5113b7f2c3caa686b98c84b7b3103c75a..fe073d123752ffbfeadf6e6fb23c6699d54a78ec 100644 (file)
@@ -18,7 +18,7 @@
     <%= link_to t(".edit"), edit_redaction_path(@redaction), :class => "btn btn-outline-primary" %>
   <% end %>
   <% if can?(:destroy, Redaction) %>
-    <%= link_to t(".destroy"), @redaction, :method => "delete", :class => "btn btn-outline-danger", :remote => true, :data => { :confirm => t(".confirm") } %>
+    <%= link_to t(".destroy"), @redaction, :class => "btn btn-outline-danger", :data => { :turbo => true, :turbo_method => "DELETE", :turbo_confirm => t(".confirm") } %>
   <% end %>
 </div>
 <% end %>
diff --git a/test/system/redaction_destroy_test.rb b/test/system/redaction_destroy_test.rb
new file mode 100644 (file)
index 0000000..db0b016
--- /dev/null
@@ -0,0 +1,33 @@
+require "application_system_test_case"
+
+class RedactionDestroyTest < ApplicationSystemTestCase
+  test "fails to delete nonempty redaction" do
+    redaction = create(:redaction, :title => "Some-unwanted-data-redaction")
+    create(:old_node, :redaction => redaction)
+
+    sign_in_as create(:moderator_user)
+    visit redaction_path(redaction)
+    assert_text "Some-unwanted-data-redaction"
+
+    accept_alert do
+      click_on "Remove this redaction"
+    end
+    assert_text "Redaction is not empty"
+    assert_text "Some-unwanted-data-redaction"
+  end
+
+  test "deletes empty redaction" do
+    redaction = create(:redaction, :title => "No-unwanted-data-redaction")
+
+    sign_in_as create(:moderator_user)
+    visit redaction_path(redaction)
+    assert_text "No-unwanted-data-redaction"
+
+    accept_alert do
+      click_on "Remove this redaction"
+    end
+    assert_text "Redaction destroyed"
+    assert_text "List of Redactions"
+    assert_no_text "No-unwanted-data-redaction"
+  end
+end