Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ActiveModel::Model's inclusion chain #11004

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions activemodel/lib/active_model/model.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def initialize(params={})
params.each do |attr, value| params.each do |attr, value|
self.public_send("#{attr}=", value) self.public_send("#{attr}=", value)
end if params end if params

super
end end


# Indicates if the model is persisted. Default is +false+. # Indicates if the model is persisted. Default is +false+.
Expand Down
12 changes: 12 additions & 0 deletions activemodel/test/cases/model_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
class ModelTest < ActiveModel::TestCase class ModelTest < ActiveModel::TestCase
include ActiveModel::Lint::Tests include ActiveModel::Lint::Tests


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

class BasicModel class BasicModel
include DefaultValue
include ActiveModel::Model include ActiveModel::Model
attr_accessor :attr attr_accessor :attr
end end
Expand All @@ -29,4 +36,9 @@ def test_persisted_is_always_false
object = BasicModel.new(:attr => "value") object = BasicModel.new(:attr => "value")
assert object.persisted? == false assert object.persisted? == false
end end

def test_mixin_inclusion_chain
object = BasicModel.new
assert_equal object.attr, 'default value'
end
end end