belongs_to_remote 0.0.3 → 0.0.4

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: c35372784d2c2eef5027d3788615f4d41ad2368d
4
- data.tar.gz: ad48ccd49527a54f92123f9b47e3ea12b1faa9a5
3
+ metadata.gz: c2680bb28aa1c98de506bdbdf15db6aed8207798
4
+ data.tar.gz: 44229b46b5daee432088a19c2b2cca680a0d89a2
5
5
  SHA512:
6
- metadata.gz: cf14fdba0fafa4432fdce694e2bc5071253020f02caf430bba1d1678ffd888de2fddf438f07f1590283e7ea75df3e57a0893371d1f027ba1aaf223033cffcb9c
7
- data.tar.gz: 14e3e3112833aa2f0912180241599b8270311d24b727920a3ca8c94ca31407e06f9f23871d62207631f31926c383cc23d7eee28d05de3c32f1e3d65e7d0dc4b8
6
+ metadata.gz: 803b9ed2a21aaf0b0387e46c03765731b6d344c64d8f898332cc560f52300ca7e4209bab210a4b8384aac1d8f76a9b12ae0d25f4d9bc621b4437494867ae9507
7
+ data.tar.gz: 341af5cb53c388695aab4d839369776353c14685ce0674e7fee03edb59fff3fb38dd43c1ba1441a14e0ab11c06b0e5b34c0d18c988a06b89cd9c486e04d50ab7
@@ -1,3 +1,3 @@
1
1
  module BelongsToRemote
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -29,8 +29,8 @@ module BelongsToRemote
29
29
  end
30
30
 
31
31
  def #{name}=(object)
32
- self.#{options[:foreign_key] || name.to_s + "_id" } = object.__send__(object.class.respond_to?(:primary_key) ? object.class.primary_key.to_sym : :id)
33
- self.#{name.to_s + "_type"} = object.class.to_s
32
+ self.#{options[:foreign_key] || name.to_s + "_id" } = object ? object.__send__(object.class.respond_to?(:primary_key) ? object.class.primary_key.to_sym : :id) : nil
33
+ self.#{name.to_s + "_type"} = object ? object.class.to_s : nil
34
34
  end
35
35
  )
36
36
  else
@@ -41,7 +41,7 @@ module BelongsToRemote
41
41
  end
42
42
 
43
43
  def #{name}=(object)
44
- self.#{options[:foreign_key] || name.to_s + "_id" } = object.__send__(object.class.respond_to?(:primary_key) ? object.class.primary_key.to_sym : :id)
44
+ self.#{options[:foreign_key] || name.to_s + "_id" } = object ? object.__send__(object.class.respond_to?(:primary_key) ? object.class.primary_key.to_sym : :id) : nil
45
45
  end
46
46
  )
47
47
  end
@@ -59,13 +59,15 @@ end
59
59
 
60
60
  begin
61
61
  require 'active_resource'
62
- unless ActiveResource::Base.respond_to?(:belongs_to)
63
62
  class ActiveResource::Base
64
63
  include BelongsToRemote
65
- class << self
66
- alias_method :belongs_to, :belongs_to_remote
64
+ end
65
+ unless ActiveResource::Base.respond_to?(:belongs_to)
66
+ class ActiveResource::Base
67
+ class << self
68
+ alias_method :belongs_to, :belongs_to_remote
69
+ end
67
70
  end
68
71
  end
69
- end
70
72
  rescue LoadError
71
73
  end
@@ -54,5 +54,17 @@ describe BelongsToRemote do
54
54
  expect(subject.owner_id).to eq customer.id
55
55
  expect(subject.owner_type).to eq "Customer"
56
56
  end
57
+
58
+ it "assigns association id to nil if provided nil as association object" do
59
+ subject.user = nil
60
+ expect(subject.user_id).to be_nil
61
+ subject.depot = nil
62
+ expect(subject.depot_id).to be_nil
63
+ subject.order = nil
64
+ expect(subject.booking_id).to be_nil
65
+ subject.owner = nil
66
+ expect(subject.owner_id).to eq nil
67
+ expect(subject.owner_type).to eq nil
68
+ end
57
69
  end
58
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belongs_to_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Avoyants
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler