langalex-couch_potato 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -57,7 +57,7 @@ Alternatively you can also install Couch Potato directly as a plugin.
57
57
 
58
58
  ### Introduction
59
59
 
60
- This is a basic tutorial on how to use Couch Potato. If you want to know all the details feel free to read the specs.
60
+ This is a basic tutorial on how to use Couch Potato. If you want to know all the details feel free to read the specs and the [rdocs](http://rdoc.info/projects/langalex/couch_potato).
61
61
 
62
62
  #### Save, load objects
63
63
 
@@ -186,7 +186,7 @@ Composite keys are also possible:
186
186
  view :all, :key => [:created_at, :name]
187
187
  end
188
188
 
189
- The creation of views is based on view specification classes (see the CouchPotato::View module). The above code uses the ModelViewSpec class which is used to find models by their properties. For more sophisticated searches you can use other view specifications (either use the built-in or provide your own) by passing a type parameter:
189
+ The creation of views is based on view specification classes (see [CouchPotato::View::BaseViewSpec](http://rdoc.info/rdoc/langalex/couch_potato/blob/e8f0069e5529ad08a1bd1f02637ea8f1d6d0ab5b/CouchPotato/View/BaseViewSpec.html) and its descendants for more detailed documentation). The above code uses the ModelViewSpec class which is used to find models by their properties. For more sophisticated searches you can use other view specifications (either use the built-in or provide your own) by passing a type parameter:
190
190
 
191
191
  If you have larger structures and you only want to load some attributes you can use the PropertiesViewSpec (the full class name is automatically derived):
192
192
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 11
4
+ :patch: 12
@@ -19,7 +19,7 @@ module CouchPotato
19
19
 
20
20
  def process_results(results)
21
21
  results['rows'].map do |row|
22
- klass.json_create row['doc'] || row['value'].merge(:_id => row['id'])
22
+ klass.json_create row['doc'] || row['value'].merge(:_id => row['id'] || row['key'])
23
23
  end
24
24
  end
25
25
  end
@@ -12,6 +12,7 @@ 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.id, 1)}}", :reduce => "function(key, values) {return({\"count\": sum(values)});}", :group => true, :type => :custom
15
16
  view :raw, :type => :raw, :map => "function(doc) {emit(doc._id, doc.state)}"
16
17
  view :filtered_raw, :type => :raw, :map => "function(doc) {emit(doc._id, doc.state)}", :results_filter => lambda{|res| res['rows'].map{|row| row['value']}}
17
18
  view :with_view_options, :group => true, :key => :time
@@ -87,11 +88,16 @@ describe 'view' do
87
88
  CouchPotato.database.view(Build.custom_timeline).map(&:state).should == ['custom_success']
88
89
  end
89
90
 
91
+ it "should assign the id" do
92
+ doc = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
93
+ CouchPotato.database.view(Build.custom_timeline).map(&:_id).should == [doc['id']]
94
+ end
95
+
90
96
  it "should leave the other properties blank" do
91
97
  CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
92
98
  CouchPotato.database.view(Build.custom_timeline).map(&:time).should == [nil]
93
99
  end
94
-
100
+
95
101
  describe "that returns null documents" do
96
102
  it "should return instances of the class" do
97
103
  CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01'})
@@ -103,6 +109,15 @@ describe 'view' do
103
109
  CouchPotato.database.view(Build.custom_timeline_returns_docs).map(&:state).should == ['success']
104
110
  end
105
111
  end
112
+
113
+ describe "additional reduce function given" do
114
+ it "should still assign the id" do
115
+ doc = CouchPotato.couchrest_database.save_doc({})
116
+ CouchPotato.couchrest_database.save_doc({:foreign_key => doc['id']})
117
+ CouchPotato.database.view(Build.custom_with_reduce).map(&:_id).should == [doc['id']]
118
+
119
+ end
120
+ end
106
121
  end
107
122
 
108
123
  describe "with array as key" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langalex-couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-18 00:00:00 -07:00
12
+ date: 2009-09-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency