From be9883b09d05b90c2422502f38ab69081e29e4ce Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Sep 2010 12:53:51 -0300 Subject: Don't redefine existing attributes accessors. --- activemodel/lib/active_model/validations/confirmation.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb index 2c8a840124..00df10cef0 100644 --- a/activemodel/lib/active_model/validations/confirmation.rb +++ b/activemodel/lib/active_model/validations/confirmation.rb @@ -10,7 +10,9 @@ module ActiveModel end def setup(klass) - klass.send(:attr_accessor, *attributes.map { |attribute| :"#{attribute}_confirmation" }) + klass.send(:attr_accessor, *attributes.map do |attribute| + :"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation") + end.compact) end end -- cgit v1.2.3 From 9c57bd8578e5ed47f143a2755b03ffd2ef85c65d Mon Sep 17 00:00:00 2001 From: thedarkone Date: Sun, 26 Sep 2010 14:54:49 +0200 Subject: Fix Namind#model_name. --- activemodel/lib/active_model/naming.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index fc2abacb6d..2d580fd325 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -73,8 +73,10 @@ module ActiveModel # Returns an ActiveModel::Name object for module. It can be # used to retrieve all kinds of naming-related information. def model_name - namespace = self.parents.detect { |n| n.respond_to?(:_railtie) } - @_model_name ||= ActiveModel::Name.new(self, namespace) + @_model_name ||= begin + namespace = self.parents.detect { |n| n.respond_to?(:_railtie) } + ActiveModel::Name.new(self, namespace) + end end # Returns the plural class name of a record or class. Examples: -- cgit v1.2.3 From 72c1e19c33ca06008d5d64619a533bdf34e3fc2b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 25 Sep 2010 18:30:56 -0400 Subject: after_create in ActiveModel should in the order specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5650 state:resolved] Signed-off-by: José Valim --- activemodel/test/cases/callbacks_test.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'activemodel') diff --git a/activemodel/test/cases/callbacks_test.rb b/activemodel/test/cases/callbacks_test.rb index 64dc7b5026..069d907fb2 100644 --- a/activemodel/test/cases/callbacks_test.rb +++ b/activemodel/test/cases/callbacks_test.rb @@ -81,4 +81,34 @@ class CallbacksTest < ActiveModel::TestCase assert !ModelCallbacks.respond_to?(:around_empty) assert !ModelCallbacks.respond_to?(:after_empty) end + + class Violin + attr_reader :history + def initialize + @history = [] + end + extend ActiveModel::Callbacks + define_model_callbacks :create + def callback1; self.history << 'callback1'; end + def callback2; self.history << 'callback2'; end + def create + _run_create_callbacks {} + self + end + end + class Violin1 < Violin + after_create :callback1, :callback2 + end + class Violin2 < Violin + after_create :callback1 + after_create :callback2 + end + + test "after_create callbacks with both callbacks declared in one line" do + assert_equal ["callback1", "callback2"], Violin1.new.create.history + end + test "after_create callbacks with both callbacks declared in differnt lines" do + assert_equal ["callback1", "callback2"], Violin2.new.create.history + end + end -- cgit v1.2.3