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 +4 -4
- data/lib/belongs_to_remote/version.rb +1 -1
- data/lib/belongs_to_remote.rb +9 -7
- data/spec/belongs_to_remote_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2680bb28aa1c98de506bdbdf15db6aed8207798
|
4
|
+
data.tar.gz: 44229b46b5daee432088a19c2b2cca680a0d89a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803b9ed2a21aaf0b0387e46c03765731b6d344c64d8f898332cc560f52300ca7e4209bab210a4b8384aac1d8f76a9b12ae0d25f4d9bc621b4437494867ae9507
|
7
|
+
data.tar.gz: 341af5cb53c388695aab4d839369776353c14685ce0674e7fee03edb59fff3fb38dd43c1ba1441a14e0ab11c06b0e5b34c0d18c988a06b89cd9c486e04d50ab7
|
data/lib/belongs_to_remote.rb
CHANGED
@@ -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
|
-
|
66
|
-
|
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.
|
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-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|