langalex-couch_potato 0.1 → 0.1.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.
- data/README.textile +340 -0
- data/VERSION.yml +4 -0
- data/lib/couch_potato/ordering.rb +5 -9
- data/lib/couch_potato/persistence.rb +32 -7
- data/lib/couch_potato/persistence/belongs_to_property.rb +17 -3
- data/lib/couch_potato/persistence/callbacks.rb +9 -0
- data/lib/couch_potato/persistence/custom_view.rb +41 -0
- data/lib/couch_potato/persistence/dirty_attributes.rb +19 -0
- data/lib/couch_potato/persistence/external_collection.rb +31 -2
- data/lib/couch_potato/persistence/external_has_many_property.rb +4 -0
- data/lib/couch_potato/persistence/finder.rb +21 -65
- data/lib/couch_potato/persistence/inline_has_many_property.rb +4 -0
- data/lib/couch_potato/persistence/json.rb +1 -1
- data/lib/couch_potato/persistence/simple_property.rb +29 -1
- data/lib/couch_potato/persistence/view_query.rb +81 -0
- data/lib/couch_potato/versioning.rb +1 -1
- data/spec/attributes_spec.rb +35 -15
- data/spec/belongs_to_spec.rb +18 -0
- data/spec/callbacks_spec.rb +31 -12
- data/spec/create_spec.rb +5 -0
- data/spec/custom_view_spec.rb +44 -0
- data/spec/destroy_spec.rb +4 -0
- data/spec/dirty_attributes_spec.rb +82 -0
- data/spec/find_spec.rb +11 -3
- data/spec/finder_spec.rb +10 -0
- data/spec/has_many_spec.rb +64 -1
- data/spec/ordering_spec.rb +1 -0
- data/spec/property_spec.rb +4 -0
- data/spec/reload_spec.rb +4 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/unit/external_collection_spec.rb +84 -0
- data/spec/unit/finder_spec.rb +10 -0
- data/spec/unit/view_query_spec.rb +10 -0
- data/spec/update_spec.rb +6 -0
- data/spec/versioning_spec.rb +1 -0
- metadata +21 -48
- data/CREDITS +0 -3
- data/init.rb +0 -5
data/spec/finder_spec.rb
CHANGED
@@ -9,6 +9,7 @@ end
|
|
9
9
|
describe CouchPotato::Persistence::Finder, 'find' do
|
10
10
|
before(:each) do
|
11
11
|
CouchPotato::Persistence.Db.delete!
|
12
|
+
CouchPotato::Persistence.Db!
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "couchdb 0.9+" do
|
@@ -86,6 +87,7 @@ end
|
|
86
87
|
describe CouchPotato::Persistence::Finder, 'count' do
|
87
88
|
before(:each) do
|
88
89
|
CouchPotato::Persistence.Db.delete!
|
90
|
+
CouchPotato::Persistence.Db!
|
89
91
|
end
|
90
92
|
|
91
93
|
it "should count objects with a given attribute value pair" do
|
@@ -112,4 +114,12 @@ describe CouchPotato::Persistence::Finder, 'count' do
|
|
112
114
|
OtherComment.create! :commenter_id => '1'
|
113
115
|
CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 0
|
114
116
|
end
|
117
|
+
|
118
|
+
it "should return correct count when view engine performs group reduce" do
|
119
|
+
100.times do |t|
|
120
|
+
Comment.create! :title => 'testing mass count', :commenter_id => '1'
|
121
|
+
end
|
122
|
+
|
123
|
+
CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 100
|
124
|
+
end
|
115
125
|
end
|
data/spec/has_many_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe 'has_many stored inline' do
|
4
|
+
before(:all) do
|
5
|
+
CouchPotato::Persistence.Db!
|
6
|
+
end
|
7
|
+
|
4
8
|
before(:each) do
|
5
9
|
@user = User.new
|
6
10
|
end
|
@@ -27,6 +31,10 @@ describe 'has_many stored inline' do
|
|
27
31
|
end
|
28
32
|
|
29
33
|
describe 'has_many stored separately' do
|
34
|
+
before(:all) do
|
35
|
+
CouchPotato::Persistence.Db!
|
36
|
+
end
|
37
|
+
|
30
38
|
before(:each) do
|
31
39
|
@commenter = Commenter.new
|
32
40
|
end
|
@@ -59,6 +67,62 @@ describe 'has_many stored separately' do
|
|
59
67
|
@commenter.comments.first.title.should == 'my title'
|
60
68
|
end
|
61
69
|
|
70
|
+
describe "all" do
|
71
|
+
it "should find all dependent objects by search conditions" do
|
72
|
+
commenter = Commenter.create!
|
73
|
+
comment1 = commenter.comments.create! :title => 'my title'
|
74
|
+
comment2 = commenter.comments.create! :title => 'my title'
|
75
|
+
commenter.comments.create! :title => 'my title2'
|
76
|
+
comments = commenter.comments.all(:title => 'my title')
|
77
|
+
comments.size.should == 2
|
78
|
+
comments.should include(comment1)
|
79
|
+
comments.should include(comment2)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return all dependent objects" do
|
83
|
+
@commenter = Commenter.create!
|
84
|
+
comment1 = @commenter.comments.create! :title => 'my title'
|
85
|
+
comment2 = @commenter.comments.create! :title => 'my title2'
|
86
|
+
comments = @commenter.comments.all
|
87
|
+
comments.size.should == 2
|
88
|
+
comments.should include(comment1)
|
89
|
+
comments.should include(comment2)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "count" do
|
94
|
+
it "should count the dependent objects by search criteria" do
|
95
|
+
commenter = Commenter.create!
|
96
|
+
commenter.comments.create! :title => 'my title'
|
97
|
+
commenter.comments.create! :title => 'my title'
|
98
|
+
commenter.comments.create! :title => 'my title2'
|
99
|
+
commenter.comments.count(:title => 'my title').should == 2
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should count all dependent objects" do
|
103
|
+
commenter = Commenter.create!
|
104
|
+
commenter.comments.create! :title => 'my title'
|
105
|
+
commenter.comments.create! :title => 'my title'
|
106
|
+
commenter.comments.create! :title => 'my title2'
|
107
|
+
commenter.comments.count.should == 3
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "first" do
|
112
|
+
it "should find the first dependent object by search conditions" do
|
113
|
+
commenter = Commenter.create!
|
114
|
+
comment1 = commenter.comments.create! :title => 'my title'
|
115
|
+
comment2 = commenter.comments.create! :title => 'my title2'
|
116
|
+
commenter.comments.first(:title => 'my title2').should == comment2
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return the first dependent object" do
|
120
|
+
comment1 = @commenter.comments.build :title => 'my title'
|
121
|
+
comment2 = @commenter.comments.build :title => 'my title2'
|
122
|
+
@commenter.comments.first.should == comment1
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
62
126
|
describe "create" do
|
63
127
|
it "should persist child objects" do
|
64
128
|
@commenter.comments.build(:title => 'my title')
|
@@ -122,7 +186,6 @@ describe 'has_many stored separately' do
|
|
122
186
|
end
|
123
187
|
end
|
124
188
|
|
125
|
-
|
126
189
|
describe "destroy" do
|
127
190
|
|
128
191
|
class AdminComment
|
data/spec/ordering_spec.rb
CHANGED
data/spec/property_spec.rb
CHANGED
data/spec/reload_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,8 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
7
7
|
require 'couch_potato'
|
8
8
|
|
9
9
|
CouchPotato::Config.database_name = 'couch_potato_test'
|
10
|
-
CouchPotato::Persistence.Db.delete!
|
10
|
+
CouchPotato::Persistence.Db.delete! rescue nil
|
11
|
+
CouchPotato::Persistence.Db!
|
11
12
|
|
12
13
|
class User
|
13
14
|
include CouchPotato::Persistence
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CouchPotato::Persistence::ExternalCollection, 'all' do
|
4
|
+
before(:each) do
|
5
|
+
@collection = CouchPotato::Persistence::ExternalCollection.new Comment, :commenter_id
|
6
|
+
@collection.owner_id = 3
|
7
|
+
@finder = stub 'finder'
|
8
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(@finder)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should delegate to a new finder" do
|
12
|
+
@finder.should_receive(:find).with(Comment, {:commenter_id => 3}).and_return([])
|
13
|
+
@collection.all
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should search with the given conditions" do
|
17
|
+
@finder.should_receive(:find).with(Comment, {:commenter_id => 3, :name => 'xyz'}, {}).and_return([])
|
18
|
+
@collection.all :name => 'xyz'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return the result of the finder" do
|
22
|
+
result = stub('item', :_id => 1)
|
23
|
+
@finder.stub!(:find).and_return([result])
|
24
|
+
@collection.all.should == [result]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe CouchPotato::Persistence::ExternalCollection, 'count' do
|
29
|
+
before(:each) do
|
30
|
+
@collection = CouchPotato::Persistence::ExternalCollection.new Comment, :commenter_id
|
31
|
+
@collection.owner_id = 3
|
32
|
+
@finder = stub 'finder'
|
33
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(@finder)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should delegate to a new finder" do
|
37
|
+
@finder.should_receive(:count).with(Comment, {:commenter_id => 3}, {})
|
38
|
+
@collection.count
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should count with the given conditions" do
|
42
|
+
@finder.should_receive(:count).with(Comment, {:commenter_id => 3, :name => 'xyz'}, {})
|
43
|
+
@collection.count :name => 'xyz'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return the result of the finder" do
|
47
|
+
@finder.stub!(:count).and_return(2)
|
48
|
+
@collection.count.should == 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe CouchPotato::Persistence::ExternalCollection, 'dirty?' do
|
53
|
+
it "should return false if items haven't been loaded" do
|
54
|
+
CouchPotato::Persistence::ExternalCollection.new(Comment, :commenter_id).should_not be_dirty
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false if items haven't been touched" do
|
58
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(stub('finder', :find => [stub(:item, :dirty? => false, :_id => 1)]))
|
59
|
+
collection = CouchPotato::Persistence::ExternalCollection.new(Comment, :commenter_id)
|
60
|
+
collection.items
|
61
|
+
collection.should_not be_dirty
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return true after adding a new item" do
|
65
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(stub('finder', :find => []))
|
66
|
+
collection = CouchPotato::Persistence::ExternalCollection.new(Comment, :commenter_id)
|
67
|
+
collection.items << stub(:item, :dirty? => false, :_id => 1)
|
68
|
+
collection.should be_dirty
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return true after removing an item" do
|
72
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(stub('finder', :find => [stub(:item, :dirty? => false, :_id => 1)]))
|
73
|
+
collection = CouchPotato::Persistence::ExternalCollection.new(Comment, :commenter_id)
|
74
|
+
collection.items.pop
|
75
|
+
collection.should be_dirty
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return true when an item is dirty" do
|
79
|
+
CouchPotato::Persistence::Finder.stub!(:new).and_return(stub('finder', :find => [stub(:item, :dirty? => true, :_id => 1)]))
|
80
|
+
collection = CouchPotato::Persistence::ExternalCollection.new(Comment, :commenter_id)
|
81
|
+
collection.items
|
82
|
+
collection.should be_dirty
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CouchPotato::Persistence::Finder, 'find' do
|
4
|
+
it "should pass the count parameter to the database" do
|
5
|
+
database = stub 'database'
|
6
|
+
::CouchPotato::Persistence.stub!(:Db).and_return(database)
|
7
|
+
database.should_receive(:view).with(anything, hash_including(:count => 1)).and_return({'rows' => []})
|
8
|
+
CouchPotato::Persistence::Finder.new.find Comment, {}, :count => 1
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CouchPotato::Persistence::ViewQuery, 'query_view' do
|
4
|
+
it "should not pass a key if conditions are empty" do
|
5
|
+
db = mock 'db'
|
6
|
+
db.should_receive(:view).with(anything, {})
|
7
|
+
::CouchPotato::Persistence.stub!(:Db).and_return(db)
|
8
|
+
CouchPotato::Persistence::ViewQuery.new('', '', '', '', {}).query_view!
|
9
|
+
end
|
10
|
+
end
|
data/spec/update_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe "create" do
|
4
|
+
before(:all) do
|
5
|
+
CouchPotato::Persistence.Db!
|
6
|
+
end
|
7
|
+
|
4
8
|
before(:each) do
|
5
9
|
@comment = Comment.new :title => 'my_title'
|
6
10
|
@comment.save!
|
@@ -8,6 +12,7 @@ describe "create" do
|
|
8
12
|
|
9
13
|
it "should update the revision" do
|
10
14
|
old_rev = @comment._rev
|
15
|
+
@comment.title = 'xyz'
|
11
16
|
@comment.save!
|
12
17
|
@comment._rev.should_not == old_rev
|
13
18
|
@comment._rev.should_not be_nil
|
@@ -21,6 +26,7 @@ describe "create" do
|
|
21
26
|
|
22
27
|
it "should update updated at" do
|
23
28
|
old_updated_at = @comment.updated_at
|
29
|
+
@comment.title = 'xyz'
|
24
30
|
@comment.save!
|
25
31
|
@comment.updated_at.should > old_updated_at
|
26
32
|
end
|
data/spec/versioning_spec.rb
CHANGED
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:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
@@ -9,46 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-15 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
23
|
-
version:
|
24
|
-
- !ruby/object:Gem::Dependency
|
25
|
-
name: validatable
|
26
|
-
version_requirement:
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
requirements:
|
29
|
-
- - ">="
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version: "0"
|
32
|
-
version:
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: activesupport
|
35
|
-
version_requirement:
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: "0"
|
41
|
-
version:
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: jchris-couchrest
|
44
|
-
version_requirement:
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.9.12
|
50
|
-
version:
|
51
|
-
description:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby persistence layer for CouchDB
|
52
17
|
email: alex@upstream-berlin.com
|
53
18
|
executables: []
|
54
19
|
|
@@ -57,10 +22,9 @@ extensions: []
|
|
57
22
|
extra_rdoc_files: []
|
58
23
|
|
59
24
|
files:
|
60
|
-
- init.rb
|
61
|
-
- Readme.textile
|
62
25
|
- MIT-LICENSE.txt
|
63
|
-
-
|
26
|
+
- README.textile
|
27
|
+
- VERSION.yml
|
64
28
|
- lib/core_ext
|
65
29
|
- lib/core_ext/object.rb
|
66
30
|
- lib/core_ext/time.rb
|
@@ -73,6 +37,8 @@ files:
|
|
73
37
|
- lib/couch_potato/persistence/bulk_save_queue.rb
|
74
38
|
- lib/couch_potato/persistence/callbacks.rb
|
75
39
|
- lib/couch_potato/persistence/collection.rb
|
40
|
+
- lib/couch_potato/persistence/custom_view.rb
|
41
|
+
- lib/couch_potato/persistence/dirty_attributes.rb
|
76
42
|
- lib/couch_potato/persistence/external_collection.rb
|
77
43
|
- lib/couch_potato/persistence/external_has_many_property.rb
|
78
44
|
- lib/couch_potato/persistence/find.rb
|
@@ -82,6 +48,7 @@ files:
|
|
82
48
|
- lib/couch_potato/persistence/json.rb
|
83
49
|
- lib/couch_potato/persistence/properties.rb
|
84
50
|
- lib/couch_potato/persistence/simple_property.rb
|
51
|
+
- lib/couch_potato/persistence/view_query.rb
|
85
52
|
- lib/couch_potato/persistence.rb
|
86
53
|
- lib/couch_potato/versioning.rb
|
87
54
|
- lib/couch_potato.rb
|
@@ -89,7 +56,9 @@ files:
|
|
89
56
|
- spec/belongs_to_spec.rb
|
90
57
|
- spec/callbacks_spec.rb
|
91
58
|
- spec/create_spec.rb
|
59
|
+
- spec/custom_view_spec.rb
|
92
60
|
- spec/destroy_spec.rb
|
61
|
+
- spec/dirty_attributes_spec.rb
|
93
62
|
- spec/find_spec.rb
|
94
63
|
- spec/finder_spec.rb
|
95
64
|
- spec/has_many_spec.rb
|
@@ -99,16 +68,20 @@ files:
|
|
99
68
|
- spec/reload_spec.rb
|
100
69
|
- spec/spec.opts
|
101
70
|
- spec/spec_helper.rb
|
71
|
+
- spec/unit
|
72
|
+
- spec/unit/external_collection_spec.rb
|
73
|
+
- spec/unit/finder_spec.rb
|
74
|
+
- spec/unit/view_query_spec.rb
|
102
75
|
- spec/update_spec.rb
|
103
76
|
- spec/versioning_spec.rb
|
104
|
-
has_rdoc:
|
77
|
+
has_rdoc: true
|
105
78
|
homepage: http://github.com/langalex/couch_potato
|
106
79
|
post_install_message:
|
107
|
-
rdoc_options:
|
108
|
-
|
80
|
+
rdoc_options:
|
81
|
+
- --inline-source
|
82
|
+
- --charset=UTF-8
|
109
83
|
require_paths:
|
110
84
|
- lib
|
111
|
-
- lib
|
112
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
86
|
requirements:
|
114
87
|
- - ">="
|
@@ -127,6 +100,6 @@ rubyforge_project:
|
|
127
100
|
rubygems_version: 1.2.0
|
128
101
|
signing_key:
|
129
102
|
specification_version: 2
|
130
|
-
summary:
|
103
|
+
summary: Ruby persistence layer for CouchDB
|
131
104
|
test_files: []
|
132
105
|
|
data/CREDITS
DELETED