couch_rest_adapter 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/lib/couch_rest_adapter/attribute_method.rb +3 -0
- data/lib/couch_rest_adapter/document_management.rb +29 -2
- data/lib/couch_rest_adapter/query_views.rb +2 -2
- data/lib/couch_rest_adapter/version.rb +1 -1
- data/lib/couch_rest_adapter.rb +1 -11
- data/test/couch_rest_adapter/attribute_method_test.rb +18 -0
- data/test/couch_rest_adapter/document_management_test.rb +33 -0
- data/test/dummy/log/test.log +177 -1401
- metadata +8 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7b96cd3e242f65785013feb23396a745182ba30
|
4
|
+
data.tar.gz: 557bf704b3d52af56e3978b8d645ac9ee8bd6530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d166a2f936e01cf0bf6772693328c7b99676c3cd39194a61a6756f82db4c4fe6a3b4f004648b1ab6e9f9b0670c1f51c2cbd1f76e3260498da3cde69992bbf2e
|
7
|
+
data.tar.gz: dd4816b8a31ad8acf54ea95ac72d46907b9f0bad9fdaf1e10d3f6557179a7446345d49b4dd8cd3fb745feed1cac7909615bd27747fa0c383b94955a25850adee
|
@@ -1,9 +1,31 @@
|
|
1
|
+
using CouchRestAdapter::Helpers
|
2
|
+
|
3
|
+
#TODO write some tests for this module
|
1
4
|
module CouchRestAdapter
|
2
5
|
module DocumentManagement
|
6
|
+
module ClassMethods
|
7
|
+
def namespace=(namespace)
|
8
|
+
@@_namespace = namespace
|
9
|
+
end
|
10
|
+
|
11
|
+
def namespace
|
12
|
+
@@_namespace ||= object_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def object_name
|
16
|
+
model_name.singular
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.extend(ClassMethods)
|
22
|
+
end
|
23
|
+
|
3
24
|
UUID_DOC = '_uuids/?'
|
4
25
|
|
5
|
-
|
6
|
-
|
26
|
+
#override this method if you want to set your own id
|
27
|
+
def set_id
|
28
|
+
uuids.first
|
7
29
|
end
|
8
30
|
|
9
31
|
def uuids opts = {}
|
@@ -16,6 +38,11 @@ module CouchRestAdapter
|
|
16
38
|
CGI.unescape(opts.to_query)
|
17
39
|
end
|
18
40
|
|
41
|
+
def _set_id_and_namespace
|
42
|
+
self['_id'] = set_id if self['_id'].blank?
|
43
|
+
self['_id'] = self['_id'].namespace_me self.class.namespace
|
44
|
+
end
|
45
|
+
|
19
46
|
end
|
20
47
|
end
|
21
48
|
|
@@ -10,8 +10,8 @@ module CouchRestAdapter
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
|
14
|
-
DEFAULT_DESIGN =
|
13
|
+
|
14
|
+
DEFAULT_DESIGN = Rails.application.class.to_s.split("::").first.downcase
|
15
15
|
|
16
16
|
def find_by_attribute attr_name, value, doc_name = nil
|
17
17
|
document_name = 'by_attribute'
|
data/lib/couch_rest_adapter.rb
CHANGED
@@ -26,9 +26,6 @@ module CouchRestAdapter
|
|
26
26
|
#TODO: add custom callback calls.
|
27
27
|
define_model_callbacks :save
|
28
28
|
|
29
|
-
#TODO set_id not be a callback. Need a better way to do this, possibilty using class methods
|
30
|
-
before_save :set_id
|
31
|
-
|
32
29
|
def initialize attributes = {}
|
33
30
|
raise NotImplementedError if abstract?
|
34
31
|
super attributes
|
@@ -65,6 +62,7 @@ module CouchRestAdapter
|
|
65
62
|
def save
|
66
63
|
return false if invalid?
|
67
64
|
return false unless run_callbacks(:save)
|
65
|
+
_set_id_and_namespace
|
68
66
|
super
|
69
67
|
end
|
70
68
|
|
@@ -88,13 +86,5 @@ module CouchRestAdapter
|
|
88
86
|
def abstract?
|
89
87
|
self.class.to_s == 'CouchRestAdapter::Base'
|
90
88
|
end
|
91
|
-
|
92
|
-
def self.object_name
|
93
|
-
self.model_name.singular
|
94
|
-
end
|
95
|
-
|
96
|
-
def set_id
|
97
|
-
self['_id'] = next_id if self['_id'].blank?
|
98
|
-
end
|
99
89
|
end
|
100
90
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CouchRestAdapter::AttributeMethodTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@foo = FooBar.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'base_id' do
|
10
|
+
@foo['_id'] = 'some_namespace/value_desired'
|
11
|
+
assert_equal @foo.base_id, 'value_desired'
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class FooBar < CouchRestAdapter::Base
|
17
|
+
use_default_database
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CouchRestAdapter::DocumentManagementTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@foo = FooBar.new
|
7
|
+
@klass = @foo.class
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'class_method object_name returns model_name in singular form' do
|
11
|
+
assert_equal @klass.object_name, @klass.model_name.singular
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'class_method namespace defaults to object_name' do
|
15
|
+
assert_equal @klass.namespace, @klass.object_name
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'class_method namespace= allows override of namespace' do
|
19
|
+
@klass.namespace = 'something'
|
20
|
+
assert_equal @klass.namespace, 'something'
|
21
|
+
@klass.namespace = @klass.object_name
|
22
|
+
end
|
23
|
+
|
24
|
+
test '_set_id_and_namespace will set the _id variable with an id and namespace' do
|
25
|
+
@foo._set_id_and_namespace
|
26
|
+
assert @foo['_id'].start_with?("foo_bar/")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class FooBar < CouchRestAdapter::Base
|
31
|
+
use_default_database
|
32
|
+
end
|
33
|
+
|