diff --git a/test/factories/checks.rb b/test/factories/checks.rb index 27c383c..885ffd2 100644 --- a/test/factories/checks.rb +++ b/test/factories/checks.rb @@ -83,13 +83,5 @@ FactoryBot.define do trait :inactive do active false end - - trait :with_notifications do - after :create do |check| - create_list :check_notification, 2, - check: check, - notification: build(:notification, user: check.user) - end - end end end diff --git a/test/factories/notifications.rb b/test/factories/notifications.rb index 434e386..6d5b348 100644 --- a/test/factories/notifications.rb +++ b/test/factories/notifications.rb @@ -31,7 +31,7 @@ FactoryBot.define do user interval 30 channel :email - label { "#{recipient} (#{interval})" } + sequence(:label) { |n| "#{recipient}-#{n} (#{interval})" } recipient "recipient@domain.fr" trait :email do diff --git a/test/system/checks_test.rb b/test/system/checks_test.rb index 71e459d..14b4fb4 100644 --- a/test/system/checks_test.rb +++ b/test/system/checks_test.rb @@ -53,48 +53,54 @@ class ChecksTest < ApplicationSystemTestCase fill_and_valid_new_check end - test "dissociate a notification" do - check = create(:check, :with_notifications, user: @user) + test "dettach a notification from a check" do + initial_notifications_count = 2 + check = create(:check, user: @user) + existing_notifications = create_list(:notification, initial_notifications_count, user: @user) + check.notifications << existing_notifications + notification = create(:notification, label: "label-notification", user: @user) check.notifications << notification visit edit_check_path(check) - uncheck notification.label - click_button "Update Check" notification.reload + check.reload + assert_equal 0, notification.checks_count - assert_equal 2, check.check_notifications.count + assert_equal initial_notifications_count, check.notifications.count end - test "associate a notification" do + test "attach a notification to a check" do check = create(:check, user: @user) notification = create(:notification, label: "label-notification", user: @user) - visit edit_check_path(check) + visit edit_check_path(check) check notification.label click_button "Update Check" notification.reload + check.reload assert_equal 1, notification.checks_count assert_equal 1, check.check_notifications.count end test "update a check" do - check = create(:check, :with_notifications, domain: "dom-with-notif.net", user: @user) + check = create(:check, domain: "dom-with-notif.net", user: @user) + check.notifications << create_list(:notification, 2, user: @user) + visit edit_check_path(check) - fill_in "check[comment]", with: "My comment" - click_button "Update Check" assert_equal checks_path, page.current_path - assert page.has_css?(".alert-success") + check.reload + assert_equal "My comment", check.comment end