couchrest 0.23 → 0.24
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/lib/couchrest.rb +1 -1
- data/lib/couchrest/mixins/properties.rb +2 -2
- data/lib/couchrest/more/casted_model.rb +2 -1
- data/lib/couchrest/more/extended_document.rb +6 -1
- data/lib/couchrest/more/property.rb +2 -2
- data/lib/couchrest/support/rails.rb +35 -0
- data/spec/couchrest/more/casted_model_spec.rb +9 -0
- data/spec/couchrest/more/extended_doc_spec.rb +29 -1
- data/spec/spec_helper.rb +12 -0
- metadata +6 -28
data/lib/couchrest.rb
CHANGED
@@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
|
|
28
28
|
|
29
29
|
# = CouchDB, close to the metal
|
30
30
|
module CouchRest
|
31
|
-
VERSION = '0.
|
31
|
+
VERSION = '0.24' unless self.const_defined?("VERSION")
|
32
32
|
|
33
33
|
autoload :Server, 'couchrest/core/server'
|
34
34
|
autoload :Database, 'couchrest/core/database'
|
@@ -24,7 +24,7 @@ module CouchRest
|
|
24
24
|
self.class.properties.each do |property|
|
25
25
|
key = property.name.to_s
|
26
26
|
# let's make sure we have a default and we can assign the value
|
27
|
-
if property.default && (self.respond_to?("#{key}=") || self.key?(key))
|
27
|
+
if !property.default.nil? && (self.respond_to?("#{key}=") || self.key?(key))
|
28
28
|
if property.default.class == Proc
|
29
29
|
self[key] = property.default.call
|
30
30
|
else
|
@@ -126,4 +126,4 @@ module CouchRest
|
|
126
126
|
|
127
127
|
end
|
128
128
|
end
|
129
|
-
end
|
129
|
+
end
|
@@ -33,6 +33,11 @@ module CouchRest
|
|
33
33
|
|
34
34
|
def initialize(passed_keys={})
|
35
35
|
apply_defaults # defined in CouchRest::Mixins::Properties
|
36
|
+
passed_keys.each do |k,v|
|
37
|
+
if self.respond_to?("#{k}=")
|
38
|
+
self.send("#{k}=", passed_keys.delete(k))
|
39
|
+
end
|
40
|
+
end if passed_keys
|
36
41
|
super
|
37
42
|
cast_keys # defined in CouchRest::Mixins::Properties
|
38
43
|
unless self['_id'] && self['_rev']
|
@@ -212,4 +217,4 @@ module CouchRest
|
|
212
217
|
end
|
213
218
|
|
214
219
|
end
|
215
|
-
end
|
220
|
+
end
|
@@ -30,11 +30,11 @@ module CouchRest
|
|
30
30
|
@validation_format = options.delete(:format) if options[:format]
|
31
31
|
@read_only = options.delete(:read_only) if options[:read_only]
|
32
32
|
@alias = options.delete(:alias) if options[:alias]
|
33
|
-
@default = options.delete(:default)
|
33
|
+
@default = options.delete(:default) unless options[:default].nil?
|
34
34
|
@casted = options[:casted] ? true : false
|
35
35
|
@init_method = options[:send] ? options.delete(:send) : 'new'
|
36
36
|
@options = options
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This file contains various hacks for Rails compatibility.
|
2
|
+
# To use, just require in environment.rb, like so:
|
3
|
+
#
|
4
|
+
# require 'couchrest/support/rails'
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
# Hack so that CouchRest::Document, which descends from Hash,
|
8
|
+
# doesn't appear to Rails routing as a Hash of options
|
9
|
+
def self.===(other)
|
10
|
+
return false if self == Hash && other.is_a?(CouchRest::Document)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
CouchRest::Document.class_eval do
|
17
|
+
# Hack so that CouchRest::Document, which descends from Hash,
|
18
|
+
# doesn't appear to Rails routing as a Hash of options
|
19
|
+
def is_a?(o)
|
20
|
+
return false if o == Hash
|
21
|
+
super
|
22
|
+
end
|
23
|
+
alias_method :kind_of?, :is_a?
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
require Pathname.new(File.dirname(__FILE__)).join('..', 'validation', 'validation_errors')
|
28
|
+
|
29
|
+
CouchRest::Validation::ValidationErrors.class_eval do
|
30
|
+
# Returns the total number of errors added. Two errors added to the same attribute will be counted as such.
|
31
|
+
# This method is called by error_messages_for
|
32
|
+
def count
|
33
|
+
errors.values.inject(0) { |error_count, errors_for_attribute| error_count + errors_for_attribute.size }
|
34
|
+
end
|
35
|
+
end
|
@@ -4,6 +4,7 @@ require File.join(FIXTURE_PATH, 'more', 'card')
|
|
4
4
|
class WithCastedModelMixin < Hash
|
5
5
|
include CouchRest::CastedModel
|
6
6
|
property :name
|
7
|
+
property :no_value
|
7
8
|
end
|
8
9
|
|
9
10
|
class DummyModel < CouchRest::ExtendedDocument
|
@@ -54,6 +55,14 @@ describe CouchRest::CastedModel do
|
|
54
55
|
it "should know who casted it" do
|
55
56
|
@casted_obj.casted_by.should == @obj
|
56
57
|
end
|
58
|
+
|
59
|
+
it "should return nil for the 'no_value' attribute" do
|
60
|
+
@casted_obj.no_value.should be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return nil for the unknown attribute" do
|
64
|
+
@casted_obj["unknown"].should be_nil
|
65
|
+
end
|
57
66
|
end
|
58
67
|
|
59
68
|
describe "casted as an array of a different type" do
|
@@ -10,6 +10,7 @@ describe "ExtendedDocument" do
|
|
10
10
|
property :preset, :default => {:right => 10, :top_align => false}
|
11
11
|
property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
|
12
12
|
property :tags, :default => []
|
13
|
+
property :false_default, :default => false
|
13
14
|
property :name
|
14
15
|
timestamps!
|
15
16
|
end
|
@@ -52,6 +53,19 @@ describe "ExtendedDocument" do
|
|
52
53
|
property :preset, :default => 'value'
|
53
54
|
property :has_no_default
|
54
55
|
end
|
56
|
+
|
57
|
+
class WithGetterAndSetterMethods < CouchRest::ExtendedDocument
|
58
|
+
use_database TEST_SERVER.default_database
|
59
|
+
|
60
|
+
property :other_arg
|
61
|
+
def arg
|
62
|
+
other_arg
|
63
|
+
end
|
64
|
+
|
65
|
+
def arg=(value)
|
66
|
+
self.other_arg = "foo-#{value}"
|
67
|
+
end
|
68
|
+
end
|
55
69
|
|
56
70
|
before(:each) do
|
57
71
|
@obj = WithDefaultValues.new
|
@@ -144,6 +158,11 @@ describe "ExtendedDocument" do
|
|
144
158
|
obj = WithDefaultValues.new(:tags => ['spec'])
|
145
159
|
obj.tags.should == ['spec']
|
146
160
|
end
|
161
|
+
|
162
|
+
it "should work with a default value of false" do
|
163
|
+
obj = WithDefaultValues.new
|
164
|
+
obj.false_default.should == false
|
165
|
+
end
|
147
166
|
end
|
148
167
|
|
149
168
|
describe "a doc with template values (CR::Model spec)" do
|
@@ -506,4 +525,13 @@ describe "ExtendedDocument" do
|
|
506
525
|
|
507
526
|
end
|
508
527
|
end
|
509
|
-
|
528
|
+
|
529
|
+
describe "getter and setter methods" do
|
530
|
+
it "should try to call the arg= method before setting :arg in the hash" do
|
531
|
+
@doc = WithGetterAndSetterMethods.new(:arg => "foo")
|
532
|
+
@doc['arg'].should be_nil
|
533
|
+
@doc[:arg].should be_nil
|
534
|
+
@doc.other_arg.should == "foo-foo"
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -23,4 +23,16 @@ def reset_test_db!
|
|
23
23
|
db = cr.database(TESTDB)
|
24
24
|
db.recreate! rescue nil
|
25
25
|
db
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Runner.configure do |config|
|
29
|
+
config.before(:all) { reset_test_db! }
|
30
|
+
|
31
|
+
config.after(:all) do
|
32
|
+
cr = TEST_SERVER
|
33
|
+
test_dbs = cr.databases.select { |db| db =~ /^#{TESTDB}/ }
|
34
|
+
test_dbs.each do |db|
|
35
|
+
cr.database(db).delete! rescue nil
|
36
|
+
end
|
37
|
+
end
|
26
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.24"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J. Chris Anderson
|
@@ -58,39 +58,28 @@ files:
|
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
60
|
- THANKS.md
|
61
|
-
- examples/model
|
62
61
|
- examples/model/example.rb
|
63
|
-
- examples/word_count
|
64
62
|
- examples/word_count/markov
|
65
|
-
- examples/word_count/views
|
66
|
-
- examples/word_count/views/books
|
67
63
|
- examples/word_count/views/books/chunked-map.js
|
68
64
|
- examples/word_count/views/books/united-map.js
|
69
|
-
- examples/word_count/views/markov
|
70
65
|
- examples/word_count/views/markov/chain-map.js
|
71
66
|
- examples/word_count/views/markov/chain-reduce.js
|
72
|
-
- examples/word_count/views/word_count
|
73
67
|
- examples/word_count/views/word_count/count-map.js
|
74
68
|
- examples/word_count/views/word_count/count-reduce.js
|
75
69
|
- examples/word_count/word_count.rb
|
76
70
|
- examples/word_count/word_count_query.rb
|
77
71
|
- examples/word_count/word_count_views.rb
|
78
|
-
- lib/couchrest
|
79
|
-
- lib/couchrest/commands
|
80
72
|
- lib/couchrest/commands/generate.rb
|
81
73
|
- lib/couchrest/commands/push.rb
|
82
|
-
- lib/couchrest/core
|
83
74
|
- lib/couchrest/core/database.rb
|
84
75
|
- lib/couchrest/core/design.rb
|
85
76
|
- lib/couchrest/core/document.rb
|
86
77
|
- lib/couchrest/core/response.rb
|
87
78
|
- lib/couchrest/core/server.rb
|
88
79
|
- lib/couchrest/core/view.rb
|
89
|
-
- lib/couchrest/helper
|
90
80
|
- lib/couchrest/helper/pager.rb
|
91
81
|
- lib/couchrest/helper/streamer.rb
|
92
82
|
- lib/couchrest/helper/upgrade.rb
|
93
|
-
- lib/couchrest/mixins
|
94
83
|
- lib/couchrest/mixins/attachments.rb
|
95
84
|
- lib/couchrest/mixins/callbacks.rb
|
96
85
|
- lib/couchrest/mixins/class_proxy.rb
|
@@ -103,22 +92,18 @@ files:
|
|
103
92
|
- lib/couchrest/mixins/views.rb
|
104
93
|
- lib/couchrest/mixins.rb
|
105
94
|
- lib/couchrest/monkeypatches.rb
|
106
|
-
- lib/couchrest/more
|
107
95
|
- lib/couchrest/more/casted_model.rb
|
108
96
|
- lib/couchrest/more/extended_document.rb
|
109
97
|
- lib/couchrest/more/property.rb
|
110
|
-
- lib/couchrest/support
|
111
98
|
- lib/couchrest/support/blank.rb
|
112
99
|
- lib/couchrest/support/class.rb
|
113
|
-
- lib/couchrest/
|
100
|
+
- lib/couchrest/support/rails.rb
|
114
101
|
- lib/couchrest/validation/auto_validate.rb
|
115
102
|
- lib/couchrest/validation/contextual_validators.rb
|
116
103
|
- lib/couchrest/validation/validation_errors.rb
|
117
|
-
- lib/couchrest/validation/validators
|
118
104
|
- lib/couchrest/validation/validators/absent_field_validator.rb
|
119
105
|
- lib/couchrest/validation/validators/confirmation_validator.rb
|
120
106
|
- lib/couchrest/validation/validators/format_validator.rb
|
121
|
-
- lib/couchrest/validation/validators/formats
|
122
107
|
- lib/couchrest/validation/validators/formats/email.rb
|
123
108
|
- lib/couchrest/validation/validators/formats/url.rb
|
124
109
|
- lib/couchrest/validation/validators/generic_validator.rb
|
@@ -127,17 +112,13 @@ files:
|
|
127
112
|
- lib/couchrest/validation/validators/numeric_validator.rb
|
128
113
|
- lib/couchrest/validation/validators/required_field_validator.rb
|
129
114
|
- lib/couchrest.rb
|
130
|
-
- spec/couchrest
|
131
|
-
- spec/couchrest/core
|
132
115
|
- spec/couchrest/core/couchrest_spec.rb
|
133
116
|
- spec/couchrest/core/database_spec.rb
|
134
117
|
- spec/couchrest/core/design_spec.rb
|
135
118
|
- spec/couchrest/core/document_spec.rb
|
136
119
|
- spec/couchrest/core/server_spec.rb
|
137
|
-
- spec/couchrest/helpers
|
138
120
|
- spec/couchrest/helpers/pager_spec.rb
|
139
121
|
- spec/couchrest/helpers/streamer_spec.rb
|
140
|
-
- spec/couchrest/more
|
141
122
|
- spec/couchrest/more/casted_extended_doc_spec.rb
|
142
123
|
- spec/couchrest/more/casted_model_spec.rb
|
143
124
|
- spec/couchrest/more/extended_doc_attachment_spec.rb
|
@@ -145,12 +126,9 @@ files:
|
|
145
126
|
- spec/couchrest/more/extended_doc_subclass_spec.rb
|
146
127
|
- spec/couchrest/more/extended_doc_view_spec.rb
|
147
128
|
- spec/couchrest/more/property_spec.rb
|
148
|
-
- spec/fixtures
|
149
|
-
- spec/fixtures/attachments
|
150
129
|
- spec/fixtures/attachments/couchdb.png
|
151
130
|
- spec/fixtures/attachments/README
|
152
131
|
- spec/fixtures/attachments/test.html
|
153
|
-
- spec/fixtures/more
|
154
132
|
- spec/fixtures/more/article.rb
|
155
133
|
- spec/fixtures/more/card.rb
|
156
134
|
- spec/fixtures/more/course.rb
|
@@ -159,9 +137,7 @@ files:
|
|
159
137
|
- spec/fixtures/more/person.rb
|
160
138
|
- spec/fixtures/more/question.rb
|
161
139
|
- spec/fixtures/more/service.rb
|
162
|
-
- spec/fixtures/views
|
163
140
|
- spec/fixtures/views/lib.js
|
164
|
-
- spec/fixtures/views/test_view
|
165
141
|
- spec/fixtures/views/test_view/lib.js
|
166
142
|
- spec/fixtures/views/test_view/only-map.js
|
167
143
|
- spec/fixtures/views/test_view/test-map.js
|
@@ -172,6 +148,8 @@ files:
|
|
172
148
|
- utils/subset.rb
|
173
149
|
has_rdoc: true
|
174
150
|
homepage: http://github.com/jchris/couchrest
|
151
|
+
licenses: []
|
152
|
+
|
175
153
|
post_install_message:
|
176
154
|
rdoc_options: []
|
177
155
|
|
@@ -192,9 +170,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
170
|
requirements: []
|
193
171
|
|
194
172
|
rubyforge_project:
|
195
|
-
rubygems_version: 1.3.
|
173
|
+
rubygems_version: 1.3.2
|
196
174
|
signing_key:
|
197
|
-
specification_version:
|
175
|
+
specification_version: 3
|
198
176
|
summary: Lean and RESTful interface to CouchDB.
|
199
177
|
test_files: []
|
200
178
|
|