riagent 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +202 -0
- data/README.md +230 -0
- data/Rakefile +47 -0
- data/lib/rails/generators/riagent/install/install_generator.rb +35 -0
- data/lib/rails/generators/riagent/install/templates/riak.yml +16 -0
- data/lib/riagent/active_document.rb +53 -0
- data/lib/riagent/associations.rb +119 -0
- data/lib/riagent/configuration.rb +73 -0
- data/lib/riagent/conversion.rb +83 -0
- data/lib/riagent/errors.rb +33 -0
- data/lib/riagent/persistence/riak_json_strategy.rb +62 -0
- data/lib/riagent/persistence.rb +166 -0
- data/lib/riagent/railtie.rb +35 -0
- data/lib/riagent/search_schema.rb +58 -0
- data/lib/riagent/version.rb +23 -0
- data/lib/riagent.rb +29 -0
- data/riagent.gemspec +51 -0
- data/test/config/riak.yml.example +19 -0
- data/test/examples/models/address_book.rb +32 -0
- data/test/examples/models/blog_post.rb +31 -0
- data/test/examples/models/contact.rb +29 -0
- data/test/examples/models/user.rb +41 -0
- data/test/integration/persistence_integration_test.rb +76 -0
- data/test/seeds.rb +30 -0
- data/test/test_helper.rb +33 -0
- data/test/unit/active_document_test.rb +41 -0
- data/test/unit/active_model_lint_test.rb +33 -0
- data/test/unit/associations_has_many_test.rb +32 -0
- data/test/unit/associations_has_one_test.rb +85 -0
- data/test/unit/config_test.rb +37 -0
- data/test/unit/embedded_test.rb +38 -0
- data/test/unit/persistence_riak_json_test.rb +118 -0
- data/test/unit/persistence_test.rb +57 -0
- data/test/unit/search_schema_test.rb +26 -0
- data/test/unit/validation_test.rb +39 -0
- metadata +227 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
|
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 to RiakJson" do
|
24
|
+
it "saves via collection.insert()" do
|
25
|
+
user = User.new
|
26
|
+
User.collection = MiniTest::Mock.new
|
27
|
+
User.collection.expect :insert, nil, [user]
|
28
|
+
|
29
|
+
# Calling model.save() should result in a collection.insert() call
|
30
|
+
user.save({:validate => false})
|
31
|
+
User.collection.verify
|
32
|
+
|
33
|
+
# Reset
|
34
|
+
User.collection = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "updates via collection.update()" do
|
38
|
+
user = User.new username: 'TestUserInitial'
|
39
|
+
User.collection = MiniTest::Mock.new
|
40
|
+
User.collection.expect :insert, nil, [user]
|
41
|
+
|
42
|
+
# model.update() is implemented as a save() call (with updated attributes)
|
43
|
+
user.update({ username: 'TestUserNewName'} )
|
44
|
+
User.collection.verify
|
45
|
+
|
46
|
+
# Reset
|
47
|
+
User.collection = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "destroys via collection.remove()" do
|
51
|
+
user = User.new
|
52
|
+
User.collection = MiniTest::Mock.new
|
53
|
+
User.collection.expect :remove, nil, [user]
|
54
|
+
|
55
|
+
# Calling model.destroy() should result in a collection.remove() call
|
56
|
+
user.destroy
|
57
|
+
User.collection.verify
|
58
|
+
|
59
|
+
# Reset
|
60
|
+
User.collection = nil
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns nil when doing a find() for nil or empty key" do
|
64
|
+
User.find(nil).must_be_nil
|
65
|
+
User.find('').must_be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it "performs a find() via collection.find_by_key()" do
|
69
|
+
test_key = 'user123'
|
70
|
+
User.collection = MiniTest::Mock.new
|
71
|
+
User.collection.expect :find_by_key, nil, [test_key]
|
72
|
+
|
73
|
+
# Calling Model class find() should result in a collection.find_by_key()
|
74
|
+
User.find(test_key)
|
75
|
+
User.collection.verify
|
76
|
+
|
77
|
+
# Reset
|
78
|
+
User.collection = nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "performs a where() via collection.find_all()" do
|
82
|
+
User.collection = MiniTest::Mock.new
|
83
|
+
query = { country: 'USA' }
|
84
|
+
User.collection.expect :find_all, [], [query.to_json]
|
85
|
+
|
86
|
+
# Calling Model class where() should result in a collection.find_all()
|
87
|
+
User.where(query)
|
88
|
+
User.collection.verify
|
89
|
+
|
90
|
+
# Reset
|
91
|
+
User.collection = nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it "performs a find_one() via collection.find_one()" do
|
95
|
+
User.collection = MiniTest::Mock.new
|
96
|
+
query = { username: 'TestUser' }
|
97
|
+
User.collection.expect :find_one, [], [query.to_json]
|
98
|
+
|
99
|
+
# Calling Model class find_one() should result in a collection.find_one()
|
100
|
+
User.find_one(query)
|
101
|
+
User.collection.verify
|
102
|
+
|
103
|
+
# Reset
|
104
|
+
User.collection = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it "performs an all_for_field() via collection.find_all()" do
|
108
|
+
User.collection = MiniTest::Mock.new
|
109
|
+
User.collection.expect :find_all, [], [String]
|
110
|
+
|
111
|
+
# Calling Model class all_for_field() should result in a collection.find_all()
|
112
|
+
User.all_for_field(:username)
|
113
|
+
User.collection.verify
|
114
|
+
|
115
|
+
# Reset
|
116
|
+
User.collection = nil
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
|
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 has Persistence options" do
|
24
|
+
context "via collection_type :riak_json" do
|
25
|
+
it "#model class methods" do
|
26
|
+
# Adding the line +collection_type :riak_json+ to a model
|
27
|
+
# means that it will be persisted to a RiakJson::Collection
|
28
|
+
User.get_collection_type.must_equal :riak_json
|
29
|
+
User.persistence_strategy.must_equal :riak_json
|
30
|
+
|
31
|
+
# It also grants access to a RiakJson::Client instance, to the model class
|
32
|
+
User.client.must_be_kind_of RiakJson::Client
|
33
|
+
|
34
|
+
User.collection.must_be_kind_of RiakJson::Collection
|
35
|
+
User.collection_name.must_equal 'users'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "#model persistence instance methods" do
|
39
|
+
user = User.new
|
40
|
+
|
41
|
+
# Adding the line +collection_type :riak_json+ to a model
|
42
|
+
# exposes the usual array of persistence methods
|
43
|
+
user.must_respond_to :save
|
44
|
+
user.must_respond_to :save!
|
45
|
+
user.must_respond_to :update
|
46
|
+
user.must_respond_to :update_attributes # alias for update()
|
47
|
+
user.must_respond_to :update!
|
48
|
+
user.must_respond_to :destroy
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#model persistence class methods" do
|
52
|
+
User.must_respond_to :find
|
53
|
+
User.must_respond_to :find_one
|
54
|
+
User.must_respond_to :where
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe "an Active Document" do
|
4
|
+
it "can build a RiakJson schema from the annotated attributes" do
|
5
|
+
schema = User.schema
|
6
|
+
schema.must_be_kind_of RiakJson::CollectionSchema
|
7
|
+
schema.fields.wont_be_empty
|
8
|
+
schema.fields.count.must_equal 2
|
9
|
+
schema.fields[0][:name].to_s.must_equal 'username'
|
10
|
+
schema.fields[0][:type].must_equal 'text'
|
11
|
+
schema.fields[0][:require].must_equal true
|
12
|
+
schema.fields[1][:name].to_s.must_equal 'email'
|
13
|
+
schema.fields[1][:type].must_equal 'string'
|
14
|
+
schema.fields[1][:require].must_equal true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can save the Solr indexing schema to RiakJson" do
|
18
|
+
schema = User.schema
|
19
|
+
User.collection = MiniTest::Mock.new
|
20
|
+
|
21
|
+
# Ensure that calling User.save_solr_schema() results in a call to collection.set_schema()
|
22
|
+
User.collection.expect :set_schema, nil, [RiakJson::CollectionSchema]
|
23
|
+
User.save_solr_schema
|
24
|
+
User.collection.verify
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Copyright (c) "2014" Dmitri Zagidulin and Basho Technologies, Inc.
|
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" do
|
24
|
+
it "supports ActiveModel validations" do
|
25
|
+
@new_user = User.new
|
26
|
+
refute @new_user.valid?, "User requires a username to be present"
|
27
|
+
assert @new_user.errors.messages.include?(:username), "Missing username validation error when saving"
|
28
|
+
|
29
|
+
@new_user.username = "TestUser"
|
30
|
+
assert @new_user.valid?, "User should now be valid, after setting a username"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises InvalidDocumentError on save!()" do
|
34
|
+
@new_user = User.new
|
35
|
+
refute @new_user.valid?, "User requires a username to be present"
|
36
|
+
refute @new_user.save, "User requires a username, save should fail"
|
37
|
+
lambda { @new_user.save! }.must_raise Riagent::InvalidDocumentError # save! should raise an exception
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riagent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitri Zagidulin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: riak_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: riak-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: riagent-document
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activemodel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '4.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.2'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: minitest-spec-context
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Provides Ruby on Rails integration for RiakJson (Riak + Solr document
|
140
|
+
store API)
|
141
|
+
email:
|
142
|
+
- dzagidulin@gmail.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- ".gitignore"
|
148
|
+
- Gemfile
|
149
|
+
- Gemfile.lock
|
150
|
+
- LICENSE
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- lib/rails/generators/riagent/install/install_generator.rb
|
154
|
+
- lib/rails/generators/riagent/install/templates/riak.yml
|
155
|
+
- lib/riagent.rb
|
156
|
+
- lib/riagent/active_document.rb
|
157
|
+
- lib/riagent/associations.rb
|
158
|
+
- lib/riagent/configuration.rb
|
159
|
+
- lib/riagent/conversion.rb
|
160
|
+
- lib/riagent/errors.rb
|
161
|
+
- lib/riagent/persistence.rb
|
162
|
+
- lib/riagent/persistence/riak_json_strategy.rb
|
163
|
+
- lib/riagent/railtie.rb
|
164
|
+
- lib/riagent/search_schema.rb
|
165
|
+
- lib/riagent/version.rb
|
166
|
+
- riagent.gemspec
|
167
|
+
- test/config/riak.yml.example
|
168
|
+
- test/examples/models/address_book.rb
|
169
|
+
- test/examples/models/blog_post.rb
|
170
|
+
- test/examples/models/contact.rb
|
171
|
+
- test/examples/models/user.rb
|
172
|
+
- test/integration/persistence_integration_test.rb
|
173
|
+
- test/seeds.rb
|
174
|
+
- test/test_helper.rb
|
175
|
+
- test/unit/active_document_test.rb
|
176
|
+
- test/unit/active_model_lint_test.rb
|
177
|
+
- test/unit/associations_has_many_test.rb
|
178
|
+
- test/unit/associations_has_one_test.rb
|
179
|
+
- test/unit/config_test.rb
|
180
|
+
- test/unit/embedded_test.rb
|
181
|
+
- test/unit/persistence_riak_json_test.rb
|
182
|
+
- test/unit/persistence_test.rb
|
183
|
+
- test/unit/search_schema_test.rb
|
184
|
+
- test/unit/validation_test.rb
|
185
|
+
homepage: https://github.com/dmitrizagidulin/riagent
|
186
|
+
licenses:
|
187
|
+
- Apache 2.0
|
188
|
+
metadata: {}
|
189
|
+
post_install_message:
|
190
|
+
rdoc_options: []
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ">="
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
requirements: []
|
204
|
+
rubyforge_project:
|
205
|
+
rubygems_version: 2.2.1
|
206
|
+
signing_key:
|
207
|
+
specification_version: 4
|
208
|
+
summary: Rails integration for RiakJson document store
|
209
|
+
test_files:
|
210
|
+
- test/config/riak.yml.example
|
211
|
+
- test/examples/models/address_book.rb
|
212
|
+
- test/examples/models/blog_post.rb
|
213
|
+
- test/examples/models/contact.rb
|
214
|
+
- test/examples/models/user.rb
|
215
|
+
- test/integration/persistence_integration_test.rb
|
216
|
+
- test/seeds.rb
|
217
|
+
- test/test_helper.rb
|
218
|
+
- test/unit/active_document_test.rb
|
219
|
+
- test/unit/active_model_lint_test.rb
|
220
|
+
- test/unit/associations_has_many_test.rb
|
221
|
+
- test/unit/associations_has_one_test.rb
|
222
|
+
- test/unit/config_test.rb
|
223
|
+
- test/unit/embedded_test.rb
|
224
|
+
- test/unit/persistence_riak_json_test.rb
|
225
|
+
- test/unit/persistence_test.rb
|
226
|
+
- test/unit/search_schema_test.rb
|
227
|
+
- test/unit/validation_test.rb
|