couchrest_model 2.0.1 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/couchrest_model.gemspec +3 -4
- data/history.md +10 -0
- data/lib/couchrest/model/casted_array.rb +4 -0
- data/lib/couchrest/model/designs/view.rb +3 -0
- data/lib/couchrest/model/persistence.rb +1 -1
- data/lib/couchrest/model/proxyable.rb +3 -0
- data/lib/couchrest/model/typecast.rb +1 -1
- data/spec/unit/casted_array_spec.rb +50 -0
- data/spec/unit/designs/view_spec.rb +19 -0
- data/spec/unit/persistence_spec.rb +28 -1
- data/spec/unit/proxyable_spec.rb +9 -0
- data/spec/unit/typecast_spec.rb +5 -0
- metadata +38 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d13ee6807a1d8e08ec19b1402ec3e222c62731
|
4
|
+
data.tar.gz: c5eec5eea342a0c58ca60df0e63f45239398fbfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20fa41cff63d880fb8b681338935ffd946ff9bc32e2bb6de33a913d01e466c341708c80af011cf0c7785cd992e7d2963c7ebdce2c5ca625fe43b4e20360c7300
|
7
|
+
data.tar.gz: 10af0f1dee17c7ca5098ccd0aab103686b1714ce95b0f3cccbbe9544faa716d024e11c9b579a04e4ae10594d5dcc5b4da9a45c819316fa3ea631ac034fc4bee8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.3
|
data/couchrest_model.gemspec
CHANGED
@@ -24,15 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
25
|
s.require_paths = ["lib"]
|
26
26
|
|
27
|
-
s.add_dependency(%q<couchrest>, "
|
28
|
-
s.add_dependency(%q<mime-types>, ">= 1.
|
29
|
-
s.add_dependency(%q<activemodel>, ">= 3.0")
|
27
|
+
s.add_dependency(%q<couchrest>, ">= 1.2")
|
28
|
+
s.add_dependency(%q<mime-types>, ">= 1.16")
|
29
|
+
s.add_dependency(%q<activemodel>, ">= 4.0", ">= 3.0")
|
30
30
|
s.add_dependency(%q<tzinfo>, ">= 0.3.22")
|
31
31
|
s.add_development_dependency(%q<rspec>, "~> 2.6.0")
|
32
32
|
s.add_development_dependency(%q<json>, ["~> 1.5.1"])
|
33
33
|
s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
|
34
34
|
s.add_development_dependency("rake", ">= 0.8.0")
|
35
|
-
s.add_development_dependency(%q<activemodel>, ">= 4.0")
|
36
35
|
#s.add_development_dependency("debugger", "~> 1.2.0") # TODO put in Gemfile
|
37
36
|
#s.add_development_dependency(%q<oj>, "~> 1.3.4") # TODO put in Gemfile (fails in JRuby)
|
38
37
|
s.add_development_dependency("kaminari", "~> 0.14.1")
|
data/history.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CouchRest Model Change History
|
2
2
|
|
3
|
+
## 2.0.3 - 2014-07-04
|
4
|
+
|
5
|
+
* Added find_by_view! method support for raising DocumentNotFound error when searching.
|
6
|
+
* Upgraded CouchRest to ~> 1.2.0
|
7
|
+
|
8
|
+
## 2.0.2 - 2014-02-06
|
9
|
+
|
10
|
+
* Fix for model_type_value, not being used correctly from database.
|
11
|
+
* CastedArray now supports `as_couch_json` method.
|
12
|
+
|
3
13
|
## 2.0.1 - 2013-12-03
|
4
14
|
|
5
15
|
* nil keys in view requests are now sent to server, avoiding returning first document issue. (Thanks to @svoboda-jan for pointer.)
|
@@ -120,7 +120,7 @@ module CouchRest
|
|
120
120
|
#
|
121
121
|
def build_from_database(doc = {}, options = {}, &block)
|
122
122
|
src = doc[model_type_key]
|
123
|
-
base = (src.blank? || src ==
|
123
|
+
base = (src.blank? || src == model_type_value) ? self : src.constantize
|
124
124
|
base.new(doc, options.merge(:directly_set_attributes => true), &block)
|
125
125
|
end
|
126
126
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
#
|
5
|
+
# TODO This requires much more testing, although most of the basics
|
6
|
+
# are checked by other parts of the code.
|
7
|
+
#
|
8
|
+
|
9
|
+
describe CouchRest::Model::CastedArray do
|
10
|
+
|
11
|
+
let :klass do
|
12
|
+
CouchRest::Model::CastedArray
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
it "should set the casted properties" do
|
17
|
+
prop = double('Property')
|
18
|
+
parent = double('Parent')
|
19
|
+
obj = klass.new([], prop, parent)
|
20
|
+
obj.casted_by_property.should eql(prop)
|
21
|
+
obj.casted_by.should eql(parent)
|
22
|
+
obj.should be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#as_couch_json" do
|
27
|
+
let :property do
|
28
|
+
CouchRest::Model::Property.new(:cat, :type => Cat)
|
29
|
+
end
|
30
|
+
let :obj do
|
31
|
+
klass.new([
|
32
|
+
{ :name => 'Felix' },
|
33
|
+
{ :name => 'Garfield' }
|
34
|
+
], property)
|
35
|
+
end
|
36
|
+
it "should return an array" do
|
37
|
+
obj.as_couch_json.should be_a(Array)
|
38
|
+
end
|
39
|
+
it "should call as_couch_json on each value" do
|
40
|
+
obj.first.should_receive(:as_couch_json)
|
41
|
+
obj.as_couch_json
|
42
|
+
end
|
43
|
+
it "should return value if no as_couch_json method" do
|
44
|
+
obj = klass.new(['Felix', 'Garfield'], CouchRest::Model::Property.new(:title, :type => String))
|
45
|
+
obj.first.should_not respond_to(:as_couch_json)
|
46
|
+
obj.as_couch_json.first.should eql('Felix')
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -182,6 +182,25 @@ describe "Design View" do
|
|
182
182
|
@design_doc.should_receive('view').and_return(view)
|
183
183
|
@model.find_by_name('fred')
|
184
184
|
end
|
185
|
+
it "should create find_! view method" do
|
186
|
+
@klass.create_model_methods(@design_doc, 'by_name')
|
187
|
+
@model.should respond_to('find_by_name!')
|
188
|
+
obj = mock("SomeKlass")
|
189
|
+
view = mock("View")
|
190
|
+
view.should_receive('key').with('fred').and_return(view)
|
191
|
+
view.should_receive('first').and_return(obj)
|
192
|
+
@design_doc.should_receive('view').and_return(view)
|
193
|
+
@model.find_by_name!('fred').should eql(obj)
|
194
|
+
end
|
195
|
+
it "should create find_! view method and raise error when nil" do
|
196
|
+
@klass.create_model_methods(@design_doc, 'by_name')
|
197
|
+
view = mock("View")
|
198
|
+
view.should_receive('key').with('fred').and_return(view)
|
199
|
+
view.should_receive('first').and_return(nil)
|
200
|
+
@design_doc.should_receive('view').and_return(view)
|
201
|
+
lambda { @model.find_by_name!('fred') }.should raise_error(CouchRest::Model::DocumentNotFound)
|
202
|
+
end
|
203
|
+
|
185
204
|
end
|
186
205
|
end
|
187
206
|
|
@@ -19,13 +19,14 @@ describe CouchRest::Model::Persistence do
|
|
19
19
|
doc.class.should eql(Article)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should
|
22
|
+
it "should instantiate document of different type" do
|
23
23
|
doc = Article.build_from_database({'_id' => 'testitem2', '_rev' => 123, Article.model_type_key => 'WithTemplateAndUniqueID', 'name' => 'my test'})
|
24
24
|
doc.class.should eql(WithTemplateAndUniqueID)
|
25
25
|
end
|
26
26
|
|
27
27
|
end
|
28
28
|
|
29
|
+
|
29
30
|
describe "basic saving and retrieving" do
|
30
31
|
it "should work fine" do
|
31
32
|
@obj.name = "should be easily saved and retrieved"
|
@@ -482,6 +483,32 @@ describe CouchRest::Model::Persistence do
|
|
482
483
|
it "should always return string value of class" do
|
483
484
|
Article.model_type_value.should eql('Article')
|
484
485
|
end
|
486
|
+
|
487
|
+
describe "usage" do
|
488
|
+
let :klass do
|
489
|
+
Class.new(CouchRest::Model::Base) do
|
490
|
+
property :name, String
|
491
|
+
def self.model_type_value
|
492
|
+
'something_else'
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
it "should use the model type value if overridden" do
|
497
|
+
obj = klass.build_from_database(
|
498
|
+
'_id' => '1234', 'type' => 'something_else', 'name' => 'Test'
|
499
|
+
)
|
500
|
+
obj['type'].should eql('something_else')
|
501
|
+
obj.name.should eql('Test')
|
502
|
+
end
|
503
|
+
it "should fail if different model type value provided" do
|
504
|
+
expect {
|
505
|
+
obj = klass.build_from_database(
|
506
|
+
'_id' => '1234', 'type' => 'something', 'name' => 'Test'
|
507
|
+
)
|
508
|
+
}.to raise_error(NameError)
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
485
512
|
end
|
486
513
|
|
487
514
|
end
|
data/spec/unit/proxyable_spec.rb
CHANGED
@@ -194,6 +194,7 @@ describe CouchRest::Model::Proxyable do
|
|
194
194
|
@obj.should respond_to('by_name')
|
195
195
|
@obj.should respond_to('find_all')
|
196
196
|
@obj.should respond_to('find_by_name')
|
197
|
+
@obj.should respond_to('find_by_name!')
|
197
198
|
end
|
198
199
|
|
199
200
|
it "should create 'all' view method that forward to model's view with proxy" do
|
@@ -214,6 +215,14 @@ describe CouchRest::Model::Proxyable do
|
|
214
215
|
@obj.find_by_name('name')
|
215
216
|
end
|
216
217
|
|
218
|
+
it "should create 'find_by_name!' that raises error when there are no results" do
|
219
|
+
view = mock('view')
|
220
|
+
view.should_receive('key').with('name').and_return(view)
|
221
|
+
view.should_receive('first').and_return(nil)
|
222
|
+
@obj.should_receive(:by_name).and_return(view)
|
223
|
+
lambda { @obj.find_by_name!('name') }.should raise_error(CouchRest::Model::DocumentNotFound)
|
224
|
+
end
|
225
|
+
|
217
226
|
end
|
218
227
|
|
219
228
|
describe "instance" do
|
data/spec/unit/typecast_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J. Chris Anderson
|
@@ -12,146 +12,138 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: couchrest
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: '1.2'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ">="
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 1.
|
30
|
+
version: '1.2'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: mime-types
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ">="
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '1.
|
37
|
+
version: '1.16'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '1.
|
44
|
+
version: '1.16'
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: activemodel
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '4.0'
|
52
|
+
- - ">="
|
50
53
|
- !ruby/object:Gem::Version
|
51
54
|
version: '3.0'
|
52
55
|
type: :runtime
|
53
56
|
prerelease: false
|
54
57
|
version_requirements: !ruby/object:Gem::Requirement
|
55
58
|
requirements:
|
56
|
-
- -
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
- - ">="
|
57
63
|
- !ruby/object:Gem::Version
|
58
64
|
version: '3.0'
|
59
65
|
- !ruby/object:Gem::Dependency
|
60
66
|
name: tzinfo
|
61
67
|
requirement: !ruby/object:Gem::Requirement
|
62
68
|
requirements:
|
63
|
-
- -
|
69
|
+
- - ">="
|
64
70
|
- !ruby/object:Gem::Version
|
65
71
|
version: 0.3.22
|
66
72
|
type: :runtime
|
67
73
|
prerelease: false
|
68
74
|
version_requirements: !ruby/object:Gem::Requirement
|
69
75
|
requirements:
|
70
|
-
- -
|
76
|
+
- - ">="
|
71
77
|
- !ruby/object:Gem::Version
|
72
78
|
version: 0.3.22
|
73
79
|
- !ruby/object:Gem::Dependency
|
74
80
|
name: rspec
|
75
81
|
requirement: !ruby/object:Gem::Requirement
|
76
82
|
requirements:
|
77
|
-
- - ~>
|
83
|
+
- - "~>"
|
78
84
|
- !ruby/object:Gem::Version
|
79
85
|
version: 2.6.0
|
80
86
|
type: :development
|
81
87
|
prerelease: false
|
82
88
|
version_requirements: !ruby/object:Gem::Requirement
|
83
89
|
requirements:
|
84
|
-
- - ~>
|
90
|
+
- - "~>"
|
85
91
|
- !ruby/object:Gem::Version
|
86
92
|
version: 2.6.0
|
87
93
|
- !ruby/object:Gem::Dependency
|
88
94
|
name: json
|
89
95
|
requirement: !ruby/object:Gem::Requirement
|
90
96
|
requirements:
|
91
|
-
- - ~>
|
97
|
+
- - "~>"
|
92
98
|
- !ruby/object:Gem::Version
|
93
99
|
version: 1.5.1
|
94
100
|
type: :development
|
95
101
|
prerelease: false
|
96
102
|
version_requirements: !ruby/object:Gem::Requirement
|
97
103
|
requirements:
|
98
|
-
- - ~>
|
104
|
+
- - "~>"
|
99
105
|
- !ruby/object:Gem::Version
|
100
106
|
version: 1.5.1
|
101
107
|
- !ruby/object:Gem::Dependency
|
102
108
|
name: rack-test
|
103
109
|
requirement: !ruby/object:Gem::Requirement
|
104
110
|
requirements:
|
105
|
-
- -
|
111
|
+
- - ">="
|
106
112
|
- !ruby/object:Gem::Version
|
107
113
|
version: 0.5.7
|
108
114
|
type: :development
|
109
115
|
prerelease: false
|
110
116
|
version_requirements: !ruby/object:Gem::Requirement
|
111
117
|
requirements:
|
112
|
-
- -
|
118
|
+
- - ">="
|
113
119
|
- !ruby/object:Gem::Version
|
114
120
|
version: 0.5.7
|
115
121
|
- !ruby/object:Gem::Dependency
|
116
122
|
name: rake
|
117
123
|
requirement: !ruby/object:Gem::Requirement
|
118
124
|
requirements:
|
119
|
-
- -
|
125
|
+
- - ">="
|
120
126
|
- !ruby/object:Gem::Version
|
121
127
|
version: 0.8.0
|
122
128
|
type: :development
|
123
129
|
prerelease: false
|
124
130
|
version_requirements: !ruby/object:Gem::Requirement
|
125
131
|
requirements:
|
126
|
-
- -
|
132
|
+
- - ">="
|
127
133
|
- !ruby/object:Gem::Version
|
128
134
|
version: 0.8.0
|
129
|
-
- !ruby/object:Gem::Dependency
|
130
|
-
name: activemodel
|
131
|
-
requirement: !ruby/object:Gem::Requirement
|
132
|
-
requirements:
|
133
|
-
- - '>='
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version: '4.0'
|
136
|
-
type: :development
|
137
|
-
prerelease: false
|
138
|
-
version_requirements: !ruby/object:Gem::Requirement
|
139
|
-
requirements:
|
140
|
-
- - '>='
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
version: '4.0'
|
143
135
|
- !ruby/object:Gem::Dependency
|
144
136
|
name: kaminari
|
145
137
|
requirement: !ruby/object:Gem::Requirement
|
146
138
|
requirements:
|
147
|
-
- - ~>
|
139
|
+
- - "~>"
|
148
140
|
- !ruby/object:Gem::Version
|
149
141
|
version: 0.14.1
|
150
142
|
type: :development
|
151
143
|
prerelease: false
|
152
144
|
version_requirements: !ruby/object:Gem::Requirement
|
153
145
|
requirements:
|
154
|
-
- - ~>
|
146
|
+
- - "~>"
|
155
147
|
- !ruby/object:Gem::Version
|
156
148
|
version: 0.14.1
|
157
149
|
description: CouchRest Model provides aditional features to the standard CouchRest
|
@@ -165,9 +157,9 @@ extra_rdoc_files:
|
|
165
157
|
- README.md
|
166
158
|
- THANKS.md
|
167
159
|
files:
|
168
|
-
- .gitignore
|
169
|
-
- .rspec
|
170
|
-
- .travis.yml
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".travis.yml"
|
171
163
|
- Gemfile
|
172
164
|
- LICENSE
|
173
165
|
- README.md
|
@@ -254,6 +246,7 @@ files:
|
|
254
246
|
- spec/unit/assocations_spec.rb
|
255
247
|
- spec/unit/attachment_spec.rb
|
256
248
|
- spec/unit/base_spec.rb
|
249
|
+
- spec/unit/casted_array_spec.rb
|
257
250
|
- spec/unit/casted_spec.rb
|
258
251
|
- spec/unit/configuration_spec.rb
|
259
252
|
- spec/unit/connection_spec.rb
|
@@ -285,17 +278,17 @@ require_paths:
|
|
285
278
|
- lib
|
286
279
|
required_ruby_version: !ruby/object:Gem::Requirement
|
287
280
|
requirements:
|
288
|
-
- -
|
281
|
+
- - ">="
|
289
282
|
- !ruby/object:Gem::Version
|
290
283
|
version: '0'
|
291
284
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
292
285
|
requirements:
|
293
|
-
- -
|
286
|
+
- - ">"
|
294
287
|
- !ruby/object:Gem::Version
|
295
288
|
version: 1.3.1
|
296
289
|
requirements: []
|
297
290
|
rubyforge_project:
|
298
|
-
rubygems_version: 2.
|
291
|
+
rubygems_version: 2.2.2
|
299
292
|
signing_key:
|
300
293
|
specification_version: 4
|
301
294
|
summary: Extends the CouchRest Document for advanced modelling.
|
@@ -334,6 +327,7 @@ test_files:
|
|
334
327
|
- spec/unit/assocations_spec.rb
|
335
328
|
- spec/unit/attachment_spec.rb
|
336
329
|
- spec/unit/base_spec.rb
|
330
|
+
- spec/unit/casted_array_spec.rb
|
337
331
|
- spec/unit/casted_spec.rb
|
338
332
|
- spec/unit/configuration_spec.rb
|
339
333
|
- spec/unit/connection_spec.rb
|