File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * Added ActiveModel::Model, a mixin to make Ruby objects work with AP out of box * Guillermo Iguaran*
2+
13* ` AM::Errors#to_json ` : support ` :full_messages ` parameter * Bogdan Gusiev*
24
35* Trim down Active Model API by removing ` valid? ` and ` errors.full_messages ` * José Valim*
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ module ActiveModel
3939 autoload :Errors
4040 autoload :Lint
4141 autoload :MassAssignmentSecurity
42+ autoload :Model
4243 autoload :Name , 'active_model/naming'
4344 autoload :Naming
4445 autoload :Observer , 'active_model/observing'
Original file line number Diff line number Diff line change 1+ module ActiveModel
2+ module Model
3+ def self . included ( base )
4+ base . class_eval do
5+ extend ActiveModel ::Naming
6+ extend ActiveModel ::Translation
7+ include ActiveModel ::Validations
8+ include ActiveModel ::Conversion
9+ end
10+ end
11+
12+ def initialize ( params = { } )
13+ params . each do |attr , value |
14+ self . send ( :"#{ attr } =" , value )
15+ end if params
16+ end
17+
18+ def persisted?
19+ false
20+ end
21+ end
22+ end
Original file line number Diff line number Diff line change 1+ require 'cases/helper'
2+
3+ class ModelTest < ActiveModel ::TestCase
4+ include ActiveModel ::Lint ::Tests
5+
6+ class BasicModel
7+ include ActiveModel ::Model
8+ attr_accessor :attr
9+ end
10+
11+ def setup
12+ @model = BasicModel . new
13+ end
14+
15+ def test_initialize_with_params
16+ object = BasicModel . new ( :attr => "value" )
17+ assert_equal object . attr , "value"
18+ end
19+ end
You can’t perform that action at this time.
0 commit comments