andrewtimberlake-couch_potato 0.2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +19 -0
- data/README.md +279 -0
- data/VERSION.yml +4 -0
- data/init.rb +3 -0
- data/lib/core_ext/date.rb +10 -0
- data/lib/core_ext/object.rb +5 -0
- data/lib/core_ext/string.rb +19 -0
- data/lib/core_ext/symbol.rb +15 -0
- data/lib/core_ext/time.rb +11 -0
- data/lib/couch_potato.rb +40 -0
- data/lib/couch_potato/database.rb +105 -0
- data/lib/couch_potato/persistence.rb +96 -0
- data/lib/couch_potato/persistence/belongs_to_property.rb +58 -0
- data/lib/couch_potato/persistence/callbacks.rb +60 -0
- data/lib/couch_potato/persistence/dirty_attributes.rb +27 -0
- data/lib/couch_potato/persistence/json.rb +46 -0
- data/lib/couch_potato/persistence/magic_timestamps.rb +13 -0
- data/lib/couch_potato/persistence/properties.rb +57 -0
- data/lib/couch_potato/persistence/simple_property.rb +83 -0
- data/lib/couch_potato/persistence/validation.rb +18 -0
- data/lib/couch_potato/view/base_view_spec.rb +24 -0
- data/lib/couch_potato/view/custom_view_spec.rb +27 -0
- data/lib/couch_potato/view/custom_views.rb +44 -0
- data/lib/couch_potato/view/model_view_spec.rb +63 -0
- data/lib/couch_potato/view/properties_view_spec.rb +39 -0
- data/lib/couch_potato/view/raw_view_spec.rb +25 -0
- data/lib/couch_potato/view/view_query.rb +44 -0
- data/rails/init.rb +7 -0
- data/spec/callbacks_spec.rb +271 -0
- data/spec/create_spec.rb +22 -0
- data/spec/custom_view_spec.rb +134 -0
- data/spec/destroy_spec.rb +29 -0
- data/spec/fixtures/address.rb +9 -0
- data/spec/fixtures/person.rb +6 -0
- data/spec/property_spec.rb +83 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/unit/attributes_spec.rb +26 -0
- data/spec/unit/callbacks_spec.rb +33 -0
- data/spec/unit/create_spec.rb +58 -0
- data/spec/unit/customs_views_spec.rb +15 -0
- data/spec/unit/database_spec.rb +38 -0
- data/spec/unit/dirty_attributes_spec.rb +113 -0
- data/spec/unit/string_spec.rb +13 -0
- data/spec/unit/view_query_spec.rb +9 -0
- data/spec/update_spec.rb +40 -0
- metadata +144 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CouchPotato::View::CustomViews do
|
4
|
+
|
5
|
+
class MyViewSpec; end
|
6
|
+
class ModelWithView
|
7
|
+
include CouchPotato::Persistence
|
8
|
+
view :all, :type => MyViewSpec
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should use a custom viewspec class" do
|
12
|
+
MyViewSpec.should_receive(:new)
|
13
|
+
ModelWithView.all
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class DbTestUser
|
4
|
+
end
|
5
|
+
|
6
|
+
describe CouchPotato::Database, 'new' do
|
7
|
+
it "should raise an exception if the database doesn't exist" do
|
8
|
+
lambda {
|
9
|
+
CouchPotato::Database.new CouchRest.database('couch_potato_invalid')
|
10
|
+
}.should raise_error('Database \'couch_potato_invalid\' does not exist.')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe CouchPotato::Database, 'load' do
|
15
|
+
it "should raise an exception if nil given" do
|
16
|
+
db = CouchPotato::Database.new(stub('couchrest db', :info => nil))
|
17
|
+
lambda {
|
18
|
+
db.load nil
|
19
|
+
}.should raise_error("Can't load a document without an id (got nil)")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should set itself on the model" do
|
23
|
+
user = mock 'user'
|
24
|
+
DbTestUser.stub!(:new).and_return(user)
|
25
|
+
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => {'ruby_class' => 'DbTestUser'}))
|
26
|
+
user.should_receive(:database=).with(db)
|
27
|
+
db.load '1'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe CouchPotato::Database, 'save_document' do
|
32
|
+
it "should set itself on the model for a new object before doing anything else" do
|
33
|
+
db = CouchPotato::Database.new(stub('couchrest db', :info => nil))
|
34
|
+
user = stub('user', :new? => true, :valid? => false).as_null_object
|
35
|
+
user.should_receive(:database=).with(db)
|
36
|
+
db.save_document user
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class Plate
|
4
|
+
include CouchPotato::Persistence
|
5
|
+
|
6
|
+
property :food
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'dirty attribute tracking' do
|
10
|
+
before(:each) do
|
11
|
+
@couchrest_db = stub('database', :save_doc => {'id' => '1', 'rev' => '2'}, :info => nil)
|
12
|
+
@db = CouchPotato::Database.new(@couchrest_db)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "save" do
|
16
|
+
it "should not save when nothing dirty" do
|
17
|
+
plate = Plate.new :food => 'sushi'
|
18
|
+
@db.save_document!(plate)
|
19
|
+
@couchrest_db.should_not_receive(:save_doc)
|
20
|
+
@db.save_document(plate)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return true when not dirty" do
|
24
|
+
plate = Plate.new :food => 'sushi'
|
25
|
+
@db.save_document!(plate)
|
26
|
+
@db.save_document(plate).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should save when there are dirty attributes" do
|
30
|
+
plate = Plate.new :food => 'sushi'
|
31
|
+
@db.save_document!(plate)
|
32
|
+
plate.food = 'burger'
|
33
|
+
@couchrest_db.should_receive(:save_doc)
|
34
|
+
@db.save_document(plate)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "newly created object" do
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
@plate = Plate.new :food => 'sushi'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "access old values" do
|
45
|
+
it "should return the old value" do
|
46
|
+
@plate.food = 'burger'
|
47
|
+
@plate.food_was.should == 'sushi'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "check for dirty" do
|
52
|
+
it "should return true if attribute changed" do
|
53
|
+
@plate.food = 'burger'
|
54
|
+
@plate.should be_food_changed
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return false if attribute not changed" do
|
58
|
+
@plate.should_not be_food_changed
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return false if attribute forced not changed" do
|
62
|
+
@plate.food = 'burger'
|
63
|
+
@plate.food_not_changed
|
64
|
+
@plate.should_not be_food_changed
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "object loaded from database" do
|
70
|
+
before(:each) do
|
71
|
+
couchrest_db = stub('database', :get => {'_id' => '1', '_rev' => '2', 'food' => 'sushi', 'ruby_class' => 'Plate'}, :info => nil)
|
72
|
+
@plate = CouchPotato::Database.new(couchrest_db).load_document '1'
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "access old values" do
|
76
|
+
it "should return the old value" do
|
77
|
+
@plate.food = 'burger'
|
78
|
+
@plate.food_was.should == 'sushi'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "check for dirty" do
|
83
|
+
it "should return true if attribute changed" do
|
84
|
+
@plate.food = 'burger'
|
85
|
+
@plate.should be_food_changed
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return true if array attribute changed" do
|
89
|
+
couchrest_db = stub('database', :get => {'_id' => '1', '_rev' => '2', 'food' => ['sushi'], 'ruby_class' => 'Plate'}, :info => nil)
|
90
|
+
plate = CouchPotato::Database.new(couchrest_db).load_document '1'
|
91
|
+
plate.food << 'burger'
|
92
|
+
plate.should be_food_changed
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should return false if attribute not changed" do
|
96
|
+
@plate.should_not be_food_changed
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
describe "after save" do
|
103
|
+
it "should reset all attributes to not dirty" do
|
104
|
+
couchrest_db = stub('database', :get => {'_id' => '1', '_rev' => '2', 'food' => 'sushi', 'ruby_class' => 'Plate'}, :info => nil, :save_doc => {})
|
105
|
+
db = CouchPotato::Database.new(couchrest_db)
|
106
|
+
@plate = db.load_document '1'
|
107
|
+
@plate.food = 'burger'
|
108
|
+
db.save! @plate
|
109
|
+
@plate.should_not be_food_changed
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe String, 'camelize' do
|
4
|
+
it "should camelize a string" do
|
5
|
+
'my_string'.camelize.should == 'MyString'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe String, 'underscore' do
|
10
|
+
it "should underscore a string" do
|
11
|
+
'MyString'.underscore.should == 'my_string'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe CouchPotato::View::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::View::ViewQuery.new(db, '', '', '', '').query_view!
|
8
|
+
end
|
9
|
+
end
|
data/spec/update_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "create" do
|
4
|
+
before(:all) do
|
5
|
+
recreate_db
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@comment = Comment.new :title => 'my_title'
|
10
|
+
CouchPotato.database.save_document! @comment
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should update the revision" do
|
14
|
+
old_rev = @comment._rev
|
15
|
+
@comment.title = 'xyz'
|
16
|
+
CouchPotato.database.save_document! @comment
|
17
|
+
@comment._rev.should_not == old_rev
|
18
|
+
@comment._rev.should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not update created at" do
|
22
|
+
old_created_at = @comment.created_at
|
23
|
+
@comment.title = 'xyz'
|
24
|
+
CouchPotato.database.save_document! @comment
|
25
|
+
@comment.created_at.should == old_created_at
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should update updated at" do
|
29
|
+
old_updated_at = @comment.updated_at
|
30
|
+
@comment.title = 'xyz'
|
31
|
+
CouchPotato.database.save_document! @comment
|
32
|
+
@comment.updated_at.should > old_updated_at
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should update the attributes" do
|
36
|
+
@comment.title = 'new title'
|
37
|
+
CouchPotato.database.save_document! @comment
|
38
|
+
CouchPotato.couchrest_database.get("#{@comment.id}")['title'].should == 'new title'
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: andrewtimberlake-couch_potato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.8.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Lang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-01 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: validatable
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: couchrest
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0.24"
|
44
|
+
version:
|
45
|
+
description: Ruby persistence layer for CouchDB
|
46
|
+
email: alex@upstream-berlin.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- README.md
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- VERSION.yml
|
57
|
+
- init.rb
|
58
|
+
- lib/core_ext/date.rb
|
59
|
+
- lib/core_ext/object.rb
|
60
|
+
- lib/core_ext/string.rb
|
61
|
+
- lib/core_ext/symbol.rb
|
62
|
+
- lib/core_ext/time.rb
|
63
|
+
- lib/couch_potato.rb
|
64
|
+
- lib/couch_potato/database.rb
|
65
|
+
- lib/couch_potato/persistence.rb
|
66
|
+
- lib/couch_potato/persistence/belongs_to_property.rb
|
67
|
+
- lib/couch_potato/persistence/callbacks.rb
|
68
|
+
- lib/couch_potato/persistence/dirty_attributes.rb
|
69
|
+
- lib/couch_potato/persistence/json.rb
|
70
|
+
- lib/couch_potato/persistence/magic_timestamps.rb
|
71
|
+
- lib/couch_potato/persistence/properties.rb
|
72
|
+
- lib/couch_potato/persistence/simple_property.rb
|
73
|
+
- lib/couch_potato/persistence/validation.rb
|
74
|
+
- lib/couch_potato/view/base_view_spec.rb
|
75
|
+
- lib/couch_potato/view/custom_view_spec.rb
|
76
|
+
- lib/couch_potato/view/custom_views.rb
|
77
|
+
- lib/couch_potato/view/model_view_spec.rb
|
78
|
+
- lib/couch_potato/view/properties_view_spec.rb
|
79
|
+
- lib/couch_potato/view/raw_view_spec.rb
|
80
|
+
- lib/couch_potato/view/view_query.rb
|
81
|
+
- rails/init.rb
|
82
|
+
- spec/callbacks_spec.rb
|
83
|
+
- spec/create_spec.rb
|
84
|
+
- spec/custom_view_spec.rb
|
85
|
+
- spec/destroy_spec.rb
|
86
|
+
- spec/fixtures/address.rb
|
87
|
+
- spec/fixtures/person.rb
|
88
|
+
- spec/property_spec.rb
|
89
|
+
- spec/spec.opts
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/unit/attributes_spec.rb
|
92
|
+
- spec/unit/callbacks_spec.rb
|
93
|
+
- spec/unit/create_spec.rb
|
94
|
+
- spec/unit/customs_views_spec.rb
|
95
|
+
- spec/unit/database_spec.rb
|
96
|
+
- spec/unit/dirty_attributes_spec.rb
|
97
|
+
- spec/unit/string_spec.rb
|
98
|
+
- spec/unit/view_query_spec.rb
|
99
|
+
- spec/update_spec.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/langalex/couch_potato
|
102
|
+
licenses:
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options:
|
105
|
+
- --charset=UTF-8
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
version:
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.5
|
124
|
+
signing_key:
|
125
|
+
specification_version: 2
|
126
|
+
summary: Ruby persistence layer for CouchDB
|
127
|
+
test_files:
|
128
|
+
- spec/callbacks_spec.rb
|
129
|
+
- spec/create_spec.rb
|
130
|
+
- spec/custom_view_spec.rb
|
131
|
+
- spec/destroy_spec.rb
|
132
|
+
- spec/fixtures/address.rb
|
133
|
+
- spec/fixtures/person.rb
|
134
|
+
- spec/property_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/unit/attributes_spec.rb
|
137
|
+
- spec/unit/callbacks_spec.rb
|
138
|
+
- spec/unit/create_spec.rb
|
139
|
+
- spec/unit/customs_views_spec.rb
|
140
|
+
- spec/unit/database_spec.rb
|
141
|
+
- spec/unit/dirty_attributes_spec.rb
|
142
|
+
- spec/unit/string_spec.rb
|
143
|
+
- spec/unit/view_query_spec.rb
|
144
|
+
- spec/update_spec.rb
|