couch_potato 0.6.0 → 0.7.0.pre.1
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.
- data/.gitignore +0 -1
- data/.travis.yml +9 -1
- data/CHANGES.md +12 -0
- data/Gemfile.lock +29 -23
- data/MIT-LICENSE.txt +1 -1
- data/README.md +68 -38
- data/Rakefile +19 -60
- data/active_support_3_0.lock +4 -0
- data/active_support_3_1.lock +4 -0
- data/active_support_3_2 +4 -0
- data/active_support_3_2.lock +55 -0
- data/couch_potato.gemspec +1 -0
- data/lib/couch_potato/database.rb +55 -27
- data/lib/couch_potato/persistence/active_model_compliance.rb +6 -2
- data/lib/couch_potato/persistence/callbacks.rb +0 -1
- data/lib/couch_potato/persistence/dirty_attributes.rb +8 -17
- data/lib/couch_potato/persistence/json.rb +3 -2
- data/lib/couch_potato/persistence/properties.rb +19 -8
- data/lib/couch_potato/persistence/simple_property.rb +1 -3
- data/lib/couch_potato/persistence/type_caster.rb +7 -2
- data/lib/couch_potato/persistence.rb +27 -13
- data/lib/couch_potato/railtie.rb +1 -1
- data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +12 -12
- data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +8 -8
- data/lib/couch_potato/rspec/matchers/reduce_to_matcher.rb +10 -10
- data/lib/couch_potato/rspec/matchers.rb +8 -7
- data/lib/couch_potato/validation.rb +15 -11
- data/lib/couch_potato/version.rb +1 -1
- data/lib/couch_potato/view/base_view_spec.rb +14 -12
- data/lib/couch_potato/view/model_view_spec.rb +134 -39
- data/lib/couch_potato/view/properties_view_spec.rb +11 -7
- data/lib/couch_potato/view/view_query.rb +10 -9
- data/lib/couch_potato.rb +25 -10
- data/spec/callbacks_spec.rb +88 -0
- data/spec/create_spec.rb +22 -4
- data/spec/default_property_spec.rb +6 -0
- data/spec/property_spec.rb +81 -44
- data/spec/railtie_spec.rb +20 -18
- data/spec/spec_helper.rb +19 -1
- data/spec/unit/active_model_compliance_spec.rb +17 -11
- data/spec/unit/attributes_spec.rb +33 -10
- data/spec/unit/base_view_spec_spec.rb +19 -5
- data/spec/unit/couch_potato_spec.rb +1 -20
- data/spec/unit/create_spec.rb +2 -2
- data/spec/unit/database_spec.rb +113 -47
- data/spec/unit/dirty_attributes_spec.rb +19 -19
- data/spec/unit/model_view_spec_spec.rb +78 -1
- data/spec/unit/properties_view_spec_spec.rb +18 -5
- data/spec/unit/validation_spec.rb +1 -55
- data/spec/unit/view_query_spec.rb +48 -26
- data/spec/{custom_view_spec.rb → views_spec.rb} +59 -17
- metadata +88 -90
- data/.rvmrc +0 -1
- data/lib/core_ext/object.rb +0 -5
- data/lib/core_ext/string.rb +0 -12
- data/lib/core_ext/symbol.rb +0 -15
- data/lib/couch_potato/validation/with_active_model.rb +0 -27
- data/lib/couch_potato/validation/with_validatable.rb +0 -41
data/spec/property_spec.rb
CHANGED
@@ -4,16 +4,19 @@ require 'fixtures/person'
|
|
4
4
|
|
5
5
|
class Watch
|
6
6
|
include CouchPotato::Persistence
|
7
|
-
|
7
|
+
|
8
8
|
property :time, :type => Time
|
9
9
|
property :date, :type => Date
|
10
|
+
property :custom, :type => [String]
|
11
|
+
property :custom_date, :type => [Date]
|
12
|
+
property :custom_address, :type => [Address]
|
10
13
|
property :overwritten_read
|
11
14
|
property :overwritten_write
|
12
|
-
|
15
|
+
|
13
16
|
def overwritten_read
|
14
17
|
super.to_s
|
15
18
|
end
|
16
|
-
|
19
|
+
|
17
20
|
def overwritten_write=(value)
|
18
21
|
super value.to_s
|
19
22
|
end
|
@@ -27,40 +30,40 @@ describe 'properties' do
|
|
27
30
|
before(:all) do
|
28
31
|
recreate_db
|
29
32
|
end
|
30
|
-
|
33
|
+
|
31
34
|
it "should allow me to overwrite read accessor and call super" do
|
32
35
|
Watch.new(:overwritten_read => 1).overwritten_read.should == '1'
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
it "should allow me to overwrite write accessor and call super" do
|
36
39
|
Watch.new(:overwritten_write => 1).overwritten_write.should == '1'
|
37
40
|
end
|
38
|
-
|
41
|
+
|
39
42
|
it "should return the property names" do
|
40
43
|
Comment.property_names.should == [:created_at, :updated_at, :title]
|
41
44
|
end
|
42
|
-
|
45
|
+
|
43
46
|
it "should persist a string" do
|
44
47
|
c = Comment.new :title => 'my title'
|
45
48
|
CouchPotato.database.save_document! c
|
46
49
|
c = CouchPotato.database.load_document c.id
|
47
50
|
c.title.should == 'my title'
|
48
51
|
end
|
49
|
-
|
52
|
+
|
50
53
|
it "should persist a number" do
|
51
54
|
c = Comment.new :title => 3
|
52
55
|
CouchPotato.database.save_document! c
|
53
56
|
c = CouchPotato.database.load_document c.id
|
54
57
|
c.title.should == 3
|
55
58
|
end
|
56
|
-
|
59
|
+
|
57
60
|
it "should persist a hash" do
|
58
61
|
c = Comment.new :title => {'key' => 'value'}
|
59
62
|
CouchPotato.database.save_document! c
|
60
63
|
c = CouchPotato.database.load_document c.id
|
61
64
|
c.title.should == {'key' => 'value'}
|
62
65
|
end
|
63
|
-
|
66
|
+
|
64
67
|
def it_should_persist value
|
65
68
|
c = Comment.new :title => value
|
66
69
|
CouchPotato.database.save_document! c
|
@@ -99,7 +102,7 @@ describe 'properties' do
|
|
99
102
|
]
|
100
103
|
it_should_persist something_very_complex
|
101
104
|
end
|
102
|
-
|
105
|
+
|
103
106
|
it "should persist an object" do
|
104
107
|
p = Person.new
|
105
108
|
a = Address.new :city => 'Denver'
|
@@ -108,7 +111,7 @@ describe 'properties' do
|
|
108
111
|
p = CouchPotato.database.load_document p.id
|
109
112
|
p.ship_address.should === a
|
110
113
|
end
|
111
|
-
|
114
|
+
|
112
115
|
it "should persist null for a null " do
|
113
116
|
p = Person.new
|
114
117
|
p.ship_address = nil
|
@@ -116,7 +119,7 @@ describe 'properties' do
|
|
116
119
|
p = CouchPotato.database.load_document p.id
|
117
120
|
p.ship_address.should be_nil
|
118
121
|
end
|
119
|
-
|
122
|
+
|
120
123
|
it "should actually pass the null value down in the JSON document " do
|
121
124
|
p = Person.new
|
122
125
|
p.ship_address = nil
|
@@ -135,7 +138,7 @@ describe 'properties' do
|
|
135
138
|
p = CouchPotato.database.load_document p.id
|
136
139
|
p.ship_address.should be_false
|
137
140
|
end
|
138
|
-
|
141
|
+
|
139
142
|
describe "time properties" do
|
140
143
|
it "should persist a Time as utc" do
|
141
144
|
time = Time.now
|
@@ -144,7 +147,7 @@ describe 'properties' do
|
|
144
147
|
w = CouchPotato.database.load_document w.id
|
145
148
|
w.time.to_s.should == time.utc.to_s
|
146
149
|
end
|
147
|
-
|
150
|
+
|
148
151
|
it "should parse a string and persist it as utc time" do
|
149
152
|
w = Watch.new :time => '2009-01-01 13:25 +0100'
|
150
153
|
CouchPotato.database.save_document! w
|
@@ -152,14 +155,14 @@ describe 'properties' do
|
|
152
155
|
w.time.should be_a(Time)
|
153
156
|
w.time.should == Time.parse('2009-01-01 12:25 +0000')
|
154
157
|
end
|
155
|
-
|
158
|
+
|
156
159
|
it "should store nil" do
|
157
160
|
w = Watch.new :time => nil
|
158
161
|
CouchPotato.database.save_document! w
|
159
162
|
w = CouchPotato.database.load_document w.id
|
160
163
|
w.time.should be_nil
|
161
164
|
end
|
162
|
-
|
165
|
+
|
163
166
|
it "should store an empty string as nil" do
|
164
167
|
w = Watch.new :time => ''
|
165
168
|
CouchPotato.database.save_document! w
|
@@ -167,7 +170,7 @@ describe 'properties' do
|
|
167
170
|
w.time.should be_nil
|
168
171
|
end
|
169
172
|
end
|
170
|
-
|
173
|
+
|
171
174
|
describe "date properties" do
|
172
175
|
it "should persist a date" do
|
173
176
|
date = Date.today
|
@@ -176,21 +179,21 @@ describe 'properties' do
|
|
176
179
|
w = CouchPotato.database.load_document w.id
|
177
180
|
w.date.should == date
|
178
181
|
end
|
179
|
-
|
182
|
+
|
180
183
|
it "should parse a string and persist it as a date" do
|
181
184
|
w = Watch.new :date => '2009-01-10'
|
182
185
|
CouchPotato.database.save_document! w
|
183
186
|
w = CouchPotato.database.load_document w.id
|
184
187
|
w.date.should == Date.parse('2009-01-10')
|
185
188
|
end
|
186
|
-
|
189
|
+
|
187
190
|
it "should store nil" do
|
188
191
|
w = Watch.new :date => nil
|
189
192
|
CouchPotato.database.save_document! w
|
190
193
|
w = CouchPotato.database.load_document w.id
|
191
194
|
w.date.should be_nil
|
192
195
|
end
|
193
|
-
|
196
|
+
|
194
197
|
it "should store an empty string as nil" do
|
195
198
|
w = Watch.new :date => ''
|
196
199
|
CouchPotato.database.save_document! w
|
@@ -198,7 +201,40 @@ describe 'properties' do
|
|
198
201
|
w.date.should be_nil
|
199
202
|
end
|
200
203
|
end
|
201
|
-
|
204
|
+
|
205
|
+
describe "array properties" do
|
206
|
+
it "should persist an array of strings" do
|
207
|
+
w = Watch.new :custom => ["moin"]
|
208
|
+
CouchPotato.database.save_document! w
|
209
|
+
w = CouchPotato.database.load_document w.id
|
210
|
+
w.custom.should eql(["moin"])
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should persist an array of dates" do
|
214
|
+
date = Date.today
|
215
|
+
w = Watch.new :custom_date => [date]
|
216
|
+
CouchPotato.database.save_document! w
|
217
|
+
w = CouchPotato.database.load_document w.id
|
218
|
+
w.custom_date.should eql([date])
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should persist an array of nested documents" do
|
222
|
+
address = Address.new(:verified => 1)
|
223
|
+
w = Watch.new :custom_address => [address]
|
224
|
+
CouchPotato.database.save_document! w
|
225
|
+
w = CouchPotato.database.load_document w.id
|
226
|
+
w.custom_address.should eql([address])
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should handle nil values" do
|
230
|
+
address = Address.new(:verified => 1)
|
231
|
+
w = Watch.new :custom_address => nil
|
232
|
+
CouchPotato.database.save_document! w
|
233
|
+
w = CouchPotato.database.load_document w.id
|
234
|
+
w.custom_address.should eql(nil)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
202
238
|
describe "boolean properties" do
|
203
239
|
it "should persist '0' as false" do
|
204
240
|
a = Address.new
|
@@ -207,7 +243,7 @@ describe 'properties' do
|
|
207
243
|
a = CouchPotato.database.load_document a.id
|
208
244
|
a.verified.should be_false
|
209
245
|
end
|
210
|
-
|
246
|
+
|
211
247
|
it "should persist 0 as false" do
|
212
248
|
a = Address.new
|
213
249
|
a.verified = 0
|
@@ -215,7 +251,7 @@ describe 'properties' do
|
|
215
251
|
a = CouchPotato.database.load_document a.id
|
216
252
|
a.verified.should be_false
|
217
253
|
end
|
218
|
-
|
254
|
+
|
219
255
|
it "should persist 'false' as false" do
|
220
256
|
a = Address.new
|
221
257
|
a.verified = 'false'
|
@@ -223,7 +259,7 @@ describe 'properties' do
|
|
223
259
|
a = CouchPotato.database.load_document a.id
|
224
260
|
a.verified.should be_false
|
225
261
|
end
|
226
|
-
|
262
|
+
|
227
263
|
it "should persist '1' as true" do
|
228
264
|
a = Address.new
|
229
265
|
a.verified = '1'
|
@@ -231,7 +267,7 @@ describe 'properties' do
|
|
231
267
|
a = CouchPotato.database.load_document a.id
|
232
268
|
a.verified.should be_true
|
233
269
|
end
|
234
|
-
|
270
|
+
|
235
271
|
it "should persist 1 as true" do
|
236
272
|
a = Address.new
|
237
273
|
a.verified = 1
|
@@ -239,7 +275,7 @@ describe 'properties' do
|
|
239
275
|
a = CouchPotato.database.load_document a.id
|
240
276
|
a.verified.should be_true
|
241
277
|
end
|
242
|
-
|
278
|
+
|
243
279
|
it "should leave nil as nil" do
|
244
280
|
a = Address.new
|
245
281
|
a.verified = nil
|
@@ -253,33 +289,33 @@ describe 'properties' do
|
|
253
289
|
it "should return true if property set" do
|
254
290
|
Comment.new(:title => 'title').title?.should be_true
|
255
291
|
end
|
256
|
-
|
292
|
+
|
257
293
|
it "should return false if property nil" do
|
258
294
|
Comment.new.title?.should be_false
|
259
295
|
end
|
260
|
-
|
296
|
+
|
261
297
|
it "should return false if property false" do
|
262
298
|
Comment.new(:title => false).title?.should be_false
|
263
299
|
end
|
264
|
-
|
300
|
+
|
265
301
|
it "should return false if property blank" do
|
266
302
|
Comment.new(:title => '').title?.should be_false
|
267
303
|
end
|
268
304
|
end
|
269
|
-
|
305
|
+
|
270
306
|
describe "with subclasses" do
|
271
307
|
it "should include properties of superclasses" do
|
272
308
|
CuckooClock.properties.map(&:name).should include(:time)
|
273
309
|
CuckooClock.properties.map(&:name).should include(:cuckoo)
|
274
310
|
end
|
275
|
-
|
311
|
+
|
276
312
|
it "should return attributes of superclasses" do
|
277
313
|
clock = CuckooClock.new(:time => Time.now, :cuckoo => 'bavarian')
|
278
|
-
clock.attributes[:time].should_not
|
279
|
-
clock.attributes[:cuckoo].should
|
314
|
+
clock.attributes[:time].should_not be_nil
|
315
|
+
clock.attributes[:cuckoo].should eql('bavarian')
|
280
316
|
end
|
281
317
|
end
|
282
|
-
|
318
|
+
|
283
319
|
describe "inspecting an object" do
|
284
320
|
let(:comment) do
|
285
321
|
comment = Comment.new(:title => 'title')
|
@@ -289,35 +325,36 @@ describe 'properties' do
|
|
289
325
|
end
|
290
326
|
comment
|
291
327
|
end
|
292
|
-
|
328
|
+
|
293
329
|
it "should not include change-tracking variables" do
|
294
330
|
comment.inspect.should_not include('title_was')
|
295
331
|
end
|
296
|
-
|
332
|
+
|
297
333
|
it "should include the normal persistent variables" do
|
298
334
|
comment.inspect.should include('title: "title"')
|
299
335
|
end
|
300
|
-
|
336
|
+
|
301
337
|
it "should include the id" do
|
302
338
|
comment.inspect.should include(%Q{_id: "123456abcdef",})
|
303
339
|
end
|
304
|
-
|
340
|
+
|
305
341
|
it "should include the revision" do
|
306
342
|
comment.inspect.should include(%Q{_rev: "1-654321fedcba",})
|
307
343
|
end
|
308
|
-
|
344
|
+
|
309
345
|
it "should return a complete string" do
|
310
346
|
# stub to work around (un)sorted hash on different rubies
|
311
347
|
comment.stub!(:attributes).and_return([['created_at', ''], ['updated_at', ''], ['title', 'title']])
|
312
|
-
|
348
|
+
doc = '#<Comment _id: "123456abcdef", _rev: "1-654321fedcba", created_at: "", updated_at: "", title: "title">'
|
349
|
+
comment.inspect.should eql(doc)
|
313
350
|
end
|
314
|
-
|
351
|
+
|
315
352
|
it "should include complex datatypes fully inspected" do
|
316
353
|
comment.title = {'en' => 'Blog post'}
|
317
354
|
comment.inspect.should include('title: {"en"=>"Blog post"}')
|
318
|
-
|
355
|
+
|
319
356
|
comment.title = nil
|
320
357
|
comment.inspect.should include('title: nil')
|
321
358
|
end
|
322
359
|
end
|
323
|
-
end
|
360
|
+
end
|
data/spec/railtie_spec.rb
CHANGED
@@ -10,7 +10,7 @@ module Rails
|
|
10
10
|
def self.initializer(*args)
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def self.root
|
15
15
|
RSpec::Mocks::Mock.new :join => ''
|
16
16
|
end
|
@@ -20,46 +20,48 @@ require 'couch_potato/railtie'
|
|
20
20
|
|
21
21
|
describe "railtie" do
|
22
22
|
before(:all) do
|
23
|
-
@
|
23
|
+
@database_name = CouchPotato::Config.database_name
|
24
|
+
@default_language = CouchPotato::Config.default_language
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
after(:all) do
|
27
|
-
CouchPotato::Config.
|
28
|
+
CouchPotato::Config.database_name = @database_name
|
29
|
+
CouchPotato::Config.default_language = @default_language
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
context 'yaml file contains only database names' do
|
31
33
|
it "should set the database name from the yaml file" do
|
32
34
|
File.stub(:read => "test: test_db")
|
33
|
-
|
35
|
+
|
34
36
|
CouchPotato::Config.should_receive(:database_name=).with('test_db')
|
35
|
-
|
37
|
+
|
36
38
|
CouchPotato.rails_init
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
context 'yaml file contains more configuration' do
|
41
43
|
before(:each) do
|
42
|
-
File.stub(:read => "test: \n database: test_db\n
|
44
|
+
File.stub(:read => "test: \n database: test_db\n default_language: :erlang")
|
43
45
|
end
|
44
|
-
|
45
|
-
it "
|
46
|
+
|
47
|
+
it "set the database name from the yaml file" do
|
46
48
|
CouchPotato::Config.should_receive(:database_name=).with('test_db')
|
47
|
-
|
49
|
+
|
48
50
|
CouchPotato.rails_init
|
49
51
|
end
|
50
|
-
|
51
|
-
it
|
52
|
-
CouchPotato::Config.should_receive(:
|
53
|
-
|
52
|
+
|
53
|
+
it 'sets the default language from the yaml file' do
|
54
|
+
CouchPotato::Config.should_receive(:default_language=).with(:erlang)
|
55
|
+
|
54
56
|
CouchPotato.rails_init
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
59
|
+
|
58
60
|
it "should process the yml file with erb" do
|
59
61
|
File.stub(:read => "test: \n database: <%= 'db' %>")
|
60
62
|
|
61
63
|
CouchPotato::Config.should_receive(:database_name=).with('db')
|
62
|
-
|
64
|
+
|
63
65
|
CouchPotato.rails_init
|
64
66
|
end
|
65
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,6 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
9
9
|
require 'couch_potato'
|
10
10
|
|
11
11
|
CouchPotato::Config.database_name = ENV['DATABASE'] || 'couch_potato_test'
|
12
|
-
CouchPotato::Config.validation_framework = ENV['VALIDATION_FRAMEWORK'].to_sym unless ENV['VALIDATION_FRAMEWORK'].blank?
|
13
12
|
|
14
13
|
# silence deprecation warnings from ActiveModel as the Spec uses Errors#on
|
15
14
|
begin
|
@@ -42,3 +41,22 @@ RSpec::Matchers.define :string_matching do |regex|
|
|
42
41
|
string =~ regex
|
43
42
|
end
|
44
43
|
end
|
44
|
+
|
45
|
+
RSpec::Matchers.define :eql_ignoring_indentation do |expected|
|
46
|
+
match do |string|
|
47
|
+
strip_indentation(string) == strip_indentation(expected)
|
48
|
+
end
|
49
|
+
|
50
|
+
failure_message_for_should do |actual|
|
51
|
+
"expected\n#{strip_indentation(actual).inspect} to == \n#{strip_indentation(expected).inspect} but wasn't."
|
52
|
+
end
|
53
|
+
|
54
|
+
failure_message_for_should_not do |actual|
|
55
|
+
"expected\n#{strip_indentation(actual).inspect} to not == \n#{strip_indentation(expected).inspect} but wasn."
|
56
|
+
end
|
57
|
+
|
58
|
+
def strip_indentation(string)
|
59
|
+
string.gsub(/^\s+/m, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'active_model'
|
5
|
-
|
5
|
+
|
6
6
|
describe 'ActiveModel conformance of couch potato objects' do
|
7
7
|
include ActiveModel::Lint::Tests
|
8
8
|
|
@@ -23,47 +23,53 @@ begin
|
|
23
23
|
before(:each) do
|
24
24
|
@model = ActiveComment.new
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
describe '#to_partial_path' do
|
28
|
+
it 'returns a path based on the class name' do
|
29
|
+
@model.to_partial_path.should == 'active_comments/active_comment'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
27
33
|
describe "#persisted?" do
|
28
34
|
it "should return false if it is a new document " do
|
29
35
|
@model.should_not be_persisted
|
30
36
|
end
|
31
|
-
|
37
|
+
|
32
38
|
it "should be true if it was saved" do
|
33
39
|
@comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
|
34
40
|
CouchPotato.database.save_document! @comment
|
35
41
|
@comment.should be_persisted
|
36
42
|
end
|
37
43
|
end
|
38
|
-
|
44
|
+
|
39
45
|
describe "#to_key" do
|
40
46
|
it "should return nil if the document was not persisted" do
|
41
47
|
@model.to_key.should be_nil
|
42
48
|
end
|
43
|
-
|
49
|
+
|
44
50
|
it "should return the id of the document if it was persisted" do
|
45
51
|
@comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
|
46
52
|
CouchPotato.database.save_document! @comment
|
47
53
|
@comment.to_key.should == [@comment.id]
|
48
54
|
end
|
49
55
|
end
|
50
|
-
|
51
|
-
|
56
|
+
|
57
|
+
|
52
58
|
describe "#errors" do
|
53
59
|
it "should return a single error as array" do
|
54
60
|
@model.valid?
|
55
61
|
@model.errors[:name].should be_kind_of(Array)
|
56
62
|
end
|
57
|
-
|
63
|
+
|
58
64
|
it "should return multiple errors as array" do
|
59
65
|
@model.valid?
|
60
66
|
@model.errors[:email].size.should == 2
|
61
67
|
end
|
62
|
-
|
68
|
+
|
63
69
|
it "should return no error as an empty array" do
|
64
70
|
@model.errors[:name].should == []
|
65
71
|
end
|
66
|
-
|
72
|
+
|
67
73
|
it "should be able to be Marshal.dump'ed" do
|
68
74
|
lambda { Marshal.dump(@model.errors) }.should_not raise_error
|
69
75
|
end
|
@@ -88,7 +94,7 @@ begin
|
|
88
94
|
object.should be_a(klass)
|
89
95
|
end
|
90
96
|
end
|
91
|
-
|
97
|
+
|
92
98
|
rescue LoadError
|
93
99
|
STDERR.puts "WARNING: active_model gem not installed. Not running ActiveModel specs."
|
94
100
|
end
|
@@ -12,7 +12,7 @@ class Plant
|
|
12
12
|
property :leaf_count
|
13
13
|
property :typed_leaf_count, :type => Fixnum
|
14
14
|
property :typed_leaf_size, :type => Float
|
15
|
-
property :branch, type
|
15
|
+
property :branch, :type => Branch
|
16
16
|
end
|
17
17
|
|
18
18
|
|
@@ -23,13 +23,32 @@ describe "attributes" do
|
|
23
23
|
plant.attributes = {:leaf_count => 1}
|
24
24
|
plant.leaf_count.should == 1
|
25
25
|
end
|
26
|
+
|
27
|
+
it "should assign the attributes via []=" do
|
28
|
+
plant = Plant.new
|
29
|
+
plant[:leaf_count] = 1
|
30
|
+
plant.leaf_count.should == 1
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
context "attributes" do
|
29
35
|
it "should return the attributes" do
|
30
36
|
plant = Plant.new(:leaf_count => 1)
|
31
37
|
plant.attributes.should == {:leaf_count => 1, :created_at => nil, :updated_at => nil,
|
32
|
-
|
38
|
+
:typed_leaf_count => nil, :typed_leaf_size => nil, :branch => nil}
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the attributes via []" do
|
42
|
+
plant = Plant.new(:leaf_count => 1)
|
43
|
+
plant.attributes[:leaf_count].should eql(plant[:leaf_count])
|
44
|
+
plant.attributes[:leaf_count].should eql(1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "has_key?" do
|
49
|
+
it "should respond to has_key?" do
|
50
|
+
plant = Plant.new(:leaf_count => 1)
|
51
|
+
plant.has_key?(:leaf_count).should be_true
|
33
52
|
end
|
34
53
|
end
|
35
54
|
|
@@ -67,37 +86,42 @@ describe "attributes" do
|
|
67
86
|
end
|
68
87
|
|
69
88
|
describe "fixnum" do
|
70
|
-
it
|
89
|
+
it 'rounds a float to a fixnum' do
|
90
|
+
@plant.typed_leaf_count = 4.5
|
91
|
+
@plant.typed_leaf_count.should == 5
|
92
|
+
end
|
93
|
+
|
94
|
+
it "converts a string into a fixnum" do
|
71
95
|
@plant.typed_leaf_count = '4'
|
72
96
|
@plant.typed_leaf_count.should == 4
|
73
97
|
end
|
74
98
|
|
75
|
-
it "
|
99
|
+
it "converts a string into a negative fixnum" do
|
76
100
|
@plant.typed_leaf_count = '-4'
|
77
101
|
@plant.typed_leaf_count.should == -4
|
78
102
|
end
|
79
103
|
|
80
|
-
it "
|
104
|
+
it "leaves a fixnum as is" do
|
81
105
|
@plant.typed_leaf_count = 4
|
82
106
|
@plant.typed_leaf_count.should == 4
|
83
107
|
end
|
84
108
|
|
85
|
-
it "
|
109
|
+
it "leaves nil as is" do
|
86
110
|
@plant.typed_leaf_count = nil
|
87
111
|
@plant.typed_leaf_count.should be_nil
|
88
112
|
end
|
89
113
|
|
90
|
-
it "
|
114
|
+
it "sets the attributes to zero if a string given" do
|
91
115
|
@plant.typed_leaf_count = 'x'
|
92
116
|
@plant.typed_leaf_count.should == 0
|
93
117
|
end
|
94
118
|
|
95
|
-
it "
|
119
|
+
it "parses numbers out of a string" do
|
96
120
|
@plant.typed_leaf_count = 'x123'
|
97
121
|
@plant.typed_leaf_count.should == 123
|
98
122
|
end
|
99
123
|
|
100
|
-
it "
|
124
|
+
it "set the attributes to nil if given a blank string" do
|
101
125
|
@plant.typed_leaf_count = ''
|
102
126
|
@plant.typed_leaf_count.should be_nil
|
103
127
|
end
|
@@ -146,4 +170,3 @@ describe "attributes" do
|
|
146
170
|
end
|
147
171
|
end
|
148
172
|
end
|
149
|
-
|
@@ -4,6 +4,11 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
|
|
4
4
|
describe "view parameters" do
|
5
5
|
before(:each) do
|
6
6
|
CouchPotato::Config.split_design_documents_per_view = false
|
7
|
+
@default_language = CouchPotato::Config.default_language
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
CouchPotato::Config.default_language = @default_language
|
7
12
|
end
|
8
13
|
|
9
14
|
it "should raise an error when passing invalid view parameters" do
|
@@ -32,7 +37,7 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
|
|
32
37
|
}
|
33
38
|
}.should_not raise_error
|
34
39
|
end
|
35
|
-
|
40
|
+
|
36
41
|
it "should remove stale when it's nil" do
|
37
42
|
spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {:stale => nil}
|
38
43
|
spec.view_parameters.should == {}
|
@@ -81,17 +86,17 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
|
|
81
86
|
spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => :test_list}, {}
|
82
87
|
spec.list_name.should == :test_list
|
83
88
|
end
|
84
|
-
|
89
|
+
|
85
90
|
it "should extract the list from the view parameters" do
|
86
91
|
spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {}, {:list => :test_list}
|
87
92
|
spec.list_name.should == :test_list
|
88
93
|
end
|
89
|
-
|
94
|
+
|
90
95
|
it "should prefer the list name from the view parameters over the one from the options" do
|
91
96
|
spec = CouchPotato::View::BaseViewSpec.new stub(:lists => nil), 'all', {:list => 'my_list'}, {:list => :test_list}
|
92
97
|
spec.list_name.should == :test_list
|
93
98
|
end
|
94
|
-
|
99
|
+
|
95
100
|
it "should return the list function" do
|
96
101
|
klass = stub 'class'
|
97
102
|
klass.stub(:lists).with('test_list').and_return('<list_code>')
|
@@ -99,8 +104,17 @@ describe CouchPotato::View::BaseViewSpec, 'initialize' do
|
|
99
104
|
spec.list_function.should == '<list_code>'
|
100
105
|
end
|
101
106
|
|
102
|
-
|
107
|
+
it 'reads the language from the couch potato config by default' do
|
108
|
+
CouchPotato::Config.default_language = :ruby
|
109
|
+
spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {}, {}
|
110
|
+
spec.language.should == :ruby
|
111
|
+
end
|
103
112
|
|
113
|
+
it 'sets the language to the given language' do
|
114
|
+
spec = CouchPotato::View::BaseViewSpec.new Object, 'all', {:language => :erlang}, {}
|
115
|
+
spec.language.should == :erlang
|
116
|
+
end
|
117
|
+
end
|
104
118
|
end
|
105
119
|
|
106
120
|
|