couch_potato 0.2.28 → 0.2.29

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
@@ -1,5 +1,9 @@
1
1
  ## Changes
2
2
 
3
+ ### master
4
+ * nicer inspect() for models (mattmatt)
5
+ * fixed (re)reduce for property views wasn't working (langalex)
6
+
3
7
  ### 0.2.28
4
8
  * fixed reloading nested classes (langalex)
5
9
  * fixed constant missing error when loading models with uninitialized classes via views (langalex)
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :major: 0
2
3
  :minor: 2
3
- :patch: 28
4
+ :patch: 29
4
5
  :build:
5
- :major: 0
@@ -94,6 +94,10 @@ module CouchPotato
94
94
  def ==(other) #:nodoc:
95
95
  other.class == self.class && self.to_json == other.to_json
96
96
  end
97
-
97
+
98
+ def inspect
99
+ attributes_as_string = attributes.map {|attribute, value| "#{attribute}: '#{value}'"}.join(", ")
100
+ "#<#{self.class} _id: '#{_id}', _rev: '#{_rev}', #{attributes_as_string}>"
101
+ end
98
102
  end
99
103
  end
@@ -11,6 +11,18 @@ module CouchPotato
11
11
  end
12
12
  end
13
13
 
14
+ def reduce_function
15
+ <<-JS
16
+ function(key, values, rereduce) {
17
+ if(rereduce) {
18
+ return sum(values);
19
+ } else {
20
+ return values.length;
21
+ }
22
+ }
23
+ JS
24
+ end
25
+
14
26
  def process_results(results)
15
27
  results['rows'].map do |row|
16
28
  klass.json_create row['value'].merge(:_id => row['id'])
@@ -271,4 +271,37 @@ describe 'properties' do
271
271
  clock.attributes[:cuckoo].should == 'bavarian'
272
272
  end
273
273
  end
274
+
275
+ describe "inspecting an object" do
276
+ let(:comment) do
277
+ comment = Comment.new(:title => 'title')
278
+ comment.instance_eval do
279
+ @_id = "123456abcdef"
280
+ @_rev = "1-654321fedcba"
281
+ end
282
+ comment
283
+ end
284
+
285
+ it "should not include change-tracking variables" do
286
+ comment.inspect.should_not include('title_was')
287
+ end
288
+
289
+ it "should include the normal persistent variables" do
290
+ comment.inspect.should include("title: 'title'")
291
+ end
292
+
293
+ it "should include the id" do
294
+ comment.inspect.should include("_id: '123456abcdef',")
295
+ end
296
+
297
+ it "should include the revision" do
298
+ comment.inspect.should include("_rev: '1-654321fedcba',")
299
+ end
300
+
301
+ it "should return a complete string" do
302
+ # stub to work around (un)sorted hash on different rubies
303
+ comment.stub!(:attributes).and_return([['created_at', ''], ['updated_at', ''], ['title', 'title']])
304
+ comment.inspect.should == "#<Comment _id: '123456abcdef', _rev: '1-654321fedcba', created_at: '', updated_at: '', title: 'title'>"
305
+ end
306
+ end
274
307
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'couch_potato/rspec'
3
+
4
+ class Contract
5
+ include CouchPotato::Persistence
6
+
7
+ property :date
8
+ property :terms
9
+
10
+ view :by_date, :type => :properties, :key => :_id, :properties => [:date]
11
+ end
12
+
13
+ describe CouchPotato::View::PropertiesViewSpec do
14
+ it "should map the given properties" do
15
+ Contract.by_date.should map(
16
+ Contract.new(:date => '2010-01-01', :_id => '1')
17
+ ).to(['1', {"date" => "2010-01-01"}])
18
+ end
19
+
20
+ it "should reduce to the number of documents" do
21
+ Contract.by_date.should reduce(
22
+ ['1', {"date" => "2010-01-01"}], ['2', {"date" => "2010-01-02"}]
23
+ ).to(2)
24
+ end
25
+
26
+ it "should rereduce the number of documents" do
27
+ Contract.by_date.should rereduce(
28
+ nil, [12, 13]
29
+ ).to(25)
30
+ end
31
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 28
9
- version: 0.2.28
8
+ - 29
9
+ version: 0.2.29
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-03-31 00:00:00 +02:00
17
+ date: 2010-04-06 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -129,6 +129,7 @@ files:
129
129
  - spec/unit/dirty_attributes_spec.rb
130
130
  - spec/unit/json_create_id_spec.rb
131
131
  - spec/unit/model_view_spec_spec.rb
132
+ - spec/unit/properties_view_spec_spec.rb
132
133
  - spec/unit/rspec_matchers_spec.rb
133
134
  - spec/unit/rspec_stub_db_spec.rb
134
135
  - spec/unit/string_spec.rb
@@ -191,6 +192,7 @@ test_files:
191
192
  - spec/unit/dirty_attributes_spec.rb
192
193
  - spec/unit/json_create_id_spec.rb
193
194
  - spec/unit/model_view_spec_spec.rb
195
+ - spec/unit/properties_view_spec_spec.rb
194
196
  - spec/unit/rspec_matchers_spec.rb
195
197
  - spec/unit/rspec_stub_db_spec.rb
196
198
  - spec/unit/string_spec.rb