active_node 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2401f4a711f45da3c03f5d9950e39e50e7a2dfaf
|
4
|
+
data.tar.gz: eec605cd8b1bdb9a0f930aaf238569780eac6946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84f8abfac7991f1917389f32833d90eaa35043738ed16c4ff8695e8f631866f7ca42e9cf8efeb2ca55f32e4b54c445fd1518fcc28e01283d7d4e22c77bcd2bde
|
7
|
+
data.tar.gz: 6ac1809212df8a9211148c10a11d60e09efac009b1d1ceeb41af72f29f143f45ee01c9e96f32894800cbe0b63043ff566e4d34dc65dda4cc5708d91f21ca897d
|
@@ -27,9 +27,12 @@ module ActiveNode
|
|
27
27
|
# <tt>new_record?</tt>.
|
28
28
|
|
29
29
|
module Validations
|
30
|
+
extend ActiveSupport::Autoload
|
30
31
|
extend ActiveSupport::Concern
|
31
32
|
include ActiveModel::Validations
|
32
33
|
|
34
|
+
autoload :UniquenessValidator, 'active_node/validations/uniqueness_validator'
|
35
|
+
|
33
36
|
module ClassMethods
|
34
37
|
# Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+
|
35
38
|
# so an exception is raised if the record is invalid.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ActiveNode
|
2
|
+
module Validations
|
3
|
+
class UniquenessValidator < ActiveModel::EachValidator # :nodoc:
|
4
|
+
def validate_each(record, attribute, value)
|
5
|
+
if value && !record.class.find_by_cypher("Match (n:#{record.class.label}) where n.#{attribute} = {value} return n", value: value).empty?
|
6
|
+
record.errors.add(attribute, :taken, value: value)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/active_node/version.rb
CHANGED
@@ -6,9 +6,14 @@ describe ActiveNode::Validations do
|
|
6
6
|
Client.new.save.should be_false
|
7
7
|
end
|
8
8
|
|
9
|
-
it "should save
|
9
|
+
it "should save valid object" do
|
10
10
|
Client.new(name: 'abc7').save.should be_true
|
11
11
|
Client.all.first.name.should == 'abc7'
|
12
12
|
end
|
13
|
+
|
14
|
+
it "should validate uniqueness" do
|
15
|
+
Person.create! name: 'abc'
|
16
|
+
Person.new(name: 'abc').should_not be_valid
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
data/spec/models/person.rb
CHANGED
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.2
|
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-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/active_node/reflection.rb
|
158
158
|
- lib/active_node/relationship.rb
|
159
159
|
- lib/active_node/validations.rb
|
160
|
+
- lib/active_node/validations/uniqueness_validator.rb
|
160
161
|
- lib/active_node/version.rb
|
161
162
|
- spec/functional/associations_spec.rb
|
162
163
|
- spec/functional/base_spec.rb
|