From 17ed0a13f66f9d1f3b0ab0f10c6e5bf72c61a810 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Thu, 14 Mar 2019 14:01:29 +0100 Subject: [PATCH] Refactoring: Migrate user_mail_delivery_failed to RSpec --- spec/models/user_spec.rb | 23 ++++++++++++ test/unit/user_mail_delivery_failed_test.rb | 40 --------------------- 2 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 test/unit/user_mail_delivery_failed_test.rb diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 03d5388b7..9bc4cd07b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -436,6 +436,29 @@ RSpec.describe User, type: :model do end end end + + describe '#preferences' do + describe '"mail_delivery_failed{,_data}" keys' do + before do + user.update( + preferences: { + mail_delivery_failed: true, + mail_delivery_failed_data: Time.current + } + ) + end + + it 'deletes "mail_delivery_failed"' do + expect { user.update(email: Faker::Internet.email) } + .to change { user.preferences.key?(:mail_delivery_failed) }.to(false) + end + + it 'leaves "mail_delivery_failed_data" untouched' do + expect { user.update(email: Faker::Internet.email) } + .to not_change { user.preferences[:mail_delivery_failed_data] } + end + end + end end describe 'Associations:' do diff --git a/test/unit/user_mail_delivery_failed_test.rb b/test/unit/user_mail_delivery_failed_test.rb deleted file mode 100644 index 749e6e2fd..000000000 --- a/test/unit/user_mail_delivery_failed_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'test_helper' - -class UserMailDeliveryFailedTest < ActiveSupport::TestCase - setup do - - UserInfo.current_user_id = 1 - - roles = Role.where(name: 'Customer') - @customer1 = User.create_or_update( - login: 'user-mail-delivery-failed-customer1@example.com', - firstname: 'UserOutOfOffice', - lastname: 'Customer1', - email: 'user-mail-delivery-failed-customer1@example.com', - password: 'agentpw', - active: true, - roles: roles, - ) - - end - - test 'check reset of mail_delivery_failed' do - - @customer1.preferences[:mail_delivery_failed] = true - @customer1.preferences[:mail_delivery_failed_data] = Time.zone.now - @customer1.save! - @customer1.reload - - assert_equal(@customer1.preferences[:mail_delivery_failed], true) - assert(@customer1.preferences[:mail_delivery_failed_data]) - - @customer1.email = 'new-user-mail-delivery-failed-customer1@example.com' - @customer1.save! - @customer1.reload - - assert_not(@customer1.preferences[:mail_delivery_failed], true) - assert(@customer1.preferences[:mail_delivery_failed_data]) - - end - -end