couch_potato 0.2.29 → 0.2.30
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/CHANGES.md
CHANGED
data/VERSION.yml
CHANGED
@@ -32,7 +32,7 @@ module CouchPotato
|
|
32
32
|
#
|
33
33
|
# db.view(User.all(limit: 5, startkey: 2, reduce: false))
|
34
34
|
#
|
35
|
-
# For your convenience when passing a
|
35
|
+
# For your convenience when passing a hash with only a key parameter you can just pass in the value
|
36
36
|
#
|
37
37
|
# db.view(User.all(key: 1)) == db.view(User.all(1))
|
38
38
|
#
|
@@ -40,6 +40,9 @@ module CouchPotato
|
|
40
40
|
#
|
41
41
|
# db.view(User.all(key: 1..20)) == db.view(startkey: 1, endkey: 20) == db.view(User.all(1..20))
|
42
42
|
#
|
43
|
+
# You can also pass in multiple keys:
|
44
|
+
#
|
45
|
+
# db.view(User.all(keys: [1, 2, 3]))
|
43
46
|
def view(spec)
|
44
47
|
results = CouchPotato::View::ViewQuery.new(database,
|
45
48
|
spec.design_document, spec.view_name, spec.map_function,
|
@@ -54,7 +54,7 @@ module CouchPotato
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def valid_view_parameters
|
57
|
-
%w(key startkey startkey_docid endkey endkey_docid limit stale descending skip group group_level reduce include_docs inclusive_end)
|
57
|
+
%w(key keys startkey startkey_docid endkey endkey_docid limit stale descending skip group group_level reduce include_docs inclusive_end)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/spec/custom_view_spec.rb
CHANGED
@@ -12,8 +12,8 @@ class Build
|
|
12
12
|
view :key_array_timeline, :key => [:time, :state]
|
13
13
|
view :custom_timeline, :map => "function(doc) { emit(doc._id, {state: 'custom_' + doc.state}); }", :type => :custom
|
14
14
|
view :custom_timeline_returns_docs, :map => "function(doc) { emit(doc._id, null); }", :include_docs => true, :type => :custom
|
15
|
-
view :custom_with_reduce, :map => "function(doc) {if(doc.foreign_key) {emit(doc.foreign_key, 1);} else {emit(doc.
|
16
|
-
view :custom_count_with_reduce, :map => "function(doc) {if(doc.foreign_key) {emit(doc.foreign_key, 1);} else {emit(doc.
|
15
|
+
view :custom_with_reduce, :map => "function(doc) {if(doc.foreign_key) {emit(doc.foreign_key, 1);} else {emit(doc._id, 1)}}", :reduce => "function(key, values) {return({\"count\": sum(values)});}", :group => true, :type => :custom
|
16
|
+
view :custom_count_with_reduce, :map => "function(doc) {if(doc.foreign_key) {emit(doc.foreign_key, 1);} else {emit(doc._id, 1)}}", :reduce => "function(key, values) {return(sum(values));}", :group => true, :type => :custom
|
17
17
|
view :raw, :type => :raw, :map => "function(doc) {emit(doc._id, doc.state)}"
|
18
18
|
view :filtered_raw, :type => :raw, :map => "function(doc) {emit(doc._id, doc.state)}", :results_filter => lambda{|res| res['rows'].map{|row| row['value']}}
|
19
19
|
view :with_view_options, :group => true, :key => :time
|
@@ -25,11 +25,12 @@ end
|
|
25
25
|
describe 'view' do
|
26
26
|
before(:each) do
|
27
27
|
recreate_db
|
28
|
+
@db = CouchPotato.database
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should return instances of the class" do
|
31
|
-
|
32
|
-
results =
|
32
|
+
@db.save_document Build.new(:state => 'success', :time => '2008-01-01')
|
33
|
+
results = @db.view(Build.timeline)
|
33
34
|
results.map(&:class).should == [Build]
|
34
35
|
end
|
35
36
|
|
@@ -37,49 +38,63 @@ describe 'view' do
|
|
37
38
|
query = mock 'query'
|
38
39
|
CouchPotato::View::ViewQuery.stub!(:new).and_return(query)
|
39
40
|
query.should_receive(:query_view!).with(hash_including(:key => 1)).and_return('rows' => [])
|
40
|
-
|
41
|
+
@db.view Build.timeline(:key => 1)
|
41
42
|
end
|
42
43
|
|
43
44
|
it "should not return documents that don't have a matching JSON.create_id" do
|
44
45
|
CouchPotato.couchrest_database.save_doc({:time => 'x'})
|
45
|
-
|
46
|
+
@db.view(Build.timeline).should == []
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should count documents" do
|
49
|
-
|
50
|
-
|
50
|
+
@db.save_document! Build.new(:state => 'success', :time => '2008-01-01')
|
51
|
+
@db.view(Build.count(:reduce => true)).should == 1
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should count zero documents" do
|
54
|
-
|
55
|
+
@db.view(Build.count(:reduce => true)).should == 0
|
55
56
|
end
|
56
57
|
|
57
58
|
it "should return the total_rows" do
|
58
|
-
|
59
|
-
|
59
|
+
@db.save_document! Build.new(:state => 'success', :time => '2008-01-01')
|
60
|
+
@db.view(Build.count(:reduce => false)).total_rows.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "with multiple keys" do
|
64
|
+
it "should return the documents with matching keys" do
|
65
|
+
build = Build.new(:state => 'success', :time => '2008-01-01')
|
66
|
+
@db.save! build
|
67
|
+
@db.view(Build.timeline(:keys => ['2008-01-01'])).should == [build]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not return documents with non-matching keys" do
|
71
|
+
build = Build.new(:state => 'success', :time => '2008-01-01')
|
72
|
+
@db.save! build
|
73
|
+
@db.view(Build.timeline(:keys => ['2008-01-02'])).should be_empty
|
74
|
+
end
|
60
75
|
end
|
61
76
|
|
62
77
|
describe "properties defined" do
|
63
78
|
it "should assign the configured properties" do
|
64
79
|
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')
|
65
|
-
|
80
|
+
@db.view(Build.minimal_timeline).first.state.should == 'success'
|
66
81
|
end
|
67
82
|
|
68
83
|
it "should not assign the properties not configured" do
|
69
84
|
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')
|
70
|
-
|
85
|
+
@db.view(Build.minimal_timeline).first.time.should be_nil
|
71
86
|
end
|
72
87
|
|
73
88
|
it "should assign the id even if it is not configured" do
|
74
89
|
id = CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')['id']
|
75
|
-
|
90
|
+
@db.view(Build.minimal_timeline).first._id.should == id
|
76
91
|
end
|
77
92
|
end
|
78
93
|
|
79
94
|
describe "no properties defined" do
|
80
95
|
it "should assign all properties to the objects by default" do
|
81
96
|
id = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build'})['id']
|
82
|
-
result =
|
97
|
+
result = @db.view(Build.timeline).first
|
83
98
|
result.state.should == 'success'
|
84
99
|
result.time.should == '2008-01-01'
|
85
100
|
result._id.should == id
|
@@ -89,38 +104,38 @@ describe 'view' do
|
|
89
104
|
describe "map function given" do
|
90
105
|
it "should still return instances of the class" do
|
91
106
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
92
|
-
|
107
|
+
@db.view(Build.custom_timeline).map(&:class).should == [Build]
|
93
108
|
end
|
94
109
|
|
95
110
|
it "should assign the properties from the value" do
|
96
111
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
97
|
-
|
112
|
+
@db.view(Build.custom_timeline).map(&:state).should == ['custom_success']
|
98
113
|
end
|
99
114
|
|
100
115
|
it "should assign the id" do
|
101
116
|
doc = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
102
|
-
|
117
|
+
@db.view(Build.custom_timeline).map(&:_id).should == [doc['id']]
|
103
118
|
end
|
104
119
|
|
105
120
|
it "should leave the other properties blank" do
|
106
121
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
107
|
-
|
122
|
+
@db.view(Build.custom_timeline).map(&:time).should == [nil]
|
108
123
|
end
|
109
124
|
|
110
125
|
describe "that returns null documents" do
|
111
126
|
it "should return instances of the class" do
|
112
127
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
113
|
-
|
128
|
+
@db.view(Build.custom_timeline_returns_docs).map(&:class).should == [Build]
|
114
129
|
end
|
115
130
|
|
116
131
|
it "should assign the properties from the value" do
|
117
132
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
|
118
|
-
|
133
|
+
@db.view(Build.custom_timeline_returns_docs).map(&:state).should == ['success']
|
119
134
|
end
|
120
135
|
|
121
136
|
it "should still return instance of class if document included JSON.create_id" do
|
122
137
|
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => "Build"})
|
123
|
-
view_data =
|
138
|
+
view_data = @db.view(Build.custom_timeline_returns_docs)
|
124
139
|
view_data.map(&:class).should == [Build]
|
125
140
|
view_data.map(&:state).should == ['success']
|
126
141
|
end
|
@@ -130,14 +145,14 @@ describe 'view' do
|
|
130
145
|
it "should still assign the id" do
|
131
146
|
doc = CouchPotato.couchrest_database.save_doc({})
|
132
147
|
CouchPotato.couchrest_database.save_doc({:foreign_key => doc['id']})
|
133
|
-
|
148
|
+
@db.view(Build.custom_with_reduce).map(&:_id).should == [doc['id']]
|
134
149
|
end
|
135
150
|
|
136
151
|
describe "when the additional reduce function is a typical count" do
|
137
152
|
it "should parse the reduce count" do
|
138
153
|
doc = CouchPotato.couchrest_database.save_doc({})
|
139
154
|
CouchPotato.couchrest_database.save_doc({:foreign_key => doc['id']})
|
140
|
-
|
155
|
+
@db.view(Build.custom_count_with_reduce(:reduce => true)).should == 2
|
141
156
|
end
|
142
157
|
end
|
143
158
|
end
|
@@ -146,34 +161,34 @@ describe 'view' do
|
|
146
161
|
describe "with array as key" do
|
147
162
|
it "should create a map function with the composite key" do
|
148
163
|
CouchPotato::View::ViewQuery.should_receive(:new).with(anything, anything, anything, string_matching(/emit\(\[doc\['time'\], doc\['state'\]\]/), anything).and_return(stub('view query', :query_view! => {'rows' => []}))
|
149
|
-
|
164
|
+
@db.view Build.key_array_timeline
|
150
165
|
end
|
151
166
|
end
|
152
167
|
|
153
168
|
describe "raw view" do
|
154
169
|
it "should return the raw data" do
|
155
|
-
|
156
|
-
|
170
|
+
@db.save_document Build.new(:state => 'success', :time => '2008-01-01')
|
171
|
+
@db.view(Build.raw)['rows'][0]['value'].should == 'success'
|
157
172
|
end
|
158
173
|
|
159
174
|
it "should return filtred raw data" do
|
160
|
-
|
161
|
-
|
175
|
+
@db.save_document Build.new(:state => 'success', :time => '2008-01-01')
|
176
|
+
@db.view(Build.filtered_raw).should == ['success']
|
162
177
|
end
|
163
178
|
|
164
179
|
it "should pass view options declared in the view declaration to the query" do
|
165
180
|
view_query = mock 'view_query'
|
166
181
|
CouchPotato::View::ViewQuery.stub!(:new).and_return(view_query)
|
167
182
|
view_query.should_receive(:query_view!).with(hash_including(:group => true)).and_return({'rows' => []})
|
168
|
-
|
183
|
+
@db.view(Build.with_view_options)
|
169
184
|
end
|
170
185
|
end
|
171
186
|
|
172
187
|
describe "inherited views" do
|
173
188
|
it "should support parent views for objects of the subclass" do
|
174
|
-
|
175
|
-
|
176
|
-
|
189
|
+
@db.save_document CustomBuild.new(:state => 'success', :time => '2008-01-01')
|
190
|
+
@db.view(CustomBuild.timeline).size.should == 1
|
191
|
+
@db.view(CustomBuild.timeline).first.should be_kind_of(CustomBuild)
|
177
192
|
end
|
178
193
|
end
|
179
194
|
end
|
File without changes
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 30
|
9
|
+
version: 0.2.30
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexander Lang
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -123,7 +123,7 @@ files:
|
|
123
123
|
- spec/unit/callbacks_spec.rb
|
124
124
|
- spec/unit/couch_potato_spec.rb
|
125
125
|
- spec/unit/create_spec.rb
|
126
|
-
- spec/unit/
|
126
|
+
- spec/unit/custom_views_spec.rb
|
127
127
|
- spec/unit/database_spec.rb
|
128
128
|
- spec/unit/date_spec.rb
|
129
129
|
- spec/unit/dirty_attributes_spec.rb
|
@@ -186,7 +186,7 @@ test_files:
|
|
186
186
|
- spec/unit/callbacks_spec.rb
|
187
187
|
- spec/unit/couch_potato_spec.rb
|
188
188
|
- spec/unit/create_spec.rb
|
189
|
-
- spec/unit/
|
189
|
+
- spec/unit/custom_views_spec.rb
|
190
190
|
- spec/unit/database_spec.rb
|
191
191
|
- spec/unit/date_spec.rb
|
192
192
|
- spec/unit/dirty_attributes_spec.rb
|