active_node 2.0.2 → 2.0.3
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/.travis.yml +1 -1
- data/README.md +69 -0
- data/lib/active_node/persistence.rb +3 -3
- data/lib/active_node/validations/uniqueness_validator.rb +10 -1
- data/lib/active_node/version.rb +1 -1
- data/spec/functional/base_spec.rb +2 -0
- data/spec/functional/persistence_spec.rb +13 -1
- data/spec/functional/validations_spec.rb +10 -3
- data/spec/spec_helper.rb +6 -2
- data/spec/support/shared/active_model_specs.rb +23 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fba7d60bad2e08d7dc4e0750638d7307e04fc17
|
4
|
+
data.tar.gz: 65347e49175fad7daae68761797e7c195bcfb287
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35794dbe68d4e3345b8860fce9597a095d7888090b2da7336a175a4492e8c11577a339b0a2832242f03cbd7e23c11aa61ed6c723c1d62aa965500856a45fca96
|
7
|
+
data.tar.gz: 9cf27db0e024749342e86a971a8156a4e5efa99e91e327899fb0797ebacbf7817012f7d2867f2ccada1eb1256e799cb7b4a67bff469ca4c8b0e6815f346b1c39
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,3 +2,72 @@ active_node
|
|
2
2
|
===========
|
3
3
|
|
4
4
|
ActiveRecord style Object Graph Mapping for neo4j
|
5
|
+
|
6
|
+
|
7
|
+
gem install active_node
|
8
|
+
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require 'rubygems'
|
12
|
+
require 'active_node'
|
13
|
+
require 'neography'
|
14
|
+
|
15
|
+
Neography.configure do |config|
|
16
|
+
config.protocol = "http://"
|
17
|
+
config.server = "localhost"
|
18
|
+
config.port = 7474
|
19
|
+
config.directory = "" # prefix this path with '/'
|
20
|
+
config.cypher_path = "/cypher"
|
21
|
+
config.gremlin_path = "/ext/GremlinPlugin/graphdb/execute_script"
|
22
|
+
config.log_file = "neography.log"
|
23
|
+
config.log_enabled = false
|
24
|
+
config.slow_log_threshold = 0 # time in ms for query logging
|
25
|
+
config.max_threads = 20
|
26
|
+
config.authentication = nil # 'basic' or 'digest'
|
27
|
+
config.username = nil
|
28
|
+
config.password = nil
|
29
|
+
config.parser = MultiJsonParser
|
30
|
+
end
|
31
|
+
|
32
|
+
class NeoUser < ActiveNode::Base
|
33
|
+
attribute :name, type: String
|
34
|
+
has_many :clients
|
35
|
+
validates :name, presence: true
|
36
|
+
|
37
|
+
def self.label
|
38
|
+
'User'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Client < ActiveNode::Base
|
43
|
+
attribute :name, type: String
|
44
|
+
|
45
|
+
has_many :users, direction: :incoming, class_name: 'NeoUser'
|
46
|
+
has_one :address
|
47
|
+
|
48
|
+
validates :name, presence: true
|
49
|
+
end
|
50
|
+
|
51
|
+
class Address < ActiveNode::Base
|
52
|
+
end
|
53
|
+
|
54
|
+
class Person < ActiveNode::Base
|
55
|
+
attribute :name, type: String
|
56
|
+
attribute :multi
|
57
|
+
timestamps
|
58
|
+
|
59
|
+
has_many :people
|
60
|
+
has_many :children, class_name: "Person"
|
61
|
+
#has_many :sons, class_name: "Person"
|
62
|
+
has_one :father, type: :child, direction: :incoming, class_name: "Person"
|
63
|
+
has_one :address
|
64
|
+
|
65
|
+
validates :name, uniqueness: true
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
user = NeoUser.new(name: 'Heinrich')
|
70
|
+
user.save
|
71
|
+
client = Client.new(name: 'a', users: [user])
|
72
|
+
client.save
|
73
|
+
```
|
@@ -81,11 +81,11 @@ module ActiveNode
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def to_param
|
84
|
-
id
|
84
|
+
id.to_s if persisted?
|
85
85
|
end
|
86
86
|
|
87
87
|
def persisted?
|
88
|
-
id
|
88
|
+
id.present?
|
89
89
|
end
|
90
90
|
|
91
91
|
def initialize hash={}, split_by=:respond_to_writer?
|
@@ -222,4 +222,4 @@ module ActiveNode
|
|
222
222
|
end
|
223
223
|
|
224
224
|
end
|
225
|
-
end
|
225
|
+
end
|
@@ -2,10 +2,19 @@ module ActiveNode
|
|
2
2
|
module Validations
|
3
3
|
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
|
4
4
|
def validate_each(record, attribute, value)
|
5
|
-
if value &&
|
5
|
+
if value && other_matching_records(record, attribute, value).any?
|
6
6
|
record.errors.add(attribute, :taken, value: value)
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def other_matching_records(record, attribute, value)
|
13
|
+
record.class.find_by_cypher(
|
14
|
+
"Match (n:#{record.class.label}) where n.#{attribute} = {value}#{' and id(n) <> {id}' if record.persisted?} return n",
|
15
|
+
value: value, id: record.id
|
16
|
+
)
|
17
|
+
end
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
data/lib/active_node/version.rb
CHANGED
@@ -80,6 +80,18 @@ describe ActiveNode::Persistence do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
describe "#to_param" do
|
84
|
+
it "should return a string version of the id" do
|
85
|
+
person = Person.create!
|
86
|
+
person.to_param.should == person.id.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return nil if the id is nil" do
|
90
|
+
person = Person.new
|
91
|
+
person.to_param.should be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
83
95
|
describe "#incoming" do
|
84
96
|
it "can retrieve heterogenous models" do
|
85
97
|
a = Address.create!
|
@@ -88,4 +100,4 @@ describe ActiveNode::Persistence do
|
|
88
100
|
a.incoming(:address).should include(p, c)
|
89
101
|
end
|
90
102
|
end
|
91
|
-
end
|
103
|
+
end
|
@@ -11,9 +11,16 @@ describe ActiveNode::Validations do
|
|
11
11
|
Client.all.first.name.should == 'abc7'
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
describe "with uniqueness constraint" do
|
15
|
+
it "should validate uniqueness" do
|
16
|
+
Person.create! name: 'abc'
|
17
|
+
Person.new(name: 'abc').should_not be_valid
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should still be valid after save" do
|
21
|
+
person = Person.create! name: "abc"
|
22
|
+
person.should be_valid
|
23
|
+
end
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,6 +22,10 @@ Coveralls.wear!
|
|
22
22
|
|
23
23
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
24
24
|
|
25
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
26
|
+
# in spec/support/ and its subdirectories.
|
27
|
+
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
|
28
|
+
|
25
29
|
def generate_text(length=8)
|
26
30
|
chars = 'abcdefghjkmnpqrstuvwxyz'
|
27
31
|
key = ''
|
@@ -50,10 +54,10 @@ end
|
|
50
54
|
def error_response(attributes)
|
51
55
|
request_uri = double()
|
52
56
|
request_uri.stub(:request_uri).and_return("")
|
53
|
-
|
57
|
+
|
54
58
|
http_header = double()
|
55
59
|
http_header.stub(:request_uri).and_return(request_uri)
|
56
|
-
|
60
|
+
|
57
61
|
stub(
|
58
62
|
http_header: http_header,
|
59
63
|
code: attributes[:code],
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Adapated from http://pivotallabs.com/making-sure-you-implement-the-activemodel-interface-fully/
|
2
|
+
#
|
3
|
+
# Originally adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
|
4
|
+
# put this in a file in your spec/support directory
|
5
|
+
# USAGE:
|
6
|
+
#
|
7
|
+
# let(:model) { ModelUnderTest.new(params) }
|
8
|
+
# it_behaves_like "ActiveModel"
|
9
|
+
|
10
|
+
shared_examples_for "ActiveModel" do
|
11
|
+
require 'test/unit/assertions'
|
12
|
+
require 'active_model/lint'
|
13
|
+
include Test::Unit::Assertions
|
14
|
+
include ActiveModel::Lint::Tests
|
15
|
+
|
16
|
+
ActiveModel::Lint::Tests.public_instance_methods.map { |method| method.to_s }.grep(/^test/).each do |method|
|
17
|
+
example(method.gsub('_', ' ')) { send method }
|
18
|
+
end
|
19
|
+
|
20
|
+
def model
|
21
|
+
subject
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_node
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heinrich Klobuczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- spec/models/neo_user.rb
|
169
169
|
- spec/models/person.rb
|
170
170
|
- spec/spec_helper.rb
|
171
|
+
- spec/support/shared/active_model_specs.rb
|
171
172
|
homepage: ''
|
172
173
|
licenses: []
|
173
174
|
metadata: {}
|
@@ -201,3 +202,4 @@ test_files:
|
|
201
202
|
- spec/models/neo_user.rb
|
202
203
|
- spec/models/person.rb
|
203
204
|
- spec/spec_helper.rb
|
205
|
+
- spec/support/shared/active_model_specs.rb
|