couch_potato 1.22.0 → 1.22.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.
- checksums.yaml +4 -4
- data/CHANGES.md +89 -76
- data/lib/couch_potato/persistence/simple_property.rb +9 -6
- data/lib/couch_potato/version.rb +2 -2
- data/spec/property_spec.rb +11 -0
- data/spec/unit/rspec_stub_db_spec.rb +92 -0
- metadata +46 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a67f7979fa5b4e50e7b2a99229692134dddb0938d8aa8b9e194a3beecadc9baf
|
|
4
|
+
data.tar.gz: 781f887008ef098b75f91a642ec373bc43a1e4be46a4452182c335af8a173ed6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1b30feb5418351056c70e7b2ae0f257e41339317cd0c20649046ad0a645efc42a52814e38fb7d9f6398e23eb16eef7710e25cbc4905db2fc13e85733d8fc3c5
|
|
7
|
+
data.tar.gz: 4c754a82ca5710332b363fbdfc75a813ac6212a2140993f67b271182e795e9e1540efae3cec1f06c9c356463f698266590b28c8ec9993e96bddea96cdbe5ef9f
|
data/CHANGES.md
CHANGED
|
@@ -1,159 +1,172 @@
|
|
|
1
|
-
|
|
1
|
+
# Changes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
## 1.22.1
|
|
5
|
+
|
|
6
|
+
- fix lazy property loading calling overridden setters (use private `assign_attribute` instead)
|
|
7
|
+
|
|
8
|
+
## couch_potato-rspec 4.4.0
|
|
9
|
+
|
|
10
|
+
- support multiple return values in `stub_view(...).and_return` for consecutive `view` / `first` / `first!` / `view_in_batches` calls
|
|
11
|
+
|
|
12
|
+
## couch_potato-rspec 4.3.0
|
|
13
|
+
|
|
14
|
+
- support flex views in `stub_db` / `stub_view` (array returns a `FlexViewSpec::Results` stub with `docs`; `first`/`first!` stubbed on the db)
|
|
15
|
+
|
|
16
|
+
## 1.22.00
|
|
4
17
|
|
|
5
18
|
- support `Database#first` / `#first!` for flex views
|
|
6
19
|
|
|
7
|
-
|
|
20
|
+
## 1.21.0
|
|
8
21
|
|
|
9
22
|
- add railties 8.1, Ruby 3.4 to CI
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
## 1.20.1
|
|
12
25
|
|
|
13
26
|
- fix `database.save!` did not use passed block
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
## 1.20.0
|
|
16
29
|
|
|
17
30
|
- add passing validation context to save methods
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
## 1.19.2
|
|
20
33
|
|
|
21
34
|
- fix 404/409 error when querying single design doc with `digest_view_names` enabled
|
|
22
35
|
|
|
23
|
-
|
|
36
|
+
## 1.19.1
|
|
24
37
|
|
|
25
38
|
- add digest to design doc name if `single_design_document` and `digest_view_names` are enabled
|
|
26
39
|
|
|
27
|
-
|
|
40
|
+
## 1.19.0 / rspec-matchers 4.2.0
|
|
28
41
|
|
|
29
42
|
- add `single_design_document` config option
|
|
30
43
|
- remove support for lists and lib
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
## 1.18.0
|
|
33
46
|
|
|
34
47
|
- add testing Rails 7.2/8 on CI
|
|
35
48
|
- change gemspec to allow for Rails 8
|
|
36
49
|
- remove support for Rails < 7.2
|
|
37
50
|
|
|
38
|
-
|
|
51
|
+
## 1.17.0
|
|
39
52
|
|
|
40
53
|
- filter out nil ids for loading multiple documents
|
|
41
54
|
- cache nil documents
|
|
42
55
|
|
|
43
|
-
|
|
56
|
+
## 1.16.0
|
|
44
57
|
|
|
45
58
|
- add payload to ActiveSupport instrumentation calls
|
|
46
59
|
- only notify load.cached when there are cached documents
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
## 1.15.0
|
|
49
62
|
|
|
50
63
|
- cache loading multiple documents
|
|
51
64
|
- keep the database cache when switching to another database and back to the original one
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
## 1.14.0
|
|
54
67
|
|
|
55
68
|
- add database_collection to models to help avoid n+1 requests
|
|
56
69
|
|
|
57
|
-
|
|
70
|
+
## 1.13.0
|
|
58
71
|
|
|
59
72
|
- add Ruby 3.2 support
|
|
60
73
|
- remove Ruby 2.7 support
|
|
61
74
|
- add active_support 7.1 support
|
|
62
75
|
- remove active_support 6.x support
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
## 1.12.1
|
|
65
78
|
|
|
66
79
|
- re-enable aliases when parsing config yaml file
|
|
67
80
|
|
|
68
|
-
|
|
81
|
+
## 1.12.0
|
|
69
82
|
|
|
70
83
|
- remove active_support 5.x
|
|
71
84
|
- add Ruby 3.1 support (active_support 6.1, 7.0)
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
## 1.11.0
|
|
74
87
|
|
|
75
88
|
- improve view_in_batches performance by switching to using startkey_docid over skip
|
|
76
89
|
|
|
77
|
-
|
|
90
|
+
## 1.10.1
|
|
78
91
|
|
|
79
92
|
- support passing an empty array to CouchPotato::Database#load
|
|
80
93
|
|
|
81
|
-
|
|
94
|
+
## 1.10.0
|
|
82
95
|
|
|
83
96
|
- add spec/support for Rails 7
|
|
84
97
|
|
|
85
|
-
|
|
98
|
+
## 1.9.0
|
|
86
99
|
|
|
87
100
|
- add spec/support for Rails 6.1
|
|
88
101
|
- add caching Couchrest connections to reduce total number created
|
|
89
102
|
|
|
90
|
-
|
|
103
|
+
## 1.8.0
|
|
91
104
|
|
|
92
105
|
- remove not saving model if it is not dirty. this could lead to missed document updates if the document has been updated in a different process in-between being loaded and saved in the current process.
|
|
93
106
|
|
|
94
107
|
- remove deep dirty tracking
|
|
95
108
|
|
|
96
|
-
|
|
109
|
+
## 1.7.1
|
|
97
110
|
|
|
98
111
|
- added support for properties of type Integer
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
## 1.7.0
|
|
101
114
|
|
|
102
115
|
- added `_revisions` method that returns all available revisions of a document.
|
|
103
116
|
|
|
104
|
-
|
|
117
|
+
## 1.6.4
|
|
105
118
|
|
|
106
119
|
- bug fix for accessing inherited properties (Alexander Lang)
|
|
107
120
|
|
|
108
|
-
|
|
121
|
+
## 1.6.3
|
|
109
122
|
|
|
110
123
|
- added ActiveSupport instrumentation (Alexander Lang)
|
|
111
124
|
|
|
112
|
-
|
|
125
|
+
## 1.6.2
|
|
113
126
|
|
|
114
127
|
- view digest bugfix (Alexander Lang)
|
|
115
128
|
|
|
116
|
-
|
|
129
|
+
## 1.6.1
|
|
117
130
|
|
|
118
131
|
- added option to add digests to a single view (Alexander Lang)
|
|
119
132
|
|
|
120
|
-
|
|
133
|
+
## 1.6.0
|
|
121
134
|
|
|
122
135
|
- added global option to add digests to view names (Alexander Lang)
|
|
123
136
|
|
|
124
|
-
|
|
137
|
+
## 1.5.1
|
|
125
138
|
|
|
126
139
|
- updated CouchRest to 2.0.0.rc3 in order to re-use http connections. Performance improvements. (Thilo Utke)
|
|
127
140
|
- added passing params to lists (Alexander Lang)
|
|
128
141
|
|
|
129
|
-
|
|
142
|
+
## 1.5.0
|
|
130
143
|
|
|
131
144
|
- Moved RSpec matchers into couch_potato-rspec gem. This way, people not using RSpec don't need to install the helpers, plus we can release separate matchers for RSpec 2 and 3.
|
|
132
145
|
|
|
133
|
-
|
|
146
|
+
## 1.4.0
|
|
134
147
|
|
|
135
148
|
- Added support for passing the model to blocks for computing the default value of a property (Alexander Lang)
|
|
136
149
|
|
|
137
|
-
|
|
150
|
+
## 1.3.0
|
|
138
151
|
|
|
139
152
|
- Add support for built-in couchdb reduce functions in map reduce specs (Andy Morris)
|
|
140
153
|
- Make specs handle CommonJS modules via module.exports as well as exports (Andy Morris)
|
|
141
154
|
- Changed #attributes to return a HashWithIndifferentAccess (Owen Davies)
|
|
142
155
|
|
|
143
|
-
|
|
156
|
+
## 1.2.0
|
|
144
157
|
|
|
145
158
|
- adds optional deep dirty tracking (andymorris)
|
|
146
159
|
- fixes an exception when deleting an already deleted document (Alexander Lang)
|
|
147
160
|
|
|
148
|
-
|
|
161
|
+
## 1.1.4
|
|
149
162
|
|
|
150
163
|
- Removes the dependency to json/add/core (cstettner)
|
|
151
164
|
|
|
152
|
-
|
|
165
|
+
## 1.1.3
|
|
153
166
|
|
|
154
167
|
- removes check if database exists to avoid lots of additional requests (Alexander Lang)
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
## 1.1.2
|
|
157
170
|
|
|
158
171
|
- fixes `CouchPotato.models` did not include subclasses
|
|
159
172
|
- adds `CouchPotato.use` (Daniel Lohse)
|
|
@@ -161,19 +174,19 @@
|
|
|
161
174
|
- adds `CouchPotato::Config.database_host` for using multiple databases in a project (Daniel Lohse)
|
|
162
175
|
- makes `cast_native` cast floats with no leading digits (wrshawn)
|
|
163
176
|
|
|
164
|
-
|
|
177
|
+
## 1.1.1
|
|
165
178
|
|
|
166
179
|
- fixes properties were leaked to sibling classes (Alexander Lang)
|
|
167
180
|
|
|
168
|
-
|
|
181
|
+
## 1.1.0
|
|
169
182
|
|
|
170
183
|
- adds conflict handling for Database#save/destroy (Alexander Lang)
|
|
171
184
|
|
|
172
|
-
|
|
185
|
+
## 1.0.1
|
|
173
186
|
|
|
174
187
|
- fixes error when bulk loaded document does not respond to database= (Alexander Lang)
|
|
175
188
|
|
|
176
|
-
|
|
189
|
+
## 1.0.0
|
|
177
190
|
|
|
178
191
|
- adds `reload` method (Alexander Lang)
|
|
179
192
|
- removes `total_rows` from database results (Alexander Lang)
|
|
@@ -187,11 +200,11 @@
|
|
|
187
200
|
- adds suppot for BigDecimal properties (Fredrik Rubensson)
|
|
188
201
|
- adds support for 2.0, Rubinius, 1.9.3, drops Ruby 1.8, 1.9.2
|
|
189
202
|
|
|
190
|
-
|
|
203
|
+
## 0.7.1
|
|
191
204
|
|
|
192
205
|
- fixes a bug when trying to bulk-load non-existant documents
|
|
193
206
|
|
|
194
|
-
|
|
207
|
+
## 0.7.0
|
|
195
208
|
|
|
196
209
|
- ActiveSupport/Rails 3.2 compatibility (Alexander Lang)
|
|
197
210
|
- removed Object#try, String#blank? as they are part of ActiveSupport - ActiveSupport's try behaves differently than the couch potato implementation so this change might break your app (now calling a non-existant method on a non-nil raises a NoMethodError, before it did not) (Alexander Lang)
|
|
@@ -205,168 +218,168 @@
|
|
|
205
218
|
- don't crash, only warn if couchdb.yml is missing (Alexander Lang)
|
|
206
219
|
- use the therubyracer gem to run view specs instead of relying on a `js` executable (Alexander Lang)
|
|
207
220
|
|
|
208
|
-
|
|
221
|
+
## 0.6.0
|
|
209
222
|
|
|
210
223
|
- ActiveSupport/Rails 3.1 compatibility (Maximilian Mack)
|
|
211
224
|
- fix no such file to load with json/add/rails (Simone Carletti)
|
|
212
225
|
|
|
213
|
-
|
|
226
|
+
## 0.5.7
|
|
214
227
|
|
|
215
228
|
- support CouchPotato::Database#first/#first! calls when using `stub_db` from tests (langalex)
|
|
216
229
|
- support RSpec2 block syntax in `stub_db` (langalex)
|
|
217
230
|
|
|
218
|
-
|
|
231
|
+
## 0.5.6
|
|
219
232
|
|
|
220
233
|
- remove the stale parameter from a view query if it's nil, as couchdb only allows stale to be ok or update_after (langalex)
|
|
221
234
|
|
|
222
|
-
|
|
235
|
+
## 0.5.5
|
|
223
236
|
|
|
224
237
|
- support for split_design_documents_per_view (jweiss)
|
|
225
238
|
- errors now returns a Hash instead of an Array (bterkuile)
|
|
226
239
|
- support passing in list names as symbols in view specs (langalex)
|
|
227
240
|
|
|
228
|
-
|
|
241
|
+
## 0.5.4
|
|
229
242
|
|
|
230
243
|
- cast 'false' to false for boolean properties (langalex)
|
|
231
244
|
|
|
232
|
-
|
|
245
|
+
## 0.5.3
|
|
233
246
|
|
|
234
247
|
- added CouchPotato::Database.load! (langalex)
|
|
235
248
|
|
|
236
|
-
|
|
249
|
+
## 0.5.2
|
|
237
250
|
|
|
238
251
|
- added CouchPotato::Database#first and #first! methods (langalex)
|
|
239
252
|
- added workaround for BigCouch/Cloudant to not add null reduce functions to views (langalex)
|
|
240
253
|
- don't add \_attachments if there are none (langalex)
|
|
241
254
|
|
|
242
|
-
|
|
255
|
+
## 0.5.1
|
|
243
256
|
|
|
244
257
|
- fixed issues with tzinfo gem (Bernd Ahlers)
|
|
245
258
|
|
|
246
|
-
|
|
259
|
+
## 0.5.0
|
|
247
260
|
|
|
248
261
|
- time zone support (Time properties are now converted to current Time.zone) (langalex)
|
|
249
262
|
- lazy property initialization (performance!) (langalex)
|
|
250
263
|
- active_model is now the default validation framework (langalex)
|
|
251
264
|
|
|
252
|
-
|
|
265
|
+
## 0.4.0
|
|
253
266
|
|
|
254
267
|
- ruby 1.9.2 compatibility (langalex)
|
|
255
268
|
- couch potato objects now behave correctly when used as keys in Hashes (langalex)
|
|
256
269
|
- use as_json instead of to_s(:json), which is the rails way
|
|
257
270
|
- use ActiveModel dirty tracking (langalex) - this means no more "deep tracking", e.g. `user.tags << 'new_tag'; user.dirty? # false`
|
|
258
271
|
|
|
259
|
-
|
|
272
|
+
## 0.3.2
|
|
260
273
|
|
|
261
274
|
- support yielding to blocks on #initialize (martinrehfeld)
|
|
262
275
|
- support for negative numbers in Fixnum/Float properties (langalex)
|
|
263
276
|
|
|
264
|
-
|
|
277
|
+
## 0.3.1
|
|
265
278
|
|
|
266
279
|
- ActiveModel callbacks (kazjote)
|
|
267
280
|
- do not use Rails.env in initializer as it will free Rails.env for all times and in Rails 2.3.x apps it will be called too early thus always beeing development (jweiss)
|
|
268
281
|
- ruby 1.9.2 compatibility (langalex)
|
|
269
282
|
- can configure validation framework in couchdb.yml, process couchdb.yml with erb (langalex)
|
|
270
283
|
|
|
271
|
-
|
|
284
|
+
## 0.3.0
|
|
272
285
|
|
|
273
286
|
- support for lists (langalex)
|
|
274
287
|
|
|
275
|
-
|
|
288
|
+
## 0.2.32
|
|
276
289
|
|
|
277
290
|
- added persisted? and to_key for proper ActiveModel compliance (thilo)
|
|
278
291
|
- id setter (jhohertz-work)
|
|
279
292
|
- load document ids if include_documents is false (jweiss)
|
|
280
293
|
- persist given created_at/updated_at instead of Time.now (langalex)
|
|
281
294
|
|
|
282
|
-
|
|
295
|
+
## 0.2.31
|
|
283
296
|
|
|
284
297
|
- Removed requirement for validatable gem. Allows for using more uptodate versions of the library, or doesn't install it when you're using ActiveModel. (mattmatt)
|
|
285
298
|
- fixed callbacks of super classes were not run (langalex)
|
|
286
299
|
|
|
287
|
-
|
|
300
|
+
## 0.2.30
|
|
288
301
|
|
|
289
302
|
- pass in multiple keys when querying a view (langalex)
|
|
290
303
|
|
|
291
|
-
|
|
304
|
+
## 0.2.29
|
|
292
305
|
|
|
293
306
|
- nicer inspect() for models (mattmatt)
|
|
294
307
|
- fixed (re)reduce for property views wasn't working (langalex)
|
|
295
308
|
|
|
296
|
-
|
|
309
|
+
## 0.2.28
|
|
297
310
|
|
|
298
311
|
- fixed reloading nested classes (langalex)
|
|
299
312
|
- fixed constant missing error when loading models with uninitialized classes via views (langalex)
|
|
300
313
|
- added rspec helpers for stubbing out views (langalex)
|
|
301
314
|
- fixed design document names for nested model classes (svenfuchs)
|
|
302
315
|
|
|
303
|
-
|
|
316
|
+
## 0.2.27
|
|
304
317
|
|
|
305
318
|
- workaround for Rails apps using bundler: database name was not initialized from couchdb.yml (langalex)
|
|
306
319
|
|
|
307
|
-
|
|
320
|
+
## 0.2.26
|
|
308
321
|
|
|
309
322
|
- added to_s(:json) to Date and Time to be able to get properly formatted dates/times for searching with dates/times (langalex)
|
|
310
323
|
- all times are now stored as UTC (langalex)
|
|
311
324
|
- added support for Float attributes (arbovm)
|
|
312
325
|
|
|
313
|
-
|
|
326
|
+
## 0.2.25
|
|
314
327
|
|
|
315
328
|
- automatic view updates: when you change the definition of a view couch potato will now update the design document in the database (langalex)
|
|
316
329
|
- support for properties of type Date, better support for Time (langalex)
|
|
317
330
|
- support for default reduce count methods in custom views (jweiss)
|
|
318
331
|
|
|
319
|
-
|
|
332
|
+
## 0.2.24
|
|
320
333
|
|
|
321
334
|
- persistent instances can now be marked as dirty with #is_dirty (langalex)
|
|
322
335
|
|
|
323
|
-
|
|
336
|
+
## 0.2.23
|
|
324
337
|
|
|
325
338
|
- Couch Potato models now conform to the ActiveModel interface when ActiveModel is installed, see http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/ (langalex)
|
|
326
339
|
- fixed error with dirty tracking and BigDecimals (thilo)
|
|
327
340
|
- added the ability to use ActiveModel validations instead of validatable (martinrehfeld)
|
|
328
341
|
|
|
329
|
-
|
|
342
|
+
## 0.2.22
|
|
330
343
|
|
|
331
344
|
- fixed properties with default values returned default when a blank value like '' or [] was set (langalex)
|
|
332
345
|
|
|
333
|
-
|
|
346
|
+
## 0.2.21
|
|
334
347
|
|
|
335
348
|
- automatically set a database instance on results of CouchPotato::Database#view (langalex)
|
|
336
349
|
- improved auto loading of unloaded constants - can now load constants that have never been loaded before (langalex)
|
|
337
350
|
- raise exception on invalid parameters passed to a couchdb view query (langalex)
|
|
338
351
|
- when querying a view: pass in ranges as key instead of startkey/endkey, pass in plain value instead of hash with key (langalex)
|
|
339
352
|
|
|
340
|
-
|
|
353
|
+
## 0.2.20
|
|
341
354
|
|
|
342
355
|
- support for :boolean properties (jweiss)
|
|
343
356
|
- return the total_rows when querying a view (langalex)
|
|
344
357
|
|
|
345
|
-
|
|
358
|
+
## 0.2.19
|
|
346
359
|
|
|
347
360
|
- added conditions to views (langalex)
|
|
348
361
|
|
|
349
|
-
|
|
362
|
+
## 0.2.18
|
|
350
363
|
|
|
351
364
|
- set Fixnum property to nil when given a blank string (langalex)
|
|
352
365
|
|
|
353
|
-
|
|
366
|
+
## 0.2.17
|
|
354
367
|
|
|
355
368
|
- fixed nil attributes were omitted in json (jweiss, mattmatt)
|
|
356
369
|
- support for properties of type Fixnum (langalex)
|
|
357
370
|
|
|
358
|
-
|
|
371
|
+
## 0.2.16
|
|
359
372
|
|
|
360
373
|
- fixed problem with classes being not loaded in rails development mode (langalex)
|
|
361
374
|
- fixed persist boolean false value (bernd)
|
|
362
375
|
|
|
363
|
-
|
|
376
|
+
## 0.2.15
|
|
364
377
|
|
|
365
378
|
- ability to change the name of the attribute that stores the ruby class in the documents by setting JSON.create_id (lennart)
|
|
366
379
|
- fixed double loading issue with bundler (jweiss)
|
|
367
380
|
- fixed an issue with setting attachments (endor)
|
|
368
381
|
|
|
369
|
-
|
|
382
|
+
## 0.2.13
|
|
370
383
|
|
|
371
384
|
- support adding errors in before_validation callbacks (mattmatt)
|
|
372
385
|
- support for inheritance (mattmatt)
|
|
@@ -374,11 +387,11 @@
|
|
|
374
387
|
- improved (de)serialization now supports deserializing nested objects (railsbros, specs by hagenburger)
|
|
375
388
|
- RSpec matchers for testing map/reduce functions (langalex)
|
|
376
389
|
|
|
377
|
-
|
|
390
|
+
## 0.2.10
|
|
378
391
|
|
|
379
392
|
- fixed bug with hardcoded timezone
|
|
380
393
|
|
|
381
|
-
|
|
394
|
+
## 0.2.9
|
|
382
395
|
|
|
383
396
|
- allow to overwrite attribute accessor of properties and use super to call the original accessors
|
|
384
397
|
- allow read access to attributes that are present in the Couchdb document but not defined as properties
|
|
@@ -12,6 +12,13 @@ module CouchPotato
|
|
|
12
12
|
value
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def assign_attribute(name, value)
|
|
17
|
+
property = self.class.properties.find_property(name)
|
|
18
|
+
typecasted_value = type_caster.cast(value, property.type)
|
|
19
|
+
send("#{name}_will_change!") unless @skip_dirty_tracking || typecasted_value == send(name)
|
|
20
|
+
instance_variable_set("@#{name}", typecasted_value)
|
|
21
|
+
end
|
|
15
22
|
end
|
|
16
23
|
|
|
17
24
|
class SimpleProperty #:nodoc:
|
|
@@ -19,7 +26,6 @@ module CouchPotato
|
|
|
19
26
|
|
|
20
27
|
def initialize(owner_clazz, name, options = {})
|
|
21
28
|
self.name = name
|
|
22
|
-
@setter_name = "#{name}="
|
|
23
29
|
self.type = options[:type]
|
|
24
30
|
self.default_value = options[:default]
|
|
25
31
|
@type_caster = TypeCaster.new
|
|
@@ -29,8 +35,7 @@ module CouchPotato
|
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
def build(object, json)
|
|
32
|
-
|
|
33
|
-
object.send @setter_name, value
|
|
38
|
+
object.send(:assign_attribute, name, json[name])
|
|
34
39
|
end
|
|
35
40
|
|
|
36
41
|
def serialize(json, object)
|
|
@@ -77,9 +82,7 @@ module CouchPotato
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
define_method "#{name}=" do |value|
|
|
80
|
-
|
|
81
|
-
send("#{name}_will_change!") unless @skip_dirty_tracking || typecasted_value == send(name)
|
|
82
|
-
self.instance_variable_set(ivar_name, typecasted_value)
|
|
85
|
+
assign_attribute(name, value)
|
|
83
86
|
end
|
|
84
87
|
|
|
85
88
|
define_method "#{name}?" do
|
data/lib/couch_potato/version.rb
CHANGED
data/spec/property_spec.rb
CHANGED
|
@@ -12,6 +12,7 @@ class Watch
|
|
|
12
12
|
property :custom_address, type: [Address]
|
|
13
13
|
property :overwritten_read
|
|
14
14
|
property :overwritten_write
|
|
15
|
+
property :normalized_title
|
|
15
16
|
property :diameter, type: Float
|
|
16
17
|
|
|
17
18
|
def overwritten_read
|
|
@@ -21,6 +22,10 @@ class Watch
|
|
|
21
22
|
def overwritten_write=(value)
|
|
22
23
|
super value.to_s
|
|
23
24
|
end
|
|
25
|
+
|
|
26
|
+
def normalized_title=(value)
|
|
27
|
+
super(value.to_s.upcase)
|
|
28
|
+
end
|
|
24
29
|
end
|
|
25
30
|
|
|
26
31
|
class Address2 < Address
|
|
@@ -59,6 +64,12 @@ describe 'properties' do
|
|
|
59
64
|
expect(Watch.new(:overwritten_write => 1).overwritten_write).to eq('1')
|
|
60
65
|
end
|
|
61
66
|
|
|
67
|
+
it "does not call overwritten write accessors when loading from a document" do
|
|
68
|
+
watch = Watch.json_create('normalized_title' => 'Hello', JSON.create_id => 'Watch')
|
|
69
|
+
|
|
70
|
+
expect(watch.normalized_title).to eq('Hello')
|
|
71
|
+
end
|
|
72
|
+
|
|
62
73
|
it "should return the property names" do
|
|
63
74
|
expect(Comment.property_names).to eq([:created_at, :updated_at, :title])
|
|
64
75
|
end
|
|
@@ -9,6 +9,12 @@ class WithStubbedView
|
|
|
9
9
|
view :stubbed_view, key: :x
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
class WithStubbedFlexView
|
|
13
|
+
include CouchPotato::Persistence
|
|
14
|
+
|
|
15
|
+
view :stubbed_flex_view, type: :flex, key: :x
|
|
16
|
+
end
|
|
17
|
+
|
|
12
18
|
describe 'stubbing the db' do
|
|
13
19
|
it 'replaces CouchPotato.database with a double' do
|
|
14
20
|
CouchPotato.stub_db
|
|
@@ -37,6 +43,40 @@ describe 'stubbing a view' do
|
|
|
37
43
|
expect(@db.view(WithStubbedView.stubbed_view('123'))).to eq([:result])
|
|
38
44
|
end
|
|
39
45
|
|
|
46
|
+
it 'returns successive values on consecutive view calls' do
|
|
47
|
+
@db.stub_view(WithStubbedView, :stubbed_view).with('123').and_return([:first], [:second])
|
|
48
|
+
|
|
49
|
+
expect(@db.view(WithStubbedView.stubbed_view('123'))).to eq([:first])
|
|
50
|
+
expect(@db.view(WithStubbedView.stubbed_view('123'))).to eq([:second])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'returns successive first values on consecutive first calls' do
|
|
54
|
+
@db.stub_view(WithStubbedView, :stubbed_view).with('123').and_return([:a], [:b])
|
|
55
|
+
|
|
56
|
+
expect(@db.first(WithStubbedView.stubbed_view('123'))).to eq(:a)
|
|
57
|
+
expect(@db.first(WithStubbedView.stubbed_view('123'))).to eq(:b)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'returns successive values on consecutive first! calls and raises for a nil first value' do
|
|
61
|
+
@db.stub_view(WithStubbedView, :stubbed_view).with('123').and_return([:a], [], [:b])
|
|
62
|
+
|
|
63
|
+
expect(@db.first!(WithStubbedView.stubbed_view('123'))).to eq(:a)
|
|
64
|
+
expect { @db.first!(WithStubbedView.stubbed_view('123')) }.to raise_error(CouchPotato::NotFound)
|
|
65
|
+
expect(@db.first!(WithStubbedView.stubbed_view('123'))).to eq(:b)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'yields successive return values on consecutive view_in_batches calls' do
|
|
69
|
+
@db.stub_view(WithStubbedView, :stubbed_view).with('123').and_return([:a, :b], [:c])
|
|
70
|
+
|
|
71
|
+
expect do |b|
|
|
72
|
+
@db.view_in_batches(WithStubbedView.stubbed_view('123'), batch_size: 2, &b)
|
|
73
|
+
end.to yield_successive_args([:a, :b])
|
|
74
|
+
|
|
75
|
+
expect do |b|
|
|
76
|
+
@db.view_in_batches(WithStubbedView.stubbed_view('123'), batch_size: 2, &b)
|
|
77
|
+
end.to yield_successive_args([:c])
|
|
78
|
+
end
|
|
79
|
+
|
|
40
80
|
it 'stubs the database to return the first fake result' do
|
|
41
81
|
expect(@db.first(WithStubbedView.stubbed_view('123'))).to eq(:result)
|
|
42
82
|
expect(@db.first!(WithStubbedView.stubbed_view('123'))).to eq(:result)
|
|
@@ -96,3 +136,55 @@ describe 'stubbing a view' do
|
|
|
96
136
|
expect(@db.view(WithStubbedView.stubbed_view('123'))).to eq(:results)
|
|
97
137
|
end
|
|
98
138
|
end
|
|
139
|
+
|
|
140
|
+
describe 'stubbing a flex view' do
|
|
141
|
+
before(:each) do
|
|
142
|
+
@db = CouchPotato.stub_db
|
|
143
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).with('123').and_return([:result])
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it 'stubs the database to return a results stub with docs when given an array' do
|
|
147
|
+
expect(@db.view(WithStubbedFlexView.stubbed_flex_view('123')).docs).to eq([:result])
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it 'stubs the database to return the first fake result' do
|
|
151
|
+
expect(@db.first(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:result)
|
|
152
|
+
expect(@db.first!(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:result)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it 'returns successive results stubs on consecutive view calls' do
|
|
156
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).with('123').and_return([:first], [:second])
|
|
157
|
+
|
|
158
|
+
expect(@db.view(WithStubbedFlexView.stubbed_flex_view('123')).docs).to eq([:first])
|
|
159
|
+
expect(@db.view(WithStubbedFlexView.stubbed_flex_view('123')).docs).to eq([:second])
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it 'returns successive first values on consecutive first calls' do
|
|
163
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).with('123').and_return([:a], [:b])
|
|
164
|
+
|
|
165
|
+
expect(@db.first(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:a)
|
|
166
|
+
expect(@db.first(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:b)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'returns successive values on consecutive first! calls and raises for a nil first value' do
|
|
170
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).with('123').and_return([:a], [], [:b])
|
|
171
|
+
|
|
172
|
+
expect(@db.first!(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:a)
|
|
173
|
+
expect { @db.first!(WithStubbedFlexView.stubbed_flex_view('123')) }.to raise_error(CouchPotato::NotFound)
|
|
174
|
+
expect(@db.first!(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:b)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'raises from db.first! when the array is empty' do
|
|
178
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).and_return([])
|
|
179
|
+
|
|
180
|
+
expect do
|
|
181
|
+
@db.first!(WithStubbedFlexView.stubbed_flex_view)
|
|
182
|
+
end.to raise_error(CouchPotato::NotFound)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'returns a non-array return value directly' do
|
|
186
|
+
@db.stub_view(WithStubbedFlexView, :stubbed_flex_view).with('123').and_return(:reduced)
|
|
187
|
+
|
|
188
|
+
expect(@db.view(WithStubbedFlexView.stubbed_flex_view('123'))).to eq(:reduced)
|
|
189
|
+
end
|
|
190
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: couch_potato
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.22.
|
|
4
|
+
version: 1.22.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Lang
|
|
@@ -249,4 +249,48 @@ requirements: []
|
|
|
249
249
|
rubygems_version: 3.6.9
|
|
250
250
|
specification_version: 4
|
|
251
251
|
summary: Ruby persistence layer for CouchDB
|
|
252
|
-
test_files:
|
|
252
|
+
test_files:
|
|
253
|
+
- spec/attachments_spec.rb
|
|
254
|
+
- spec/callbacks_spec.rb
|
|
255
|
+
- spec/conflict_handling_spec.rb
|
|
256
|
+
- spec/create_spec.rb
|
|
257
|
+
- spec/default_property_spec.rb
|
|
258
|
+
- spec/destroy_spec.rb
|
|
259
|
+
- spec/fixtures/address.rb
|
|
260
|
+
- spec/fixtures/person.rb
|
|
261
|
+
- spec/property_spec.rb
|
|
262
|
+
- spec/rails_spec.rb
|
|
263
|
+
- spec/railtie_spec.rb
|
|
264
|
+
- spec/reload_spec.rb
|
|
265
|
+
- spec/revisions_spec.rb
|
|
266
|
+
- spec/single_design_document_spec.rb
|
|
267
|
+
- spec/spec.opts
|
|
268
|
+
- spec/spec_helper.rb
|
|
269
|
+
- spec/unit/active_model_compliance_spec.rb
|
|
270
|
+
- spec/unit/attributes_spec.rb
|
|
271
|
+
- spec/unit/base_view_spec_spec.rb
|
|
272
|
+
- spec/unit/caching_spec.rb
|
|
273
|
+
- spec/unit/callbacks_spec.rb
|
|
274
|
+
- spec/unit/couch_potato_spec.rb
|
|
275
|
+
- spec/unit/create_spec.rb
|
|
276
|
+
- spec/unit/custom_view_spec_spec.rb
|
|
277
|
+
- spec/unit/custom_views_spec.rb
|
|
278
|
+
- spec/unit/database_spec.rb
|
|
279
|
+
- spec/unit/date_spec.rb
|
|
280
|
+
- spec/unit/dirty_attributes_spec.rb
|
|
281
|
+
- spec/unit/flex_view_spec_spec.rb
|
|
282
|
+
- spec/unit/forbidden_attributes_protection_spec.rb
|
|
283
|
+
- spec/unit/initialize_spec.rb
|
|
284
|
+
- spec/unit/json_spec.rb
|
|
285
|
+
- spec/unit/model_view_spec_spec.rb
|
|
286
|
+
- spec/unit/persistence_spec.rb
|
|
287
|
+
- spec/unit/properties_view_spec_spec.rb
|
|
288
|
+
- spec/unit/rspec_stub_db_spec.rb
|
|
289
|
+
- spec/unit/string_spec.rb
|
|
290
|
+
- spec/unit/time_spec.rb
|
|
291
|
+
- spec/unit/validation_spec.rb
|
|
292
|
+
- spec/unit/view_query_spec.rb
|
|
293
|
+
- spec/update_spec.rb
|
|
294
|
+
- spec/validation_context_spec.rb
|
|
295
|
+
- spec/view_updates_spec.rb
|
|
296
|
+
- spec/views_spec.rb
|