diff options
Diffstat (limited to 'activerecord/test/cases/callbacks_test.rb')
-rw-r--r-- | activerecord/test/cases/callbacks_test.rb | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/activerecord/test/cases/callbacks_test.rb b/activerecord/test/cases/callbacks_test.rb index 8a722b4f22..e2352bd9f9 100644 --- a/activerecord/test/cases/callbacks_test.rb +++ b/activerecord/test/cases/callbacks_test.rb @@ -1,9 +1,9 @@ require "cases/helper" -require 'models/developer' -require 'models/computer' +require "models/developer" +require "models/computer" class CallbackDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" class << self def callback_string(callback_method) @@ -16,7 +16,7 @@ class CallbackDeveloper < ActiveRecord::Base def define_callback_method(callback_method) define_method(callback_method) do - self.history << [callback_method, :method] + history << [callback_method, :method] end send(callback_method, :"#{callback_method}") end @@ -31,7 +31,7 @@ class CallbackDeveloper < ActiveRecord::Base end ActiveRecord::Callbacks::CALLBACKS.each do |callback_method| - next if callback_method.to_s.start_with?('around_') + next if callback_method.to_s.start_with?("around_") define_callback_method(callback_method) ActiveSupport::Deprecation.silence { send(callback_method, callback_string(callback_method)) } send(callback_method, callback_proc(callback_method)) @@ -55,19 +55,18 @@ class CallbackDeveloperWithHaltedValidation < CallbackDeveloper end class ParentDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" attr_accessor :after_save_called before_validation {|record| record.after_save_called = true} end class ChildDeveloper < ParentDeveloper - end class ImmutableDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" - validates_inclusion_of :salary, :in => 50000..200000 + validates_inclusion_of :salary, in: 50000..200000 before_save :cancel before_destroy :cancel @@ -79,7 +78,7 @@ class ImmutableDeveloper < ActiveRecord::Base end class DeveloperWithCanceledCallbacks < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" validates_inclusion_of :salary, in: 50000..200000 @@ -93,19 +92,19 @@ class DeveloperWithCanceledCallbacks < ActiveRecord::Base end class OnCallbacksDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" before_validation { history << :before_validation } - before_validation(:on => :create){ history << :before_validation_on_create } - before_validation(:on => :update){ history << :before_validation_on_update } + before_validation(on: :create){ history << :before_validation_on_create } + before_validation(on: :update){ history << :before_validation_on_update } validate do history << :validate end after_validation { history << :after_validation } - after_validation(:on => :create){ history << :after_validation_on_create } - after_validation(:on => :update){ history << :after_validation_on_update } + after_validation(on: :create){ history << :after_validation_on_create } + after_validation(on: :update){ history << :after_validation_on_update } def history @history ||= [] @@ -113,17 +112,17 @@ class OnCallbacksDeveloper < ActiveRecord::Base end class ContextualCallbacksDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" before_validation { history << :before_validation } - before_validation :before_validation_on_create_and_update, :on => [ :create, :update ] + before_validation :before_validation_on_create_and_update, on: [ :create, :update ] validate do history << :validate end after_validation { history << :after_validation } - after_validation :after_validation_on_create_and_update, :on => [ :create, :update ] + after_validation :after_validation_on_create_and_update, on: [ :create, :update ] def before_validation_on_create_and_update history << "before_validation_on_#{self.validation_context}".to_sym @@ -139,7 +138,7 @@ class ContextualCallbacksDeveloper < ActiveRecord::Base end class CallbackCancellationDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" attr_reader :after_save_called, :after_create_called, :after_update_called, :after_destroy_called attr_accessor :cancel_before_save, :cancel_before_create, :cancel_before_update, :cancel_before_destroy @@ -156,7 +155,7 @@ class CallbackCancellationDeveloper < ActiveRecord::Base end class CallbackHaltedDeveloper < ActiveRecord::Base - self.table_name = 'developers' + self.table_name = "developers" attr_reader :after_save_called, :after_create_called, :after_update_called, :after_destroy_called attr_accessor :cancel_before_save, :cancel_before_create, :cancel_before_update, :cancel_before_destroy @@ -252,7 +251,7 @@ class CallbacksTest < ActiveRecord::TestCase end def test_create - david = CallbackDeveloper.create('name' => 'David', 'salary' => 1000000) + david = CallbackDeveloper.create("name" => "David", "salary" => 1000000) assert_equal [ [ :after_initialize, :method ], [ :after_initialize, :string ], @@ -298,7 +297,7 @@ class CallbacksTest < ActiveRecord::TestCase end def test_validate_on_create - david = OnCallbacksDeveloper.create('name' => 'David', 'salary' => 1000000) + david = OnCallbacksDeveloper.create("name" => "David", "salary" => 1000000) assert_equal [ :before_validation, :before_validation_on_create, @@ -309,7 +308,7 @@ class CallbacksTest < ActiveRecord::TestCase end def test_validate_on_contextual_create - david = ContextualCallbacksDeveloper.create('name' => 'David', 'salary' => 1000000) + david = ContextualCallbacksDeveloper.create("name" => "David", "salary" => 1000000) assert_equal [ :before_validation, :before_validation_on_create, @@ -632,5 +631,4 @@ class CallbacksTest < ActiveRecord::TestCase child.save assert child.after_save_called end - end |