Scope Webhooks to Collections

This commit is contained in:
Stanko K.R.
2025-09-15 16:05:36 +02:00
parent 25b2daad93
commit 02a421675f
20 changed files with 122 additions and 68 deletions
+18 -14
View File
@@ -6,25 +6,27 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
end
test "index" do
get webhooks_path
get collection_webhooks_path(collections(:writebook))
assert_response :success
end
test "show" do
webhook = webhooks(:active)
get webhook_path(webhook)
get collection_webhook_path(webhook.collection, webhook)
assert_response :success
end
test "new" do
get new_webhook_path
get new_collection_webhook_path(collections(:writebook))
assert_response :success
assert_select "form"
end
test "create with valid params" do
collection = collections(:writebook)
assert_difference "Webhook.count", 1 do
post webhooks_path, params: {
post collection_webhooks_path(collection), params: {
webhook: {
name: "Test Webhook",
url: "https://example.com/webhook",
@@ -35,15 +37,17 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
webhook = Webhook.order(id: :desc).first
assert_redirected_to webhook_path(webhook)
assert_redirected_to collection_webhook_path(webhook.collection, webhook)
assert_equal collection, webhook.collection
assert_equal "Test Webhook", webhook.name
assert_equal "https://example.com/webhook", webhook.url
assert_equal [ "card_created", "card_closed" ], webhook.subscribed_actions
end
test "create with invalid params" do
collection = collections(:writebook)
assert_no_difference "Webhook.count" do
post webhooks_path, params: {
post collection_webhooks_path(collection), params: {
webhook: {
name: "",
url: "invalid-url"
@@ -57,14 +61,14 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
test "edit" do
webhook = webhooks(:active)
get edit_webhook_path(webhook)
get edit_collection_webhook_path(webhook.collection, webhook)
assert_response :success
assert_select "form"
end
test "update with valid params" do
webhook = webhooks(:active)
patch webhook_path(webhook), params: {
patch collection_webhook_path(webhook.collection, webhook), params: {
webhook: {
name: "Updated Webhook",
subscribed_actions: [ "card_created" ]
@@ -73,14 +77,14 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
webhook.reload
assert_redirected_to webhook_path(webhook)
assert_redirected_to collection_webhook_path(webhook.collection, webhook)
assert_equal "Updated Webhook", webhook.name
assert_equal [ "card_created" ], webhook.subscribed_actions
end
test "update with invalid params" do
webhook = webhooks(:active)
patch webhook_path(webhook), params: {
patch collection_webhook_path(webhook.collection, webhook), params: {
webhook: {
name: ""
}
@@ -90,7 +94,7 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
assert_select "form"
assert_no_changes -> { webhook.reload.url } do
patch webhook_path(webhook), params: {
patch collection_webhook_path(webhook.collection, webhook), params: {
webhook: {
name: "Updated Webhook",
url: "https://different.com/webhook"
@@ -98,16 +102,16 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest
}
end
assert_redirected_to webhook_path(webhook)
assert_redirected_to collection_webhook_path(webhook.collection, webhook)
end
test "destroy" do
webhook = webhooks(:active)
assert_difference "Webhook.count", -1 do
delete webhook_path(webhook)
delete collection_webhook_path(webhook.collection, webhook)
end
assert_redirected_to webhooks_path
assert_redirected_to collection_webhooks_path(webhook.collection)
end
end