active_attr 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of active_attr might be problematic. Click here for more details.
- data/.travis.yml +11 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -6
- data/README.md +29 -11
- data/active_attr.gemspec +3 -3
- data/gemfiles/rails_3_2.gemfile +11 -0
- data/gemfiles/rails_head.gemfile +3 -0
- data/lib/active_attr.rb +0 -1
- data/lib/active_attr/mass_assignment.rb +30 -2
- data/lib/active_attr/matchers/have_attribute_matcher.rb +17 -4
- data/lib/active_attr/model.rb +2 -2
- data/lib/active_attr/typecasting/big_decimal_typecaster.rb +2 -0
- data/lib/active_attr/typecasting/date_typecaster.rb +1 -1
- data/lib/active_attr/version.rb +1 -1
- data/spec/functional/active_attr/attribute_defaults_spec.rb +12 -12
- data/spec/functional/active_attr/attributes_spec.rb +12 -12
- data/spec/functional/active_attr/chainable_initialization_spec.rb +3 -3
- data/spec/functional/active_attr/mass_assignment_spec.rb +125 -0
- data/spec/functional/active_attr/matchers/have_attribute_matcher_spec.rb +147 -66
- data/spec/functional/active_attr/model_spec.rb +27 -19
- data/spec/functional/active_attr/serialization_spec.rb +5 -5
- data/spec/functional/active_attr/typecasted_attributes_spec.rb +45 -45
- data/spec/support/mass_assignment_shared_examples.rb +12 -12
- data/spec/unit/active_attr/attribute_defaults_spec.rb +6 -6
- data/spec/unit/active_attr/attribute_definition_spec.rb +6 -6
- data/spec/unit/active_attr/attributes_spec.rb +38 -38
- data/spec/unit/active_attr/logger_spec.rb +16 -16
- data/spec/unit/active_attr/mass_assignment_spec.rb +1 -1
- data/spec/unit/active_attr/matchers_spec.rb +3 -4
- data/spec/unit/active_attr/query_attributes_spec.rb +75 -75
- data/spec/unit/active_attr/typecasted_attributes_spec.rb +10 -10
- data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +9 -7
- data/spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb +27 -25
- data/spec/unit/active_attr/typecasting/date_time_typecaster_spec.rb +12 -10
- data/spec/unit/active_attr/typecasting/date_typecaster_spec.rb +14 -12
- data/spec/unit/active_attr/typecasting/float_typecaster_spec.rb +6 -4
- data/spec/unit/active_attr/typecasting/integer_typecaster_spec.rb +8 -6
- data/spec/unit/active_attr/typecasting/object_typecaster_spec.rb +3 -1
- data/spec/unit/active_attr/typecasting/string_typecaster_spec.rb +5 -3
- data/spec/unit/active_attr/typecasting_spec.rb +3 -5
- data/spec/unit/active_attr/version_spec.rb +5 -5
- metadata +20 -17
- data/lib/active_attr/mass_assignment_security.rb +0 -54
- data/spec/functional/active_attr/mass_assignment_security_spec.rb +0 -45
- data/spec/unit/active_attr/mass_assignment_security_spec.rb +0 -67
data/.travis.yml
CHANGED
@@ -3,17 +3,27 @@ rvm:
|
|
3
3
|
- ree
|
4
4
|
- 1.9.2
|
5
5
|
- 1.9.3
|
6
|
+
- 2.0.0
|
6
7
|
bundler_args: --without development
|
7
8
|
gemfile:
|
8
9
|
- Gemfile
|
9
10
|
- gemfiles/rails_3_0.gemfile
|
10
11
|
- gemfiles/rails_3_1.gemfile
|
12
|
+
- gemfiles/rails_3_2.gemfile
|
11
13
|
- gemfiles/rails_head.gemfile
|
12
14
|
matrix:
|
13
15
|
allow_failures:
|
14
16
|
- gemfile: gemfiles/rails_head.gemfile
|
15
17
|
exclude:
|
18
|
+
- rvm: 1.9.2
|
19
|
+
gemfile: gemfiles/rails_head.gemfile
|
16
20
|
- rvm: ree
|
17
21
|
gemfile: gemfiles/rails_head.gemfile
|
18
22
|
- rvm: 1.9.2
|
19
|
-
gemfile:
|
23
|
+
gemfile: Gemfile
|
24
|
+
- rvm: ree
|
25
|
+
gemfile: Gemfile
|
26
|
+
- rvm: 2.0.0
|
27
|
+
gemfile: gemfiles/rails_3_1.gemfile
|
28
|
+
- rvm: 2.0.0
|
29
|
+
gemfile: gemfiles/rails_3_0.gemfile
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# ActiveAttr 0.8.0 (May 2, 2013) #
|
2
|
+
|
3
|
+
* ActiveAttr now supports Rails 4.0.0
|
4
|
+
* ActiveAttr now supports Ruby 2.0.0
|
5
|
+
* HaveAttributeMatcher failure messages now use an expected/got format
|
6
|
+
* Removed MassAssignmentSecurity, sanitizer support has been merged into
|
7
|
+
MassAssignment. Include the ActiveModel::MassAssignmentSecurity module or
|
8
|
+
ActiveModel::ForbiddenAttributesProtection depending on your Rails version
|
9
|
+
|
1
10
|
# ActiveAttr 0.7.0 (December 15, 2012) #
|
2
11
|
|
3
12
|
* Added Serialization
|
data/Gemfile
CHANGED
@@ -2,12 +2,10 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec :development_group => :test
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem "strong_parameters"
|
10
|
-
end
|
5
|
+
gem "activemodel", ">= 4.0.0.rc1"
|
6
|
+
gem "activesupport", ">= 4.0.0.rc1"
|
7
|
+
gem "actionpack", ">= 4.0.0.rc1", :group => :test
|
8
|
+
gem "protected_attributes", :group => :test
|
11
9
|
|
12
10
|
group :development do
|
13
11
|
gem "debugger", :platforms => :mri_19
|
data/README.md
CHANGED
@@ -18,12 +18,13 @@ ActiveAttr is distributed as a rubygem [on rubygems.org][rubygems].
|
|
18
18
|
* [Contributors][contributors]
|
19
19
|
|
20
20
|
[api]: http://rubydoc.info/gems/active_attr
|
21
|
-
[codeclimate badge]: https://codeclimate.com/
|
21
|
+
[codeclimate badge]: https://codeclimate.com/github/cgriego/active_attr.png
|
22
22
|
[codeclimate]: https://codeclimate.com/github/cgriego/active_attr
|
23
23
|
[contributors]: https://github.com/cgriego/active_attr/contributors
|
24
24
|
[railscast poster]: http://railscasts.com/static/episodes/stills/326-activeattr.png
|
25
25
|
[railscast]: http://railscasts.com/episodes/326-activeattr
|
26
26
|
[rubygems]: http://rubygems.org/gems/active_attr
|
27
|
+
[protected_attributes]: https://github.com/rails/protected_attributes
|
27
28
|
[strong_parameters]: https://github.com/rails/strong_parameters
|
28
29
|
[speakerdeck slide]: https://speakerd.s3.amazonaws.com/presentations/4f31f1dec583b4001f008ec3/thumb_slide_0.jpg
|
29
30
|
[speakerdeck]: https://speakerdeck.com/u/cgriego/p/models-models-every-where
|
@@ -165,14 +166,30 @@ are silently ignored.
|
|
165
166
|
person.first_name #=> "Chris"
|
166
167
|
person.last_name #=> "Griego"
|
167
168
|
|
168
|
-
|
169
|
+
MassAssignment supports mass assignment security/sanitization if a sanitizer
|
170
|
+
is included in the model. If using Rails 4.0, include ActiveModel's forbidden
|
171
|
+
attributes protection module to get support for strong parameters.
|
169
172
|
|
170
|
-
|
171
|
-
MassAssignment
|
172
|
-
|
173
|
+
class Person
|
174
|
+
include ActiveAttr::MassAssignment
|
175
|
+
include ActiveModel::ForbiddenAttributesProtection
|
176
|
+
attr_accessor :first_name, :last_name
|
177
|
+
end
|
178
|
+
|
179
|
+
person = Person.new(ActionController::Parameters.new({
|
180
|
+
:first_name => "Chris",
|
181
|
+
:last_name => "Griego",
|
182
|
+
}).permit(:first_name))
|
183
|
+
person.first_name #=> "Chris"
|
184
|
+
person.last_name #=> nil
|
185
|
+
|
186
|
+
If using Rails 3.x or the [Protected Attributes gem][protected_attributes],
|
187
|
+
include ActiveModel's mass assignment security module to get support for
|
188
|
+
protected attributes, including support for mass assignment roles.
|
173
189
|
|
174
190
|
class Person
|
175
|
-
include ActiveAttr::
|
191
|
+
include ActiveAttr::MassAssignment
|
192
|
+
include ActiveModel::MassAssignmentSecurity
|
176
193
|
attr_accessor :first_name, :last_name
|
177
194
|
attr_protected :last_name
|
178
195
|
end
|
@@ -181,12 +198,13 @@ blacklists or whitelists including support for mass assignment roles.
|
|
181
198
|
person.first_name #=> "Chris"
|
182
199
|
person.last_name #=> nil
|
183
200
|
|
184
|
-
If
|
185
|
-
include the
|
186
|
-
|
201
|
+
If using the [Strong Paramters gem][strong_parameters] with Rails 3.2,
|
202
|
+
include the forbidden attributes protection module after including
|
203
|
+
the mass assignment security module.
|
187
204
|
|
188
205
|
class Person
|
189
|
-
include ActiveAttr::
|
206
|
+
include ActiveAttr::MassAssignment
|
207
|
+
include ActiveModel::MassAssignmentSecurity
|
190
208
|
include ActiveModel::ForbiddenAttributesProtection
|
191
209
|
end
|
192
210
|
|
@@ -196,7 +214,7 @@ The Serialization module is a shortcut for incorporating ActiveModel's
|
|
196
214
|
serialization functionality into your model with one include.
|
197
215
|
|
198
216
|
class Person
|
199
|
-
include ActiveAttr::
|
217
|
+
include ActiveAttr::Serialization
|
200
218
|
end
|
201
219
|
|
202
220
|
### Model ###
|
data/active_attr.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_runtime_dependency "activesupport", ">= 3.0.2", "< 4.1"
|
20
20
|
|
21
21
|
gem.add_development_dependency "bundler", "~> 1.0"
|
22
|
-
gem.add_development_dependency "factory_girl", ">= 2.2", "<
|
23
|
-
gem.add_development_dependency "rake", "
|
24
|
-
gem.add_development_dependency "rspec", "~> 2.
|
22
|
+
gem.add_development_dependency "factory_girl", ">= 2.2", "< 5.0"
|
23
|
+
gem.add_development_dependency "rake", ">= 0.9.0", "< 10.1"
|
24
|
+
gem.add_development_dependency "rspec", "~> 2.11"
|
25
25
|
gem.add_development_dependency "tzinfo", "~> 0.3.29"
|
26
26
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gemspec :development_group => :test, :path => ".."
|
4
|
+
|
5
|
+
if RUBY_VERSION < "1.9.2"
|
6
|
+
gem "factory_girl", "< 3.0", :group => :test
|
7
|
+
end
|
8
|
+
|
9
|
+
gem "activemodel", "~> 3.2.0"
|
10
|
+
gem "activesupport", "~> 3.2.0"
|
11
|
+
gem "strong_parameters", ">= 0.2.0", :group => :test
|
data/gemfiles/rails_head.gemfile
CHANGED
@@ -5,4 +5,7 @@ gemspec :development_group => :test, :path => ".."
|
|
5
5
|
git "git://github.com/rails/rails.git" do
|
6
6
|
gem "activemodel"
|
7
7
|
gem "activesupport"
|
8
|
+
gem "actionpack", :group => :test
|
8
9
|
end
|
10
|
+
|
11
|
+
gem "protected_attributes", :git => "git://github.com/rails/protected_attributes.git", :group => :test
|
data/lib/active_attr.rb
CHANGED
@@ -26,13 +26,20 @@ module ActiveAttr
|
|
26
26
|
#
|
27
27
|
# @param [Hash{#to_s => Object}, #each] attributes Attributes used to
|
28
28
|
# populate the model
|
29
|
+
# @param [Hash, #[]] options Options that affect mass assignment
|
30
|
+
#
|
31
|
+
# @option options [Symbol] :as (:default) Mass assignment role
|
32
|
+
# @option options [true, false] :without_protection (false) Bypass mass
|
33
|
+
# assignment security if true
|
29
34
|
#
|
30
35
|
# @since 0.1.0
|
31
36
|
def assign_attributes(new_attributes, options={})
|
32
|
-
|
37
|
+
sanitized_new_attributes = sanitize_for_mass_assignment_if_sanitizer new_attributes, options
|
38
|
+
|
39
|
+
sanitized_new_attributes.each do |name, value|
|
33
40
|
writer = "#{name}="
|
34
41
|
send writer, value if respond_to? writer
|
35
|
-
end if
|
42
|
+
end if sanitized_new_attributes
|
36
43
|
end
|
37
44
|
|
38
45
|
# Mass update a model's attributes
|
@@ -63,5 +70,26 @@ module ActiveAttr
|
|
63
70
|
assign_attributes attributes, options
|
64
71
|
super
|
65
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# @since 0.8.0
|
77
|
+
def sanitize_for_mass_assignment_if_sanitizer(new_attributes, options={})
|
78
|
+
if new_attributes && !options[:without_protection] && respond_to?(:sanitize_for_mass_assignment, true)
|
79
|
+
sanitize_for_mass_assignment_with_or_without_role new_attributes, options
|
80
|
+
else
|
81
|
+
new_attributes
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Rails 3.0 and 4.0 do not take a role argument for the sanitizer
|
86
|
+
# @since 0.7.0
|
87
|
+
def sanitize_for_mass_assignment_with_or_without_role(new_attributes, options)
|
88
|
+
if method(:sanitize_for_mass_assignment).arity.abs > 1
|
89
|
+
sanitize_for_mass_assignment new_attributes, options[:as] || :default
|
90
|
+
else
|
91
|
+
sanitize_for_mass_assignment new_attributes
|
92
|
+
end
|
93
|
+
end
|
66
94
|
end
|
67
95
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_attr/attribute_definition"
|
2
|
+
|
1
3
|
module ActiveAttr
|
2
4
|
module Matchers
|
3
5
|
# Specify that a model should have an attribute matching the criteria. See
|
@@ -30,9 +32,10 @@ module ActiveAttr
|
|
30
32
|
def initialize(attribute_name)
|
31
33
|
raise TypeError, "can't convert #{attribute_name.class} into Symbol" unless attribute_name.respond_to? :to_sym
|
32
34
|
@attribute_name = attribute_name.to_sym
|
35
|
+
@attribute_options = {}
|
33
36
|
@description = "attribute named #{attribute_name}"
|
34
37
|
@expected_ancestors = ["ActiveAttr::Attributes"]
|
35
|
-
@attribute_expectations = [lambda {
|
38
|
+
@attribute_expectations = [lambda { actual_attribute_definition }]
|
36
39
|
end
|
37
40
|
|
38
41
|
# Specify that the attribute should have the given type
|
@@ -48,6 +51,7 @@ module ActiveAttr
|
|
48
51
|
#
|
49
52
|
# @since 0.5.0
|
50
53
|
def of_type(type)
|
54
|
+
@attribute_options[:type] = type
|
51
55
|
@description << " of type #{type}"
|
52
56
|
@expected_ancestors << "ActiveAttr::TypecastedAttributes"
|
53
57
|
@attribute_expectations << lambda { @model_class._attribute_type(attribute_name) == type }
|
@@ -69,9 +73,10 @@ module ActiveAttr
|
|
69
73
|
#
|
70
74
|
# @since 0.5.0
|
71
75
|
def with_default_value_of(default_value)
|
76
|
+
@attribute_options[:default] = default_value
|
72
77
|
@description << " with a default value of #{default_value.inspect}"
|
73
78
|
@expected_ancestors << "ActiveAttr::AttributeDefaults"
|
74
|
-
@attribute_expectations << lambda {
|
79
|
+
@attribute_expectations << lambda { actual_attribute_definition[:default] == default_value }
|
75
80
|
self
|
76
81
|
end
|
77
82
|
|
@@ -92,6 +97,9 @@ module ActiveAttr
|
|
92
97
|
def failure_message
|
93
98
|
if missing_ancestors.any?
|
94
99
|
"expected #{@model_class.name} to include #{missing_ancestors.first}"
|
100
|
+
elsif actual_attribute_definition
|
101
|
+
"expected: #{expected_attribute_definition.inspect}\n" +
|
102
|
+
" got: #{actual_attribute_definition.inspect}"
|
95
103
|
else
|
96
104
|
"expected #{@model_class.name} to have #{@description}"
|
97
105
|
end
|
@@ -100,15 +108,20 @@ module ActiveAttr
|
|
100
108
|
# @return [String] Negative failure message
|
101
109
|
# @private
|
102
110
|
def negative_failure_message
|
103
|
-
"expected
|
111
|
+
"expected not: #{expected_attribute_definition.inspect}\n" +
|
112
|
+
" got: #{actual_attribute_definition.inspect}"
|
104
113
|
end
|
105
114
|
|
106
115
|
private
|
107
116
|
|
108
|
-
def
|
117
|
+
def actual_attribute_definition
|
109
118
|
@model_class.attributes[attribute_name]
|
110
119
|
end
|
111
120
|
|
121
|
+
def expected_attribute_definition
|
122
|
+
AttributeDefinition.new @attribute_name, @attribute_options
|
123
|
+
end
|
124
|
+
|
112
125
|
def missing_ancestors
|
113
126
|
model_ancestor_names = @model_class.ancestors.map(&:name)
|
114
127
|
|
data/lib/active_attr/model.rb
CHANGED
@@ -2,7 +2,7 @@ require "active_attr/attribute_defaults"
|
|
2
2
|
require "active_attr/basic_model"
|
3
3
|
require "active_attr/block_initialization"
|
4
4
|
require "active_attr/logger"
|
5
|
-
require "active_attr/
|
5
|
+
require "active_attr/mass_assignment"
|
6
6
|
require "active_attr/query_attributes"
|
7
7
|
require "active_attr/serialization"
|
8
8
|
require "active_attr/typecasted_attributes"
|
@@ -25,7 +25,7 @@ module ActiveAttr
|
|
25
25
|
include BasicModel
|
26
26
|
include BlockInitialization
|
27
27
|
include Logger
|
28
|
-
include
|
28
|
+
include MassAssignment
|
29
29
|
include AttributeDefaults
|
30
30
|
include QueryAttributes
|
31
31
|
include TypecastedAttributes
|
data/lib/active_attr/version.rb
CHANGED
@@ -6,7 +6,7 @@ require "active_model"
|
|
6
6
|
|
7
7
|
module ActiveAttr
|
8
8
|
describe AttributeDefaults do
|
9
|
-
subject { model_class.new }
|
9
|
+
subject(:model) { model_class.new }
|
10
10
|
|
11
11
|
let :model_class do
|
12
12
|
Class.new.tap do |model_class|
|
@@ -20,20 +20,20 @@ module ActiveAttr
|
|
20
20
|
before { model_class.attribute :first_name, :default => "John" }
|
21
21
|
|
22
22
|
it "the attribute getter returns the string by default" do
|
23
|
-
|
23
|
+
model.first_name.should == "John"
|
24
24
|
end
|
25
25
|
|
26
26
|
it "#attributes includes the default attributes" do
|
27
|
-
|
27
|
+
model.attributes["first_name"].should == "John"
|
28
28
|
end
|
29
29
|
|
30
30
|
it "#read_attribute returns the string by default" do
|
31
|
-
|
31
|
+
model.read_attribute("first_name").should == "John"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "assigning nil sets nil as the attribute value" do
|
35
|
-
|
36
|
-
|
35
|
+
model.first_name = nil
|
36
|
+
model.first_name.should be_nil
|
37
37
|
end
|
38
38
|
|
39
39
|
it "mutating the default value does not mutate the attribute definition" do
|
@@ -46,7 +46,7 @@ module ActiveAttr
|
|
46
46
|
before { model_class.attribute :admin, :default => false }
|
47
47
|
|
48
48
|
it "the attribute getter returns false by default" do
|
49
|
-
|
49
|
+
model.admin.should == false
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -54,7 +54,7 @@ module ActiveAttr
|
|
54
54
|
before { model_class.attribute :remember_me, :default => true }
|
55
55
|
|
56
56
|
it "the attribute getter returns true by default" do
|
57
|
-
|
57
|
+
model.remember_me.should == true
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ module ActiveAttr
|
|
62
62
|
before { model_class.attribute :roles, :default => [] }
|
63
63
|
|
64
64
|
it "the attribute getter returns an empty array by default" do
|
65
|
-
|
65
|
+
model.roles.should == []
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,11 +70,11 @@ module ActiveAttr
|
|
70
70
|
before { model_class.attribute :created_at, :default => lambda { Time.now } }
|
71
71
|
|
72
72
|
it "the attribute getter returns a Time instance" do
|
73
|
-
|
73
|
+
model.created_at.should be_a_kind_of Time
|
74
74
|
end
|
75
75
|
|
76
76
|
it "the attribute default is only evaulated once per instance" do
|
77
|
-
|
77
|
+
model.created_at.should == model.created_at
|
78
78
|
end
|
79
79
|
|
80
80
|
it "the attribute default is different per instance" do
|
@@ -86,7 +86,7 @@ module ActiveAttr
|
|
86
86
|
before { model_class.attribute :id, :default => lambda { object_id } }
|
87
87
|
|
88
88
|
it "the attribute getter returns the default based on the instance" do
|
89
|
-
|
89
|
+
model.id.should == model.object_id
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -23,10 +23,10 @@ module ActiveAttr
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
subject { model_class.new }
|
26
|
+
subject(:model) { model_class.new }
|
27
27
|
|
28
28
|
it "correctly defines methods for the attributes instead of relying on method_missing" do
|
29
|
-
|
29
|
+
model.id.should be_nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -95,7 +95,7 @@ module ActiveAttr
|
|
95
95
|
context "serializing a model" do
|
96
96
|
let(:first_name) { "Chris" }
|
97
97
|
|
98
|
-
let :
|
98
|
+
let :model do
|
99
99
|
model_class.new.tap do |model|
|
100
100
|
model.first_name = first_name
|
101
101
|
end
|
@@ -129,34 +129,34 @@ module ActiveAttr
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "includes unassigned, defined attributes" do
|
132
|
-
|
133
|
-
|
132
|
+
serialized_model.keys.should include("last_name")
|
133
|
+
serialized_model["last_name"].should be_nil
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
137
|
describe "#as_json" do
|
138
|
-
subject {
|
138
|
+
subject(:serialized_model) { model.as_json["person"] }
|
139
139
|
include_examples "serialization method"
|
140
140
|
end
|
141
141
|
|
142
142
|
describe "#serializable_hash" do
|
143
|
-
subject {
|
143
|
+
subject(:serialized_model) { model.serializable_hash }
|
144
144
|
include_examples "serialization method"
|
145
145
|
end
|
146
146
|
|
147
147
|
describe "#to_json" do
|
148
|
-
subject { ActiveSupport::JSON.decode(
|
148
|
+
subject(:serialized_model) { ActiveSupport::JSON.decode(model.to_json)["person"] }
|
149
149
|
include_examples "serialization method"
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "#to_xml" do
|
153
|
-
subject { Hash.
|
153
|
+
subject(:serialized_model) { Hash.from_trusted_xml(model.to_xml)["person"] }
|
154
154
|
include_examples "serialization method"
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
158
|
context "building with FactoryGirl" do
|
159
|
-
subject { FactoryGirl.build(:person) }
|
159
|
+
subject(:model) { FactoryGirl.build(:person) }
|
160
160
|
|
161
161
|
before do
|
162
162
|
Object.const_set("Person", model_class)
|
@@ -187,8 +187,8 @@ module ActiveAttr
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "sets the attributes" do
|
190
|
-
|
191
|
-
|
190
|
+
model.first_name.should eq "Chris"
|
191
|
+
model.last_name.should == "Griego"
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|