langalex-couch_potato 0.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/CREDITS +3 -0
- data/MIT-LICENSE.txt +19 -0
- data/init.rb +5 -0
- data/lib/core_ext/object.rb +5 -0
- data/lib/core_ext/time.rb +14 -0
- data/lib/couch_potato/active_record/compatibility.rb +9 -0
- data/lib/couch_potato/ordering.rb +88 -0
- data/lib/couch_potato/persistence/belongs_to_property.rb +44 -0
- data/lib/couch_potato/persistence/bulk_save_queue.rb +47 -0
- data/lib/couch_potato/persistence/callbacks.rb +96 -0
- data/lib/couch_potato/persistence/collection.rb +51 -0
- data/lib/couch_potato/persistence/external_collection.rb +54 -0
- data/lib/couch_potato/persistence/external_has_many_property.rb +68 -0
- data/lib/couch_potato/persistence/find.rb +21 -0
- data/lib/couch_potato/persistence/finder.rb +109 -0
- data/lib/couch_potato/persistence/inline_collection.rb +14 -0
- data/lib/couch_potato/persistence/inline_has_many_property.rb +39 -0
- data/lib/couch_potato/persistence/json.rb +46 -0
- data/lib/couch_potato/persistence/properties.rb +40 -0
- data/lib/couch_potato/persistence/simple_property.rb +33 -0
- data/lib/couch_potato/persistence.rb +186 -0
- data/lib/couch_potato/versioning.rb +46 -0
- data/lib/couch_potato.rb +20 -0
- data/spec/attributes_spec.rb +22 -0
- data/spec/belongs_to_spec.rb +37 -0
- data/spec/callbacks_spec.rb +229 -0
- data/spec/create_spec.rb +68 -0
- data/spec/destroy_spec.rb +24 -0
- data/spec/find_spec.rb +88 -0
- data/spec/finder_spec.rb +115 -0
- data/spec/has_many_spec.rb +178 -0
- data/spec/inline_collection_spec.rb +15 -0
- data/spec/ordering_spec.rb +94 -0
- data/spec/property_spec.rb +46 -0
- data/spec/reload_spec.rb +46 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/update_spec.rb +33 -0
- data/spec/versioning_spec.rb +149 -0
- metadata +132 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
6
|
+
|
7
|
+
require 'couch_potato'
|
8
|
+
|
9
|
+
CouchPotato::Config.database_name = 'couch_potato_test'
|
10
|
+
CouchPotato::Persistence.Db.delete!
|
11
|
+
|
12
|
+
class User
|
13
|
+
include CouchPotato::Persistence
|
14
|
+
|
15
|
+
has_many :comments, :stored => :inline
|
16
|
+
end
|
17
|
+
|
18
|
+
class Commenter
|
19
|
+
include CouchPotato::Persistence
|
20
|
+
|
21
|
+
has_many :comments, :stored => :separately
|
22
|
+
end
|
23
|
+
|
24
|
+
class Comment
|
25
|
+
include CouchPotato::Persistence
|
26
|
+
|
27
|
+
validates_presence_of :title
|
28
|
+
|
29
|
+
property :title
|
30
|
+
belongs_to :commenter
|
31
|
+
end
|
data/spec/update_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "create" do
|
4
|
+
before(:each) do
|
5
|
+
@comment = Comment.new :title => 'my_title'
|
6
|
+
@comment.save!
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should update the revision" do
|
10
|
+
old_rev = @comment._rev
|
11
|
+
@comment.save!
|
12
|
+
@comment._rev.should_not == old_rev
|
13
|
+
@comment._rev.should_not be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not update created at" do
|
17
|
+
old_created_at = @comment.created_at
|
18
|
+
@comment.save!
|
19
|
+
@comment.created_at.should == old_created_at
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should update updated at" do
|
23
|
+
old_updated_at = @comment.updated_at
|
24
|
+
@comment.save!
|
25
|
+
@comment.updated_at.should > old_updated_at
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should update the attributes" do
|
29
|
+
@comment.title = 'new title'
|
30
|
+
@comment.save!
|
31
|
+
CouchPotato::Persistence.Db.get("#{@comment.id}")['title'].should == 'new title'
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,149 @@
|
|
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
|
+
end
|
25
|
+
|
26
|
+
describe "create" do
|
27
|
+
it "should not create a version" do
|
28
|
+
Document.create! :title => 'first doc'
|
29
|
+
CouchPotato::Persistence.Db.documents['rows'].size.should == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set version to 1" do
|
33
|
+
Document.create!(:title => 'first doc').version.should == 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "save" do
|
38
|
+
it "should create a new version" do
|
39
|
+
doc = Document.create! :title => 'first doc'
|
40
|
+
doc.title = 'new title'
|
41
|
+
doc.save!
|
42
|
+
CouchPotato::Persistence.Db.documents['rows'].size.should == 2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should store the old attributes in the old version" do
|
46
|
+
doc = Document.create! :title => 'first doc'
|
47
|
+
doc.title = 'new title'
|
48
|
+
doc.save!
|
49
|
+
CouchPotato::Persistence.Db.get(
|
50
|
+
CouchPotato::Persistence.Db.documents['rows'].select{|row| row['id'] != doc._id}.first['id']
|
51
|
+
)['title'].should == 'first doc'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should store the old version number in the old version" do
|
55
|
+
doc = Document.create! :title => 'first doc'
|
56
|
+
doc.title = 'new title'
|
57
|
+
id = doc._id
|
58
|
+
doc.save!
|
59
|
+
CouchPotato::Persistence.Db.get(
|
60
|
+
CouchPotato::Persistence.Db.documents['rows'].select{|row| row['id'] != doc._id}.first['id']
|
61
|
+
)['version'].should == 1
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should store the new attributes in the new version" do
|
65
|
+
doc = Document.create! :title => 'first doc'
|
66
|
+
doc.title = 'new title'
|
67
|
+
doc.save!
|
68
|
+
CouchPotato::Persistence.Db.get(doc._id)['title'].should == 'new title'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should increase the version" do
|
72
|
+
doc = Document.create! :title => 'first doc'
|
73
|
+
doc.title = 'new title'
|
74
|
+
doc.save!
|
75
|
+
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 2
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not create a new version if condition not met" do
|
79
|
+
doc = ConditionDocument.create! :title => 'first doc'
|
80
|
+
doc.new_version = false
|
81
|
+
doc.title = 'new title'
|
82
|
+
doc.save!
|
83
|
+
CouchPotato::Persistence.Db.documents['rows'].size.should == 1
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not increase the version if condition not met" do
|
87
|
+
doc = ConditionDocument.create! :title => 'first doc'
|
88
|
+
doc.new_version = false
|
89
|
+
doc.title = 'new title'
|
90
|
+
doc.save!
|
91
|
+
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 1
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should create a new version if condition met" do
|
95
|
+
doc = ConditionDocument.create! :title => 'first doc'
|
96
|
+
doc.new_version = true
|
97
|
+
doc.title = 'new title'
|
98
|
+
doc.save!
|
99
|
+
CouchPotato::Persistence.Db.documents['rows'].size.should == 2
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should increase the version if condition met" do
|
103
|
+
doc = ConditionDocument.create! :title => 'first doc'
|
104
|
+
doc.new_version = true
|
105
|
+
doc.title = 'new title'
|
106
|
+
doc.save!
|
107
|
+
CouchPotato::Persistence.Db.get(doc._id)['version'].should == 2
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should load a specific version" do
|
112
|
+
doc = Document.create! :title => 'first doc'
|
113
|
+
doc.title = 'new title'
|
114
|
+
doc.save!
|
115
|
+
doc.versions(1).version.should == 1
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should load all versions" do
|
119
|
+
doc = Document.create! :title => 'first doc'
|
120
|
+
doc.title = 'new title'
|
121
|
+
doc.save!
|
122
|
+
doc.title = 'even newer title'
|
123
|
+
doc.save!
|
124
|
+
doc.versions.map(&:version).should == [1, 2, 3]
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should load the only version" do
|
128
|
+
doc = Document.create! :title => 'first doc'
|
129
|
+
doc.versions.map(&:version).should == [1]
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should load version 1" do
|
133
|
+
doc = Document.create! :title => 'first doc'
|
134
|
+
doc.versions(1).version.should == 1
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not find versions of other instances" do
|
138
|
+
doc = Document.create! :title => 'first doc'
|
139
|
+
doc.title = 'new title'
|
140
|
+
doc.save!
|
141
|
+
|
142
|
+
doc2 = Document.create! :title => 'first doc2'
|
143
|
+
doc2.title = 'new title2'
|
144
|
+
doc2.save!
|
145
|
+
|
146
|
+
doc.versions.map(&:title).should == ['first doc', 'new title']
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: langalex-couch_potato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Lang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-26 16:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
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:
|
52
|
+
email: alex@upstream-berlin.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- init.rb
|
61
|
+
- Readme.textile
|
62
|
+
- MIT-LICENSE.txt
|
63
|
+
- CREDITS
|
64
|
+
- lib/core_ext
|
65
|
+
- lib/core_ext/object.rb
|
66
|
+
- lib/core_ext/time.rb
|
67
|
+
- lib/couch_potato
|
68
|
+
- lib/couch_potato/active_record
|
69
|
+
- lib/couch_potato/active_record/compatibility.rb
|
70
|
+
- lib/couch_potato/ordering.rb
|
71
|
+
- lib/couch_potato/persistence
|
72
|
+
- lib/couch_potato/persistence/belongs_to_property.rb
|
73
|
+
- lib/couch_potato/persistence/bulk_save_queue.rb
|
74
|
+
- lib/couch_potato/persistence/callbacks.rb
|
75
|
+
- lib/couch_potato/persistence/collection.rb
|
76
|
+
- lib/couch_potato/persistence/external_collection.rb
|
77
|
+
- lib/couch_potato/persistence/external_has_many_property.rb
|
78
|
+
- lib/couch_potato/persistence/find.rb
|
79
|
+
- lib/couch_potato/persistence/finder.rb
|
80
|
+
- lib/couch_potato/persistence/inline_collection.rb
|
81
|
+
- lib/couch_potato/persistence/inline_has_many_property.rb
|
82
|
+
- lib/couch_potato/persistence/json.rb
|
83
|
+
- lib/couch_potato/persistence/properties.rb
|
84
|
+
- lib/couch_potato/persistence/simple_property.rb
|
85
|
+
- lib/couch_potato/persistence.rb
|
86
|
+
- lib/couch_potato/versioning.rb
|
87
|
+
- lib/couch_potato.rb
|
88
|
+
- spec/attributes_spec.rb
|
89
|
+
- spec/belongs_to_spec.rb
|
90
|
+
- spec/callbacks_spec.rb
|
91
|
+
- spec/create_spec.rb
|
92
|
+
- spec/destroy_spec.rb
|
93
|
+
- spec/find_spec.rb
|
94
|
+
- spec/finder_spec.rb
|
95
|
+
- spec/has_many_spec.rb
|
96
|
+
- spec/inline_collection_spec.rb
|
97
|
+
- spec/ordering_spec.rb
|
98
|
+
- spec/property_spec.rb
|
99
|
+
- spec/reload_spec.rb
|
100
|
+
- spec/spec.opts
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/update_spec.rb
|
103
|
+
- spec/versioning_spec.rb
|
104
|
+
has_rdoc: "false"
|
105
|
+
homepage: http://github.com/langalex/couch_potato
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
version:
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
version:
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.2.0
|
128
|
+
signing_key:
|
129
|
+
specification_version: 2
|
130
|
+
summary: a couchdb persistence layer in ruby
|
131
|
+
test_files: []
|
132
|
+
|