couchbase-jruby-client 0.2.2-java → 1.0.4-java

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +103 -0
  3. data/.ruby-version +1 -1
  4. data/Rakefile +13 -2
  5. data/couchbase-jruby-client.gemspec +7 -6
  6. data/lib/couchbase/bucket.rb +11 -338
  7. data/lib/couchbase/cluster.rb +10 -88
  8. data/lib/couchbase/configuration.rb +39 -0
  9. data/lib/couchbase/design_doc.rb +18 -73
  10. data/lib/couchbase/document.rb +34 -0
  11. data/lib/couchbase/error.rb +0 -35
  12. data/lib/couchbase/operations.rb +60 -40
  13. data/lib/couchbase/version.rb +1 -1
  14. data/lib/couchbase/view.rb +55 -345
  15. data/lib/couchbase.rb +37 -141
  16. data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
  17. data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
  18. data/lib/jars/rxjava-1.0.8.jar +0 -0
  19. data/lib/jars/rxjruby-0.0.1.jar +0 -0
  20. data/test/{test_cas.rb → helper.rb} +15 -10
  21. data/test/test_bucket.rb +14 -228
  22. data/test/test_cluster.rb +1 -29
  23. data/test/test_configuration.rb +51 -0
  24. data/test/test_couchbase.rb +28 -28
  25. data/test/test_design_doc.rb +29 -0
  26. data/test/test_document.rb +51 -0
  27. data/test/test_operations.rb +49 -0
  28. data/test/test_view.rb +62 -116
  29. metadata +43 -125
  30. data/lib/couchbase/async/callback.rb +0 -38
  31. data/lib/couchbase/async/queue.rb +0 -26
  32. data/lib/couchbase/async.rb +0 -32
  33. data/lib/couchbase/constants.rb +0 -29
  34. data/lib/couchbase/operations/arithmetic.rb +0 -290
  35. data/lib/couchbase/operations/delete.rb +0 -115
  36. data/lib/couchbase/operations/design_docs.rb +0 -99
  37. data/lib/couchbase/operations/fetch.rb +0 -33
  38. data/lib/couchbase/operations/get.rb +0 -303
  39. data/lib/couchbase/operations/stats.rb +0 -42
  40. data/lib/couchbase/operations/store.rb +0 -463
  41. data/lib/couchbase/operations/touch.rb +0 -140
  42. data/lib/couchbase/operations/unlock.rb +0 -209
  43. data/lib/couchbase/operations/utils.rb +0 -68
  44. data/lib/couchbase/query.rb +0 -76
  45. data/lib/couchbase/result.rb +0 -60
  46. data/lib/couchbase/transcoder.rb +0 -81
  47. data/lib/couchbase/utils.rb +0 -62
  48. data/lib/couchbase/view_row.rb +0 -227
  49. data/lib/jars/commons-codec-1.5.jar +0 -0
  50. data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
  51. data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
  52. data/lib/jars/couchbase-client-1.3.2.jar +0 -0
  53. data/lib/jars/httpcore-4.3.1.jar +0 -0
  54. data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
  55. data/lib/jars/jettison-1.1.jar +0 -0
  56. data/lib/jars/netty-3.5.5.Final.jar +0 -0
  57. data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
  58. data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
  59. data/lib/jars/spymemcached-2.10.5.jar +0 -0
  60. data/tasks/benchmark.rake +0 -6
  61. data/tasks/test.rake +0 -36
  62. data/tasks/util.rake +0 -21
  63. data/test/mock.rb +0 -85
  64. data/test/profile/.gitignore +0 -1
  65. data/test/profile/.jrubyrc +0 -722
  66. data/test/profile/Gemfile +0 -7
  67. data/test/profile/benchmark.rb +0 -177
  68. data/test/profile/profile.rb +0 -59
  69. data/test/setup.rb +0 -74
  70. data/test/test_arithmetic.rb +0 -155
  71. data/test/test_async.rb +0 -24
  72. data/test/test_couchbase_rails_cache_store.rb +0 -341
  73. data/test/test_delete.rb +0 -139
  74. data/test/test_design_docs.rb +0 -67
  75. data/test/test_errors.rb +0 -74
  76. data/test/test_fetch.rb +0 -71
  77. data/test/test_format.rb +0 -142
  78. data/test/test_get.rb +0 -363
  79. data/test/test_query.rb +0 -23
  80. data/test/test_result.rb +0 -15
  81. data/test/test_stats.rb +0 -44
  82. data/test/test_store.rb +0 -203
  83. data/test/test_touch.rb +0 -90
  84. data/test/test_unlock.rb +0 -89
  85. data/test/test_utils.rb +0 -67
  86. data/test/test_version.rb +0 -28
  87. data/test/test_view_row.rb +0 -74
data/test/test_store.rb DELETED
@@ -1,203 +0,0 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestStore < Minitest::Test
21
-
22
- def test_trivial_set
23
- cas = cb.set(uniq_id, "bar")
24
- assert(cas > 0)
25
- end
26
-
27
- def test_set_with_cas
28
- cas1 = cb.set(uniq_id, "bar1")
29
- assert cas1 > 0
30
-
31
- assert_raises(Couchbase::Error::KeyExists) do
32
- cb.set(uniq_id, "bar2", :cas => cas1+1)
33
- end
34
-
35
- cas2 = cb.set(uniq_id, "bar2", :cas => cas1)
36
- assert cas2 > 0
37
- refute_equal cas2, cas1
38
-
39
- cas3 = cb.set(uniq_id, "bar3")
40
- assert cas3 > 0
41
- refute_equal cas3, cas2
42
- refute_equal cas3, cas1
43
- end
44
-
45
- def test_add
46
- cas1 = cb.add(uniq_id, "bar")
47
- assert cas1 > 0
48
-
49
- assert_raises(Couchbase::Error::KeyExists) do
50
- cb.add(uniq_id, "bar")
51
- end
52
-
53
- assert_raises(Couchbase::Error::KeyExists) do
54
- cb.add(uniq_id, "bar", :cas => cas1)
55
- end
56
- end
57
-
58
- def test_replace
59
- assert_raises(Couchbase::Error::NotFound) do
60
- cb.replace(uniq_id, "bar")
61
- end
62
-
63
- cas1 = cb.set(uniq_id, "bar")
64
- assert cas1 > 0
65
-
66
- cb.replace(uniq_id, "bar")
67
- end
68
-
69
- def test_acceptable_keys
70
- cas = cb.set(uniq_id.to_sym, "bar")
71
- assert cas > 0
72
-
73
- cas = cb.set(uniq_id.to_s, "bar")
74
- assert cas > 0
75
-
76
- assert_raises(ArgumentError) do
77
- cb.set(nil, "bar")
78
- end
79
-
80
- obj = {:foo => "bar", :baz => 1}
81
- assert_raises(TypeError) do
82
- cb.set(obj, "bar")
83
- end
84
-
85
- class << obj
86
- alias :to_str :to_s
87
- end
88
-
89
- cb.set(obj, "bar")
90
- assert cas > 0
91
- end
92
-
93
- def test_asynchronous_set
94
- ret = nil
95
- future = cb.async_set(uniq_id, "foo1") { |res| ret = res }
96
- future.get
97
- sleep 0.1
98
-
99
- assert ret.is_a?(Couchbase::Result)
100
- assert ret.success?
101
- assert_equal uniq_id, ret.key
102
- assert_equal :set, ret.operation
103
- assert ret.cas.is_a?(Numeric)
104
- end
105
-
106
- def test_asynchronous_set_wtihout_block
107
- future = cb.async_set(uniq_id, 'fu')
108
- future.get
109
- sleep 0.1
110
-
111
- assert_equal 'fu', cb.get(uniq_id)
112
- end
113
-
114
- def test_it_raises_error_when_appending_or_prepending_to_missing_key
115
- assert_raises(Couchbase::Error::NotStored) do
116
- cb.append(uniq_id(:missing), "foo")
117
- end
118
-
119
- assert_raises(Couchbase::Error::NotStored) do
120
- cb.prepend(uniq_id(:missing), "foo")
121
- end
122
- end
123
-
124
- def test_append
125
- cas1 = cb.set(uniq_id, "foo", format: :plain)
126
- assert cas1 > 0
127
- cas2 = cb.append(uniq_id, "bar")
128
- assert cas2 > 0
129
- refute_equal cas2, cas1
130
-
131
- val = cb.get(uniq_id)
132
- assert_equal "foobar", val
133
- end
134
-
135
- def test_prepend
136
- cb.default_format = :plain
137
-
138
- cas1 = cb.set(uniq_id, "foo")
139
- assert cas1 > 0
140
- cas2 = cb.prepend(uniq_id, "bar")
141
- assert cas2 > 0
142
- refute_equal cas2, cas1
143
-
144
- val = cb.get(uniq_id)
145
- assert_equal "barfoo", val
146
- ensure
147
- cb.default_format = :document
148
- end
149
-
150
- def test_set_with_prefix
151
- skip
152
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => "prefix:")
153
- cb.set(uniq_id(:foo), "bar")
154
- assert_equal "bar", cb.get(uniq_id(:foo))
155
- expected = {uniq_id(:foo) => "bar"}
156
- assert_equal expected, cb.get(uniq_id(:foo), :assemble_hash => true)
157
-
158
- connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :key_prefix => nil)
159
- expected = {"prefix:#{uniq_id(:foo)}" => "bar"}
160
- assert_equal expected, cb.get("prefix:#{uniq_id(:foo)}", :assemble_hash => true)
161
- end
162
-
163
- ArbitraryData = Struct.new(:baz)
164
-
165
- def test_set_with_marshal
166
- cb.set(uniq_id, ArbitraryData.new('thing'), format: :marshal)
167
- val = cb.get(uniq_id)
168
- assert val.is_a?(ArbitraryData)
169
- assert_equal "thing", val.baz
170
- end
171
-
172
- def test_set_using_brackets
173
- cb[uniq_id(1)] = "foo"
174
- val = cb.get(uniq_id(1))
175
- assert_equal "foo", val
176
-
177
- cb[uniq_id(3), :format => :marshal] = ArbitraryData.new("thing")
178
- val = cb.get(uniq_id(3))
179
- assert val.is_a?(ArbitraryData)
180
- assert_equal "thing", val.baz
181
- end
182
-
183
- def test_multi_store
184
- cb.default_format = :plain
185
- cb.add(uniq_id(:a) => "bbb", uniq_id(:z) => "yyy")
186
- assert_equal ["bbb", "yyy"], cb.get(uniq_id(:a), uniq_id(:z))
187
-
188
- # cb.prepend(uniq_id(:a) => "aaa", uniq_id(:z) => "xxx")
189
- # assert_equal ["aaabbb", "xxxyyy"], cb.get(uniq_id(:a), uniq_id(:z))
190
-
191
- # cb.append(uniq_id(:a) => "ccc", uniq_id(:z) => "zzz")
192
- # assert_equal ["aaabbbccc", "xxxyyyzzz"], cb.get(uniq_id(:a), uniq_id(:z))
193
-
194
- # cb.replace(uniq_id(:a) => "foo", uniq_id(:z) => "bar")
195
- # assert_equal ["foo", "bar"], cb.get(uniq_id(:a), uniq_id(:z))
196
-
197
- res = cb.set(uniq_id(:a) => "bar", uniq_id(:z) => "foo")
198
- assert_equal ["bar", "foo"], cb.get(uniq_id(:a), uniq_id(:z))
199
- assert res.is_a?(Hash)
200
- ensure
201
- cb.default_format = :document
202
- end
203
- end
data/test/test_touch.rb DELETED
@@ -1,90 +0,0 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestTouch < Minitest::Test
21
-
22
- def test_trivial_touch
23
- cb.set(uniq_id, "bar", :ttl => 1)
24
- cb.touch(uniq_id, :ttl => 2)
25
- sleep(1)
26
- assert cb.get(uniq_id)
27
- sleep(2)
28
- assert_raises(Couchbase::Error::NotFound) do
29
- cb.get(uniq_id)
30
- end
31
- end
32
-
33
- def test_multi_touch
34
- cb.set(uniq_id(1), "bar")
35
- cb.set(uniq_id(2), "baz")
36
- ret = cb.touch(uniq_id(1) => 1, uniq_id(2) => 1)
37
- assert ret[uniq_id(1)]
38
- assert ret[uniq_id(2)]
39
- sleep(2)
40
- assert_raises(Couchbase::Error::NotFound) do
41
- cb.get(uniq_id(1))
42
- end
43
- assert_raises(Couchbase::Error::NotFound) do
44
- cb.get(uniq_id(2))
45
- end
46
- end
47
-
48
- def test_it_uses_default_ttl_for_touch
49
- cb.default_ttl = 1
50
- cb.set(uniq_id, "bar", :ttl => 10)
51
- cb.touch(uniq_id)
52
- sleep(2)
53
- assert_raises(Couchbase::Error::NotFound) do
54
- cb.get(uniq_id)
55
- end
56
- ensure
57
- cb.default_ttl = 0
58
- end
59
-
60
- def test_it_accepts_ttl_for_get_command
61
- cb.set(uniq_id, "bar", :ttl => 10)
62
- val = cb.get(uniq_id, :ttl => 1)
63
- assert_equal "bar", val
64
- sleep(2)
65
- assert_raises(Couchbase::Error::NotFound) do
66
- cb.get(uniq_id)
67
- end
68
- end
69
-
70
- def test_missing_in_quiet_mode
71
- cb.quiet = true
72
- cas1 = cb.set(uniq_id(1), "foo1")
73
- cas2 = cb.set(uniq_id(2), "foo2")
74
-
75
- assert_raises(Couchbase::Error::NotFound) do
76
- cb.touch(uniq_id(:missing), :quiet => false)
77
- end
78
-
79
- val = cb.touch(uniq_id(:missing))
80
- refute(val)
81
-
82
- ret = cb.touch(uniq_id(1), uniq_id(:missing), uniq_id(2))
83
- assert_equal true, ret[uniq_id(1)]
84
- assert_equal false, ret[uniq_id(:missing)]
85
- assert_equal true, ret[uniq_id(2)]
86
- ensure
87
- cb.quiet = false
88
- end
89
-
90
- end
data/test/test_unlock.rb DELETED
@@ -1,89 +0,0 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestUnlock < Minitest::Test
21
-
22
- def test_trivial_unlock
23
- cb.set(uniq_id, "foo")
24
- _, _, cas = cb.get(uniq_id, :lock => true, :extended => true)
25
- assert_raises Couchbase::Error::KeyExists do
26
- cb.set(uniq_id, "bar")
27
- end
28
- assert cb.unlock(uniq_id, :cas => cas)
29
- cb.set(uniq_id, "bar")
30
- end
31
-
32
- def test_alternative_syntax_for_single_key
33
- cb.set(uniq_id, "foo")
34
- _, _, cas = cb.get(uniq_id, :lock => true, :extended => true)
35
- assert_raises Couchbase::Error::KeyExists do
36
- cb.set(uniq_id, "bar")
37
- end
38
- assert cb.unlock(uniq_id, cas)
39
- cb.set(uniq_id, "bar")
40
- end
41
-
42
- def test_multiple_unlock
43
- skip
44
- cb.set(uniq_id(1), "foo")
45
- cb.set(uniq_id(2), "foo")
46
- info = cb.get(uniq_id(1), uniq_id(2), :lock => true, :extended => true)
47
- assert_raises Couchbase::Error::KeyExists do
48
- cb.set(uniq_id(1), "bar")
49
- end
50
- assert_raises Couchbase::Error::KeyExists do
51
- cb.set(uniq_id(2), "bar")
52
- end
53
- ret = cb.unlock(uniq_id(1) => info[uniq_id(1)][2],
54
- uniq_id(2) => info[uniq_id(2)][2])
55
- assert ret[uniq_id(1)]
56
- assert ret[uniq_id(2)]
57
- cb.set(uniq_id(1), "bar")
58
- cb.set(uniq_id(2), "bar")
59
- end
60
-
61
- def test_quiet_mode
62
- skip
63
- cb.set(uniq_id, "foo")
64
- _, _, cas = cb.get(uniq_id, :lock => true, :extended => true)
65
- assert_raises Couchbase::Error::NotFound do
66
- cb.unlock(uniq_id(:missing), :cas => 0xdeadbeef)
67
- end
68
- keys = {
69
- uniq_id => cas,
70
- uniq_id(:missing) => 0xdeadbeef
71
- }
72
- ret = cb.unlock(keys, :quiet => true)
73
- assert ret[uniq_id]
74
- refute ret[uniq_id(:missing)]
75
- end
76
-
77
- def test_tmp_failure
78
- skip unless $mock.real?
79
- cas1 = cb.set(uniq_id(1), "foo")
80
- cas2 = cb.set(uniq_id(2), "foo")
81
- cb.get(uniq_id(1), :lock => true) # get with lock will update CAS
82
- assert_raises Couchbase::Error::TemporaryFail do
83
- cb.unlock(uniq_id(1), cas1)
84
- end
85
- assert_raises Couchbase::Error::TemporaryFail do
86
- cb.unlock(uniq_id(2), cas2)
87
- end
88
- end
89
- end
data/test/test_utils.rb DELETED
@@ -1,67 +0,0 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestUtils < Minitest::Test
21
-
22
- def test_nil_or_empty_key
23
- assert_raises ArgumentError do
24
- cb.set(nil, 'fu')
25
- end
26
-
27
- assert_raises ArgumentError do
28
- cb.set('', 'bar')
29
- end
30
- end
31
-
32
- def test_truncate_long_keys
33
- key = 'a' * 500
34
-
35
- assert cb.set(key, 'fu')
36
- assert_equal 'fu', cb.get(key)
37
- assert cb.delete(key)
38
- end
39
-
40
- def test_complex_startkey
41
- assert_equal "all_docs?startkey=%5B%22Deadmau5%22%2C%22%22%5D", Couchbase::Utils.build_query("all_docs", :startkey => ["Deadmau5", ""])
42
- end
43
-
44
- def test_it_provides_enough_info_with_value_error
45
- class << MultiJson
46
- alias dump_good dump
47
- def dump(obj)
48
- raise ArgumentError, "cannot accept your object"
49
- end
50
- end
51
- assert_raises(Couchbase::Error::ValueFormat) do
52
- cb.set(uniq_id, "foo")
53
- end
54
- begin
55
- cb.set(uniq_id, "foo")
56
- rescue Couchbase::Error::ValueFormat => ex
57
- assert_match /cannot accept your object/, ex.to_s
58
- assert_instance_of ArgumentError, ex.inner_exception
59
- end
60
- ensure
61
- class << MultiJson
62
- undef dump
63
- alias dump dump_good
64
- end
65
- end
66
-
67
- end
data/test/test_version.rb DELETED
@@ -1,28 +0,0 @@
1
- # Author:: Couchbase <info@couchbase.com>
2
- # Copyright:: 2011, 2012 Couchbase, Inc.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestVersion < Minitest::Test
21
-
22
- def test_version
23
- ver = cb.version
24
- assert ver.is_a?(Hash)
25
- assert_equal 1, ver.size
26
- end
27
-
28
- end
@@ -1,74 +0,0 @@
1
- # Author:: Mike Evans <mike@urlgonomics.com>
2
- # Copyright:: 2013 Urlgonomics LLC.
3
- # License:: Apache License, Version 2.0
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- #
17
-
18
- require File.join(File.dirname(__FILE__), 'setup')
19
-
20
- class TestViewRow < Minitest::Test
21
-
22
- def setup
23
- return unless $mock.real?
24
-
25
- cb.save_design_doc(design_doc)
26
- { baltimore: 'md' , philadelphia: 'pa', pittsburgh: 'pa' }.each_pair do |city, state|
27
- cb.set(city, { type: 'city', city: city, state: state })
28
- end
29
- end
30
-
31
- def view
32
- @view ||= Couchbase::View.new(cb, '_design/cities/_view/by_state')
33
- end
34
-
35
- def test_doc
36
- skip unless $mock.real?
37
- assert result = view.fetch(include_docs: true, stale: false).first
38
-
39
- data = result.data
40
-
41
- assert_instance_of Java::ComCouchbaseClientProtocolViews::ViewRowWithDocs, data
42
-
43
- assert_equal({'id' => result.id}, data.doc['meta'])
44
- assert_equal({'type' => result['type'], 'city' => result['city'], 'state' => result['state']}, data.doc['value'])
45
- end
46
-
47
- def test_doc_for_ViewRowNoDocs_objects
48
- skip unless $mock.real?
49
- assert result = view.fetch(include_docs: false, stale: false).first
50
-
51
- data = result.data
52
-
53
- assert_instance_of Java::ComCouchbaseClientProtocolViews::ViewRowNoDocs, data
54
- assert_equal({ id: result.id, key: data.key, value: data.value }, data.doc)
55
- end
56
-
57
- def design_doc
58
- {
59
- '_id' => '_design/cities',
60
- 'language' => 'javascript',
61
- 'views' => {
62
- 'by_state' => {
63
- 'map' => <<-JS
64
- function (doc, meta) {
65
- if (doc.type && doc.type == 'city')
66
- emit(meta.id, doc.state);
67
- }
68
- JS
69
- }
70
- }
71
- }
72
- end
73
-
74
- end