couch_potato 0.2.15 → 0.2.16
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +4 -0
- data/VERSION.yml +2 -3
- data/lib/couch_potato/database.rb +1 -1
- data/lib/couch_potato/persistence/properties.rb +2 -2
- data/lib/couch_potato/persistence/simple_property.rb +1 -1
- data/rails/init.rb +1 -0
- data/rails/reload_classes.rb +37 -0
- data/spec/property_spec.rb +11 -3
- data/spec/rails_spec.rb +22 -0
- data/spec/unit/database_spec.rb +1 -1
- metadata +5 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## Changes
|
2
2
|
|
3
|
+
### 0.2.16
|
4
|
+
* fixed problem with classes being not loaded in rails development mode (langalex)
|
5
|
+
* fixed persist boolean false value (bernd)
|
6
|
+
|
3
7
|
### 0.2.15
|
4
8
|
* ability to change the name of the attribute that stores the ruby class in the documents by setting JSON.create_id (lennart)
|
5
9
|
* fixed double loading issue with bundler (jweiss)
|
data/VERSION.yml
CHANGED
@@ -62,7 +62,7 @@ module CouchPotato
|
|
62
62
|
instance
|
63
63
|
end
|
64
64
|
|
65
|
-
# Declare a
|
65
|
+
# Declare a property on a model class. properties are not typed by default. You can use any of the basic types by JSON (String, Integer, Fixnum, Array, Hash). If you want a property to be of a custom class you have to define it using the :class option.
|
66
66
|
#
|
67
67
|
# example:
|
68
68
|
# class Book
|
@@ -78,4 +78,4 @@ module CouchPotato
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
-
end
|
81
|
+
end
|
@@ -11,7 +11,7 @@ module CouchPotato
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def build(object, json)
|
14
|
-
value = json[name.to_s]
|
14
|
+
value = json[name.to_s].nil? ? json[name.to_sym] : json[name.to_s]
|
15
15
|
typecast_value = if type && !value.instance_of?(type)
|
16
16
|
type.json_create value
|
17
17
|
else
|
data/rails/init.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# this is for rails only
|
2
2
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/couch_potato')
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + '/reload_classes')
|
4
5
|
|
5
6
|
CouchPotato::Config.database_name = YAML::load(File.read(Rails.root.to_s + '/config/couchdb.yml'))[RAILS_ENV]
|
6
7
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module CouchPotato
|
2
|
+
module Persistence
|
3
|
+
|
4
|
+
def self.persistent_classes #:nodoc:
|
5
|
+
@persistent_classes ||= []
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.reload_persistent_classes #:nodoc:
|
9
|
+
persistent_classes.each do |clazz|
|
10
|
+
eval clazz.name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def self.included_with_class_reloading(base) #:nodoc:
|
16
|
+
persistent_classes << base
|
17
|
+
included_without_class_reloading(base)
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
alias_method :included_without_class_reloading, :included
|
22
|
+
alias_method :included, :included_with_class_reloading
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Database.class_eval do
|
27
|
+
def load_document_with_class_reloading(id)
|
28
|
+
Persistence.reload_persistent_classes
|
29
|
+
load_document_without_class_reloading id
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :load_document_without_class_reloading, :load_document
|
33
|
+
alias_method :load_document, :load_document_with_class_reloading
|
34
|
+
alias_method :load, :load_document
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/spec/property_spec.rb
CHANGED
@@ -107,7 +107,7 @@ describe 'properties' do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should persist an object" do
|
110
|
-
p = Person.new
|
110
|
+
p = Person.new
|
111
111
|
a = Address.new :city => 'Denver'
|
112
112
|
p.ship_address = a
|
113
113
|
CouchPotato.database.save_document! p
|
@@ -116,13 +116,21 @@ describe 'properties' do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should persist null for a null " do
|
119
|
-
p = Person.new
|
119
|
+
p = Person.new
|
120
120
|
p.ship_address = nil
|
121
121
|
CouchPotato.database.save_document! p
|
122
122
|
p = CouchPotato.database.load_document p.id
|
123
123
|
p.ship_address.should be_nil
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
|
+
it "should persist false for a false" do
|
127
|
+
p = Person.new
|
128
|
+
p.ship_address = false
|
129
|
+
CouchPotato.database.save_document! p
|
130
|
+
p = CouchPotato.database.load_document p.id
|
131
|
+
p.ship_address.should be_false
|
132
|
+
end
|
133
|
+
|
126
134
|
describe "predicate" do
|
127
135
|
it "should return true if property set" do
|
128
136
|
Comment.new(:title => 'title').title?.should be_true
|
data/spec/rails_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/../rails/reload_classes'
|
3
|
+
|
4
|
+
class Autoloader
|
5
|
+
def self.const_missing(name)
|
6
|
+
eval("#{name} = Class.new; #{name}.send(:include, CouchPotato::Persistence)")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
describe CouchPotato::Database, 'rails specific behavior' do
|
12
|
+
|
13
|
+
it "should load load models whose constants are currently uninitialized (like with rails in development mode)" do
|
14
|
+
Autoloader::Uninitialized
|
15
|
+
Autoloader.send :remove_const, 'Uninitialized'
|
16
|
+
recreate_db
|
17
|
+
CouchPotato.couchrest_database.save_doc(JSON.create_id => 'Autoloader::Uninitialized', '_id' => '1')
|
18
|
+
CouchPotato.database.load('1').class.name.should == 'Autoloader::Uninitialized'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
data/spec/unit/database_spec.rb
CHANGED
@@ -43,7 +43,6 @@ describe CouchPotato::Database, 'full_url_to_database' do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
46
|
describe CouchPotato::Database, 'load' do
|
48
47
|
it "should raise an exception if nil given" do
|
49
48
|
db = CouchPotato::Database.new(stub('couchrest db', :info => nil))
|
@@ -64,6 +63,7 @@ describe CouchPotato::Database, 'load' do
|
|
64
63
|
db = CouchPotato::Database.new(stub('couchrest db', :info => nil, :get => Parent::Child.json_create({JSON.create_id => 'Parent::Child'})))
|
65
64
|
db.load('1').class.should == Parent::Child
|
66
65
|
end
|
66
|
+
|
67
67
|
end
|
68
68
|
|
69
69
|
describe CouchPotato::Database, 'save_document' do
|
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.16
|
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-11-
|
12
|
+
date: 2009-11-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/couch_potato/view/raw_view_spec.rb
|
86
86
|
- lib/couch_potato/view/view_query.rb
|
87
87
|
- rails/init.rb
|
88
|
+
- rails/reload_classes.rb
|
88
89
|
- spec/attachments_spec.rb
|
89
90
|
- spec/callbacks_spec.rb
|
90
91
|
- spec/create_spec.rb
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- spec/fixtures/address.rb
|
95
96
|
- spec/fixtures/person.rb
|
96
97
|
- spec/property_spec.rb
|
98
|
+
- spec/rails_spec.rb
|
97
99
|
- spec/spec.opts
|
98
100
|
- spec/spec_helper.rb
|
99
101
|
- spec/unit/attributes_spec.rb
|
@@ -146,6 +148,7 @@ test_files:
|
|
146
148
|
- spec/fixtures/address.rb
|
147
149
|
- spec/fixtures/person.rb
|
148
150
|
- spec/property_spec.rb
|
151
|
+
- spec/rails_spec.rb
|
149
152
|
- spec/spec_helper.rb
|
150
153
|
- spec/unit/attributes_spec.rb
|
151
154
|
- spec/unit/callbacks_spec.rb
|