active_node 2.2.4 → 2.2.5

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: f099f7600aea945cfd5006b737360b8d5403909c
4
- data.tar.gz: b2505371bcbc5ed36a5692fc6720aab6bff55985
3
+ metadata.gz: 60ff69e2274154cc899f7955b7da5a56148bcd35
4
+ data.tar.gz: 497a3b7bcd3599b9248ba43df678dddf3883d13e
5
5
  SHA512:
6
- metadata.gz: 52822ad900508188e43d78788179768eb0dcde8cbbb4e543fc28c63cb1d259913dbbaeb0f50a3e6af29e4977fb063f5b8f4f57864d00778e2d0ea94cf981314a
7
- data.tar.gz: aa4ca077908e7d79375059bfe776291bb4d3267d1b088e80515c6127ca8293e86c94c49945c55a39e216a40543ac5e22d9fae22da335c8b06d8447b19ca164d2
6
+ metadata.gz: 886b22a090a25a587852868740b533b92654d85b3506ba965efebc61c2fc04ba46374759d6596ea8641754f60aa86fa2ef74854dc39edb6495bfe9005fe18171
7
+ data.tar.gz: 5856304d1cf59aa53fd755f06017c9d335360ccae2f0bca6203bed5460023c21ec392921095067e900728d5162b0020aac6f8307b9c8b3dbe0f78ccbb8bf1228
@@ -46,11 +46,18 @@ module ActiveNode
46
46
 
47
47
  # Implements the writer method, e.g. foo.items= for Foo.has_many :items
48
48
  def writer(records)
49
+ validate_type(records)
49
50
  @dirty = true
50
51
  @rel_target = nil
51
52
  @target = records
52
53
  end
53
54
 
55
+ def validate_type(records)
56
+ unless records.all? {|r| r.is_a?(reflection.klass)}
57
+ raise ArgumentError, "#{reflection.name} can only accept object(s) of class #{reflection.klass}"
58
+ end
59
+ end
60
+
54
61
  alias :super_writer :writer
55
62
 
56
63
  # Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
@@ -133,11 +133,20 @@ module ActiveNode
133
133
  end
134
134
 
135
135
  def update_attributes attributes
136
- attributes.each { |key, value| respond_to_non_id_writer?(key) ? write_attr(key, value) : self[key]=value }
136
+ attributes.each { |key, value| modify_attribute(key, value) }
137
137
  save
138
138
  end
139
139
 
140
+ def update_attribute(key, value)
141
+ modify_attribute(key, value)
142
+ save!(validate: false)
143
+ end
144
+
140
145
  private
146
+ def modify_attribute(key, value)
147
+ respond_to_non_id_writer?(key) ? write_attr(key, value) : self[key]=value
148
+ end
149
+
141
150
  def respond_to_non_id_writer? attr
142
151
  respond_to_writer?(attr) && attr.to_s != 'id'
143
152
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveNode
2
- VERSION = "2.2.4"
2
+ VERSION = "2.2.5"
3
3
  end
@@ -152,4 +152,14 @@ describe ActiveNode::Persistence do
152
152
  a.incoming(:address).should include(p, c)
153
153
  end
154
154
  end
155
+
156
+ describe "#update_attribute" do
157
+ it "should update atribute without validation" do
158
+ client = Client.create!(name: 'abc')
159
+ client.update_attribute(:name, nil)
160
+ Client.find(client.id).name.should be_nil
161
+ end
162
+ end
163
+
164
+ describe "#upd"
155
165
  end
data/spec/spec_helper.rb CHANGED
@@ -3,14 +3,6 @@ CodeClimate::TestReporter.start
3
3
  #require 'rubygems'
4
4
  #require 'bundler/setup'
5
5
  require 'active_node'
6
- #
7
- #require "active_node/version"
8
- #require "active_model/version"
9
- #require 'active_support'
10
- #require 'active_model/validator'
11
- #require 'active_model/validations'
12
- #require 'active_model'
13
- #require 'active_attr'
14
6
  require 'neography'
15
7
  require 'benchmark'
16
8
  #require 'matchers'
@@ -37,14 +29,9 @@ end
37
29
 
38
30
  RSpec.configure do |c|
39
31
  c.filter_run_excluding :slow => true, :gremlin => true
40
- #c.around(:each) do
41
- # Neography::Rest.new.execute_query("START n0=node(0),nx=node(*) MATCH n0-[r0?]-(),nx-[rx?]-() WHERE nx <> n0 DELETE r0,rx,nx")
42
- #end
43
32
  c.before(:each) do
44
33
  @neo=Neography::Rest.new
45
34
  @neo.execute_query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r")
46
- #@neo.set_node_auto_index_status(true)
47
- #@neo.add_node_auto_index_property('type')
48
35
  end
49
36
  end
50
37
 
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.2.4
4
+ version: 2.2.5
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-05-14 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr