riagent 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) "2014" Dmitri Zagidulin
4
+ ##
5
+ ## This file is provided to you under the Apache License,
6
+ ## Version 2.0 (the "License"); you may not use this file
7
+ ## except in compliance with the License. You may obtain
8
+ ## a copy of the License at
9
+ ##
10
+ ## http://www.apache.org/licenses/LICENSE-2.0
11
+ ##
12
+ ## Unless required by applicable law or agreed to in writing,
13
+ ## software distributed under the License is distributed on an
14
+ ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ ## KIND, either express or implied. See the License for the
16
+ ## specific language governing permissions and limitations
17
+ ## under the License.
18
+ ##
19
+ ## -------------------------------------------------------------------
20
+
21
+ require 'test_helper'
22
+
23
+ describe "RiakDTSetStrategy persistence" do
24
+ it "can add keys to its collection key list" do
25
+ assert Category.all.empty?
26
+ Category.persistence.add_key('new_key123')
27
+ Category.persistence.all_keys.must_equal ['new_key123']
28
+ Category.persistence.delete_key_list
29
+ end
30
+
31
+ it "adding a document adds the key to the key list" do
32
+ assert Category.all.empty?
33
+ new_category = Category.new name: 'Test Category'
34
+ new_category.key = 'category123'
35
+ new_category.save
36
+
37
+ collection_keys = Category.persistence.all_keys
38
+ collection_keys.must_include 'category123'
39
+
40
+ new_category.destroy
41
+ collection_keys = Category.persistence.all_keys
42
+ collection_keys.must_be_empty
43
+ end
44
+ end
@@ -28,11 +28,7 @@ describe "RiakNoIndexStrategy persistence" do
28
28
  generated_key.wont_be_empty
29
29
  assert user_pref.persisted?
30
30
  user_pref.source_object.must_be_kind_of Riak::RObject
31
-
32
- # Test all() / List Keys operation. (Obviously not recommended in production)
33
- all_docs = UserPreference.all()
34
- all_docs[0].must_be_kind_of UserPreference
35
-
31
+
36
32
  # Now read the object back
37
33
  fetched_pref = UserPreference.find(generated_key)
38
34
  fetched_pref.must_be_kind_of UserPreference
data/test/seeds.rb CHANGED
@@ -27,4 +27,10 @@ Riagent.load_config_file('test/config/riak.yml')
27
27
  Riagent.init_clients(:test) # Set up the client for the test environment
28
28
 
29
29
  # Store the Solr indexing schema for the User model
30
- User.save_solr_schema()
30
+ User.save_solr_schema()
31
+
32
+ # Run these commands in the shell, in the riak/bin path:
33
+
34
+ # Create a 'sets' bucket type. (The RiakDTSetStrategy uses it to store key lists, etc)
35
+ # > riak-admin bucket-type create sets '{"props":{"datatype":"set"}}'
36
+ # > riak-admin bucket-type activate sets
data/test/test_helper.rb CHANGED
@@ -22,6 +22,7 @@ require 'minitest/autorun'
22
22
  require 'minitest-spec-context'
23
23
  require 'riagent'
24
24
  require 'examples/models/address_book'
25
+ require 'examples/models/category'
25
26
  require 'examples/models/contact'
26
27
  require 'examples/models/user'
27
28
  require 'examples/models/user_preference'
@@ -40,6 +40,5 @@ describe "Riagent" do
40
40
  it "initializes a Riak ruby client" do
41
41
  # This should have been initialized from config file in test_helper.rb
42
42
  Riagent.riak_client.must_be_kind_of Riak::Client
43
- Riagent.riak_client.protocol.must_equal 'pbc'
44
43
  end
45
44
  end
@@ -0,0 +1,78 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) "2014" Dmitri Zagidulin
4
+ ##
5
+ ## This file is provided to you under the Apache License,
6
+ ## Version 2.0 (the "License"); you may not use this file
7
+ ## except in compliance with the License. You may obtain
8
+ ## a copy of the License at
9
+ ##
10
+ ## http://www.apache.org/licenses/LICENSE-2.0
11
+ ##
12
+ ## Unless required by applicable law or agreed to in writing,
13
+ ## software distributed under the License is distributed on an
14
+ ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ ## KIND, either express or implied. See the License for the
16
+ ## specific language governing permissions and limitations
17
+ ## under the License.
18
+ ##
19
+ ## -------------------------------------------------------------------
20
+
21
+ require 'test_helper'
22
+
23
+ describe "a Riagent::ActiveDocument that persists via RiakDTSetStrategy" do
24
+ it "#model persistence instance methods" do
25
+ category = Category.new
26
+
27
+ category.must_respond_to :save
28
+ category.must_respond_to :save!
29
+ category.must_respond_to :update
30
+ category.must_respond_to :update_attributes # alias for update()
31
+ category.must_respond_to :update!
32
+ category.must_respond_to :destroy
33
+ end
34
+
35
+ it "#model persistence class methods" do
36
+ Category.persistence.must_respond_to :all
37
+ Category.persistence.must_respond_to :find
38
+ end
39
+
40
+ it "keeps collection key lists in a Set type bucket" do
41
+ Category.persistence.key_lists_bucket.must_be_kind_of Riak::Bucket
42
+
43
+ Category.persistence.key_list_set.must_be_kind_of Riak::Crdt::Set
44
+ Category.persistence.key_list_set.key.must_equal '_rg_keys_categories'
45
+ end
46
+
47
+ it "keeps a list of keys in a Crdt::Set object" do
48
+ Category.persistence.key_list_set = MiniTest::Mock.new
49
+ # Collection retrieves a list of all keys as a contents (members()) of a set object
50
+ Category.persistence.key_list_set.expect :members, []
51
+ Category.persistence.all_keys
52
+ Category.persistence.key_list_set.verify
53
+
54
+ Category.persistence.key_list_set = nil # reset
55
+ end
56
+
57
+ it "uses a multi-get (get_many()) to fetch all documents in a collection" do
58
+ # Mock the key list operation
59
+ mock_key_list = ['123']
60
+ Category.persistence.key_list_set = MiniTest::Mock.new
61
+ Category.persistence.key_list_set.expect :members, mock_key_list # return mock key list
62
+
63
+ # Now mock and verify the 'get all documents' operation
64
+ mock_document = Category.new
65
+ mock_document.key = '123'
66
+ Category.persistence.bucket = MiniTest::Mock.new
67
+
68
+ # get_many() returns the document key/value hash
69
+ Category.persistence.bucket.expect :get_many, { '123' => mock_document }, [mock_key_list]
70
+ all_docs = Category.all
71
+ Category.persistence.bucket.verify
72
+ all_docs.must_equal [ mock_document ] # all() returns just the documents
73
+
74
+ # Reset
75
+ Category.persistence.key_list_set = nil
76
+ Category.persistence.bucket = nil
77
+ end
78
+ end
@@ -0,0 +1,41 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) "2014" Dmitri Zagidulin
4
+ ##
5
+ ## This file is provided to you under the Apache License,
6
+ ## Version 2.0 (the "License"); you may not use this file
7
+ ## except in compliance with the License. You may obtain
8
+ ## a copy of the License at
9
+ ##
10
+ ## http://www.apache.org/licenses/LICENSE-2.0
11
+ ##
12
+ ## Unless required by applicable law or agreed to in writing,
13
+ ## software distributed under the License is distributed on an
14
+ ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ ## KIND, either express or implied. See the License for the
16
+ ## specific language governing permissions and limitations
17
+ ## under the License.
18
+ ##
19
+ ## -------------------------------------------------------------------
20
+
21
+ require 'test_helper'
22
+
23
+ describe "a Riagent::ActiveDocument that persists via RiakKVStrategy" do
24
+ it "#model persistence instance methods" do
25
+ user_pref = UserPreference.new
26
+
27
+ # Adding the line +collection_type :riak_no_index+ to a model
28
+ # exposes the usual array of persistence methods
29
+ user_pref.must_respond_to :save
30
+ user_pref.must_respond_to :save!
31
+ user_pref.must_respond_to :update
32
+ user_pref.must_respond_to :update_attributes # alias for update()
33
+ user_pref.must_respond_to :update!
34
+ user_pref.must_respond_to :destroy
35
+ end
36
+
37
+ it "#model persistence class methods" do
38
+ UserPreference.persistence.wont_respond_to :all
39
+ UserPreference.persistence.must_respond_to :find
40
+ end
41
+ end
@@ -22,20 +22,18 @@ require 'test_helper'
22
22
 
23
23
  describe "a Riagent::ActiveDocument that persists via RiakNoIndex strategy" do
24
24
  it "#model persistence instance methods" do
25
- user_pref = UserPreference.new
25
+ contact = Contact.new
26
26
 
27
- # Adding the line +collection_type :riak_no_index+ to a model
28
- # exposes the usual array of persistence methods
29
- user_pref.must_respond_to :save
30
- user_pref.must_respond_to :save!
31
- user_pref.must_respond_to :update
32
- user_pref.must_respond_to :update_attributes # alias for update()
33
- user_pref.must_respond_to :update!
34
- user_pref.must_respond_to :destroy
27
+ contact.must_respond_to :save
28
+ contact.must_respond_to :save!
29
+ contact.must_respond_to :update
30
+ contact.must_respond_to :update_attributes # alias for update()
31
+ contact.must_respond_to :update!
32
+ contact.must_respond_to :destroy
35
33
  end
36
34
 
37
35
  it "#model persistence class methods" do
38
- UserPreference.must_respond_to :all
39
- UserPreference.must_respond_to :find
36
+ Contact.persistence.must_respond_to :all
37
+ Contact.persistence.must_respond_to :find
40
38
  end
41
39
  end
@@ -41,11 +41,11 @@ describe "a Riagent::ActiveDocument has Persistence options" do
41
41
  assert User.persistence.allows_query?
42
42
  end
43
43
 
44
- it "#:riak_no_index collection type" do
45
- # Adding the line +collection_type :riak_no_index+ to a model
44
+ it "#:riak_kv collection type" do
45
+ # Adding the line +collection_type :riak_kv+ to a model
46
46
  # means that it will be persisted as a Riak object with no indices (k/v operations only)
47
- UserPreference.get_collection_type.must_equal :riak_no_index
48
- UserPreference.persistence.must_be_kind_of Riagent::Persistence::RiakNoIndexStrategy
47
+ UserPreference.get_collection_type.must_equal :riak_kv
48
+ UserPreference.persistence.class.must_equal Riagent::Persistence::RiakKVStrategy
49
49
 
50
50
  # It also grants access to a RiakJson::Client instance, to the model class
51
51
  UserPreference.persistence.client.must_be_kind_of Riak::Client
@@ -53,8 +53,19 @@ describe "a Riagent::ActiveDocument has Persistence options" do
53
53
  UserPreference.persistence.collection_name.must_equal 'user_preferences'
54
54
  UserPreference.persistence.bucket.must_be_kind_of Riak::Bucket
55
55
 
56
- refute UserPreference.persistence.allows_query?, "RiakNoIndex strategy does not allow querying"
57
- lambda { UserPreference.where({}) }.must_raise NotImplementedError, "RiakNoIndex strategy does not support querying"
58
- lambda { UserPreference.find_one({}) }.must_raise NotImplementedError, "RiakNoIndex strategy does not support querying"
56
+ refute UserPreference.persistence.allows_query?, "RiakKVStrategy strategy does not allow querying"
57
+ lambda { UserPreference.where({}) }.must_raise NotImplementedError, "RiakKVStrategy strategy does not support querying"
58
+ lambda { UserPreference.find_one({}) }.must_raise NotImplementedError, "RiakKVStrategy strategy does not support querying"
59
59
  end
60
+
61
+ it "#list_keys_using: :streaming_list_keys" do
62
+ Contact.get_collection_type.must_equal :riak_kv
63
+ Contact.persistence.class.must_equal Riagent::Persistence::RiakNoIndexStrategy
64
+ end
65
+
66
+ it "#list_keys_using: :riak_dt_set" do
67
+ Category.get_collection_type.must_equal :riak_kv
68
+ Category.persistence.class.must_equal Riagent::Persistence::RiakDTSetStrategy
69
+ end
70
+
60
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Zagidulin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riak_json
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: riak-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.0.0.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.0.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: riagent-document
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '4.2'
117
+ version: '4.7'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '4.2'
124
+ version: '4.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: minitest-spec-context
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,8 +136,8 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: Provides Ruby on Rails integration for RiakJson (Riak + Solr document
140
- store API)
139
+ description: Provides Ruby on Rails integration for the Riak KV NoSQL database (plus
140
+ Solr search)
141
141
  email:
142
142
  - dzagidulin@gmail.com
143
143
  executables: []
@@ -160,7 +160,9 @@ files:
160
160
  - lib/riagent/errors.rb
161
161
  - lib/riagent/persistence.rb
162
162
  - lib/riagent/persistence/persistence_strategy.rb
163
+ - lib/riagent/persistence/riak_dt_set_strategy.rb
163
164
  - lib/riagent/persistence/riak_json_strategy.rb
165
+ - lib/riagent/persistence/riak_kv_strategy.rb
164
166
  - lib/riagent/persistence/riak_no_index_strategy.rb
165
167
  - lib/riagent/railtie.rb
166
168
  - lib/riagent/search_schema.rb
@@ -169,11 +171,13 @@ files:
169
171
  - test/config/riak.yml.example
170
172
  - test/examples/models/address_book.rb
171
173
  - test/examples/models/blog_post.rb
174
+ - test/examples/models/category.rb
172
175
  - test/examples/models/contact.rb
173
176
  - test/examples/models/user.rb
174
177
  - test/examples/models/user_preference.rb
178
+ - test/integration/persistence_riak_dt_set_integration_test.rb
175
179
  - test/integration/persistence_riak_json_integration_test.rb
176
- - test/integration/persistence_riak_no_index_integration_test.rb
180
+ - test/integration/persistence_riak_kv_integration_test.rb
177
181
  - test/seeds.rb
178
182
  - test/test_helper.rb
179
183
  - test/unit/active_document_test.rb
@@ -182,7 +186,9 @@ files:
182
186
  - test/unit/associations_has_one_test.rb
183
187
  - test/unit/config_test.rb
184
188
  - test/unit/embedded_test.rb
189
+ - test/unit/persistence_riak_dt_set_test.rb
185
190
  - test/unit/persistence_riak_json_test.rb
191
+ - test/unit/persistence_riak_kv_test.rb
186
192
  - test/unit/persistence_riak_no_index_test.rb
187
193
  - test/unit/persistence_test.rb
188
194
  - test/unit/search_schema_test.rb
@@ -207,19 +213,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
213
  version: '0'
208
214
  requirements: []
209
215
  rubyforge_project:
210
- rubygems_version: 2.2.1
216
+ rubygems_version: 2.4.6
211
217
  signing_key:
212
218
  specification_version: 4
213
- summary: Rails integration for RiakJson document store
219
+ summary: Rails integration for the Riak KV NoSQL database
214
220
  test_files:
215
221
  - test/config/riak.yml.example
216
222
  - test/examples/models/address_book.rb
217
223
  - test/examples/models/blog_post.rb
224
+ - test/examples/models/category.rb
218
225
  - test/examples/models/contact.rb
219
226
  - test/examples/models/user.rb
220
227
  - test/examples/models/user_preference.rb
228
+ - test/integration/persistence_riak_dt_set_integration_test.rb
221
229
  - test/integration/persistence_riak_json_integration_test.rb
222
- - test/integration/persistence_riak_no_index_integration_test.rb
230
+ - test/integration/persistence_riak_kv_integration_test.rb
223
231
  - test/seeds.rb
224
232
  - test/test_helper.rb
225
233
  - test/unit/active_document_test.rb
@@ -228,7 +236,9 @@ test_files:
228
236
  - test/unit/associations_has_one_test.rb
229
237
  - test/unit/config_test.rb
230
238
  - test/unit/embedded_test.rb
239
+ - test/unit/persistence_riak_dt_set_test.rb
231
240
  - test/unit/persistence_riak_json_test.rb
241
+ - test/unit/persistence_riak_kv_test.rb
232
242
  - test/unit/persistence_riak_no_index_test.rb
233
243
  - test/unit/persistence_test.rb
234
244
  - test/unit/search_schema_test.rb