@@ -126,7 +126,6 @@ class Address < ActiveRecord::Base
126126end
127127
128128class ActiveRecordTest < Minitest ::Test
129-
130129 def setup
131130 drop_all_tables
132131 create_tables
@@ -221,6 +220,32 @@ def test_attribute_was_works_when_options_for_old_encrypted_value_are_different_
221220 assert_equal pw . reverse , account . password
222221 end
223222
223+ # Add ActiveRecord 5.2 specific methods
224+ if ::ActiveRecord ::VERSION ::STRING >= "5.2"
225+ def test_should_create_will_save_change_to_predicate
226+ person = Person . create! ( email : 'test@example.com' )
227+ refute person . will_save_change_to_email?
228+ person . email = 'test@example.com'
229+ refute person . will_save_change_to_email?
230+ person . email = nil
231+ assert person . will_save_change_to_email?
232+ person . email = 'test2@example.com'
233+ assert person . will_save_change_to_email?
234+ end
235+
236+ def test_should_create_saved_change_to_predicate
237+ person = Person . create! ( email : 'test@example.com' )
238+ assert person . saved_change_to_email?
239+ person . reload
240+ person . email = 'test@example.com'
241+ refute person . saved_change_to_email?
242+ person . email = nil
243+ refute person . saved_change_to_email?
244+ person . email = 'test2@example.com'
245+ refute person . saved_change_to_email?
246+ end
247+ end
248+
224249 if ::ActiveRecord ::VERSION ::STRING > "4.0"
225250 def test_should_assign_attributes
226251 @user = UserWithProtectedAttribute . new ( login : 'login' , is_admin : false )
0 commit comments