langalex-couch_potato 0.1.1 → 0.2.0

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.
Files changed (61) hide show
  1. data/README.md +260 -0
  2. data/VERSION.yml +2 -2
  3. data/init.rb +3 -0
  4. data/lib/core_ext/date.rb +10 -0
  5. data/lib/core_ext/string.rb +15 -0
  6. data/lib/core_ext/time.rb +6 -9
  7. data/lib/couch_potato/database.rb +90 -0
  8. data/lib/couch_potato/persistence/belongs_to_property.rb +1 -1
  9. data/lib/couch_potato/persistence/callbacks.rb +14 -11
  10. data/lib/couch_potato/persistence/dirty_attributes.rb +13 -6
  11. data/lib/couch_potato/persistence/json.rb +9 -14
  12. data/lib/couch_potato/persistence/magic_timestamps.rb +13 -0
  13. data/lib/couch_potato/persistence/properties.rb +10 -8
  14. data/lib/couch_potato/persistence/simple_property.rb +14 -11
  15. data/lib/couch_potato/persistence.rb +11 -165
  16. data/lib/couch_potato/view/base_view_spec.rb +20 -0
  17. data/lib/couch_potato/view/custom_view_spec.rb +26 -0
  18. data/lib/couch_potato/view/custom_views.rb +30 -0
  19. data/lib/couch_potato/view/model_view_spec.rb +39 -0
  20. data/lib/couch_potato/view/properties_view_spec.rb +35 -0
  21. data/lib/couch_potato/view/raw_view_spec.rb +21 -0
  22. data/lib/couch_potato/view/view_query.rb +45 -0
  23. data/lib/couch_potato.rb +23 -6
  24. data/rails/init.rb +7 -0
  25. data/spec/callbacks_spec.rb +40 -43
  26. data/spec/create_spec.rb +9 -60
  27. data/spec/custom_view_spec.rb +93 -19
  28. data/spec/destroy_spec.rb +5 -4
  29. data/spec/property_spec.rb +22 -8
  30. data/spec/spec_helper.rb +12 -14
  31. data/spec/unit/attributes_spec.rb +26 -0
  32. data/spec/unit/create_spec.rb +58 -0
  33. data/spec/{dirty_attributes_spec.rb → unit/dirty_attributes_spec.rb} +31 -13
  34. data/spec/unit/string_spec.rb +13 -0
  35. data/spec/unit/view_query_spec.rb +2 -3
  36. data/spec/update_spec.rb +8 -7
  37. metadata +54 -32
  38. data/README.textile +0 -340
  39. data/lib/couch_potato/active_record/compatibility.rb +0 -9
  40. data/lib/couch_potato/ordering.rb +0 -84
  41. data/lib/couch_potato/persistence/bulk_save_queue.rb +0 -47
  42. data/lib/couch_potato/persistence/collection.rb +0 -51
  43. data/lib/couch_potato/persistence/custom_view.rb +0 -41
  44. data/lib/couch_potato/persistence/external_collection.rb +0 -83
  45. data/lib/couch_potato/persistence/external_has_many_property.rb +0 -72
  46. data/lib/couch_potato/persistence/find.rb +0 -21
  47. data/lib/couch_potato/persistence/finder.rb +0 -65
  48. data/lib/couch_potato/persistence/inline_has_many_property.rb +0 -43
  49. data/lib/couch_potato/persistence/view_query.rb +0 -81
  50. data/lib/couch_potato/versioning.rb +0 -46
  51. data/spec/attributes_spec.rb +0 -42
  52. data/spec/belongs_to_spec.rb +0 -55
  53. data/spec/find_spec.rb +0 -96
  54. data/spec/finder_spec.rb +0 -125
  55. data/spec/has_many_spec.rb +0 -241
  56. data/spec/inline_collection_spec.rb +0 -15
  57. data/spec/ordering_spec.rb +0 -95
  58. data/spec/reload_spec.rb +0 -50
  59. data/spec/unit/external_collection_spec.rb +0 -84
  60. data/spec/unit/finder_spec.rb +0 -10
  61. data/spec/versioning_spec.rb +0 -150
@@ -1,55 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'belongs_to' do
4
- before(:all) do
5
- CouchPotato::Persistence.Db!
6
- end
7
-
8
- before(:each) do
9
- @commenter = Commenter.create!
10
- end
11
-
12
- it "should return nil by default" do
13
- c = Comment.new :title => 'title'
14
- c.commenter.should be_nil
15
- c.commenter_id.should be_nil
16
- end
17
-
18
- it "should assign the parent object" do
19
- c = Comment.new :title => 'title'
20
- c.commenter = @commenter
21
- c.commenter.should == @commenter
22
- c.commenter_id.should == @commenter.id
23
- end
24
-
25
- it "should assign the parent object id" do
26
- c = Comment.new :title => 'title'
27
- c.commenter_id = @commenter.id
28
- c.commenter.should == @commenter
29
- c.commenter_id.should == @commenter.id
30
- end
31
-
32
- it "should unassign the parent object" do
33
- c = Comment.new :title => 'title', :commenter => stub('comenter', :id => 1)
34
- c.commenter = nil
35
- c.commenter.should be_nil
36
- c.commenter_id.should be_nil
37
- end
38
-
39
- it "should unassign the parent object id" do
40
- c = Comment.new :title => 'title', :commenter => stub('comenter', :id => 1)
41
- c.commenter_id = nil
42
- c.commenter.should be_nil
43
- c.commenter_id.should be_nil
44
- end
45
-
46
- it "should persist the link to the parent object" do
47
- c = Comment.new :title => 'title'
48
- c.commenter_id = @commenter.id
49
- c.save!
50
- c = Comment.find c.id
51
- c.commenter._id.should == @commenter.id
52
- c.commenter_id.should == @commenter._id
53
- end
54
-
55
- end
data/spec/find_spec.rb DELETED
@@ -1,96 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe "find" do
4
- before(:all) do
5
- CouchPotato::Persistence.Db!
6
- end
7
- before(:each) do
8
- @comment = Comment.create! :title => 'title'
9
- end
10
-
11
- it "should find by id" do
12
- Comment.find(@comment.id).should == @comment
13
- end
14
-
15
- it "should assign the id" do
16
- Comment.find(@comment.id)._id.should == @comment._id
17
- end
18
-
19
- it "should assign the revision" do
20
- Comment.find(@comment.id)._rev.should == @comment._rev
21
- end
22
-
23
- it "should reurn nil of nothing found" do
24
- Comment.find(@comment.id.succ).should be_nil
25
- end
26
- end
27
-
28
- describe 'first' do
29
- before(:each) do
30
- CouchPotato::Persistence.Db.delete!
31
- CouchPotato::Persistence.Db!
32
- @comment = Comment.create! :title => 'title'
33
- end
34
-
35
- it "should find the first matching object" do
36
- Comment.first(:title =>'title').should == @comment
37
- end
38
-
39
- it "should return nil if nothing found" do
40
- Comment.first(:title =>'title2').should be_nil
41
- end
42
- end
43
-
44
- describe 'last' do
45
- before(:each) do
46
- CouchPotato::Persistence.Db.delete!
47
- CouchPotato::Persistence.Db!
48
- @comment = Comment.create! :title => 'title'
49
- end
50
-
51
- it "should find the last matching object" do
52
- Comment.last(:title =>'title').should == @comment
53
- end
54
-
55
- it "should return nil if nothing found" do
56
- Comment.last(:title =>'title2').should be_nil
57
- end
58
- end
59
-
60
-
61
- describe 'all' do
62
- before(:each) do
63
- CouchPotato::Persistence.Db.delete!
64
- CouchPotato::Persistence.Db!
65
- @comment = Comment.create! :title => 'title'
66
- @comment2 = Comment.create! :title => 'title'
67
- end
68
-
69
- it "should find the matching objects" do
70
- comments = Comment.all(:title =>'title')
71
- comments.size.should == 2
72
- comments.should include(@comment)
73
- comments.should include(@comment2)
74
- end
75
-
76
- it "should return [] if nothing found" do
77
- Comment.all(:title =>'title2').should == []
78
- end
79
- end
80
-
81
- describe 'count' do
82
- before(:each) do
83
- CouchPotato::Persistence.Db.delete!
84
- CouchPotato::Persistence.Db!
85
- @comment = Comment.create! :title => 'title'
86
- @comment2 = Comment.create! :title => 'title'
87
- end
88
-
89
- it "should count the matching objects" do
90
- Comment.count(:title =>'title').should == 2
91
- end
92
-
93
- it "should not count non matching objects" do
94
- Comment.count(:title =>'title2').should == 0
95
- end
96
- end
data/spec/finder_spec.rb DELETED
@@ -1,125 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class OtherComment
4
- include CouchPotato::Persistence
5
-
6
- belongs_to :commenter
7
- end
8
-
9
- describe CouchPotato::Persistence::Finder, 'find' do
10
- before(:each) do
11
- CouchPotato::Persistence.Db.delete!
12
- CouchPotato::Persistence.Db!
13
- end
14
-
15
- describe "couchdb 0.9+" do
16
- it "should find items by an array of values" do
17
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
18
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
19
- c3 = Comment.create! :title => 'test', :commenter_id => '3'
20
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => ['2', '3']
21
- comments.should == [c2, c3]
22
- end
23
-
24
- it "should find items by an array of values combined with other attributes" do
25
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
26
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
27
- c3 = Comment.create! :title => 'test2', :commenter_id => '3'
28
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => ['2', '3'], :title => 'test'
29
- comments.should == [c2]
30
- end
31
- end
32
-
33
- it "should find objects with a given attribute value pair" do
34
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
35
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
36
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
37
- comments.should == [c1]
38
- end
39
-
40
- it "should find items by range" do
41
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
42
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
43
- c3 = Comment.create! :title => 'test', :commenter_id => '3'
44
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '2'..'3'
45
- comments.should == [c2, c3]
46
- end
47
-
48
- it "should find items by range and other atributes" do
49
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
50
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
51
- c3 = Comment.create! :title => 'test', :commenter_id => '3'
52
- c4 = Comment.create! :title => 'test2', :commenter_id => '3'
53
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '2'..'3', :title => 'test'
54
- comments.should == [c2, c3]
55
- end
56
-
57
- it "should find objects with multiple given attribute value pair" do
58
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
59
- c2 = Comment.create! :title => 'test2', :commenter_id => '1'
60
- c3 = Comment.create! :title => 'test', :commenter_id => '2'
61
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1', :title => 'test'
62
- comments.should == [c1]
63
- end
64
-
65
- it "should find them when the view has been created already" do
66
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
67
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
68
- CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
69
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
70
- comments.should == [c1]
71
- end
72
-
73
- it "should not find instances of other classes" do
74
- OtherComment.create! :commenter_id => '1'
75
- comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
76
- comments.should be_empty
77
- end
78
-
79
- it "should update the design document correctly when running multiple finds" do
80
- CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
81
- lambda {
82
- CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1', :title => 'test'
83
- }.should_not raise_error(RestClient::RequestFailed)
84
- end
85
- end
86
-
87
- describe CouchPotato::Persistence::Finder, 'count' do
88
- before(:each) do
89
- CouchPotato::Persistence.Db.delete!
90
- CouchPotato::Persistence.Db!
91
- end
92
-
93
- it "should count objects with a given attribute value pair" do
94
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
95
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
96
- CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 1
97
- end
98
-
99
- it "should count objects with multiple given attribute value pair" do
100
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
101
- c2 = Comment.create! :title => 'test2', :commenter_id => '1'
102
- c3 = Comment.create! :title => 'test', :commenter_id => '2'
103
- CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1', :title => 'test').should == 1
104
- end
105
-
106
- it "should count them when the view has been created already" do
107
- c1 = Comment.create! :title => 'test', :commenter_id => '1'
108
- c2 = Comment.create! :title => 'test', :commenter_id => '2'
109
- CouchPotato::Persistence::Finder.new.count Comment, :commenter_id => '1'
110
- CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 1
111
- end
112
-
113
- it "should not count instances of other classes" do
114
- OtherComment.create! :commenter_id => '1'
115
- CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 0
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
125
- end
@@ -1,241 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'has_many stored inline' do
4
- before(:all) do
5
- CouchPotato::Persistence.Db!
6
- end
7
-
8
- before(:each) do
9
- @user = User.new
10
- end
11
-
12
- it "should build child objects" do
13
- @user.comments.build(:title => 'my title')
14
- @user.comments.first.class.should == Comment
15
- @user.comments.first.title.should == 'my title'
16
- end
17
-
18
- it "should add child objects" do
19
- @user.comments << Comment.new(:title => 'my title')
20
- @user.comments.first.class.should == Comment
21
- @user.comments.first.title.should == 'my title'
22
- end
23
-
24
- it "should persist child objects" do
25
- @user.comments.build(:title => 'my title')
26
- @user.save!
27
- @user = User.find @user._id
28
- @user.comments.first.class.should == Comment
29
- @user.comments.first.title.should == 'my title'
30
- end
31
- end
32
-
33
- describe 'has_many stored separately' do
34
- before(:all) do
35
- CouchPotato::Persistence.Db!
36
- end
37
-
38
- before(:each) do
39
- @commenter = Commenter.new
40
- end
41
-
42
- it "should build child objects" do
43
- @commenter.comments.build(:title => 'my title')
44
- @commenter.comments.first.class.should == Comment
45
- @commenter.comments.first.title.should == 'my title'
46
- end
47
-
48
- it "should create child objects" do
49
- @commenter.save!
50
- @commenter.comments.create(:title => 'my title')
51
- @commenter = Commenter.find @commenter._id
52
- @commenter.comments.first.class.should == Comment
53
- @commenter.comments.first.title.should == 'my title'
54
- end
55
-
56
- it "should create! child objects" do
57
- @commenter.save!
58
- @commenter.comments.create!(:title => 'my title')
59
- @commenter = Commenter.find @commenter._id
60
- @commenter.comments.first.class.should == Comment
61
- @commenter.comments.first.title.should == 'my title'
62
- end
63
-
64
- it "should add child objects" do
65
- @commenter.comments << Comment.new(:title => 'my title')
66
- @commenter.comments.first.class.should == Comment
67
- @commenter.comments.first.title.should == 'my title'
68
- end
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
-
126
- describe "create" do
127
- it "should persist child objects" do
128
- @commenter.comments.build(:title => 'my title')
129
- @commenter.save!
130
- @commenter = Commenter.find @commenter._id
131
- @commenter.comments.first.class.should == Comment
132
- @commenter.comments.first.title.should == 'my title'
133
- end
134
-
135
- it "should set the _id in child objects" do
136
- @commenter.comments.build(:title => 'my title')
137
- @commenter.save!
138
- @commenter.comments.first._id.should_not be_nil
139
- end
140
-
141
- it "should set the _rev in child objects" do
142
- @commenter.comments.build(:title => 'my title')
143
- @commenter.save!
144
- @commenter.comments.first._rev.should_not be_nil
145
- end
146
-
147
- it "should set updated_at in child objects" do
148
- @commenter.comments.build(:title => 'my title')
149
- @commenter.save!
150
- @commenter.comments.first.updated_at.should_not be_nil
151
- end
152
-
153
- it "should set created_at in child objects" do
154
- @commenter.comments.build(:title => 'my title')
155
- @commenter.save!
156
- @commenter.comments.first.created_at.should_not be_nil
157
- end
158
- end
159
-
160
- describe "update" do
161
- it "should persist child objects" do
162
- comment = @commenter.comments.build(:title => 'my title')
163
- @commenter.save!
164
- comment.title = 'new title'
165
- @commenter.save!
166
- @commenter = Commenter.find @commenter._id
167
- @commenter.comments.first.title.should == 'new title'
168
- end
169
-
170
- it "should set the _rev in child objects" do
171
- comment = @commenter.comments.build(:title => 'my title')
172
- @commenter.save!
173
- old_rev = comment._rev
174
- comment.title = 'new title'
175
- @commenter.save!
176
- @commenter.comments.first._rev.should_not == old_rev
177
- end
178
-
179
- it "should set updated_at in child objects" do
180
- comment = @commenter.comments.build(:title => 'my title')
181
- @commenter.save!
182
- old_updated_at = comment.updated_at
183
- comment.title = 'new title'
184
- @commenter.save!
185
- @commenter.comments.first.updated_at.should > old_updated_at
186
- end
187
- end
188
-
189
- describe "destroy" do
190
-
191
- class AdminComment
192
- include CouchPotato::Persistence
193
- belongs_to :admin
194
- end
195
-
196
- class AdminFriend
197
- include CouchPotato::Persistence
198
- belongs_to :admin
199
- end
200
-
201
- class Admin
202
- include CouchPotato::Persistence
203
- has_many :admin_comments, :stored => :separately, :dependent => :destroy
204
- has_many :admin_friends, :stored => :separately
205
- end
206
-
207
- it "should destroy all dependent objects" do
208
- admin = Admin.create!
209
- comment = admin.admin_comments.create!
210
- id = comment._id
211
- admin.destroy
212
- lambda {
213
- CouchPotato::Persistence.Db.get(id).should
214
- }.should raise_error(RestClient::ResourceNotFound)
215
- end
216
-
217
- it "should unset _id in dependent objects" do
218
- admin = Admin.create!
219
- comment = admin.admin_comments.create!
220
- id = comment._id
221
- admin.destroy
222
- comment._id.should be_nil
223
- end
224
-
225
- it "should unset _rev in dependent objects" do
226
- admin = Admin.create!
227
- comment = admin.admin_comments.create!
228
- id = comment._id
229
- admin.destroy
230
- comment._rev.should be_nil
231
- end
232
-
233
- it "should nullify independent objects" do
234
- admin = Admin.create!
235
- friend = admin.admin_friends.create!
236
- id = friend._id
237
- admin.destroy
238
- AdminFriend.get(id).admin.should be_nil
239
- end
240
- end
241
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe CouchPotato::Persistence::InlineCollection do
4
- it "should build elements with the item class" do
5
- collection = CouchPotato::Persistence::InlineCollection.new Comment
6
- collection.build :title => 'mytitle'
7
- collection[0].class.should == Comment
8
- end
9
-
10
- it "should build elements with the given attributes" do
11
- collection = CouchPotato::Persistence::InlineCollection.new Comment
12
- collection.build :title => 'mytitle'
13
- collection[0].title.should == 'mytitle'
14
- end
15
- end
@@ -1,95 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
-
4
- describe CouchPotato::Ordering do
5
-
6
- class Album
7
- include CouchPotato::Persistence
8
- has_many :photos
9
- end
10
-
11
- class Photo
12
- include CouchPotato::Persistence
13
- include CouchPotato::Ordering
14
- set_ordering_scope :album_id
15
- belongs_to :album
16
- end
17
-
18
- before(:each) do
19
- CouchPotato::Persistence.Db.delete!
20
- CouchPotato::Persistence.Db!
21
- @album = Album.create!
22
- end
23
-
24
- describe "create" do
25
- it "should add a position" do
26
- photo = @album.photos.create!
27
- photo.position.should == 1
28
- end
29
-
30
- it "should increase the position when adding a second item" do
31
- @album.photos.create!
32
- photo = @album.photos.create!
33
- photo.position.should == 2
34
- end
35
- end
36
-
37
- describe 'insert' do
38
- it "should increse the position of the items that are now lower than this" do
39
- photo1 = @album.photos.create!
40
- photo2 = @album.photos.create! :position => 1
41
- CouchPotato::Persistence.Db.get(photo1._id)['position'].should == 2
42
- end
43
- end
44
-
45
- describe "decrease position" do
46
- it "should increase the position of the items that are now lower than this" do
47
- photo1 = @album.photos.create!
48
- photo2 = @album.photos.create!
49
- photo2.position = 1
50
- photo2.save!
51
- CouchPotato::Persistence.Db.get(photo1._id)['position'].should == 2
52
- end
53
- end
54
-
55
- describe "increase position" do
56
- it "should decrease the position of the items that are now higher than this" do
57
- photo1 = @album.photos.create!
58
- photo2 = @album.photos.create!
59
- photo1.position = 2
60
- photo1.save!
61
- CouchPotato::Persistence.Db.get(photo2._id)['position'].should == 1
62
- end
63
- end
64
-
65
- it "should order by position" do
66
- @album.photos.create!
67
- @album.photos.create! :position => 1
68
- @album = Album.get @album._id
69
- @album.photos.map(&:position).should == [1,2]
70
- end
71
-
72
- describe "destroy" do
73
- it "should decrease the position of the lower items" do
74
- photo1 = @album.photos.create!
75
- photo2 = @album.photos.create!
76
- photo1.destroy
77
- CouchPotato::Persistence.Db.get(photo2._id)['position'].should == 1
78
- end
79
- end
80
-
81
- describe "scoping" do
82
- it "should only update objects within the scope" do
83
- photo1 = @album.photos.create!
84
- photo2 = @album.photos.create!
85
- album2 = Album.create!
86
- album2.photos.create!
87
-
88
- photo2.position = 1
89
- photo2.save!
90
-
91
- album2.photos.first.position.should == 1
92
- end
93
- end
94
-
95
- end
data/spec/reload_spec.rb DELETED
@@ -1,50 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe 'reload' do
4
- class Table
5
- include CouchPotato::Persistence
6
- property :rows
7
- has_many :cols, :stored => :inline
8
- has_many :ext_cols, :stored => :separately
9
- end
10
-
11
- class ExtCol
12
- include CouchPotato::Persistence
13
- belongs_to :table
14
- property :name
15
- end
16
-
17
- class Col
18
- include CouchPotato::Persistence
19
- property :name
20
- end
21
-
22
- before(:all) do
23
- CouchPotato::Persistence.Db!
24
- end
25
-
26
- it "should reload simple properties" do
27
- table = Table.create! :rows => 3
28
- table.rows = 4
29
- table.reload
30
- table.rows.should == 3
31
- end
32
-
33
- it "should reload inline has_many associations" do
34
- table = Table.new
35
- table.cols.build :name => 'col1'
36
- table.save!
37
- table.cols.build :name => 'col2'
38
- table.reload
39
- table.cols.size.should == 1
40
- end
41
-
42
- it "should reload external has_many associations" do
43
- table = Table.new
44
- table.ext_cols.build :name => 'col1'
45
- table.save!
46
- table.ext_cols.build :name => 'col2'
47
- table.reload
48
- table.ext_cols.size.should == 1
49
- end
50
- end