langalex-couch_potato 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CREDITS +3 -0
  2. data/MIT-LICENSE.txt +19 -0
  3. data/init.rb +5 -0
  4. data/lib/core_ext/object.rb +5 -0
  5. data/lib/core_ext/time.rb +14 -0
  6. data/lib/couch_potato/active_record/compatibility.rb +9 -0
  7. data/lib/couch_potato/ordering.rb +88 -0
  8. data/lib/couch_potato/persistence/belongs_to_property.rb +44 -0
  9. data/lib/couch_potato/persistence/bulk_save_queue.rb +47 -0
  10. data/lib/couch_potato/persistence/callbacks.rb +96 -0
  11. data/lib/couch_potato/persistence/collection.rb +51 -0
  12. data/lib/couch_potato/persistence/external_collection.rb +54 -0
  13. data/lib/couch_potato/persistence/external_has_many_property.rb +68 -0
  14. data/lib/couch_potato/persistence/find.rb +21 -0
  15. data/lib/couch_potato/persistence/finder.rb +109 -0
  16. data/lib/couch_potato/persistence/inline_collection.rb +14 -0
  17. data/lib/couch_potato/persistence/inline_has_many_property.rb +39 -0
  18. data/lib/couch_potato/persistence/json.rb +46 -0
  19. data/lib/couch_potato/persistence/properties.rb +40 -0
  20. data/lib/couch_potato/persistence/simple_property.rb +33 -0
  21. data/lib/couch_potato/persistence.rb +186 -0
  22. data/lib/couch_potato/versioning.rb +46 -0
  23. data/lib/couch_potato.rb +20 -0
  24. data/spec/attributes_spec.rb +22 -0
  25. data/spec/belongs_to_spec.rb +37 -0
  26. data/spec/callbacks_spec.rb +229 -0
  27. data/spec/create_spec.rb +68 -0
  28. data/spec/destroy_spec.rb +24 -0
  29. data/spec/find_spec.rb +88 -0
  30. data/spec/finder_spec.rb +115 -0
  31. data/spec/has_many_spec.rb +178 -0
  32. data/spec/inline_collection_spec.rb +15 -0
  33. data/spec/ordering_spec.rb +94 -0
  34. data/spec/property_spec.rb +46 -0
  35. data/spec/reload_spec.rb +46 -0
  36. data/spec/spec.opts +4 -0
  37. data/spec/spec_helper.rb +31 -0
  38. data/spec/update_spec.rb +33 -0
  39. data/spec/versioning_spec.rb +149 -0
  40. metadata +132 -0
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "create" do
4
+ describe "succeeds" do
5
+ before(:each) do
6
+ @comment = Comment.new :title => 'my_title'
7
+ @comment.save!
8
+ end
9
+
10
+ it "should assign an id" do
11
+ @comment._id.should_not be_nil
12
+ end
13
+
14
+ it "should assign a revision" do
15
+ @comment._rev.should_not be_nil
16
+ end
17
+
18
+ it "should store the class" do
19
+ CouchPotato::Persistence.Db.get(@comment.id)['ruby_class'].should == 'Comment'
20
+ end
21
+
22
+ it "should set created at" do
23
+ DateTime.parse(CouchPotato::Persistence.Db.get(@comment.id)['created_at']).should >= 1.second.ago
24
+ @comment.created_at.should >= 10.seconds.ago
25
+ end
26
+
27
+ it "should set updated at" do
28
+ DateTime.parse(CouchPotato::Persistence.Db.get(@comment.id)['updated_at']).should >= 1.second.ago
29
+ @comment.updated_at.should >= 10.seconds.ago
30
+ end
31
+ end
32
+
33
+ describe "fails" do
34
+ before(:each) do
35
+ CouchPotato::Persistence.Db.delete!
36
+ @comment = Comment.new
37
+ @comment.save
38
+ end
39
+
40
+ it "should not assign an id" do
41
+ @comment._id.should be_nil
42
+ end
43
+
44
+ it "should not assign a revision" do
45
+ @comment._rev.should be_nil
46
+ end
47
+
48
+ it "should not store anything" do
49
+ CouchPotato::Persistence.Db.documents['rows'].should be_empty
50
+ end
51
+
52
+ it "should not set created at" do
53
+ @comment.created_at.should be_nil
54
+ end
55
+
56
+ it "should set updated at" do
57
+ @comment.updated_at.should be_nil
58
+ end
59
+
60
+ describe "with bank" do
61
+ it "should raise an exception" do
62
+ lambda {
63
+ @comment.save!
64
+ }.should raise_error
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'destroy' do
4
+ before(:each) do
5
+ @comment = Comment.create! :title => 'title'
6
+ @comment_id = @comment.id
7
+ @comment.destroy
8
+ end
9
+
10
+ it "should unset the id" do
11
+ @comment._id.should be_nil
12
+ end
13
+
14
+ it "should unset the revision" do
15
+ @comment._rev.should be_nil
16
+ end
17
+
18
+ it "should remove the document from the database" do
19
+ lambda {
20
+ CouchPotato::Persistence.Db.get(@comment_id).should
21
+ }.should raise_error(RestClient::ResourceNotFound)
22
+ end
23
+
24
+ end
data/spec/find_spec.rb ADDED
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "find" do
4
+ before(:each) do
5
+ @comment = Comment.create! :title => 'title'
6
+ end
7
+
8
+ it "should find by id" do
9
+ Comment.find(@comment.id).should == @comment
10
+ end
11
+
12
+ it "should assign the id" do
13
+ Comment.find(@comment.id)._id.should == @comment._id
14
+ end
15
+
16
+ it "should assign the revision" do
17
+ Comment.find(@comment.id)._rev.should == @comment._rev
18
+ end
19
+
20
+ it "should reurn nil of nothing found" do
21
+ Comment.find(@comment.id.succ).should be_nil
22
+ end
23
+ end
24
+
25
+ describe 'first' do
26
+ before(:each) do
27
+ CouchPotato::Persistence.Db.delete!
28
+ @comment = Comment.create! :title => 'title'
29
+ Comment.create! :title => 'title3'
30
+ end
31
+
32
+ it "should find the first matching object" do
33
+ Comment.first(:title =>'title').should == @comment
34
+ end
35
+
36
+ it "should return nil if nothing found" do
37
+ Comment.first(:title =>'title2').should be_nil
38
+ end
39
+ end
40
+
41
+ describe 'last' do
42
+ before(:each) do
43
+ CouchPotato::Persistence.Db.delete!
44
+ Comment.create! :title => 'title'
45
+ @comment = Comment.create! :title => 'title'
46
+ end
47
+
48
+ it "should find the last matching object" do
49
+ Comment.last(:title =>'title').should == @comment
50
+ end
51
+
52
+ it "should return nil if nothing found" do
53
+ Comment.last(:title =>'title2').should be_nil
54
+ end
55
+ end
56
+
57
+
58
+ describe 'all' do
59
+ before(:each) do
60
+ CouchPotato::Persistence.Db.delete!
61
+ @comment = Comment.create! :title => 'title'
62
+ @comment2 = Comment.create! :title => 'title'
63
+ end
64
+
65
+ it "should find the matching objects" do
66
+ Comment.all(:title =>'title').should == [@comment, @comment2]
67
+ end
68
+
69
+ it "should return [] if nothing found" do
70
+ Comment.all(:title =>'title2').should == []
71
+ end
72
+ end
73
+
74
+ describe 'count' do
75
+ before(:each) do
76
+ CouchPotato::Persistence.Db.delete!
77
+ @comment = Comment.create! :title => 'title'
78
+ @comment2 = Comment.create! :title => 'title'
79
+ end
80
+
81
+ it "should count the matching objects" do
82
+ Comment.count(:title =>'title').should == 2
83
+ end
84
+
85
+ it "should not count non matching objects" do
86
+ Comment.count(:title =>'title2').should == 0
87
+ end
88
+ end
@@ -0,0 +1,115 @@
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
+ end
13
+
14
+ describe "couchdb 0.9+" do
15
+ it "should find items by an array of values" do
16
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
17
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
18
+ c3 = Comment.create! :title => 'test', :commenter_id => '3'
19
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => ['2', '3']
20
+ comments.should == [c2, c3]
21
+ end
22
+
23
+ it "should find items by an array of values combined with other attributes" do
24
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
25
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
26
+ c3 = Comment.create! :title => 'test2', :commenter_id => '3'
27
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => ['2', '3'], :title => 'test'
28
+ comments.should == [c2]
29
+ end
30
+ end
31
+
32
+ it "should find objects with a given attribute value pair" do
33
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
34
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
35
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
36
+ comments.should == [c1]
37
+ end
38
+
39
+ it "should find items by range" do
40
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
41
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
42
+ c3 = Comment.create! :title => 'test', :commenter_id => '3'
43
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '2'..'3'
44
+ comments.should == [c2, c3]
45
+ end
46
+
47
+ it "should find items by range and other atributes" do
48
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
49
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
50
+ c3 = Comment.create! :title => 'test', :commenter_id => '3'
51
+ c4 = Comment.create! :title => 'test2', :commenter_id => '3'
52
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '2'..'3', :title => 'test'
53
+ comments.should == [c2, c3]
54
+ end
55
+
56
+ it "should find objects with multiple given attribute value pair" do
57
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
58
+ c2 = Comment.create! :title => 'test2', :commenter_id => '1'
59
+ c3 = Comment.create! :title => 'test', :commenter_id => '2'
60
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1', :title => 'test'
61
+ comments.should == [c1]
62
+ end
63
+
64
+ it "should find them when the view has been created already" do
65
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
66
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
67
+ CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
68
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
69
+ comments.should == [c1]
70
+ end
71
+
72
+ it "should not find instances of other classes" do
73
+ OtherComment.create! :commenter_id => '1'
74
+ comments = CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
75
+ comments.should be_empty
76
+ end
77
+
78
+ it "should update the design document correctly when running multiple finds" do
79
+ CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1'
80
+ lambda {
81
+ CouchPotato::Persistence::Finder.new.find Comment, :commenter_id => '1', :title => 'test'
82
+ }.should_not raise_error(RestClient::RequestFailed)
83
+ end
84
+ end
85
+
86
+ describe CouchPotato::Persistence::Finder, 'count' do
87
+ before(:each) do
88
+ CouchPotato::Persistence.Db.delete!
89
+ end
90
+
91
+ it "should count objects with a given attribute value pair" do
92
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
93
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
94
+ CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 1
95
+ end
96
+
97
+ it "should count objects with multiple given attribute value pair" do
98
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
99
+ c2 = Comment.create! :title => 'test2', :commenter_id => '1'
100
+ c3 = Comment.create! :title => 'test', :commenter_id => '2'
101
+ CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1', :title => 'test').should == 1
102
+ end
103
+
104
+ it "should count them when the view has been created already" do
105
+ c1 = Comment.create! :title => 'test', :commenter_id => '1'
106
+ c2 = Comment.create! :title => 'test', :commenter_id => '2'
107
+ CouchPotato::Persistence::Finder.new.count Comment, :commenter_id => '1'
108
+ CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 1
109
+ end
110
+
111
+ it "should not count instances of other classes" do
112
+ OtherComment.create! :commenter_id => '1'
113
+ CouchPotato::Persistence::Finder.new.count(Comment, :commenter_id => '1').should == 0
114
+ end
115
+ end
@@ -0,0 +1,178 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'has_many stored inline' do
4
+ before(:each) do
5
+ @user = User.new
6
+ end
7
+
8
+ it "should build child objects" do
9
+ @user.comments.build(:title => 'my title')
10
+ @user.comments.first.class.should == Comment
11
+ @user.comments.first.title.should == 'my title'
12
+ end
13
+
14
+ it "should add child objects" do
15
+ @user.comments << Comment.new(:title => 'my title')
16
+ @user.comments.first.class.should == Comment
17
+ @user.comments.first.title.should == 'my title'
18
+ end
19
+
20
+ it "should persist child objects" do
21
+ @user.comments.build(:title => 'my title')
22
+ @user.save!
23
+ @user = User.find @user._id
24
+ @user.comments.first.class.should == Comment
25
+ @user.comments.first.title.should == 'my title'
26
+ end
27
+ end
28
+
29
+ describe 'has_many stored separately' do
30
+ before(:each) do
31
+ @commenter = Commenter.new
32
+ end
33
+
34
+ it "should build child objects" do
35
+ @commenter.comments.build(:title => 'my title')
36
+ @commenter.comments.first.class.should == Comment
37
+ @commenter.comments.first.title.should == 'my title'
38
+ end
39
+
40
+ it "should create child objects" do
41
+ @commenter.save!
42
+ @commenter.comments.create(:title => 'my title')
43
+ @commenter = Commenter.find @commenter._id
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 add child objects" do
57
+ @commenter.comments << Comment.new(:title => 'my title')
58
+ @commenter.comments.first.class.should == Comment
59
+ @commenter.comments.first.title.should == 'my title'
60
+ end
61
+
62
+ describe "create" do
63
+ it "should persist child objects" do
64
+ @commenter.comments.build(:title => 'my title')
65
+ @commenter.save!
66
+ @commenter = Commenter.find @commenter._id
67
+ @commenter.comments.first.class.should == Comment
68
+ @commenter.comments.first.title.should == 'my title'
69
+ end
70
+
71
+ it "should set the _id in child objects" do
72
+ @commenter.comments.build(:title => 'my title')
73
+ @commenter.save!
74
+ @commenter.comments.first._id.should_not be_nil
75
+ end
76
+
77
+ it "should set the _rev in child objects" do
78
+ @commenter.comments.build(:title => 'my title')
79
+ @commenter.save!
80
+ @commenter.comments.first._rev.should_not be_nil
81
+ end
82
+
83
+ it "should set updated_at in child objects" do
84
+ @commenter.comments.build(:title => 'my title')
85
+ @commenter.save!
86
+ @commenter.comments.first.updated_at.should_not be_nil
87
+ end
88
+
89
+ it "should set created_at in child objects" do
90
+ @commenter.comments.build(:title => 'my title')
91
+ @commenter.save!
92
+ @commenter.comments.first.created_at.should_not be_nil
93
+ end
94
+ end
95
+
96
+ describe "update" do
97
+ it "should persist child objects" do
98
+ comment = @commenter.comments.build(:title => 'my title')
99
+ @commenter.save!
100
+ comment.title = 'new title'
101
+ @commenter.save!
102
+ @commenter = Commenter.find @commenter._id
103
+ @commenter.comments.first.title.should == 'new title'
104
+ end
105
+
106
+ it "should set the _rev in child objects" do
107
+ comment = @commenter.comments.build(:title => 'my title')
108
+ @commenter.save!
109
+ old_rev = comment._rev
110
+ comment.title = 'new title'
111
+ @commenter.save!
112
+ @commenter.comments.first._rev.should_not == old_rev
113
+ end
114
+
115
+ it "should set updated_at in child objects" do
116
+ comment = @commenter.comments.build(:title => 'my title')
117
+ @commenter.save!
118
+ old_updated_at = comment.updated_at
119
+ comment.title = 'new title'
120
+ @commenter.save!
121
+ @commenter.comments.first.updated_at.should > old_updated_at
122
+ end
123
+ end
124
+
125
+
126
+ describe "destroy" do
127
+
128
+ class AdminComment
129
+ include CouchPotato::Persistence
130
+ belongs_to :admin
131
+ end
132
+
133
+ class AdminFriend
134
+ include CouchPotato::Persistence
135
+ belongs_to :admin
136
+ end
137
+
138
+ class Admin
139
+ include CouchPotato::Persistence
140
+ has_many :admin_comments, :stored => :separately, :dependent => :destroy
141
+ has_many :admin_friends, :stored => :separately
142
+ end
143
+
144
+ it "should destroy all dependent objects" do
145
+ admin = Admin.create!
146
+ comment = admin.admin_comments.create!
147
+ id = comment._id
148
+ admin.destroy
149
+ lambda {
150
+ CouchPotato::Persistence.Db.get(id).should
151
+ }.should raise_error(RestClient::ResourceNotFound)
152
+ end
153
+
154
+ it "should unset _id in dependent objects" do
155
+ admin = Admin.create!
156
+ comment = admin.admin_comments.create!
157
+ id = comment._id
158
+ admin.destroy
159
+ comment._id.should be_nil
160
+ end
161
+
162
+ it "should unset _rev in dependent objects" do
163
+ admin = Admin.create!
164
+ comment = admin.admin_comments.create!
165
+ id = comment._id
166
+ admin.destroy
167
+ comment._rev.should be_nil
168
+ end
169
+
170
+ it "should nullify independent objects" do
171
+ admin = Admin.create!
172
+ friend = admin.admin_friends.create!
173
+ id = friend._id
174
+ admin.destroy
175
+ AdminFriend.get(id).admin.should be_nil
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,94 @@
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
+ @album = Album.create!
21
+ end
22
+
23
+ describe "create" do
24
+ it "should add a position" do
25
+ photo = @album.photos.create!
26
+ photo.position.should == 1
27
+ end
28
+
29
+ it "should increase the position when adding a second item" do
30
+ @album.photos.create!
31
+ photo = @album.photos.create!
32
+ photo.position.should == 2
33
+ end
34
+ end
35
+
36
+ describe 'insert' do
37
+ it "should increse the position of the items that are now lower than this" do
38
+ photo1 = @album.photos.create!
39
+ photo2 = @album.photos.create! :position => 1
40
+ CouchPotato::Persistence.Db.get(photo1._id)['position'].should == 2
41
+ end
42
+ end
43
+
44
+ describe "decrease position" do
45
+ it "should increase the position of the items that are now lower than this" do
46
+ photo1 = @album.photos.create!
47
+ photo2 = @album.photos.create!
48
+ photo2.position = 1
49
+ photo2.save!
50
+ CouchPotato::Persistence.Db.get(photo1._id)['position'].should == 2
51
+ end
52
+ end
53
+
54
+ describe "increase position" do
55
+ it "should decrease the position of the items that are now higher than this" do
56
+ photo1 = @album.photos.create!
57
+ photo2 = @album.photos.create!
58
+ photo1.position = 2
59
+ photo1.save!
60
+ CouchPotato::Persistence.Db.get(photo2._id)['position'].should == 1
61
+ end
62
+ end
63
+
64
+ it "should order by position" do
65
+ @album.photos.create!
66
+ @album.photos.create! :position => 1
67
+ @album = Album.get @album._id
68
+ @album.photos.map(&:position).should == [1,2]
69
+ end
70
+
71
+ describe "destroy" do
72
+ it "should decrease the position of the lower items" do
73
+ photo1 = @album.photos.create!
74
+ photo2 = @album.photos.create!
75
+ photo1.destroy
76
+ CouchPotato::Persistence.Db.get(photo2._id)['position'].should == 1
77
+ end
78
+ end
79
+
80
+ describe "scoping" do
81
+ it "should only update objects within the scope" do
82
+ photo1 = @album.photos.create!
83
+ photo2 = @album.photos.create!
84
+ album2 = Album.create!
85
+ album2.photos.create!
86
+
87
+ photo2.position = 1
88
+ photo2.save!
89
+
90
+ album2.photos.first.position.should == 1
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'properties' do
4
+ it "should return the property names" do
5
+ Comment.property_names.should == [:title, :commenter]
6
+ end
7
+
8
+ it "should persist a string" do
9
+ c = Comment.new :title => 'my title'
10
+ c.save!
11
+ c = Comment.find c.id
12
+ c.title.should == 'my title'
13
+ end
14
+
15
+ it "should persist a number" do
16
+ c = Comment.new :title => 3
17
+ c.save!
18
+ c = Comment.find c.id
19
+ c.title.should == 3
20
+ end
21
+
22
+ it "should persist a hash" do
23
+ c = Comment.new :title => {'key' => 'value'}
24
+ c.save!
25
+ c = Comment.find c.id
26
+ c.title.should == {'key' => 'value'}
27
+ end
28
+
29
+ describe "predicate" do
30
+ it "should return true if property set" do
31
+ Comment.new(:title => 'title').title?.should be_true
32
+ end
33
+
34
+ it "should return false if property nil" do
35
+ Comment.new.title?.should be_false
36
+ end
37
+
38
+ it "should return false if property false" do
39
+ Comment.new(:title => false).title?.should be_false
40
+ end
41
+
42
+ it "should return false if property blank" do
43
+ Comment.new(:title => '').title?.should be_false
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
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
+ it "should reload simple properties" do
23
+ table = Table.create! :rows => 3
24
+ table.rows = 4
25
+ table.reload
26
+ table.rows.should == 3
27
+ end
28
+
29
+ it "should reload inline has_many associations" do
30
+ table = Table.new
31
+ table.cols.build :name => 'col1'
32
+ table.save!
33
+ table.cols.build :name => 'col2'
34
+ table.reload
35
+ table.cols.size.should == 1
36
+ end
37
+
38
+ it "should reload external has_many associations" do
39
+ table = Table.new
40
+ table.ext_cols.build :name => 'col1'
41
+ table.save!
42
+ table.ext_cols.build :name => 'col2'
43
+ table.reload
44
+ table.ext_cols.size.should == 1
45
+ end
46
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse