active_remote 2.3.5 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_remote/association.rb +13 -0
- data/lib/active_remote/version.rb +1 -1
- data/spec/lib/active_remote/association_spec.rb +10 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f95e9d97b5f04b0f9cfb65f1fa67b1c28610494
|
4
|
+
data.tar.gz: 20ab489954edb8912d271122b5c153a84029328e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0766023e587197504ce97037fbcb771354ed3b99144707765bb5d924ebc35e96701f008a90278938b91457da216e1da49e13f7d71b76ae51af818e56820d10de
|
7
|
+
data.tar.gz: 929d191533ec354c95449201ef31f9f5043c603d18e6316c83b09196ef3203f8552597afd8aef354793fdfd25871ddecb63718e475b4da810379e3e3166a09d4
|
@@ -132,6 +132,17 @@ module ActiveRemote
|
|
132
132
|
|
133
133
|
private
|
134
134
|
|
135
|
+
def create_setter_method(associated_klass, options={})
|
136
|
+
writer_method = "#{associated_klass}=".to_sym
|
137
|
+
define_method(writer_method) do |new_value|
|
138
|
+
klass_name = options.fetch(:class_name){ associated_klass }
|
139
|
+
klass = klass_name.to_s.classify.constantize
|
140
|
+
|
141
|
+
instance_variable_set(:"@#{new_value.class.name.demodulize.underscore}", new_value)
|
142
|
+
new_value
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
135
146
|
def perform_association(associated_klass, options={})
|
136
147
|
define_method(associated_klass) do
|
137
148
|
klass_name = options.fetch(:class_name){ associated_klass }
|
@@ -148,6 +159,8 @@ module ActiveRemote
|
|
148
159
|
|
149
160
|
return value
|
150
161
|
end
|
162
|
+
|
163
|
+
create_setter_method(associated_klass, options)
|
151
164
|
end
|
152
165
|
end
|
153
166
|
end
|
@@ -12,6 +12,7 @@ describe ActiveRemote::Association do
|
|
12
12
|
subject { Post.new(:author_guid => author_guid, :user_guid => user_guid) }
|
13
13
|
|
14
14
|
it { is_expected.to respond_to(:author) }
|
15
|
+
it { is_expected.to respond_to(:author=) }
|
15
16
|
|
16
17
|
it "searches the associated model for a single record" do
|
17
18
|
expect(Author).to receive(:search).with(:guid => subject.author_guid).and_return(records)
|
@@ -62,7 +63,6 @@ describe ActiveRemote::Association do
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
65
|
-
|
66
66
|
end
|
67
67
|
|
68
68
|
context "specific association with class name" do
|
@@ -75,6 +75,10 @@ describe ActiveRemote::Association do
|
|
75
75
|
expect(Author).to receive(:search).with(:guid => subject.author_guid).and_return(records)
|
76
76
|
expect(subject.coauthor).to eq record
|
77
77
|
end
|
78
|
+
|
79
|
+
it "should create a setter method" do
|
80
|
+
expect(subject).to respond_to(:coauthor=)
|
81
|
+
end
|
78
82
|
end
|
79
83
|
|
80
84
|
context "specific association with class name and foreign_key" do
|
@@ -181,6 +185,7 @@ describe ActiveRemote::Association do
|
|
181
185
|
subject { Category.new(category_attributes) }
|
182
186
|
|
183
187
|
it { is_expected.to respond_to(:author) }
|
188
|
+
it { is_expected.to respond_to(:author=) }
|
184
189
|
|
185
190
|
it "searches the associated model for all associated records" do
|
186
191
|
expect(Author).to receive(:search).with(:category_guid => subject.guid).and_return(records)
|
@@ -214,6 +219,10 @@ describe ActiveRemote::Association do
|
|
214
219
|
expect(Author).to receive(:search).with(:category_guid => subject.guid).and_return(records)
|
215
220
|
expect(subject.senior_author).to eq record
|
216
221
|
end
|
222
|
+
|
223
|
+
it "should create a setter method" do
|
224
|
+
expect(subject).to respond_to(:senior_author=)
|
225
|
+
end
|
217
226
|
end
|
218
227
|
|
219
228
|
context "specific association with class name and foreign_key" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hutchison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
265
|
version: '0'
|
266
266
|
requirements: []
|
267
267
|
rubyforge_project:
|
268
|
-
rubygems_version: 2.6.
|
268
|
+
rubygems_version: 2.6.10
|
269
269
|
signing_key:
|
270
270
|
specification_version: 4
|
271
271
|
summary: Active Record for your platform
|