Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes AciveModel::Model with no ancestors, fixes #11004

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information...
commit c7f47ee10a7c44e64b40975afbb4b5dabdaf8c5d 1 parent 067153d
Fred Wu fredwu authored josevalim committed
2  activemodel/lib/active_model/model.rb
View
@@ -80,7 +80,7 @@ def initialize(params={})
self.public_send("#{attr}=", value)
end if params
- super
+ super(*params)
end
# Indicates if the model is persisted. Default is +false+.
27 activemodel/test/cases/model_test.rb
View
@@ -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 BasicModel
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"
+ object = BasicModel.new(attr: "value")
+ assert_equal "value", object.attr
end
def test_initialize_with_nil_or_empty_hash_params_does_not_explode
@@ -39,6 +47,19 @@ def test_persisted_is_always_false
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
Please sign in to comment.
Something went wrong with that request. Please try again.