couch_potato 1.4.0 → 1.6.3
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +12 -8
- data/CHANGES.md +4 -0
- data/Gemfile +1 -1
- data/README.md +396 -276
- data/Rakefile +9 -9
- data/couch_potato-rspec.gemspec +20 -0
- data/couch_potato.gemspec +15 -16
- data/{active_support_4_0 → gemfiles/active_support_4_0} +3 -3
- data/{active_support_3_2 → gemfiles/active_support_4_1} +3 -2
- data/gemfiles/active_support_4_2 +11 -0
- data/lib/couch_potato-rspec.rb +3 -0
- data/lib/couch_potato.rb +3 -1
- data/lib/couch_potato/database.rb +42 -39
- data/lib/couch_potato/persistence/magic_timestamps.rb +5 -5
- data/lib/couch_potato/persistence/properties.rb +8 -2
- data/lib/couch_potato/persistence/simple_property.rb +11 -9
- data/lib/couch_potato/persistence/type_caster.rb +1 -1
- data/lib/couch_potato/railtie.rb +2 -0
- data/lib/couch_potato/version.rb +2 -1
- data/lib/couch_potato/view/base_view_spec.rb +18 -8
- data/lib/couch_potato/view/view_query.rb +2 -3
- data/spec/attachments_spec.rb +3 -3
- data/spec/callbacks_spec.rb +193 -113
- data/spec/conflict_handling_spec.rb +4 -4
- data/spec/create_spec.rb +5 -5
- data/spec/default_property_spec.rb +6 -6
- data/spec/destroy_spec.rb +5 -5
- data/spec/property_spec.rb +71 -61
- data/spec/rails_spec.rb +3 -3
- data/spec/railtie_spec.rb +12 -13
- data/spec/spec_helper.rb +3 -3
- data/spec/unit/active_model_compliance_spec.rb +16 -16
- data/spec/unit/attributes_spec.rb +36 -34
- data/spec/unit/base_view_spec_spec.rb +82 -35
- data/spec/unit/callbacks_spec.rb +2 -2
- data/spec/unit/couch_potato_spec.rb +3 -3
- data/spec/unit/create_spec.rb +12 -12
- data/spec/unit/custom_views_spec.rb +1 -1
- data/spec/unit/database_spec.rb +95 -95
- data/spec/unit/date_spec.rb +3 -3
- data/spec/unit/deep_dirty_attributes_spec.rb +104 -104
- data/spec/unit/dirty_attributes_spec.rb +19 -19
- data/spec/unit/forbidden_attributes_protection_spec.rb +4 -4
- data/spec/unit/initialize_spec.rb +37 -19
- data/spec/unit/json_spec.rb +4 -4
- data/spec/unit/lists_spec.rb +8 -8
- data/spec/unit/model_view_spec_spec.rb +14 -14
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/properties_view_spec_spec.rb +4 -4
- data/spec/unit/rspec_matchers_spec.rb +73 -73
- data/spec/unit/rspec_stub_db_spec.rb +43 -42
- data/spec/unit/string_spec.rb +1 -1
- data/spec/unit/time_spec.rb +2 -2
- data/spec/unit/validation_spec.rb +1 -1
- data/spec/unit/view_query_spec.rb +54 -59
- data/spec/update_spec.rb +5 -5
- data/spec/view_updates_spec.rb +4 -4
- data/spec/views_spec.rb +43 -43
- metadata +18 -22
- data/lib/couch_potato/rspec.rb +0 -2
- data/lib/couch_potato/rspec/matchers.rb +0 -56
- data/lib/couch_potato/rspec/matchers/json2.js +0 -482
- data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +0 -53
- data/lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb +0 -166
- data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +0 -61
- data/lib/couch_potato/rspec/matchers/reduce_to_matcher.rb +0 -48
- data/lib/couch_potato/rspec/stub_db.rb +0 -57
@@ -23,11 +23,11 @@ describe 'conflict handling' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'raises an error after 5 tries' do
|
26
|
-
couchrest_database =
|
27
|
-
couchrest_database.
|
26
|
+
couchrest_database = double(:couchrest_database, info: double.as_null_object)
|
27
|
+
allow(couchrest_database).to receive(:save_doc).and_raise(CouchRest::Conflict)
|
28
28
|
db = CouchPotato::Database.new(couchrest_database)
|
29
|
-
measurement =
|
30
|
-
measurement.
|
29
|
+
measurement = double(:measurement).as_null_object
|
30
|
+
allow(measurement).to receive(:run_callbacks).and_yield
|
31
31
|
|
32
32
|
expect {
|
33
33
|
db.save(measurement, false) {|m| }
|
data/spec/create_spec.rb
CHANGED
@@ -9,19 +9,19 @@ describe "create" do
|
|
9
9
|
it "should store the class" do
|
10
10
|
@comment = Comment.new :title => 'my_title'
|
11
11
|
CouchPotato.database.save_document! @comment
|
12
|
-
CouchPotato.couchrest_database.get(@comment.id).send(JSON.create_id).
|
12
|
+
expect(CouchPotato.couchrest_database.get(@comment.id).send(JSON.create_id)).to eq('Comment')
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should persist a given created_at" do
|
16
16
|
@comment = Comment.new :created_at => Time.parse('2010-01-02 12:34:48 +0000'), :title => '-'
|
17
17
|
CouchPotato.database.save_document! @comment
|
18
|
-
CouchPotato.couchrest_database.get(@comment.id).created_at.
|
18
|
+
expect(CouchPotato.couchrest_database.get(@comment.id).created_at).to eq(Time.parse('2010-01-02 12:34:48 +0000'))
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should persist a given updated_at" do
|
22
22
|
@comment = Comment.new :updated_at => Time.parse('2010-01-02 12:34:48 +0000'), :title => '-'
|
23
23
|
CouchPotato.database.save_document! @comment
|
24
|
-
CouchPotato.couchrest_database.get(@comment.id).updated_at.
|
24
|
+
expect(CouchPotato.couchrest_database.get(@comment.id).updated_at).to eq(Time.parse('2010-01-02 12:34:48 +0000'))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ describe "create" do
|
|
29
29
|
it "should not store anything" do
|
30
30
|
@comment = Comment.new
|
31
31
|
CouchPotato.database.save_document @comment
|
32
|
-
CouchPotato.couchrest_database.documents['rows'].
|
32
|
+
expect(CouchPotato.couchrest_database.documents['rows']).to be_empty
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -46,7 +46,7 @@ describe "create" do
|
|
46
46
|
CouchPotato.with_database(db_name) do |couch|
|
47
47
|
couch.save_document! @comment
|
48
48
|
end
|
49
|
-
CouchPotato.couchrest_database_for_name(db_name).get(@comment.id).send(JSON.create_id).
|
49
|
+
expect(CouchPotato.couchrest_database_for_name(db_name).get(@comment.id).send(JSON.create_id)).to eq('Comment')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -18,7 +18,7 @@ describe 'default properties' do
|
|
18
18
|
it "uses the default value if nothing is supplied" do
|
19
19
|
t = Test.new
|
20
20
|
|
21
|
-
t.test.
|
21
|
+
expect(t.test).to eq('Test value')
|
22
22
|
end
|
23
23
|
|
24
24
|
it "persists the default value if nothing is supplied" do
|
@@ -26,27 +26,27 @@ describe 'default properties' do
|
|
26
26
|
CouchPotato.database.save_document! t
|
27
27
|
|
28
28
|
t = CouchPotato.database.load_document t.id
|
29
|
-
t.test.
|
29
|
+
expect(t.test).to eq('Test value')
|
30
30
|
end
|
31
31
|
|
32
32
|
it "does not have the same default for two instances of the object" do
|
33
33
|
t = Test.new
|
34
34
|
t2 = Test.new
|
35
|
-
t.complex.object_id.
|
35
|
+
expect(t.complex.object_id).not_to eq(t2.complex.object_id)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "does not return the default value when the actual value is empty" do
|
39
|
-
t = Test.new(:complex => []).complex.
|
39
|
+
t = expect(Test.new(:complex => []).complex).to eq([])
|
40
40
|
end
|
41
41
|
|
42
42
|
it "uses the default value also if the default is false" do
|
43
43
|
t = Test.new
|
44
|
-
t.false_value.
|
44
|
+
expect(t.false_value).to eq(false)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "uses the return value of a Proc given as the default" do
|
48
48
|
t = Test.new
|
49
|
-
t.proc.
|
49
|
+
expect(t.proc).to eq(3)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'passes the model to a block with arity 1' do
|
data/spec/destroy_spec.rb
CHANGED
@@ -13,17 +13,17 @@ describe 'destroy' do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should unset the id" do
|
16
|
-
@comment._id.
|
16
|
+
expect(@comment._id).to be_nil
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should unset the revision" do
|
20
|
-
@comment._rev.
|
20
|
+
expect(@comment._rev).to be_nil
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should remove the document from the database" do
|
24
|
-
|
25
|
-
CouchPotato.couchrest_database.get(@comment_id)
|
26
|
-
}.
|
24
|
+
expect{
|
25
|
+
CouchPotato.couchrest_database.get!(@comment_id)
|
26
|
+
}.to raise_error(CouchRest::NotFound)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/spec/property_spec.rb
CHANGED
@@ -5,14 +5,14 @@ require 'fixtures/person'
|
|
5
5
|
class Watch
|
6
6
|
include CouchPotato::Persistence
|
7
7
|
|
8
|
-
property :time, :
|
9
|
-
property :date, :
|
10
|
-
property :custom, :
|
11
|
-
property :custom_date, :
|
12
|
-
property :custom_address, :
|
8
|
+
property :time, type: Time
|
9
|
+
property :date, type: Date
|
10
|
+
property :custom, type: [String]
|
11
|
+
property :custom_date, type: [Date]
|
12
|
+
property :custom_address, type: [Address]
|
13
13
|
property :overwritten_read
|
14
14
|
property :overwritten_write
|
15
|
-
property :diameter, :
|
15
|
+
property :diameter, type: Float
|
16
16
|
|
17
17
|
def overwritten_read
|
18
18
|
super.to_s
|
@@ -23,6 +23,9 @@ class Watch
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
class Address2 < Address
|
27
|
+
end
|
28
|
+
|
26
29
|
class CuckooClock < Watch
|
27
30
|
property :cuckoo
|
28
31
|
end
|
@@ -49,43 +52,43 @@ describe 'properties' do
|
|
49
52
|
end
|
50
53
|
|
51
54
|
it "should allow me to overwrite read accessor and call super" do
|
52
|
-
Watch.new(:overwritten_read => 1).overwritten_read.
|
55
|
+
expect(Watch.new(:overwritten_read => 1).overwritten_read).to eq('1')
|
53
56
|
end
|
54
57
|
|
55
58
|
it "should allow me to overwrite write accessor and call super" do
|
56
|
-
Watch.new(:overwritten_write => 1).overwritten_write.
|
59
|
+
expect(Watch.new(:overwritten_write => 1).overwritten_write).to eq('1')
|
57
60
|
end
|
58
61
|
|
59
62
|
it "should return the property names" do
|
60
|
-
Comment.property_names.
|
63
|
+
expect(Comment.property_names).to eq([:created_at, :updated_at, :title])
|
61
64
|
end
|
62
65
|
|
63
66
|
it "should persist a string" do
|
64
67
|
c = Comment.new :title => 'my title'
|
65
68
|
CouchPotato.database.save_document! c
|
66
69
|
c = CouchPotato.database.load_document c.id
|
67
|
-
c.title.
|
70
|
+
expect(c.title).to eq('my title')
|
68
71
|
end
|
69
72
|
|
70
73
|
it "should persist a number" do
|
71
74
|
c = Comment.new :title => 3
|
72
75
|
CouchPotato.database.save_document! c
|
73
76
|
c = CouchPotato.database.load_document c.id
|
74
|
-
c.title.
|
77
|
+
expect(c.title).to eq(3)
|
75
78
|
end
|
76
79
|
|
77
80
|
it "should persist a float with leading digits" do
|
78
81
|
w = Watch.new :diameter => "46.5"
|
79
82
|
CouchPotato.database.save_document! w
|
80
83
|
w = CouchPotato.database.load_document w.id
|
81
|
-
w.diameter.
|
84
|
+
expect(w.diameter).to eq(46.5)
|
82
85
|
end
|
83
86
|
|
84
87
|
it "should persist a float with no leading digits" do
|
85
88
|
w = Watch.new :diameter => ".465"
|
86
89
|
CouchPotato.database.save_document! w
|
87
90
|
w = CouchPotato.database.load_document w.id
|
88
|
-
w.diameter.
|
91
|
+
expect(w.diameter).to eq(0.465)
|
89
92
|
end
|
90
93
|
|
91
94
|
it "should persist a big decimal" do
|
@@ -93,30 +96,37 @@ describe 'properties' do
|
|
93
96
|
c = BigDecimalContainer.new :number => BigDecimal.new( '42.42' )
|
94
97
|
CouchPotato.database.save_document! c
|
95
98
|
c = CouchPotato.database.load_document c.id
|
96
|
-
c.number.
|
99
|
+
expect(c.number).to eq(BigDecimal.new( '42.42' ))
|
97
100
|
end
|
98
101
|
|
99
102
|
it "should persist a hash" do
|
100
103
|
c = Comment.new :title => {'key' => 'value'}
|
101
104
|
CouchPotato.database.save_document! c
|
102
105
|
c = CouchPotato.database.load_document c.id
|
103
|
-
c.title.
|
106
|
+
expect(c.title).to eq({'key' => 'value'})
|
104
107
|
end
|
105
108
|
|
106
109
|
it "should persist a HashWithIndifferentAccess" do
|
107
110
|
c = Person.new :information => HashWithIndifferentAccess.new({"key" => "value"})
|
108
111
|
CouchPotato.database.save_document! c
|
109
112
|
c = CouchPotato.database.load_document c.id
|
110
|
-
c.information.
|
113
|
+
expect(c.information).to eq({'key' => 'value'})
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should persist subclasses of the specified type" do
|
117
|
+
w = Watch.new(:custom_address => [Address2.new])
|
118
|
+
CouchPotato.database.save_document! w
|
119
|
+
w = CouchPotato.database.load_document w.id
|
120
|
+
expect(w.custom_address[0]).to be_an_instance_of Address2
|
111
121
|
end
|
112
122
|
|
113
123
|
def it_should_persist value
|
114
124
|
c = Comment.new :title => value
|
115
125
|
CouchPotato.database.save_document! c
|
116
126
|
c = CouchPotato.database.load_document c.id
|
117
|
-
c.title.to_json.
|
127
|
+
expect(c.title.to_json).to eq(value.to_json)
|
118
128
|
# no id provided in embedded object, need to check yourself for content equality
|
119
|
-
c.title.
|
129
|
+
expect(c.title).not_to eq(value)
|
120
130
|
end
|
121
131
|
|
122
132
|
it "should persist a child class" do
|
@@ -157,7 +167,7 @@ describe 'properties' do
|
|
157
167
|
p.ship_address = a
|
158
168
|
CouchPotato.database.save_document! p
|
159
169
|
p = CouchPotato.database.load_document p.id
|
160
|
-
p.ship_address.to_json.
|
170
|
+
expect(p.ship_address.to_json).to be === a.to_json
|
161
171
|
end
|
162
172
|
|
163
173
|
it "should persist null for a null " do
|
@@ -165,17 +175,17 @@ describe 'properties' do
|
|
165
175
|
p.ship_address = nil
|
166
176
|
CouchPotato.database.save_document! p
|
167
177
|
p = CouchPotato.database.load_document p.id
|
168
|
-
p.ship_address.
|
178
|
+
expect(p.ship_address).to be_nil
|
169
179
|
end
|
170
180
|
|
171
181
|
it "should actually pass the null value down in the JSON document " do
|
172
182
|
p = Person.new
|
173
183
|
p.ship_address = nil
|
174
|
-
db =
|
175
|
-
db.
|
176
|
-
attributes.has_key?(:ship_address).
|
177
|
-
|
178
|
-
CouchPotato.database.
|
184
|
+
db = double(:database)
|
185
|
+
expect(db).to receive(:save_doc) { |attributes|
|
186
|
+
expect(attributes.has_key?(:ship_address)).to eq(true)
|
187
|
+
}.and_return({})
|
188
|
+
allow(CouchPotato.database).to receive(:couchrest_database).and_return(db)
|
179
189
|
CouchPotato.database.save_document! p
|
180
190
|
end
|
181
191
|
|
@@ -184,7 +194,7 @@ describe 'properties' do
|
|
184
194
|
p.ship_address = false
|
185
195
|
CouchPotato.database.save_document! p
|
186
196
|
p = CouchPotato.database.load_document p.id
|
187
|
-
p.ship_address.
|
197
|
+
expect(p.ship_address).to be_falsey
|
188
198
|
end
|
189
199
|
|
190
200
|
describe "time properties" do
|
@@ -193,29 +203,29 @@ describe 'properties' do
|
|
193
203
|
w = Watch.new :time => time
|
194
204
|
CouchPotato.database.save_document! w
|
195
205
|
w = CouchPotato.database.load_document w.id
|
196
|
-
w.time.to_s.
|
206
|
+
expect(w.time.to_s).to eq(time.utc.to_s)
|
197
207
|
end
|
198
208
|
|
199
209
|
it "should parse a string and persist it as utc time" do
|
200
210
|
w = Watch.new :time => '2009-01-01 13:25 +0100'
|
201
211
|
CouchPotato.database.save_document! w
|
202
212
|
w = CouchPotato.database.load_document w.id
|
203
|
-
w.time.
|
204
|
-
w.time.
|
213
|
+
expect(w.time).to be_a(Time)
|
214
|
+
expect(w.time).to eq(Time.parse('2009-01-01 12:25 +0000'))
|
205
215
|
end
|
206
216
|
|
207
217
|
it "should store nil" do
|
208
218
|
w = Watch.new :time => nil
|
209
219
|
CouchPotato.database.save_document! w
|
210
220
|
w = CouchPotato.database.load_document w.id
|
211
|
-
w.time.
|
221
|
+
expect(w.time).to be_nil
|
212
222
|
end
|
213
223
|
|
214
224
|
it "should store an empty string as nil" do
|
215
225
|
w = Watch.new :time => ''
|
216
226
|
CouchPotato.database.save_document! w
|
217
227
|
w = CouchPotato.database.load_document w.id
|
218
|
-
w.time.
|
228
|
+
expect(w.time).to be_nil
|
219
229
|
end
|
220
230
|
end
|
221
231
|
|
@@ -225,28 +235,28 @@ describe 'properties' do
|
|
225
235
|
w = Watch.new :date => date
|
226
236
|
CouchPotato.database.save_document! w
|
227
237
|
w = CouchPotato.database.load_document w.id
|
228
|
-
w.date.
|
238
|
+
expect(w.date).to eq(date)
|
229
239
|
end
|
230
240
|
|
231
241
|
it "should parse a string and persist it as a date" do
|
232
242
|
w = Watch.new :date => '2009-01-10'
|
233
243
|
CouchPotato.database.save_document! w
|
234
244
|
w = CouchPotato.database.load_document w.id
|
235
|
-
w.date.
|
245
|
+
expect(w.date).to eq(Date.parse('2009-01-10'))
|
236
246
|
end
|
237
247
|
|
238
248
|
it "should store nil" do
|
239
249
|
w = Watch.new :date => nil
|
240
250
|
CouchPotato.database.save_document! w
|
241
251
|
w = CouchPotato.database.load_document w.id
|
242
|
-
w.date.
|
252
|
+
expect(w.date).to be_nil
|
243
253
|
end
|
244
254
|
|
245
255
|
it "should store an empty string as nil" do
|
246
256
|
w = Watch.new :date => ''
|
247
257
|
CouchPotato.database.save_document! w
|
248
258
|
w = CouchPotato.database.load_document w.id
|
249
|
-
w.date.
|
259
|
+
expect(w.date).to be_nil
|
250
260
|
end
|
251
261
|
end
|
252
262
|
|
@@ -255,7 +265,7 @@ describe 'properties' do
|
|
255
265
|
w = Watch.new :custom => ["moin"]
|
256
266
|
CouchPotato.database.save_document! w
|
257
267
|
w = CouchPotato.database.load_document w.id
|
258
|
-
w.custom.
|
268
|
+
expect(w.custom).to eql(["moin"])
|
259
269
|
end
|
260
270
|
|
261
271
|
it "should persist an array of dates" do
|
@@ -263,7 +273,7 @@ describe 'properties' do
|
|
263
273
|
w = Watch.new :custom_date => [date]
|
264
274
|
CouchPotato.database.save_document! w
|
265
275
|
w = CouchPotato.database.load_document w.id
|
266
|
-
w.custom_date.
|
276
|
+
expect(w.custom_date).to eql([date])
|
267
277
|
end
|
268
278
|
|
269
279
|
it "should persist an array of nested documents" do
|
@@ -271,7 +281,7 @@ describe 'properties' do
|
|
271
281
|
w = Watch.new :custom_address => [address]
|
272
282
|
CouchPotato.database.save_document! w
|
273
283
|
w = CouchPotato.database.load_document w.id
|
274
|
-
w.custom_address.to_json.
|
284
|
+
expect(w.custom_address.to_json).to eql([address].to_json)
|
275
285
|
end
|
276
286
|
|
277
287
|
it "should handle nil values" do
|
@@ -279,7 +289,7 @@ describe 'properties' do
|
|
279
289
|
w = Watch.new :custom_address => nil
|
280
290
|
CouchPotato.database.save_document! w
|
281
291
|
w = CouchPotato.database.load_document w.id
|
282
|
-
w.custom_address.
|
292
|
+
expect(w.custom_address).to eql(nil)
|
283
293
|
end
|
284
294
|
end
|
285
295
|
|
@@ -289,7 +299,7 @@ describe 'properties' do
|
|
289
299
|
a.verified = '0'
|
290
300
|
CouchPotato.database.save_document! a
|
291
301
|
a = CouchPotato.database.load_document a.id
|
292
|
-
a.verified.
|
302
|
+
expect(a.verified).to be_falsey
|
293
303
|
end
|
294
304
|
|
295
305
|
it "should persist 0 as false" do
|
@@ -297,7 +307,7 @@ describe 'properties' do
|
|
297
307
|
a.verified = 0
|
298
308
|
CouchPotato.database.save_document! a
|
299
309
|
a = CouchPotato.database.load_document a.id
|
300
|
-
a.verified.
|
310
|
+
expect(a.verified).to be_falsey
|
301
311
|
end
|
302
312
|
|
303
313
|
it "should persist 'false' as false" do
|
@@ -305,7 +315,7 @@ describe 'properties' do
|
|
305
315
|
a.verified = 'false'
|
306
316
|
CouchPotato.database.save_document! a
|
307
317
|
a = CouchPotato.database.load_document a.id
|
308
|
-
a.verified.
|
318
|
+
expect(a.verified).to be_falsey
|
309
319
|
end
|
310
320
|
|
311
321
|
it "should persist '1' as true" do
|
@@ -313,7 +323,7 @@ describe 'properties' do
|
|
313
323
|
a.verified = '1'
|
314
324
|
CouchPotato.database.save_document! a
|
315
325
|
a = CouchPotato.database.load_document a.id
|
316
|
-
a.verified.
|
326
|
+
expect(a.verified).to be_truthy
|
317
327
|
end
|
318
328
|
|
319
329
|
it "should persist 1 as true" do
|
@@ -321,7 +331,7 @@ describe 'properties' do
|
|
321
331
|
a.verified = 1
|
322
332
|
CouchPotato.database.save_document! a
|
323
333
|
a = CouchPotato.database.load_document a.id
|
324
|
-
a.verified.
|
334
|
+
expect(a.verified).to be_truthy
|
325
335
|
end
|
326
336
|
|
327
337
|
it "should leave nil as nil" do
|
@@ -329,38 +339,38 @@ describe 'properties' do
|
|
329
339
|
a.verified = nil
|
330
340
|
CouchPotato.database.save_document! a
|
331
341
|
a = CouchPotato.database.load_document a.id
|
332
|
-
a.verified.
|
342
|
+
expect(a.verified).to be_nil
|
333
343
|
end
|
334
344
|
end
|
335
345
|
|
336
346
|
describe "predicate" do
|
337
347
|
it "should return true if property set" do
|
338
|
-
Comment.new(:title => 'title').title
|
348
|
+
expect(Comment.new(:title => 'title').title?).to be_truthy
|
339
349
|
end
|
340
350
|
|
341
351
|
it "should return false if property nil" do
|
342
|
-
Comment.new.title
|
352
|
+
expect(Comment.new.title?).to be_falsey
|
343
353
|
end
|
344
354
|
|
345
355
|
it "should return false if property false" do
|
346
|
-
Comment.new(:title => false).title
|
356
|
+
expect(Comment.new(:title => false).title?).to be_falsey
|
347
357
|
end
|
348
358
|
|
349
359
|
it "should return false if property blank" do
|
350
|
-
Comment.new(:title => '').title
|
360
|
+
expect(Comment.new(:title => '').title?).to be_falsey
|
351
361
|
end
|
352
362
|
end
|
353
363
|
|
354
364
|
describe "with subclasses" do
|
355
365
|
it "should include properties of superclasses" do
|
356
|
-
CuckooClock.properties.map(&:name).
|
357
|
-
CuckooClock.properties.map(&:name).
|
366
|
+
expect(CuckooClock.properties.map(&:name)).to include(:time)
|
367
|
+
expect(CuckooClock.properties.map(&:name)).to include(:cuckoo)
|
358
368
|
end
|
359
369
|
|
360
370
|
it "should return attributes of superclasses" do
|
361
371
|
clock = CuckooClock.new(:time => Time.now, :cuckoo => 'bavarian')
|
362
|
-
clock.attributes[:time].
|
363
|
-
clock.attributes[:cuckoo].
|
372
|
+
expect(clock.attributes[:time]).not_to be_nil
|
373
|
+
expect(clock.attributes[:cuckoo]).to eql('bavarian')
|
364
374
|
end
|
365
375
|
end
|
366
376
|
|
@@ -375,34 +385,34 @@ describe 'properties' do
|
|
375
385
|
end
|
376
386
|
|
377
387
|
it "should not include change-tracking variables" do
|
378
|
-
comment.inspect.
|
388
|
+
expect(comment.inspect).not_to include('title_was')
|
379
389
|
end
|
380
390
|
|
381
391
|
it "should include the normal persistent variables" do
|
382
|
-
comment.inspect.
|
392
|
+
expect(comment.inspect).to include('title: "title"')
|
383
393
|
end
|
384
394
|
|
385
395
|
it "should include the id" do
|
386
|
-
comment.inspect.
|
396
|
+
expect(comment.inspect).to include(%Q{_id: "123456abcdef",})
|
387
397
|
end
|
388
398
|
|
389
399
|
it "should include the revision" do
|
390
|
-
comment.inspect.
|
400
|
+
expect(comment.inspect).to include(%Q{_rev: "1-654321fedcba",})
|
391
401
|
end
|
392
402
|
|
393
403
|
it "should return a complete string" do
|
394
404
|
# stub to work around (un)sorted hash on different rubies
|
395
|
-
comment.
|
405
|
+
allow(comment).to receive(:attributes).and_return([['created_at', ''], ['updated_at', ''], ['title', 'title']])
|
396
406
|
doc = '#<Comment _id: "123456abcdef", _rev: "1-654321fedcba", created_at: "", updated_at: "", title: "title">'
|
397
|
-
comment.inspect.
|
407
|
+
expect(comment.inspect).to eql(doc)
|
398
408
|
end
|
399
409
|
|
400
410
|
it "should include complex datatypes fully inspected" do
|
401
411
|
comment.title = {'en' => 'Blog post'}
|
402
|
-
comment.inspect.
|
412
|
+
expect(comment.inspect).to include('title: {"en"=>"Blog post"}')
|
403
413
|
|
404
414
|
comment.title = nil
|
405
|
-
comment.inspect.
|
415
|
+
expect(comment.inspect).to include('title: nil')
|
406
416
|
end
|
407
417
|
end
|
408
418
|
end
|