couch_potato 0.2.14 → 0.2.15
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/CHANGES.md +5 -0
- data/README.md +3 -3
- data/VERSION.yml +2 -1
- data/lib/couch_potato/persistence/attachments.rb +1 -1
- data/lib/couch_potato/view/model_view_spec.rb +2 -2
- data/lib/couch_potato/view/properties_view_spec.rb +2 -2
- data/rails/init.rb +1 -1
- data/spec/attachments_spec.rb +1 -1
- data/spec/create_spec.rb +1 -1
- data/spec/custom_view_spec.rb +8 -8
- data/spec/spec_helper.rb +1 -2
- data/spec/unit/attributes_spec.rb +2 -2
- data/spec/unit/database_spec.rb +2 -2
- data/spec/unit/dirty_attributes_spec.rb +3 -3
- metadata +2 -2
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
## Changes
|
|
2
2
|
|
|
3
|
+
### 0.2.15
|
|
4
|
+
* ability to change the name of the attribute that stores the ruby class in the documents by setting JSON.create_id (lennart)
|
|
5
|
+
* fixed double loading issue with bundler (jweiss)
|
|
6
|
+
* fixed an issue with setting attachments (endor)
|
|
7
|
+
|
|
3
8
|
### 0.2.13
|
|
4
9
|
|
|
5
10
|
* support adding errors in before_validation callbacks (mattmatt)
|
data/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Lastly Couch Potato aims to provide a seamless integration with Ruby on Rails, e
|
|
|
20
20
|
|
|
21
21
|
### Installation
|
|
22
22
|
|
|
23
|
-
Couch Potato is hosted as a gem on
|
|
23
|
+
Couch Potato is hosted as a gem on gemcutter.org which you can install like this:
|
|
24
24
|
|
|
25
25
|
sudo gem install couch_potato --source http://gemcutter.org
|
|
26
26
|
|
|
@@ -31,7 +31,7 @@ Couch Potato is hosted as a gem on github which you can install like this:
|
|
|
31
31
|
|
|
32
32
|
Alternatively you can download or clone the source repository and then require lib/couch_potato.rb.
|
|
33
33
|
|
|
34
|
-
You MUST
|
|
34
|
+
You MUST specify the name of the database:
|
|
35
35
|
|
|
36
36
|
CouchPotato::Config.database_name = 'name_of_the_db'
|
|
37
37
|
|
|
@@ -145,7 +145,7 @@ You can also force a dirty state:
|
|
|
145
145
|
|
|
146
146
|
#### Object validations
|
|
147
147
|
|
|
148
|
-
Couch Potato uses the validatable library for
|
|
148
|
+
Couch Potato uses the validatable library for validation (http://validatable.rubyforge.org/)\
|
|
149
149
|
|
|
150
150
|
class User
|
|
151
151
|
property :name
|
data/VERSION.yml
CHANGED
|
@@ -18,7 +18,7 @@ module CouchPotato
|
|
|
18
18
|
|
|
19
19
|
def map_function
|
|
20
20
|
"function(doc) {
|
|
21
|
-
if(doc.
|
|
21
|
+
if(doc.#{JSON.create_id} && doc.#{JSON.create_id} == '#{@klass.name}') {
|
|
22
22
|
emit(#{formatted_key(key)}, null);
|
|
23
23
|
}
|
|
24
24
|
}"
|
|
@@ -58,4 +58,4 @@ module CouchPotato
|
|
|
58
58
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
|
-
end
|
|
61
|
+
end
|
|
@@ -7,7 +7,7 @@ module CouchPotato
|
|
|
7
7
|
class PropertiesViewSpec < ModelViewSpec
|
|
8
8
|
def map_function
|
|
9
9
|
"function(doc) {
|
|
10
|
-
if(doc.
|
|
10
|
+
if(doc.#{JSON.create_id} && doc.#{JSON.create_id} == '#{@klass.name}') {
|
|
11
11
|
emit(#{formatted_key(key)}, #{properties_for_map(properties)});
|
|
12
12
|
}
|
|
13
13
|
}"
|
|
@@ -36,4 +36,4 @@ module CouchPotato
|
|
|
36
36
|
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
|
-
end
|
|
39
|
+
end
|
data/rails/init.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# this is for rails only
|
|
2
2
|
|
|
3
|
-
require File.dirname(__FILE__) + '/../lib/couch_potato'
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/couch_potato')
|
|
4
4
|
|
|
5
5
|
CouchPotato::Config.database_name = YAML::load(File.read(Rails.root.to_s + '/config/couchdb.yml'))[RAILS_ENV]
|
|
6
6
|
|
data/spec/attachments_spec.rb
CHANGED
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
|
3
3
|
describe CouchPotato, 'attachments' do
|
|
4
4
|
it "should persist an attachment" do
|
|
5
5
|
comment = Comment.new :title => 'nil'
|
|
6
|
-
comment._attachments
|
|
6
|
+
comment._attachments['body'] = {'data' => 'a useful comment', 'content_type' => 'text/plain'}
|
|
7
7
|
CouchPotato.database.save! comment
|
|
8
8
|
CouchPotato.couchrest_database.fetch_attachment(comment.to_hash, 'body').to_s.should == 'a useful comment'
|
|
9
9
|
end
|
data/spec/create_spec.rb
CHANGED
|
@@ -8,7 +8,7 @@ describe "create" do
|
|
|
8
8
|
it "should store the class" do
|
|
9
9
|
@comment = Comment.new :title => 'my_title'
|
|
10
10
|
CouchPotato.database.save_document! @comment
|
|
11
|
-
CouchPotato.couchrest_database.get(@comment.id).
|
|
11
|
+
CouchPotato.couchrest_database.get(@comment.id).send(JSON.create_id).should == 'Comment'
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
describe "fails" do
|
data/spec/custom_view_spec.rb
CHANGED
|
@@ -39,7 +39,7 @@ describe 'view' do
|
|
|
39
39
|
CouchPotato.database.view Build.timeline(:key => 1)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
it "should not return documents that don't have a matching
|
|
42
|
+
it "should not return documents that don't have a matching JSON.create_id" do
|
|
43
43
|
CouchPotato.couchrest_database.save_doc({:time => 'x'})
|
|
44
44
|
CouchPotato.database.view(Build.timeline).should == []
|
|
45
45
|
end
|
|
@@ -55,24 +55,24 @@ describe 'view' do
|
|
|
55
55
|
|
|
56
56
|
describe "properties defined" do
|
|
57
57
|
it "should assign the configured properties" do
|
|
58
|
-
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01',
|
|
58
|
+
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')
|
|
59
59
|
CouchPotato.database.view(Build.minimal_timeline).first.state.should == 'success'
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "should not assign the properties not configured" do
|
|
63
|
-
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01',
|
|
63
|
+
CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')
|
|
64
64
|
CouchPotato.database.view(Build.minimal_timeline).first.time.should be_nil
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should assign the id even if it is not configured" do
|
|
68
|
-
id = CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01',
|
|
68
|
+
id = CouchPotato.couchrest_database.save_doc(:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build')['id']
|
|
69
69
|
CouchPotato.database.view(Build.minimal_timeline).first._id.should == id
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
describe "no properties defined" do
|
|
74
74
|
it "should assign all properties to the objects by default" do
|
|
75
|
-
id = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01',
|
|
75
|
+
id = CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => 'Build'})['id']
|
|
76
76
|
result = CouchPotato.database.view(Build.timeline).first
|
|
77
77
|
result.state.should == 'success'
|
|
78
78
|
result.time.should == '2008-01-01'
|
|
@@ -112,8 +112,8 @@ describe 'view' do
|
|
|
112
112
|
CouchPotato.database.view(Build.custom_timeline_returns_docs).map(&:state).should == ['success']
|
|
113
113
|
end
|
|
114
114
|
|
|
115
|
-
it "should still return instance of class if document included
|
|
116
|
-
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01',
|
|
115
|
+
it "should still return instance of class if document included JSON.create_id" do
|
|
116
|
+
CouchPotato.couchrest_database.save_doc({:state => 'success', :time => '2008-01-01', JSON.create_id.to_sym => "Build"})
|
|
117
117
|
view_data = CouchPotato.database.view(Build.custom_timeline_returns_docs)
|
|
118
118
|
view_data.map(&:class).should == [Build]
|
|
119
119
|
view_data.map(&:state).should == ['success']
|
|
@@ -163,4 +163,4 @@ describe 'view' do
|
|
|
163
163
|
CouchPotato.database.view(CustomBuild.timeline).first.should be_kind_of(CustomBuild)
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
|
-
end
|
|
166
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -25,12 +25,12 @@ describe "attributes" do
|
|
|
25
25
|
# useful when loading models from custom views
|
|
26
26
|
describe "accessing ghost attributes" do
|
|
27
27
|
it "should allow me to access attributes that are in the couchdb document but not defined as a property" do
|
|
28
|
-
plant = Plant.json_create({
|
|
28
|
+
plant = Plant.json_create({JSON.create_id => "Plant", "color" => "red", "leaf_count" => 1})
|
|
29
29
|
plant.color.should == 'red'
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "should raise a no method error when trying to read attributes that are not in the document" do
|
|
33
|
-
plant = Plant.json_create({
|
|
33
|
+
plant = Plant.json_create({JSON.create_id => "Plant", "leaf_count" => 1})
|
|
34
34
|
lambda do
|
|
35
35
|
plant.length
|
|
36
36
|
end.should raise_error(NoMethodError)
|
data/spec/unit/database_spec.rb
CHANGED
|
@@ -55,13 +55,13 @@ describe CouchPotato::Database, 'load' do
|
|
|
55
55
|
it "should set itself on the model" do
|
|
56
56
|
user = mock 'user'
|
|
57
57
|
DbTestUser.stub!(:new).and_return(user)
|
|
58
|
-
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => DbTestUser.json_create({
|
|
58
|
+
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => DbTestUser.json_create({JSON.create_id => 'DbTestUser'})))
|
|
59
59
|
user.should_receive(:database=).with(db)
|
|
60
60
|
db.load '1'
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it "should load namespaced models" do
|
|
64
|
-
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => Parent::Child.json_create({
|
|
64
|
+
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => Parent::Child.json_create({JSON.create_id => 'Parent::Child'})))
|
|
65
65
|
db.load('1').class.should == Parent::Child
|
|
66
66
|
end
|
|
67
67
|
end
|
|
@@ -86,7 +86,7 @@ describe 'dirty attribute tracking' do
|
|
|
86
86
|
|
|
87
87
|
describe "object loaded from database" do
|
|
88
88
|
before(:each) do
|
|
89
|
-
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi',
|
|
89
|
+
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', JSON.create_id => 'Plate'}), :info => nil)
|
|
90
90
|
@plate = CouchPotato::Database.new(couchrest_db).load_document '1'
|
|
91
91
|
end
|
|
92
92
|
|
|
@@ -104,7 +104,7 @@ describe 'dirty attribute tracking' do
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it "should return true if array attribute changed" do
|
|
107
|
-
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => ['sushi'],
|
|
107
|
+
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => ['sushi'], JSON.create_id => 'Plate'}), :info => nil)
|
|
108
108
|
plate = CouchPotato::Database.new(couchrest_db).load_document '1'
|
|
109
109
|
plate.food << 'burger'
|
|
110
110
|
plate.should be_food_changed
|
|
@@ -119,7 +119,7 @@ describe 'dirty attribute tracking' do
|
|
|
119
119
|
|
|
120
120
|
describe "after save" do
|
|
121
121
|
it "should reset all attributes to not dirty" do
|
|
122
|
-
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi',
|
|
122
|
+
couchrest_db = stub('database', :get => Plate.json_create({'_id' => '1', '_rev' => '2', 'food' => 'sushi', JSON.create_id => 'Plate'}), :info => nil, :save_doc => {})
|
|
123
123
|
db = CouchPotato::Database.new(couchrest_db)
|
|
124
124
|
@plate = db.load_document '1'
|
|
125
125
|
@plate.food = 'burger'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: couch_potato
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexander Lang
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-
|
|
12
|
+
date: 2009-11-09 00:00:00 +01:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|