aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Wu <ifredwu@gmail.com>2013-06-19 23:32:05 +1000
committerJosé Valim <jose.valim@plataformatec.com.br>2013-06-19 17:16:04 +0200
commit0b502cb87906505e519b404ef2cd1d607c89a44a (patch)
treebf005ea97efa34db20c2a1dfcf5fe2792cadb958
parente47b6dee858e62dceba867dd160b968d679c82e8 (diff)
downloadrails-0b502cb87906505e519b404ef2cd1d607c89a44a.tar.gz
rails-0b502cb87906505e519b404ef2cd1d607c89a44a.tar.bz2
rails-0b502cb87906505e519b404ef2cd1d607c89a44a.zip
Fixes AciveModel::Model with no ancestors, fixes #11004
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
-rw-r--r--activemodel/lib/active_model/model.rb2
-rw-r--r--activemodel/test/cases/model_test.rb25
2 files changed, 24 insertions, 3 deletions
diff --git a/activemodel/lib/active_model/model.rb b/activemodel/lib/active_model/model.rb
index ee5bc9e4d8..5904d686e5 100644
--- a/activemodel/lib/active_model/model.rb
+++ b/activemodel/lib/active_model/model.rb
@@ -80,7 +80,7 @@ module ActiveModel
self.public_send("#{attr}=", value)
end if params
- super
+ super(*params)
end
# Indicates if the model is persisted. Default is +false+.
diff --git a/activemodel/test/cases/model_test.rb b/activemodel/test/cases/model_test.rb
index 375f5907db..651d20b3cb 100644
--- a/activemodel/test/cases/model_test.rb
+++ b/activemodel/test/cases/model_test.rb
@@ -4,6 +4,10 @@ class ModelTest < ActiveModel::TestCase
include ActiveModel::Lint::Tests
module DefaultValue
+ def self.included(klass)
+ klass.class_eval { attr_accessor :hello }
+ end
+
def initialize(*args)
@attr ||= 'default value'
end
@@ -15,13 +19,17 @@ class ModelTest < ActiveModel::TestCase
attr_accessor :attr
end
+ class SimpleModel
+ include ActiveModel::Model
+ end
+
def setup
@model = BasicModel.new
end
def test_initialize_with_params
object = BasicModel.new(attr: "value")
- assert_equal object.attr, "value"
+ assert_equal "value", object.attr
end
def test_initialize_with_nil_or_empty_hash_params_does_not_explode
@@ -39,6 +47,19 @@ class ModelTest < ActiveModel::TestCase
def test_mixin_inclusion_chain
object = BasicModel.new
- assert_equal object.attr, 'default value'
+ assert_equal 'default value', object.attr
+ end
+
+ def test_mixin_initializer_when_args_exist
+ object = BasicModel.new(hello: 'world')
+ assert_equal 'world', object.hello
+ end
+
+ def test_mixin_initializer_when_args_dont_exist
+ assert_raises(NoMethodError) { SimpleModel.new(hello: 'world') }
+ end
+
+ def test_mixin_when_no_ancestors
+ assert SimpleModel.new
end
end