dolly 0.3.0 → 0.4.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/collection.rb +8 -0
- data/lib/dolly/query.rb +14 -1
- data/lib/dolly/version.rb +1 -1
- data/test/document_test.rb +34 -0
- data/test/dummy/log/test.log +123 -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: c8e886107b3a3b884726d4a2497e2e4cd47690bf
|
4
|
+
data.tar.gz: 9fd518c6a9b2c06ca14fbad305bb1afb2d9a8a49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dbe2cc21c9cd20c9f5011fb17ddc3f64856298645ce33c25f0408ba76aa684a68351c270ca76ab29a1a797bb3a4f333afa43570531d7a205616b7e837c09193
|
7
|
+
data.tar.gz: 11c1a0face5e9722e294c6d2ae093997fad57826c8be1e22915448edffd21ca86696362d805bf3ca451719becc1e41228f7873256e4c78821393c385a78b0f5a
|
data/lib/dolly/collection.rb
CHANGED
data/lib/dolly/query.rb
CHANGED
@@ -26,7 +26,20 @@ module Dolly
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def all
|
29
|
-
|
29
|
+
build_collection startkey: [name_paramitized,nil], endkey: [name_paramitized,{}]
|
30
|
+
end
|
31
|
+
|
32
|
+
def first limit = 1
|
33
|
+
res = build_collection startkey: [name_paramitized,nil], endkey: [name_paramitized,{}], limit: limit
|
34
|
+
limit == 1 ? res.first : res
|
35
|
+
end
|
36
|
+
|
37
|
+
def last limit = 1
|
38
|
+
res = build_collection startkey: [name_paramitized,{}], endkey: [name_paramitized,nil], limit: limit, descending: true
|
39
|
+
limit == 1 ? res.first : res
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_collection q
|
30
43
|
Collection.new default_view(q).parsed_response, name.constantize
|
31
44
|
end
|
32
45
|
|
data/lib/dolly/version.rb
CHANGED
data/test/document_test.rb
CHANGED
@@ -26,6 +26,10 @@ class DocumentTest < ActiveSupport::TestCase
|
|
26
26
|
build_request [["foo_bar","1"],["foo_bar","2"]], @multi_resp
|
27
27
|
|
28
28
|
FakeWeb.register_uri :get, "#{view_base_path}?startkey=%5B%22foo_bar%22%2Cnull%5D&endkey=%5B%22foo_bar%22%2C%7B%7D%5D&include_docs=true", body: @multi_resp.to_json
|
29
|
+
FakeWeb.register_uri :get, "#{view_base_path}?startkey=%5B%22foo_bar%22%2Cnull%5D&endkey=%5B%22foo_bar%22%2C%7B%7D%5D&limit=1&include_docs=true", body: view_resp.to_json
|
30
|
+
FakeWeb.register_uri :get, "#{view_base_path}?startkey=%5B%22foo_bar%22%2Cnull%5D&endkey=%5B%22foo_bar%22%2C%7B%7D%5D&limit=2&include_docs=true", body: @multi_resp.to_json
|
31
|
+
FakeWeb.register_uri :get, "#{view_base_path}?startkey=%5B%22foo_bar%22%2C%7B%7D%5D&endkey=%5B%22foo_bar%22%2Cnull%5D&limit=1&descending=true&include_docs=true", body: view_resp.to_json
|
32
|
+
FakeWeb.register_uri :get, "#{view_base_path}?startkey=%5B%22foo_bar%22%2C%7B%7D%5D&endkey=%5B%22foo_bar%22%2Cnull%5D&limit=2&descending=true&include_docs=true", body: @multi_resp.to_json
|
29
33
|
end
|
30
34
|
|
31
35
|
test 'with timestamps!' do
|
@@ -124,6 +128,16 @@ class DocumentTest < ActiveSupport::TestCase
|
|
124
128
|
assert_equal 2, all.count
|
125
129
|
end
|
126
130
|
|
131
|
+
test 'all first returns FooBar' do
|
132
|
+
first = FooBar.all.first
|
133
|
+
assert first.kind_of?(FooBar)
|
134
|
+
end
|
135
|
+
|
136
|
+
test 'all last returns FooBar' do
|
137
|
+
last = FooBar.all.last
|
138
|
+
assert last.kind_of?(FooBar)
|
139
|
+
end
|
140
|
+
|
127
141
|
test 'all will get FooBar documents' do
|
128
142
|
all = FooBar.all
|
129
143
|
all.each{ |d| assert_equal true, d.kind_of?(FooBar) }
|
@@ -139,6 +153,26 @@ class DocumentTest < ActiveSupport::TestCase
|
|
139
153
|
end
|
140
154
|
end
|
141
155
|
|
156
|
+
test 'first class method returns single item' do
|
157
|
+
first = FooBar.first
|
158
|
+
assert first.kind_of?(FooBar)
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'first class method returns collection' do
|
162
|
+
first_2 = FooBar.first 2
|
163
|
+
assert first_2.kind_of?(Dolly::Collection)
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'last class method returns single item' do
|
167
|
+
last = FooBar.last
|
168
|
+
assert last.kind_of?(FooBar)
|
169
|
+
end
|
170
|
+
|
171
|
+
test 'last class method returns collection' do
|
172
|
+
last_2 = FooBar.last 2
|
173
|
+
assert last_2.kind_of?(Dolly::Collection)
|
174
|
+
end
|
175
|
+
|
142
176
|
private
|
143
177
|
def build_view_response properties
|
144
178
|
rows = properties.map.with_index do |v, i|
|
data/test/dummy/log/test.log
CHANGED
@@ -18736,3 +18736,126 @@ DocumentTest: test_with_default_will_return_default_value_on_nil
|
|
18736
18736
|
-----------------------------------
|
18737
18737
|
DocumentTest: test_with_timestamps!
|
18738
18738
|
-----------------------------------
|
18739
|
+
-------------------------------------------
|
18740
|
+
DocumentTest: test_all_first_returns_FooBar
|
18741
|
+
-------------------------------------------
|
18742
|
+
------------------------------------------
|
18743
|
+
DocumentTest: test_all_last_returns_FooBar
|
18744
|
+
------------------------------------------
|
18745
|
+
--------------------------------------
|
18746
|
+
DocumentTest: test_all_will_get_2_docs
|
18747
|
+
--------------------------------------
|
18748
|
+
------------------------------------------------
|
18749
|
+
DocumentTest: test_all_will_get_FooBar_documents
|
18750
|
+
------------------------------------------------
|
18751
|
+
----------------------------------------------
|
18752
|
+
DocumentTest: test_default_will_be_avoerwriten
|
18753
|
+
----------------------------------------------
|
18754
|
+
------------------------------------------------
|
18755
|
+
DocumentTest: test_empty_find_should_raise_error
|
18756
|
+
------------------------------------------------
|
18757
|
+
------------------------------------------------------------
|
18758
|
+
DocumentTest: test_error_on_server_raises_Dolly::ServerError
|
18759
|
+
------------------------------------------------------------
|
18760
|
+
--------------------------------------------------
|
18761
|
+
DocumentTest: test_find_will_get_a_FooBar_document
|
18762
|
+
--------------------------------------------------
|
18763
|
+
----------------------------------------------------------------
|
18764
|
+
DocumentTest: test_find_with_multiple_ids_will_return_Collection
|
18765
|
+
----------------------------------------------------------------
|
18766
|
+
--------------------------------------------------------
|
18767
|
+
DocumentTest: test_first_class_method_returns_collection
|
18768
|
+
--------------------------------------------------------
|
18769
|
+
---------------------------------------------------------
|
18770
|
+
DocumentTest: test_first_class_method_returns_single_item
|
18771
|
+
---------------------------------------------------------
|
18772
|
+
---------------------------------------------
|
18773
|
+
DocumentTest: test_getting_not_found_document
|
18774
|
+
---------------------------------------------
|
18775
|
+
-------------------------------------------------------
|
18776
|
+
DocumentTest: test_last_class_method_returns_collection
|
18777
|
+
-------------------------------------------------------
|
18778
|
+
--------------------------------------------------------
|
18779
|
+
DocumentTest: test_last_class_method_returns_single_item
|
18780
|
+
--------------------------------------------------------
|
18781
|
+
-------------------------------------------------
|
18782
|
+
DocumentTest: test_multi_response_with_right_data
|
18783
|
+
-------------------------------------------------
|
18784
|
+
-------------------------------------------
|
18785
|
+
DocumentTest: test_will_have_key_properties
|
18786
|
+
-------------------------------------------
|
18787
|
+
--------------------------------------------------------
|
18788
|
+
DocumentTest: test_will_have_object_with_boolean?_method
|
18789
|
+
--------------------------------------------------------
|
18790
|
+
------------------------------------------------
|
18791
|
+
DocumentTest: test_will_have_only_set_properties
|
18792
|
+
------------------------------------------------
|
18793
|
+
----------------------------------------------------------------
|
18794
|
+
DocumentTest: test_with_default_will_return_default_value_on_nil
|
18795
|
+
----------------------------------------------------------------
|
18796
|
+
-----------------------------------
|
18797
|
+
DocumentTest: test_with_timestamps!
|
18798
|
+
-----------------------------------
|
18799
|
+
-------------------------------------------
|
18800
|
+
DocumentTest: test_all_first_returns_FooBar
|
18801
|
+
-------------------------------------------
|
18802
|
+
------------------------------------------
|
18803
|
+
DocumentTest: test_all_last_returns_FooBar
|
18804
|
+
------------------------------------------
|
18805
|
+
--------------------------------------
|
18806
|
+
DocumentTest: test_all_will_get_2_docs
|
18807
|
+
--------------------------------------
|
18808
|
+
------------------------------------------------
|
18809
|
+
DocumentTest: test_all_will_get_FooBar_documents
|
18810
|
+
------------------------------------------------
|
18811
|
+
----------------------------------------------
|
18812
|
+
DocumentTest: test_default_will_be_avoerwriten
|
18813
|
+
----------------------------------------------
|
18814
|
+
------------------------------------------------
|
18815
|
+
DocumentTest: test_empty_find_should_raise_error
|
18816
|
+
------------------------------------------------
|
18817
|
+
------------------------------------------------------------
|
18818
|
+
DocumentTest: test_error_on_server_raises_Dolly::ServerError
|
18819
|
+
------------------------------------------------------------
|
18820
|
+
--------------------------------------------------
|
18821
|
+
DocumentTest: test_find_will_get_a_FooBar_document
|
18822
|
+
--------------------------------------------------
|
18823
|
+
----------------------------------------------------------------
|
18824
|
+
DocumentTest: test_find_with_multiple_ids_will_return_Collection
|
18825
|
+
----------------------------------------------------------------
|
18826
|
+
--------------------------------------------------------
|
18827
|
+
DocumentTest: test_first_class_method_returns_collection
|
18828
|
+
--------------------------------------------------------
|
18829
|
+
---------------------------------------------------------
|
18830
|
+
DocumentTest: test_first_class_method_returns_single_item
|
18831
|
+
---------------------------------------------------------
|
18832
|
+
---------------------------------------------
|
18833
|
+
DocumentTest: test_getting_not_found_document
|
18834
|
+
---------------------------------------------
|
18835
|
+
-------------------------------------------------------
|
18836
|
+
DocumentTest: test_last_class_method_returns_collection
|
18837
|
+
-------------------------------------------------------
|
18838
|
+
--------------------------------------------------------
|
18839
|
+
DocumentTest: test_last_class_method_returns_single_item
|
18840
|
+
--------------------------------------------------------
|
18841
|
+
-------------------------------------------------
|
18842
|
+
DocumentTest: test_multi_response_with_right_data
|
18843
|
+
-------------------------------------------------
|
18844
|
+
-----------------------------------------
|
18845
|
+
DocumentTest: test_new_in_memory_document
|
18846
|
+
-----------------------------------------
|
18847
|
+
-------------------------------------------
|
18848
|
+
DocumentTest: test_will_have_key_properties
|
18849
|
+
-------------------------------------------
|
18850
|
+
--------------------------------------------------------
|
18851
|
+
DocumentTest: test_will_have_object_with_boolean?_method
|
18852
|
+
--------------------------------------------------------
|
18853
|
+
------------------------------------------------
|
18854
|
+
DocumentTest: test_will_have_only_set_properties
|
18855
|
+
------------------------------------------------
|
18856
|
+
----------------------------------------------------------------
|
18857
|
+
DocumentTest: test_with_default_will_return_default_value_on_nil
|
18858
|
+
----------------------------------------------------------------
|
18859
|
+
-----------------------------------
|
18860
|
+
DocumentTest: test_with_timestamps!
|
18861
|
+
-----------------------------------
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javierg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|