langalex-couch_potato 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +260 -0
- data/VERSION.yml +2 -2
- data/init.rb +3 -0
- data/lib/core_ext/date.rb +10 -0
- data/lib/core_ext/string.rb +15 -0
- data/lib/core_ext/time.rb +6 -9
- data/lib/couch_potato/database.rb +90 -0
- data/lib/couch_potato/persistence/belongs_to_property.rb +1 -1
- data/lib/couch_potato/persistence/callbacks.rb +14 -11
- data/lib/couch_potato/persistence/dirty_attributes.rb +13 -6
- data/lib/couch_potato/persistence/json.rb +9 -14
- data/lib/couch_potato/persistence/magic_timestamps.rb +13 -0
- data/lib/couch_potato/persistence/properties.rb +10 -8
- data/lib/couch_potato/persistence/simple_property.rb +14 -11
- data/lib/couch_potato/persistence.rb +11 -165
- data/lib/couch_potato/view/base_view_spec.rb +20 -0
- data/lib/couch_potato/view/custom_view_spec.rb +26 -0
- data/lib/couch_potato/view/custom_views.rb +30 -0
- data/lib/couch_potato/view/model_view_spec.rb +39 -0
- data/lib/couch_potato/view/properties_view_spec.rb +35 -0
- data/lib/couch_potato/view/raw_view_spec.rb +21 -0
- data/lib/couch_potato/view/view_query.rb +45 -0
- data/lib/couch_potato.rb +23 -6
- data/rails/init.rb +7 -0
- data/spec/callbacks_spec.rb +40 -43
- data/spec/create_spec.rb +9 -60
- data/spec/custom_view_spec.rb +93 -19
- data/spec/destroy_spec.rb +5 -4
- data/spec/property_spec.rb +22 -8
- data/spec/spec_helper.rb +12 -14
- data/spec/unit/attributes_spec.rb +26 -0
- data/spec/unit/create_spec.rb +58 -0
- data/spec/{dirty_attributes_spec.rb → unit/dirty_attributes_spec.rb} +31 -13
- data/spec/unit/string_spec.rb +13 -0
- data/spec/unit/view_query_spec.rb +2 -3
- data/spec/update_spec.rb +8 -7
- metadata +54 -32
- data/README.textile +0 -340
- data/lib/couch_potato/active_record/compatibility.rb +0 -9
- data/lib/couch_potato/ordering.rb +0 -84
- data/lib/couch_potato/persistence/bulk_save_queue.rb +0 -47
- data/lib/couch_potato/persistence/collection.rb +0 -51
- data/lib/couch_potato/persistence/custom_view.rb +0 -41
- data/lib/couch_potato/persistence/external_collection.rb +0 -83
- data/lib/couch_potato/persistence/external_has_many_property.rb +0 -72
- data/lib/couch_potato/persistence/find.rb +0 -21
- data/lib/couch_potato/persistence/finder.rb +0 -65
- data/lib/couch_potato/persistence/inline_has_many_property.rb +0 -43
- data/lib/couch_potato/persistence/view_query.rb +0 -81
- data/lib/couch_potato/versioning.rb +0 -46
- data/spec/attributes_spec.rb +0 -42
- data/spec/belongs_to_spec.rb +0 -55
- data/spec/find_spec.rb +0 -96
- data/spec/finder_spec.rb +0 -125
- data/spec/has_many_spec.rb +0 -241
- data/spec/inline_collection_spec.rb +0 -15
- data/spec/ordering_spec.rb +0 -95
- data/spec/reload_spec.rb +0 -50
- data/spec/unit/external_collection_spec.rb +0 -84
- data/spec/unit/finder_spec.rb +0 -10
- data/spec/versioning_spec.rb +0 -150
@@ -1,84 +0,0 @@
|
|
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
|
data/spec/unit/finder_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
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
|
data/spec/versioning_spec.rb
DELETED
@@ -1,150 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe CouchPotato::Versioning do
|
4
|
-
class Document
|
5
|
-
include CouchPotato::Persistence
|
6
|
-
include CouchPotato::Versioning
|
7
|
-
|
8
|
-
property :title
|
9
|
-
validates_presence_of :title
|
10
|
-
end
|
11
|
-
|
12
|
-
class ConditionDocument
|
13
|
-
attr_accessor :new_version
|
14
|
-
include CouchPotato::Persistence
|
15
|
-
include CouchPotato::Versioning
|
16
|
-
set_version_condition lambda {|doc| doc.new_version}
|
17
|
-
|
18
|
-
property :title
|
19
|
-
validates_presence_of :title
|
20
|
-
end
|
21
|
-
|
22
|
-
before(:each) do
|
23
|
-
CouchPotato::Persistence.Db.delete!
|
24
|
-
CouchPotato::Persistence.Db!
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "create" do
|
28
|
-
it "should not create a version" do
|
29
|
-
Document.create! :title => 'first doc'
|
30
|
-
CouchPotato::Persistence.Db.documents['rows'].size.should == 1
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should set version to 1" do
|
34
|
-
Document.create!(:title => 'first doc').version.should == 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "save" do
|
39
|
-
it "should create a new version" do
|
40
|
-
doc = Document.create! :title => 'first doc'
|
41
|
-
doc.title = 'new title'
|
42
|
-
doc.save!
|
43
|
-
CouchPotato::Persistence.Db.documents['rows'].size.should == 2
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should store the old attributes in the old version" do
|
47
|
-
doc = Document.create! :title => 'first doc'
|
48
|
-
doc.title = 'new title'
|
49
|
-
doc.save!
|
50
|
-
CouchPotato::Persistence.Db.get(
|
51
|
-
CouchPotato::Persistence.Db.documents['rows'].select{|row| row['id'] != doc._id}.first['id']
|
52
|
-
)['title'].should == 'first doc'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should store the old version number in the old version" do
|
56
|
-
doc = Document.create! :title => 'first doc'
|
57
|
-
doc.title = 'new title'
|
58
|
-
id = doc._id
|
59
|
-
doc.save!
|
60
|
-
CouchPotato::Persistence.Db.get(
|
61
|
-
CouchPotato::Persistence.Db.documents['rows'].select{|row| row['id'] != doc._id}.first['id']
|
62
|
-
)['version'].should == 1
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should store the new attributes in the new version" do
|
66
|
-
doc = Document.create! :title => 'first doc'
|
67
|
-
doc.title = 'new title'
|
68
|
-
doc.save!
|
69
|
-
CouchPotato::Persistence.Db.get(doc._id)['title'].should == 'new title'
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should increase the version" do
|
73
|
-
doc = Document.create! :title => 'first doc'
|
74
|
-
doc.title = 'new title'
|
75
|
-
doc.save!
|
76
|
-
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 2
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should not create a new version if condition not met" do
|
80
|
-
doc = ConditionDocument.create! :title => 'first doc'
|
81
|
-
doc.new_version = false
|
82
|
-
doc.title = 'new title'
|
83
|
-
doc.save!
|
84
|
-
CouchPotato::Persistence.Db.documents['rows'].size.should == 1
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should not increase the version if condition not met" do
|
88
|
-
doc = ConditionDocument.create! :title => 'first doc'
|
89
|
-
doc.new_version = false
|
90
|
-
doc.title = 'new title'
|
91
|
-
doc.save!
|
92
|
-
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 1
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should create a new version if condition met" do
|
96
|
-
doc = ConditionDocument.create! :title => 'first doc'
|
97
|
-
doc.new_version = true
|
98
|
-
doc.title = 'new title'
|
99
|
-
doc.save!
|
100
|
-
CouchPotato::Persistence.Db.documents['rows'].size.should == 2
|
101
|
-
end
|
102
|
-
|
103
|
-
it "should increase the version if condition met" do
|
104
|
-
doc = ConditionDocument.create! :title => 'first doc'
|
105
|
-
doc.new_version = true
|
106
|
-
doc.title = 'new title'
|
107
|
-
doc.save!
|
108
|
-
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 2
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should load a specific version" do
|
113
|
-
doc = Document.create! :title => 'first doc'
|
114
|
-
doc.title = 'new title'
|
115
|
-
doc.save!
|
116
|
-
doc.versions(1).version.should == 1
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should load all versions" do
|
120
|
-
doc = Document.create! :title => 'first doc'
|
121
|
-
doc.title = 'new title'
|
122
|
-
doc.save!
|
123
|
-
doc.title = 'even newer title'
|
124
|
-
doc.save!
|
125
|
-
doc.versions.map(&:version).should == [1, 2, 3]
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should load the only version" do
|
129
|
-
doc = Document.create! :title => 'first doc'
|
130
|
-
doc.versions.map(&:version).should == [1]
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should load version 1" do
|
134
|
-
doc = Document.create! :title => 'first doc'
|
135
|
-
doc.versions(1).version.should == 1
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should not find versions of other instances" do
|
139
|
-
doc = Document.create! :title => 'first doc'
|
140
|
-
doc.title = 'new title'
|
141
|
-
doc.save!
|
142
|
-
|
143
|
-
doc2 = Document.create! :title => 'first doc2'
|
144
|
-
doc2.title = 'new title2'
|
145
|
-
doc2.save!
|
146
|
-
|
147
|
-
doc.versions.map(&:title).should == ['first doc', 'new title']
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|