dolly 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dolly/document.rb +5 -1
- data/lib/dolly/property.rb +1 -1
- data/lib/dolly/version.rb +1 -1
- data/test/document_test.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ed634c57601285c5f226c689864684e556edbe
|
4
|
+
data.tar.gz: 343cf2e87366a95ca10a22cd76a7e9b014fe8eeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46eb110e75de2a3511cd5682bc5f8a4caddf11c4c8b41c2af20dd09b29e5413c9380385981c4b957655ac163f24b7a17beb6b43dac012695eaf6d1b2a2794275
|
7
|
+
data.tar.gz: 4cab1eb32ab93835832897fda1ed3a300063df79e1e6f6895024355939843608ba1c3a3168635d63d4a339cc39f4f06eb05322a673e91f03babee3146f180bbb
|
data/lib/dolly/document.rb
CHANGED
@@ -137,14 +137,18 @@ module Dolly
|
|
137
137
|
|
138
138
|
def init_properties options = {}
|
139
139
|
raise Dolly::ResourceNotFound if options['error'] == 'not_found'
|
140
|
-
#TODO: right now not listed properties will be ignored
|
141
140
|
options.each do |k, v|
|
142
141
|
next unless respond_to? :"#{k}="
|
143
142
|
send(:"#{k}=", v)
|
144
143
|
end
|
144
|
+
initialize_default_properties options if self.properties.present?
|
145
145
|
init_doc options
|
146
146
|
end
|
147
147
|
|
148
|
+
def initialize_default_properties options
|
149
|
+
_properties.reject { |property| options.keys.include? property.name }.each { |property| self.doc[property.name] ||= property.default }
|
150
|
+
end
|
151
|
+
|
148
152
|
def init_doc options
|
149
153
|
self.doc ||= {}
|
150
154
|
#TODO: define what will be the preference _id or id
|
data/lib/dolly/property.rb
CHANGED
data/lib/dolly/version.rb
CHANGED
data/test/document_test.rb
CHANGED
@@ -22,6 +22,10 @@ class FooBaz < Dolly::Document
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
class TestFoo < Dolly::Document
|
26
|
+
property :default_test_property, class_name: String, default: 'FOO'
|
27
|
+
end
|
28
|
+
|
25
29
|
class DocumentTest < ActiveSupport::TestCase
|
26
30
|
DB_BASE_PATH = "http://localhost:5984/test".freeze
|
27
31
|
|
@@ -334,6 +338,16 @@ class DocumentTest < ActiveSupport::TestCase
|
|
334
338
|
assert_equal foobaz.foo, {'foo' => 'bar', 'bar' => 'bar'}
|
335
339
|
end
|
336
340
|
|
341
|
+
test 'default should populate before save' do
|
342
|
+
test_foo = TestFoo.new
|
343
|
+
assert_equal 'FOO', test_foo.doc['default_test_property']
|
344
|
+
end
|
345
|
+
|
346
|
+
test 'default should be overridden by params' do
|
347
|
+
test_foo = TestFoo.new(default_test_property: 'bar')
|
348
|
+
assert_equal 'bar', test_foo.doc['default_test_property']
|
349
|
+
end
|
350
|
+
|
337
351
|
private
|
338
352
|
def generic_response rows, count = 1
|
339
353
|
{total_rows: count, offset:0, rows: rows}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javierg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|