Skip to content
This repository
Browse code

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

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
  • Loading branch information...
commit 0b502cb87906505e519b404ef2cd1d607c89a44a 1 parent e47b6de
Fred Wu authored June 19, 2013 josevalim committed June 19, 2013
2  activemodel/lib/active_model/model.rb
@@ -80,7 +80,7 @@ def initialize(params={})
80 80
         self.public_send("#{attr}=", value)
81 81
       end if params
82 82
 
83  
-      super
  83
+      super(*params)
84 84
     end
85 85
 
86 86
     # Indicates if the model is persisted. Default is +false+.
25  activemodel/test/cases/model_test.rb
@@ -4,6 +4,10 @@ class ModelTest < ActiveModel::TestCase
4 4
   include ActiveModel::Lint::Tests
5 5
 
6 6
   module DefaultValue
  7
+    def self.included(klass)
  8
+      klass.class_eval { attr_accessor :hello }
  9
+    end
  10
+
7 11
     def initialize(*args)
8 12
       @attr ||= 'default value'
9 13
     end
@@ -15,13 +19,17 @@ class BasicModel
15 19
     attr_accessor :attr
16 20
   end
17 21
 
  22
+  class SimpleModel
  23
+    include ActiveModel::Model
  24
+  end
  25
+
18 26
   def setup
19 27
     @model = BasicModel.new
20 28
   end
21 29
 
22 30
   def test_initialize_with_params
23 31
     object = BasicModel.new(attr: "value")
24  
-    assert_equal object.attr, "value"
  32
+    assert_equal "value", object.attr
25 33
   end
26 34
 
27 35
   def test_initialize_with_nil_or_empty_hash_params_does_not_explode
@@ -39,6 +47,19 @@ def test_persisted_is_always_false
39 47
 
40 48
   def test_mixin_inclusion_chain
41 49
     object = BasicModel.new
42  
-    assert_equal object.attr, 'default value'
  50
+    assert_equal 'default value', object.attr
  51
+  end
  52
+
  53
+  def test_mixin_initializer_when_args_exist
  54
+    object = BasicModel.new(hello: 'world')
  55
+    assert_equal 'world', object.hello
  56
+  end
  57
+
  58
+  def test_mixin_initializer_when_args_dont_exist
  59
+    assert_raises(NoMethodError) { SimpleModel.new(hello: 'world') }
  60
+  end
  61
+
  62
+  def test_mixin_when_no_ancestors
  63
+    assert SimpleModel.new
43 64
   end
44 65
 end

0 notes on commit 0b502cb

Please sign in to comment.
Something went wrong with that request. Please try again.