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: 05485943a60e029748218ef9bb075ac6a601e863
4
- data.tar.gz: 025ea77b6cfd4e68a839f0712d48fdb5c8de0a02
3
+ metadata.gz: 2401f4a711f45da3c03f5d9950e39e50e7a2dfaf
4
+ data.tar.gz: eec605cd8b1bdb9a0f930aaf238569780eac6946
5
5
  SHA512:
6
- metadata.gz: a0f21defc7f1b9477c886879b2fbca7aaf3e2a79ec7f39b2304084faf6cd84efc9dc3e231cf2f15fce724c23be89bff6b733ccedbcce0fbd6975aea90217aeeb
7
- data.tar.gz: 8ab33c466677513cc63a9be1009a7c10b06cd82796dc6d6a2a499cdc3bfdee1612b7e8ad5db0b0675dcc0baaf01d97170b7d92e77bac3ba5137c1f33fb54a0fd
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
@@ -1,3 +1,3 @@
1
1
  module ActiveNode
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -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 invalid object" do
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
@@ -8,4 +8,6 @@ class Person < ActiveNode::Base
8
8
  #has_many :sons, class_name: "Person"
9
9
  has_one :father, type: :child, direction: :incoming, class_name: "Person"
10
10
  has_one :address
11
+
12
+ validates :name, uniqueness: true
11
13
  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.1
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-01-31 00:00:00.000000000 Z
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