simple_model 1.2.15 → 1.2.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/simple_model/attributes.rb +2 -1
- data/lib/simple_model/extend_core.rb +1 -1
- data/lib/simple_model/version.rb +1 -1
- data/simple_model.gemspec +1 -0
- data/spec/attributes_spec.rb +16 -16
- data/spec/extend_core_spec.rb +2 -2
- data/spec/simple_model_spec.rb +20 -20
- metadata +19 -15
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGY5ZmE1MjI2ZTFlOTVjYmQ4MmVhZjUyNGY5YjRiOGNkMjM1MDY3Mw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzcyNDBmM2ZmYWIxYzVmMTllYjdlNGE2YjgyNmFjMTk2Nzc1MGU3MA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmY2MzBlYWFmZmY3NTU1NjZkMGM3OGFhZTQ1ZjJiMzU5OWYwMGM0ZDI4MGE4
|
10
|
+
YmYyNWMwZTUzNTg2YzFlYTVlOGFlMzY4ODFmMTQ4NDdlYzI1NTllNGE2MDVl
|
11
|
+
NDBiMzY0ZTA2ZjlkNzA5OGIzNGQyNzU3NWQ3YmZiZWFhZWUwN2E=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTNjZGQ0NzNiZjY5ZTBjM2ZjZTI5OTYwYmZkYTExZmUxZWQzNWJjMmE3NDM3
|
14
|
+
YzI0MDViZjk2N2E4YjUzMWNiYWQwNDhhZWM0Yjk1MmEzYzQ0NjE5YjMwNGE2
|
15
|
+
YzVmMTk2NTUxNzQ4OTliNTMzNmY4N2I4ZTVkMjU5NWY2NDhiYzE=
|
@@ -129,7 +129,7 @@ module SimpleModel
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def attribute_defined?(attr)
|
132
|
-
(self.defined_attributes
|
132
|
+
(self.defined_attributes.member?(attr) || self.superclass.respond_to?(:attribute_defined?) && self.superclass.attribute_defined?(attr))
|
133
133
|
end
|
134
134
|
|
135
135
|
# The default settings for a SimpeModel class
|
@@ -183,6 +183,7 @@ module SimpleModel
|
|
183
183
|
options[:on_get].call(self,val)
|
184
184
|
end
|
185
185
|
define_method("#{attr.to_s}?") do
|
186
|
+
return false unless initialized?(attr)
|
186
187
|
val = self.send(attr)
|
187
188
|
if val.respond_to?(:to_b)
|
188
189
|
val = val.to_b
|
@@ -60,7 +60,7 @@ module SimpleModel
|
|
60
60
|
|
61
61
|
# returns boolean value for common boolean string values
|
62
62
|
def to_b
|
63
|
-
['1',"true", "t"].include?(self)
|
63
|
+
['1',"true", "t"].include?(self.downcase)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Takes known US formatted date/time strings (MM/DD/YYYY TIME) and converts
|
data/lib/simple_model/version.rb
CHANGED
data/simple_model.gemspec
CHANGED
data/spec/attributes_spec.rb
CHANGED
@@ -36,9 +36,9 @@ describe SimpleModel::Attributes do
|
|
36
36
|
|
37
37
|
it "should run the supplied lambda" do
|
38
38
|
t = TestInit.new(:far => "")
|
39
|
-
t.initialized?(:far).should
|
39
|
+
t.initialized?(:far).should eql(false)
|
40
40
|
t = TestInit.new(:far => "t")
|
41
|
-
t.initialized?(:far).should
|
41
|
+
t.initialized?(:far).should eql(true)
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -77,10 +77,10 @@ describe SimpleModel::Attributes do
|
|
77
77
|
context "AVAILABLE_ATTRIBUTE_METHODS" do
|
78
78
|
SimpleModel::Attributes::ClassMethods::AVAILABLE_ATTRIBUTE_METHODS.each do |m,options|
|
79
79
|
it "should respond to #{m}" do
|
80
|
-
TestInit.respond_to?(m).should
|
80
|
+
TestInit.respond_to?(m).should eql(true)
|
81
81
|
end
|
82
82
|
it "should respond to alias #{options[:alias]}" do
|
83
|
-
TestInit.respond_to?(options[:alias]).should
|
83
|
+
TestInit.respond_to?(options[:alias]).should eql(true)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -112,11 +112,11 @@ describe SimpleModel::Attributes do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should define setter method" do
|
115
|
-
@default.respond_to?(:foo=).should
|
115
|
+
@default.respond_to?(:foo=).should eql(true)
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should define reader/getter method" do
|
119
|
-
@default.respond_to?(:foo).should
|
119
|
+
@default.respond_to?(:foo).should eql(true)
|
120
120
|
end
|
121
121
|
|
122
122
|
context ':initialize => false' do
|
@@ -145,14 +145,14 @@ describe SimpleModel::Attributes do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it "should create a boolean? method for each attribute" do
|
148
|
-
@default.respond_to?(:foo?).should
|
148
|
+
@default.respond_to?(:foo?).should eql(true)
|
149
149
|
end
|
150
150
|
|
151
151
|
it "should return !blank?" do
|
152
152
|
@default.my_array.should eql([]) # blank array
|
153
|
-
@default.my_array?.should
|
153
|
+
@default.my_array?.should eql(false)
|
154
154
|
@default.my_array << 1
|
155
|
-
@default.my_array?.should
|
155
|
+
@default.my_array?.should eql(true)
|
156
156
|
end
|
157
157
|
|
158
158
|
it "should not allow blank if set" do
|
@@ -164,7 +164,7 @@ describe SimpleModel::Attributes do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should try for the default if its blank on get" do
|
167
|
-
@default.hop.blank?.should
|
167
|
+
@default.hop.blank?.should eql(true)
|
168
168
|
@default.nap = "yep"
|
169
169
|
@default.hop.should eql("hop")
|
170
170
|
end
|
@@ -180,12 +180,12 @@ describe SimpleModel::Attributes do
|
|
180
180
|
end
|
181
181
|
it "should not raise error" do
|
182
182
|
new = WithConditional.new(:my_date => nil)
|
183
|
-
new.initialized?(:my_date).should
|
183
|
+
new.initialized?(:my_date).should eql(false)
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should call blank on val if :blank is supplied" do
|
187
187
|
new = WithConditional.new(:my_other_date => nil)
|
188
|
-
new.initialized?(:my_other_date).should
|
188
|
+
new.initialized?(:my_other_date).should eql(false)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -246,9 +246,9 @@ describe SimpleModel::Attributes do
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
it "should merge defined attributes when class are inherited" do
|
249
|
-
NewerBase.attribute_defined?(:bar).should
|
249
|
+
NewerBase.attribute_defined?(:bar).should eql(true)
|
250
250
|
n = NewerBase.new
|
251
|
-
n.respond_to?(:bar_will_change!).should
|
251
|
+
n.respond_to?(:bar_will_change!).should eql(true)
|
252
252
|
end
|
253
253
|
|
254
254
|
it "should defaults that were not initialized should work from parent class" do
|
@@ -266,8 +266,8 @@ describe SimpleModel::Attributes do
|
|
266
266
|
end
|
267
267
|
|
268
268
|
it "should set attribute from alias" do
|
269
|
-
MyBase.new(:other => true).bar?.should
|
270
|
-
NewerBase.new(:other => true).bar?.should
|
269
|
+
MyBase.new(:other => true).bar?.should eql(true)
|
270
|
+
NewerBase.new(:other => true).bar?.should eql(true)
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
data/spec/extend_core_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe SimpleModel::ExtendCore, 'Float.rb' do
|
|
18
18
|
0.333.to_currency_s.class.should eql(String)
|
19
19
|
end
|
20
20
|
it "should prefix string with currency symbol" do
|
21
|
-
5.12.to_currency_s.include?("$").should
|
21
|
+
5.12.to_currency_s.include?("$").should eql(true)
|
22
22
|
end
|
23
23
|
it "should padd with zeros for cents" do
|
24
24
|
5.0.to_currency_s.should eql("$5.00")
|
@@ -53,7 +53,7 @@ describe SimpleModel::ExtendCore, 'String.rb' do
|
|
53
53
|
end
|
54
54
|
it "should return true if string is '1' or 't' or 'true'"do
|
55
55
|
['1','t','true'].each do |s|
|
56
|
-
s.to_b.should
|
56
|
+
s.to_b.should eql(true)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/spec/simple_model_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe SimpleModel do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
t = TestStuff.new
|
36
|
-
t.save.should
|
36
|
+
t.save.should eql(false)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -49,7 +49,7 @@ describe SimpleModel do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
t = TestStuff.new
|
52
|
-
t.destroy.should
|
52
|
+
t.destroy.should eql(true)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
context "action methods that end with '!'" do
|
@@ -93,18 +93,18 @@ describe SimpleModel do
|
|
93
93
|
class TestStuff < SimpleModel::Base
|
94
94
|
has_booleans :test_boolean
|
95
95
|
end
|
96
|
-
TestStuff.new.methods.include?(:test_boolean).should
|
97
|
-
#a.test.should
|
96
|
+
TestStuff.new.methods.include?(:test_boolean).should eql(true)
|
97
|
+
#a.test.should eql(false)
|
98
98
|
end
|
99
99
|
it 'Should add a boolean setter' do
|
100
100
|
class TestStuff < SimpleModel::Base
|
101
101
|
has_booleans :test_boolean
|
102
102
|
end
|
103
103
|
t = TestStuff.new
|
104
|
-
t.methods.include?(:test_boolean).should
|
104
|
+
t.methods.include?(:test_boolean).should eql(true)
|
105
105
|
t.test_boolean = true
|
106
|
-
t.test_boolean.should
|
107
|
-
#a.test.should
|
106
|
+
t.test_boolean.should eql(true)
|
107
|
+
#a.test.should eql(false)
|
108
108
|
end
|
109
109
|
it 'Should add a error setter' do
|
110
110
|
|
@@ -114,14 +114,14 @@ describe SimpleModel do
|
|
114
114
|
a = TestStuff.new
|
115
115
|
|
116
116
|
a.errors.add(:test_attr, "test")
|
117
|
-
a.errors?.should
|
117
|
+
a.errors?.should eql(true)
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'Should include validation callbacks' do
|
121
121
|
class TestStuff < SimpleModel::Base
|
122
122
|
end
|
123
|
-
TestStuff.respond_to?(:before_validation).should
|
124
|
-
TestStuff.respond_to?(:after_save).should
|
123
|
+
TestStuff.respond_to?(:before_validation).should eql(true)
|
124
|
+
TestStuff.respond_to?(:after_save).should eql(true)
|
125
125
|
|
126
126
|
end
|
127
127
|
|
@@ -191,13 +191,13 @@ describe SimpleModel do
|
|
191
191
|
|
192
192
|
t = TestStuff.new
|
193
193
|
t.foo = "bar"
|
194
|
-
t.foo_changed?.should
|
195
|
-
t.respond_to?(:foo_will_change!).should
|
196
|
-
t.respond_to?(:boo_will_change!).should
|
194
|
+
t.foo_changed?.should eql(true)
|
195
|
+
t.respond_to?(:foo_will_change!).should eql(true)
|
196
|
+
t.respond_to?(:boo_will_change!).should eql(true)
|
197
197
|
t.foo_change.should eql(["def","bar"])
|
198
|
-
t.changed?.should
|
198
|
+
t.changed?.should eql(true)
|
199
199
|
t.save
|
200
|
-
t.changed?.should
|
200
|
+
t.changed?.should eql(false)
|
201
201
|
end
|
202
202
|
|
203
203
|
context "regression tests" do
|
@@ -218,15 +218,15 @@ describe SimpleModel do
|
|
218
218
|
|
219
219
|
end
|
220
220
|
it "should merge defined attributes when class are inherited" do
|
221
|
-
NewTestStuff.attribute_defined?(:bar).blank?.should
|
222
|
-
NewTestStuff.attribute_defined?(:foo).blank?.should
|
221
|
+
NewTestStuff.attribute_defined?(:bar).blank?.should eql(false)
|
222
|
+
NewTestStuff.attribute_defined?(:foo).blank?.should eql(false)
|
223
223
|
end
|
224
224
|
it "should merge defined attributes when class are inherited" do
|
225
|
-
TestStuff.new.respond_to?(:bar_will_change!).should
|
225
|
+
TestStuff.new.respond_to?(:bar_will_change!).should eql(true)
|
226
226
|
t = OtherStuff.new
|
227
227
|
t.bar = [1,2,4]
|
228
|
-
NewTestStuff.new.respond_to?(:bar_will_change!).should
|
229
|
-
NewTestStuff.new.respond_to?(:foo_will_change!).should
|
228
|
+
NewTestStuff.new.respond_to?(:bar_will_change!).should eql(true)
|
229
|
+
NewTestStuff.new.respond_to?(:foo_will_change!).should eql(true)
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should not throw exception method missing" do
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.16
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joshua T Mckinney
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activemodel
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,20 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-autotest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
65
|
requirements:
|
59
66
|
- - ! '>='
|
60
67
|
- !ruby/object:Gem::Version
|
@@ -62,7 +69,6 @@ dependencies:
|
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: autotest
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
73
|
- - ! '>='
|
68
74
|
- !ruby/object:Gem::Version
|
@@ -70,7 +76,6 @@ dependencies:
|
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
80
|
- - ! '>='
|
76
81
|
- !ruby/object:Gem::Version
|
@@ -110,27 +115,26 @@ files:
|
|
110
115
|
- spec/spec_helper.rb
|
111
116
|
homepage: ''
|
112
117
|
licenses: []
|
118
|
+
metadata: {}
|
113
119
|
post_install_message:
|
114
120
|
rdoc_options: []
|
115
121
|
require_paths:
|
116
122
|
- lib
|
117
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
124
|
requirements:
|
120
125
|
- - ! '>='
|
121
126
|
- !ruby/object:Gem::Version
|
122
127
|
version: '0'
|
123
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
129
|
requirements:
|
126
130
|
- - ! '>='
|
127
131
|
- !ruby/object:Gem::Version
|
128
132
|
version: '0'
|
129
133
|
requirements: []
|
130
134
|
rubyforge_project: simple_model
|
131
|
-
rubygems_version:
|
135
|
+
rubygems_version: 2.4.2
|
132
136
|
signing_key:
|
133
|
-
specification_version:
|
137
|
+
specification_version: 4
|
134
138
|
summary: Simpifies building tableless models or models backed by webservices
|
135
139
|
test_files:
|
136
140
|
- spec/attributes_spec.rb
|