active_attr 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of active_attr might be problematic. Click here for more details.
- data/.rvmrc +1 -1
- data/CHANGELOG.md +12 -0
- data/Gemfile +4 -3
- data/LICENSE +22 -0
- data/Rakefile +2 -0
- data/active_attr.gemspec +20 -23
- data/gemfiles/rails_3_0.gemfile +1 -0
- data/gemfiles/rails_3_1.gemfile +1 -0
- data/lib/active_attr.rb +1 -0
- data/lib/active_attr/attribute_definition.rb +16 -0
- data/lib/active_attr/attributes.rb +63 -17
- data/lib/active_attr/matchers/have_attribute_matcher.rb +39 -67
- data/lib/active_attr/typecasted_attributes.rb +11 -2
- data/lib/active_attr/typecasting.rb +21 -29
- data/lib/active_attr/typecasting/unknown_typecaster_error.rb +13 -0
- data/lib/active_attr/version.rb +1 -1
- data/spec/functional/active_attr/attribute_defaults_spec.rb +9 -1
- data/spec/functional/active_attr/attributes_spec.rb +72 -24
- data/spec/functional/active_attr/typecasted_attributes_spec.rb +22 -0
- data/spec/support/age.rb +17 -0
- data/spec/unit/active_attr/attribute_definition_spec.rb +24 -0
- data/spec/unit/active_attr/attributes_spec.rb +73 -37
- data/spec/unit/active_attr/typecasting/unknown_typecaster_error_spec.rb +11 -0
- data/spec/unit/active_attr/typecasting_spec.rb +22 -50
- metadata +74 -23
- data/MIT-LICENSE +0 -18
@@ -12,80 +12,52 @@ module ActiveAttr
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#typecast_attribute" do
|
15
|
-
let(:type) { String }
|
16
|
-
|
17
15
|
it "raises an ArgumentError when a nil type is given" do
|
18
|
-
expect { subject.typecast_attribute(nil, "foo") }.to raise_error(ArgumentError, "a
|
16
|
+
expect { subject.typecast_attribute(nil, "foo") }.to raise_error(ArgumentError, "a typecaster must be given")
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
it "returns nil" do
|
25
|
-
subject.stub(:typecast_value).and_return(nil)
|
26
|
-
subject.typecast_attribute(type, value).should be_nil
|
27
|
-
end
|
19
|
+
it "raises an ArgumentError when the given typecaster argument does not respond to #call" do
|
20
|
+
expect { subject.typecast_attribute(Object.new, "foo") }.to raise_error(ArgumentError, "a typecaster must be given")
|
28
21
|
end
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
let(:model) { model_class.new }
|
33
|
-
subject { model.typecast_attribute(type, name) }
|
34
|
-
|
35
|
-
it "returns the original value" do
|
36
|
-
should eql name
|
37
|
-
end
|
38
|
-
|
39
|
-
it "does not call try to convert the value" do
|
40
|
-
model.should_not_receive(:typecast_value)
|
41
|
-
subject
|
42
|
-
end
|
23
|
+
it "returns the original value when the value is nil" do
|
24
|
+
model_class.new.typecast_attribute(mock(:call => 1), nil).should be_nil
|
43
25
|
end
|
44
26
|
end
|
45
27
|
|
46
|
-
describe "#
|
28
|
+
describe "#typecaster_for" do
|
47
29
|
let(:model) { model_class.new }
|
48
|
-
subject { model.typecast_value(type, value) }
|
49
|
-
let(:value) { mock }
|
50
30
|
|
51
|
-
it "
|
52
|
-
|
53
|
-
model.typecast_value(BigDecimal, value)
|
31
|
+
it "returns BigDecimalTypecaster for BigDecimal" do
|
32
|
+
model.typecaster_for(BigDecimal).should be_a_kind_of Typecasting::BigDecimalTypecaster
|
54
33
|
end
|
55
34
|
|
56
|
-
it "
|
57
|
-
Typecasting::
|
58
|
-
model.typecast_value(Typecasting::Boolean, value)
|
35
|
+
it "returns BooleanTypecaster for Boolean" do
|
36
|
+
model.typecaster_for(Typecasting::Boolean).should be_a_kind_of Typecasting::BooleanTypecaster
|
59
37
|
end
|
60
38
|
|
61
|
-
it "
|
62
|
-
|
63
|
-
model.typecast_value(Date, value)
|
39
|
+
it "returns DateTypecaster for Date" do
|
40
|
+
model.typecaster_for(Date).should be_a_kind_of Typecasting::DateTypecaster
|
64
41
|
end
|
65
42
|
|
66
|
-
it "
|
67
|
-
|
68
|
-
model.typecast_value(DateTime, value)
|
43
|
+
it "returns DateTypecaster for Date" do
|
44
|
+
model.typecaster_for(DateTime).should be_a_kind_of Typecasting::DateTimeTypecaster
|
69
45
|
end
|
70
46
|
|
71
|
-
it "
|
72
|
-
|
73
|
-
model.typecast_value(Float, value)
|
47
|
+
it "returns FloatTypecaster for Float" do
|
48
|
+
model.typecaster_for(Float).should be_a_kind_of Typecasting::FloatTypecaster
|
74
49
|
end
|
75
50
|
|
76
|
-
it "
|
77
|
-
|
78
|
-
model.typecast_value(Integer, value)
|
51
|
+
it "returns IntegerTypecaster for Integer" do
|
52
|
+
model.typecaster_for(Integer).should be_a_kind_of Typecasting::IntegerTypecaster
|
79
53
|
end
|
80
54
|
|
81
|
-
it "
|
82
|
-
|
83
|
-
model.typecast_value(String, value)
|
55
|
+
it "returns StringTypecaster for String" do
|
56
|
+
model.typecaster_for(String).should be_a_kind_of Typecasting::StringTypecaster
|
84
57
|
end
|
85
58
|
|
86
|
-
it "
|
87
|
-
|
88
|
-
model.typecast_value(Object, value)
|
59
|
+
it "returns ObjectTypecaster for Object" do
|
60
|
+
model.typecaster_for(Object).should be_a_kind_of Typecasting::ObjectTypecaster
|
89
61
|
end
|
90
62
|
end
|
91
63
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -25,10 +25,18 @@ dependencies:
|
|
25
25
|
version: '4.1'
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
|
-
version_requirements:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.2
|
34
|
+
- - <
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '4.1'
|
29
37
|
- !ruby/object:Gem::Dependency
|
30
38
|
name: activesupport
|
31
|
-
requirement:
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
32
40
|
none: false
|
33
41
|
requirements:
|
34
42
|
- - ! '>='
|
@@ -39,10 +47,18 @@ dependencies:
|
|
39
47
|
version: '4.1'
|
40
48
|
type: :runtime
|
41
49
|
prerelease: false
|
42
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.0.2
|
56
|
+
- - <
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '4.1'
|
43
59
|
- !ruby/object:Gem::Dependency
|
44
60
|
name: bundler
|
45
|
-
requirement:
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
46
62
|
none: false
|
47
63
|
requirements:
|
48
64
|
- - ~>
|
@@ -50,21 +66,37 @@ dependencies:
|
|
50
66
|
version: '1.0'
|
51
67
|
type: :development
|
52
68
|
prerelease: false
|
53
|
-
version_requirements:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.0'
|
54
75
|
- !ruby/object:Gem::Dependency
|
55
76
|
name: factory_girl
|
56
|
-
requirement:
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
57
78
|
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - ! '>='
|
60
81
|
- !ruby/object:Gem::Version
|
61
82
|
version: '2.2'
|
83
|
+
- - <
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '4.0'
|
62
86
|
type: :development
|
63
87
|
prerelease: false
|
64
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.2'
|
94
|
+
- - <
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
65
97
|
- !ruby/object:Gem::Dependency
|
66
98
|
name: rake
|
67
|
-
requirement:
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
68
100
|
none: false
|
69
101
|
requirements:
|
70
102
|
- - ~>
|
@@ -72,10 +104,15 @@ dependencies:
|
|
72
104
|
version: 0.9.0
|
73
105
|
type: :development
|
74
106
|
prerelease: false
|
75
|
-
version_requirements:
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ~>
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 0.9.0
|
76
113
|
- !ruby/object:Gem::Dependency
|
77
114
|
name: rspec
|
78
|
-
requirement:
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
79
116
|
none: false
|
80
117
|
requirements:
|
81
118
|
- - ~>
|
@@ -83,10 +120,15 @@ dependencies:
|
|
83
120
|
version: '2.6'
|
84
121
|
type: :development
|
85
122
|
prerelease: false
|
86
|
-
version_requirements:
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ~>
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '2.6'
|
87
129
|
- !ruby/object:Gem::Dependency
|
88
130
|
name: tzinfo
|
89
|
-
requirement:
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
90
132
|
none: false
|
91
133
|
requirements:
|
92
134
|
- - ~>
|
@@ -94,7 +136,12 @@ dependencies:
|
|
94
136
|
version: 0.3.29
|
95
137
|
type: :development
|
96
138
|
prerelease: false
|
97
|
-
version_requirements:
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ~>
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.3.29
|
98
145
|
description: Create plain old ruby models without reinventing the wheel.
|
99
146
|
email:
|
100
147
|
- cgriego@gmail.com
|
@@ -111,7 +158,7 @@ files:
|
|
111
158
|
- CHANGELOG.md
|
112
159
|
- Gemfile
|
113
160
|
- Guardfile
|
114
|
-
-
|
161
|
+
- LICENSE
|
115
162
|
- README.md
|
116
163
|
- Rakefile
|
117
164
|
- active_attr.gemspec
|
@@ -147,6 +194,7 @@ files:
|
|
147
194
|
- lib/active_attr/typecasting/integer_typecaster.rb
|
148
195
|
- lib/active_attr/typecasting/object_typecaster.rb
|
149
196
|
- lib/active_attr/typecasting/string_typecaster.rb
|
197
|
+
- lib/active_attr/typecasting/unknown_typecaster_error.rb
|
150
198
|
- lib/active_attr/unknown_attribute_error.rb
|
151
199
|
- lib/active_attr/version.rb
|
152
200
|
- spec/functional/active_attr/attribute_defaults_spec.rb
|
@@ -158,6 +206,7 @@ files:
|
|
158
206
|
- spec/functional/active_attr/typecasted_attributes_spec.rb
|
159
207
|
- spec/spec_helper.rb
|
160
208
|
- spec/support/active_model_lint.rb
|
209
|
+
- spec/support/age.rb
|
161
210
|
- spec/support/initialization_verifier.rb
|
162
211
|
- spec/support/mass_assignment_shared_examples.rb
|
163
212
|
- spec/unit/active_attr/attribute_defaults_spec.rb
|
@@ -183,6 +232,7 @@ files:
|
|
183
232
|
- spec/unit/active_attr/typecasting/integer_typecaster_spec.rb
|
184
233
|
- spec/unit/active_attr/typecasting/object_typecaster_spec.rb
|
185
234
|
- spec/unit/active_attr/typecasting/string_typecaster_spec.rb
|
235
|
+
- spec/unit/active_attr/typecasting/unknown_typecaster_error_spec.rb
|
186
236
|
- spec/unit/active_attr/typecasting_spec.rb
|
187
237
|
- spec/unit/active_attr/unknown_attribute_error_spec.rb
|
188
238
|
- spec/unit/active_attr/version_spec.rb
|
@@ -200,7 +250,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
200
250
|
version: '0'
|
201
251
|
segments:
|
202
252
|
- 0
|
203
|
-
hash:
|
253
|
+
hash: 1481400115643803652
|
204
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
255
|
none: false
|
206
256
|
requirements:
|
@@ -209,10 +259,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
259
|
version: '0'
|
210
260
|
segments:
|
211
261
|
- 0
|
212
|
-
hash:
|
262
|
+
hash: 1481400115643803652
|
213
263
|
requirements: []
|
214
|
-
rubyforge_project:
|
215
|
-
rubygems_version: 1.8.
|
264
|
+
rubyforge_project:
|
265
|
+
rubygems_version: 1.8.21
|
216
266
|
signing_key:
|
217
267
|
specification_version: 3
|
218
268
|
summary: What ActiveModel left out
|
@@ -226,6 +276,7 @@ test_files:
|
|
226
276
|
- spec/functional/active_attr/typecasted_attributes_spec.rb
|
227
277
|
- spec/spec_helper.rb
|
228
278
|
- spec/support/active_model_lint.rb
|
279
|
+
- spec/support/age.rb
|
229
280
|
- spec/support/initialization_verifier.rb
|
230
281
|
- spec/support/mass_assignment_shared_examples.rb
|
231
282
|
- spec/unit/active_attr/attribute_defaults_spec.rb
|
@@ -251,7 +302,7 @@ test_files:
|
|
251
302
|
- spec/unit/active_attr/typecasting/integer_typecaster_spec.rb
|
252
303
|
- spec/unit/active_attr/typecasting/object_typecaster_spec.rb
|
253
304
|
- spec/unit/active_attr/typecasting/string_typecaster_spec.rb
|
305
|
+
- spec/unit/active_attr/typecasting/unknown_typecaster_error_spec.rb
|
254
306
|
- spec/unit/active_attr/typecasting_spec.rb
|
255
307
|
- spec/unit/active_attr/unknown_attribute_error_spec.rb
|
256
308
|
- spec/unit/active_attr/version_spec.rb
|
257
|
-
has_rdoc:
|
data/MIT-LICENSE
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
Copyright (C) 2011 by Chris Griego, Ben Poweski
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
5
|
-
in the Software without restriction, including without limitation the rights
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
8
|
-
furnished to do so, subject to the following conditions:
|
9
|
-
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
11
|
-
all copies or substantial portions of the Software.
|
12
|
-
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|