Skip to content

Commit

Permalink
Merge pull request #11020 from fredwu/master-activemodel-inclusion-ch…
Browse files Browse the repository at this point in the history
…ain-fix-iii

ActiveModel::Model inclusion chain backward compatibility
  • Loading branch information
rafaelfranca committed Jun 20, 2013
1 parent 84bb0b0 commit 4249c33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/model.rb
Expand Up @@ -80,7 +80,7 @@ def initialize(params={})
self.public_send("#{attr}=", value)
end if params

super(*params)
super()
end

# Indicates if the model is persisted. Default is +false+.
Expand Down
20 changes: 15 additions & 5 deletions activemodel/test/cases/model_test.rb
Expand Up @@ -10,6 +10,7 @@ def self.included(klass)

def initialize(*args)
@attr ||= 'default value'
super
end
end

Expand All @@ -19,8 +20,15 @@ class BasicModel
attr_accessor :attr
end

class BasicModelWithReversedMixins
include ActiveModel::Model
include DefaultValue
attr_accessor :attr
end

class SimpleModel
include ActiveModel::Model
attr_accessor :attr
end

def setup
Expand All @@ -32,11 +40,17 @@ def test_initialize_with_params
assert_equal "value", object.attr
end

def test_initialize_with_params_and_mixins_reversed
object = BasicModelWithReversedMixins.new(attr: "value")
assert_equal "value", object.attr
end

def test_initialize_with_nil_or_empty_hash_params_does_not_explode
assert_nothing_raised do
BasicModel.new()
BasicModel.new nil
BasicModel.new(nil)
BasicModel.new({})
SimpleModel.new(attr: 'value')
end
end

Expand All @@ -58,8 +72,4 @@ def test_mixin_initializer_when_args_exist
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

0 comments on commit 4249c33

Please sign in to comment.