active_remote 7.0.0 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/{ruby.yml → main.yml} +15 -6
- data/.rubocop.yml +2 -27
- data/.standard.yml +2 -0
- data/CHANGES.md +190 -53
- data/README.md +6 -5
- data/Rakefile +2 -5
- data/active_remote.gemspec +17 -20
- data/lib/active_remote/association.rb +3 -3
- data/lib/active_remote/base.rb +12 -12
- data/lib/active_remote/dirty.rb +2 -2
- data/lib/active_remote/dsl.rb +14 -14
- data/lib/active_remote/integration.rb +7 -7
- data/lib/active_remote/persistence.rb +7 -7
- data/lib/active_remote/query_attributes.rb +3 -3
- data/lib/active_remote/rpc.rb +2 -3
- data/lib/active_remote/rpc_adapters/protobuf_adapter.rb +2 -2
- data/lib/active_remote/search.rb +25 -8
- data/lib/active_remote/serializers/protobuf.rb +10 -9
- data/lib/active_remote/validations.rb +2 -2
- data/lib/active_remote/version.rb +1 -1
- data/spec/lib/active_remote/association_spec.rb +25 -25
- data/spec/lib/active_remote/dirty_spec.rb +8 -8
- data/spec/lib/active_remote/dsl_spec.rb +7 -7
- data/spec/lib/active_remote/errors_spec.rb +2 -2
- data/spec/lib/active_remote/integration_spec.rb +2 -2
- data/spec/lib/active_remote/persistence_spec.rb +34 -34
- data/spec/lib/active_remote/primary_key_spec.rb +2 -2
- data/spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb +1 -1
- data/spec/lib/active_remote/rpc_spec.rb +13 -15
- data/spec/lib/active_remote/scope_keys_spec.rb +2 -2
- data/spec/lib/active_remote/search_spec.rb +31 -4
- data/spec/lib/active_remote/serialization_spec.rb +2 -2
- data/spec/lib/active_remote/serializers/protobuf_spec.rb +7 -7
- data/spec/lib/active_remote/validations_spec.rb +1 -1
- data/spec/support/models/author.rb +3 -3
- data/spec/support/models/category.rb +3 -3
- data/spec/support/models/default_author.rb +3 -3
- data/spec/support/models/post.rb +4 -4
- data/spec/support/protobuf/author.pb.rb +5 -11
- data/spec/support/protobuf/category.pb.rb +5 -11
- data/spec/support/protobuf/error.pb.rb +1 -6
- data/spec/support/protobuf/post.pb.rb +6 -12
- data/spec/support/protobuf/serializer.pb.rb +1 -8
- data/spec/support/protobuf/tag.pb.rb +5 -11
- metadata +29 -80
- data/.travis.yml +0 -5
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ::ActiveRemote::Persistence do
|
4
|
-
let(:response_without_errors) { ::HashWithIndifferentAccess.new(:
|
4
|
+
let(:response_without_errors) { ::HashWithIndifferentAccess.new(errors: []) }
|
5
5
|
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
6
6
|
|
7
7
|
subject { ::Tag.new }
|
@@ -15,16 +15,16 @@ describe ::ActiveRemote::Persistence do
|
|
15
15
|
describe ".create" do
|
16
16
|
it "runs create callbacks" do
|
17
17
|
expect_any_instance_of(Tag).to receive(:after_create_callback)
|
18
|
-
Tag.create(:
|
18
|
+
Tag.create(name: "foo")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "initializes and saves a new record" do
|
22
22
|
expect_any_instance_of(Tag).to receive(:save)
|
23
|
-
Tag.create(:
|
23
|
+
Tag.create(name: "foo")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "returns a new record" do
|
27
|
-
value = Tag.create(:
|
27
|
+
value = Tag.create(name: "foo")
|
28
28
|
expect(value).to be_a(Tag)
|
29
29
|
end
|
30
30
|
end
|
@@ -32,14 +32,14 @@ describe ::ActiveRemote::Persistence do
|
|
32
32
|
describe ".create!" do
|
33
33
|
it "initializes and saves a new record" do
|
34
34
|
expect_any_instance_of(Tag).to receive(:save!)
|
35
|
-
Tag.create!(:
|
35
|
+
Tag.create!(name: "foo")
|
36
36
|
end
|
37
37
|
|
38
38
|
context "when the record has errors" do
|
39
39
|
before { allow_any_instance_of(Tag).to receive(:save!).and_raise(ActiveRemote::ActiveRemoteError) }
|
40
40
|
|
41
41
|
it "raises an exception" do
|
42
|
-
expect { Tag.create!(:
|
42
|
+
expect { Tag.create!(name: "foo") }.to raise_error(ActiveRemote::ActiveRemoteError)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -58,8 +58,8 @@ describe ::ActiveRemote::Persistence do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
context "when the response has errors" do
|
61
|
-
let(:error) { Generic::Error.new(:
|
62
|
-
let(:response) { Generic::Remote::Tag.new(:
|
61
|
+
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
62
|
+
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
63
63
|
|
64
64
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
65
65
|
|
@@ -81,8 +81,8 @@ describe ::ActiveRemote::Persistence do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
context "when an error occurs" do
|
84
|
-
let(:error) { Generic::Error.new(:
|
85
|
-
let(:response) { Generic::Remote::Tag.new(:
|
84
|
+
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
85
|
+
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
86
86
|
|
87
87
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
88
88
|
|
@@ -106,8 +106,8 @@ describe ::ActiveRemote::Persistence do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
context "when the response has errors" do
|
109
|
-
let(:error) { Generic::Error.new(:
|
110
|
-
let(:response) { Generic::Remote::Tag.new(:
|
109
|
+
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
110
|
+
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
111
111
|
|
112
112
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
113
113
|
|
@@ -129,8 +129,8 @@ describe ::ActiveRemote::Persistence do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
context "when an error occurs" do
|
132
|
-
let(:error) { Generic::Error.new(:
|
133
|
-
let(:response) { Generic::Remote::Tag.new(:
|
132
|
+
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
133
|
+
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
134
134
|
|
135
135
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
136
136
|
|
@@ -148,7 +148,7 @@ describe ::ActiveRemote::Persistence do
|
|
148
148
|
end
|
149
149
|
|
150
150
|
context "when errors are present" do
|
151
|
-
before { subject.errors.add(:base, :invalid, :
|
151
|
+
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
152
152
|
|
153
153
|
its(:has_errors?) { should be_truthy }
|
154
154
|
end
|
@@ -156,13 +156,13 @@ describe ::ActiveRemote::Persistence do
|
|
156
156
|
|
157
157
|
describe "#new_record?" do
|
158
158
|
context "when the record is created through instantiate" do
|
159
|
-
subject { Tag.instantiate(:
|
159
|
+
subject { Tag.instantiate(guid: "foo") }
|
160
160
|
|
161
161
|
its(:new_record?) { should be_falsey }
|
162
162
|
end
|
163
163
|
|
164
164
|
context "when the record is persisted" do
|
165
|
-
subject { Tag.allocate.instantiate(:
|
165
|
+
subject { Tag.allocate.instantiate(guid: "foo") }
|
166
166
|
|
167
167
|
its(:new_record?) { should be_falsey }
|
168
168
|
end
|
@@ -176,7 +176,7 @@ describe ::ActiveRemote::Persistence do
|
|
176
176
|
|
177
177
|
describe "#persisted?" do
|
178
178
|
context "when the record is persisted" do
|
179
|
-
subject { Tag.allocate.instantiate(:
|
179
|
+
subject { Tag.allocate.instantiate(guid: "foo") }
|
180
180
|
|
181
181
|
its(:persisted?) { should be_truthy }
|
182
182
|
end
|
@@ -190,7 +190,7 @@ describe ::ActiveRemote::Persistence do
|
|
190
190
|
|
191
191
|
describe "#readonly?" do
|
192
192
|
context "when the record is created through instantiate with options[:readonly]" do
|
193
|
-
subject { Tag.instantiate({
|
193
|
+
subject { Tag.instantiate({guid: "foo"}, readonly: true) }
|
194
194
|
|
195
195
|
its(:new_record?) { should be_falsey }
|
196
196
|
its(:readonly?) { should be_truthy }
|
@@ -198,9 +198,9 @@ describe ::ActiveRemote::Persistence do
|
|
198
198
|
end
|
199
199
|
|
200
200
|
describe "#remote" do
|
201
|
-
let(:response) { ::Generic::Remote::Tag.new(:
|
201
|
+
let(:response) { ::Generic::Remote::Tag.new(guid: tag.guid, name: "bar") }
|
202
202
|
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
203
|
-
let(:tag) { ::Tag.new(:
|
203
|
+
let(:tag) { ::Tag.new(guid: SecureRandom.uuid) }
|
204
204
|
|
205
205
|
subject { tag }
|
206
206
|
|
@@ -224,7 +224,7 @@ describe ::ActiveRemote::Persistence do
|
|
224
224
|
|
225
225
|
context "when request args are given" do
|
226
226
|
it "calls the given RPC method with default args" do
|
227
|
-
attributes = {
|
227
|
+
attributes = {guid: tag.guid, name: "foo"}
|
228
228
|
expect(::Tag.rpc).to receive(:execute).with(:remote_method, attributes)
|
229
229
|
tag.remote(:remote_method, attributes)
|
230
230
|
end
|
@@ -232,14 +232,14 @@ describe ::ActiveRemote::Persistence do
|
|
232
232
|
|
233
233
|
context "when response does not respond to errors" do
|
234
234
|
it "returns true" do
|
235
|
-
allow(rpc).to receive(:execute).and_return(double(:response, :
|
235
|
+
allow(rpc).to receive(:execute).and_return(double(:response, to_hash: {}))
|
236
236
|
expect(tag.remote(:remote_method)).to be(true)
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
240
|
context "when errors are returned" do
|
241
241
|
let(:response) {
|
242
|
-
::Generic::Remote::Tag.new(:
|
242
|
+
::Generic::Remote::Tag.new(guid: tag.guid, name: "bar", errors: [{field: "name", message: "message"}])
|
243
243
|
}
|
244
244
|
|
245
245
|
it "adds errors from the response" do
|
@@ -270,7 +270,7 @@ describe ::ActiveRemote::Persistence do
|
|
270
270
|
end
|
271
271
|
|
272
272
|
context "when the record is not new" do
|
273
|
-
let(:attributes) { {
|
273
|
+
let(:attributes) { {"guid" => "foo"} }
|
274
274
|
|
275
275
|
subject { Tag.allocate.instantiate(attributes) }
|
276
276
|
|
@@ -295,7 +295,7 @@ describe ::ActiveRemote::Persistence do
|
|
295
295
|
end
|
296
296
|
|
297
297
|
context "when the record has errors before the save" do
|
298
|
-
before { subject.errors.add(:base, :invalid, :
|
298
|
+
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
299
299
|
|
300
300
|
it "clears the errors before the save" do
|
301
301
|
expect(subject.errors).not_to be_empty
|
@@ -315,10 +315,10 @@ describe ::ActiveRemote::Persistence do
|
|
315
315
|
|
316
316
|
context "when the record is not saved" do
|
317
317
|
let(:errors) {
|
318
|
-
[Generic::Error.new(:
|
319
|
-
|
318
|
+
[Generic::Error.new(field: "name", message: "Error one!"),
|
319
|
+
Generic::Error.new(field: "name", message: "Error two!")]
|
320
320
|
}
|
321
|
-
let(:response) { Generic::Remote::Tag.new(:
|
321
|
+
let(:response) { Generic::Remote::Tag.new(errors: errors) }
|
322
322
|
before { allow(rpc).to receive(:execute).and_return(response) }
|
323
323
|
|
324
324
|
it "raises an exception" do
|
@@ -330,7 +330,7 @@ describe ::ActiveRemote::Persistence do
|
|
330
330
|
|
331
331
|
describe "#success?" do
|
332
332
|
context "when errors are present" do
|
333
|
-
before { subject.errors.add(:base, :invalid, :
|
333
|
+
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
334
334
|
|
335
335
|
its(:success?) { should be_falsey }
|
336
336
|
end
|
@@ -343,7 +343,7 @@ describe ::ActiveRemote::Persistence do
|
|
343
343
|
end
|
344
344
|
|
345
345
|
describe "#update_attribute" do
|
346
|
-
let(:tag) { Tag.allocate.instantiate(:
|
346
|
+
let(:tag) { Tag.allocate.instantiate(guid: "123") }
|
347
347
|
|
348
348
|
it "runs update callbacks" do
|
349
349
|
expect(tag).to receive(:after_update_callback)
|
@@ -370,8 +370,8 @@ describe ::ActiveRemote::Persistence do
|
|
370
370
|
end
|
371
371
|
|
372
372
|
describe "#update_attributes" do
|
373
|
-
let(:attributes) { HashWithIndifferentAccess.new(:
|
374
|
-
let(:tag) { Tag.allocate.instantiate(:
|
373
|
+
let(:attributes) { HashWithIndifferentAccess.new(name: "bar") }
|
374
|
+
let(:tag) { Tag.allocate.instantiate(guid: "123") }
|
375
375
|
|
376
376
|
it "runs update callbacks" do
|
377
377
|
expect(tag).to receive(:after_update_callback)
|
@@ -398,7 +398,7 @@ describe ::ActiveRemote::Persistence do
|
|
398
398
|
end
|
399
399
|
|
400
400
|
describe "#update_attributes!" do
|
401
|
-
let(:attributes) { HashWithIndifferentAccess.new(:
|
401
|
+
let(:attributes) { HashWithIndifferentAccess.new(name: "bar") }
|
402
402
|
|
403
403
|
before { allow(subject).to receive(:save!) }
|
404
404
|
after { allow(subject).to receive(:save!).and_call_original }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::PrimaryKey do
|
4
|
-
let(:tag) { Tag.new(:
|
4
|
+
let(:tag) { Tag.new(id: "1234", guid: "TAG-123", user_guid: "USR-123") }
|
5
5
|
|
6
6
|
after { Tag.instance_variable_set :@primary_key, nil }
|
7
7
|
|
@@ -42,7 +42,7 @@ describe ActiveRemote::PrimaryKey do
|
|
42
42
|
|
43
43
|
context "when no primary key is specified, but default of guid exists" do
|
44
44
|
it "returns guid in array" do
|
45
|
-
expect(Tag.new(:
|
45
|
+
expect(Tag.new(guid: "TAG-123").to_key).to eq ["TAG-123"]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -4,33 +4,31 @@ describe ::ActiveRemote::RPC do
|
|
4
4
|
subject { ::Tag.new }
|
5
5
|
|
6
6
|
describe ".build_from_rpc" do
|
7
|
-
let(:new_attributes) { {
|
7
|
+
let(:new_attributes) { {name: "test"} }
|
8
8
|
|
9
9
|
it "dups the default attributes" do
|
10
|
-
expect { ::Tag.build_from_rpc(new_attributes) }.to_not change { ::Tag._default_attributes["name"] }
|
10
|
+
expect { ::Tag.build_from_rpc(new_attributes).to_h }.to_not change { ::Tag._default_attributes["name"] }
|
11
11
|
end
|
12
12
|
|
13
13
|
context "missing attributes from rpc" do
|
14
14
|
it "initializes to nil" do
|
15
|
-
expect(::Tag.build_from_rpc(new_attributes)).to include("guid" => nil)
|
15
|
+
expect(::Tag.build_from_rpc(new_attributes).to_h).to include("guid" => nil)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "extra attributes from rpc" do
|
20
|
-
let(:new_attributes) { {
|
20
|
+
let(:new_attributes) { {foobar: "test"} }
|
21
21
|
|
22
22
|
it "ignores unknown attributes" do
|
23
|
-
expect(::Tag.build_from_rpc(new_attributes)).to_not include("foobar" => "test")
|
23
|
+
expect(::Tag.build_from_rpc(new_attributes).to_h).to_not include("foobar" => "test")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
context "typecasted attributes" do
|
28
|
-
let(:new_attributes) { {
|
28
|
+
let(:new_attributes) { {birthday: "2017-01-01"} }
|
29
29
|
|
30
30
|
it "calls the typecasters" do
|
31
|
-
expect(
|
32
|
-
::Author.build_from_rpc(new_attributes)
|
33
|
-
).to include({"birthday" => "2017-01-01".to_datetime})
|
31
|
+
expect(::Author.build_from_rpc(new_attributes).to_h).to include({"birthday" => "2017-01-01".to_datetime})
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
@@ -56,15 +54,15 @@ describe ::ActiveRemote::RPC do
|
|
56
54
|
end
|
57
55
|
|
58
56
|
describe "#assign_attributes_from_rpc" do
|
59
|
-
let(:response) { ::Generic::Remote::Tag.new(:
|
60
|
-
let(:tag) { ::Tag.new(:
|
57
|
+
let(:response) { ::Generic::Remote::Tag.new(guid: tag.guid, name: "bar") }
|
58
|
+
let(:tag) { ::Tag.new(guid: SecureRandom.uuid) }
|
61
59
|
|
62
60
|
it "updates the attributes from the response" do
|
63
61
|
expect { tag.assign_attributes_from_rpc(response) }.to change { tag.name }.to(response.name)
|
64
62
|
end
|
65
63
|
|
66
64
|
context "when response does not respond to errors" do
|
67
|
-
let(:response) { double(:response, :
|
65
|
+
let(:response) { double(:response, to_hash: {}) }
|
68
66
|
|
69
67
|
it "does not add errors from the response" do
|
70
68
|
expect { tag.assign_attributes_from_rpc(response) }.to_not change { tag.has_errors? }
|
@@ -74,9 +72,9 @@ describe ::ActiveRemote::RPC do
|
|
74
72
|
context "when errors are returned" do
|
75
73
|
let(:response) {
|
76
74
|
::Generic::Remote::Tag.new(
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
75
|
+
guid: tag.guid,
|
76
|
+
name: "bar",
|
77
|
+
errors: [{field: "name", message: "message"}]
|
80
78
|
)
|
81
79
|
}
|
82
80
|
|
@@ -5,7 +5,7 @@ describe ActiveRemote::ScopeKeys do
|
|
5
5
|
let(:_scope_keys) { ["user_guid"] }
|
6
6
|
let(:scope_keys) { ["guid"] + _scope_keys }
|
7
7
|
let(:tag) { Tag.new(tag_hash) }
|
8
|
-
let(:tag_hash) { {
|
8
|
+
let(:tag_hash) { {guid: "TAG-123", user_guid: "USR-123", name: "teh tag"} }
|
9
9
|
|
10
10
|
describe ".scope_key" do
|
11
11
|
after { Tag._scope_keys = [] }
|
@@ -31,7 +31,7 @@ describe ActiveRemote::ScopeKeys do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#scope_key_hash" do
|
34
|
-
let(:scope_key_hash) { {
|
34
|
+
let(:scope_key_hash) { {"guid" => "TAG-123", "user_guid" => "USR-123"} }
|
35
35
|
|
36
36
|
before { allow(tag).to receive(:scope_keys).and_return(scope_keys) }
|
37
37
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ActiveRemote::Search do
|
4
|
-
let(:records) { [Generic::Remote::Tag.new(:
|
5
|
-
let(:response) { Generic::Remote::Tags.new(:
|
4
|
+
let(:records) { [Generic::Remote::Tag.new(guid: "123")] }
|
5
|
+
let(:response) { Generic::Remote::Tags.new(records: records) }
|
6
6
|
let(:rpc) { double(:rpc) }
|
7
7
|
|
8
8
|
describe ".find" do
|
@@ -36,8 +36,35 @@ describe ActiveRemote::Search do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
describe ".find_by" do
|
40
|
+
let(:args) { {} }
|
41
|
+
let(:record) { double(:record) }
|
42
|
+
let(:records) { [record] }
|
43
|
+
|
44
|
+
before { allow(Tag).to receive(:search).and_return(records) }
|
45
|
+
|
46
|
+
it "searches with the given args" do
|
47
|
+
expect(Tag).to receive(:search).with(args)
|
48
|
+
Tag.find_by(args)
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when records are returned" do
|
52
|
+
it "returns the first record" do
|
53
|
+
expect(Tag.find_by(args)).to eq record
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when no records are returned" do
|
58
|
+
before { allow(Tag).to receive(:search).and_return([]) }
|
59
|
+
|
60
|
+
it "returns nil" do
|
61
|
+
expect(Tag.find_by(args)).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
39
66
|
describe ".search" do
|
40
|
-
let(:serialized_records) { [Tag.instantiate(:
|
67
|
+
let(:serialized_records) { [Tag.instantiate(guid: "123")] }
|
41
68
|
|
42
69
|
context "given args that respond to :to_hash" do
|
43
70
|
let(:args) { {} }
|
@@ -68,7 +95,7 @@ describe ActiveRemote::Search do
|
|
68
95
|
|
69
96
|
describe "#reload" do
|
70
97
|
let(:args) { attributes.slice("guid", "user_guid") }
|
71
|
-
let(:attributes) { HashWithIndifferentAccess.new(:
|
98
|
+
let(:attributes) { HashWithIndifferentAccess.new(guid: "foo", name: "bar", updated_at: nil, user_guid: "baz") }
|
72
99
|
|
73
100
|
subject { Tag.new(args) }
|
74
101
|
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActiveRemote::Serialization do
|
4
4
|
describe ".serialize_records" do
|
5
|
-
let(:records) { [{
|
5
|
+
let(:records) { [{foo: "bar"}] }
|
6
6
|
|
7
7
|
subject { Tag.new }
|
8
8
|
|
@@ -14,7 +14,7 @@ describe ActiveRemote::Serialization do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#add_errors" do
|
17
|
-
let(:error) { Generic::Error.new(:
|
17
|
+
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
18
18
|
let(:response) {
|
19
19
|
tag = Generic::Remote::Tag.new
|
20
20
|
tag.errors << error
|
@@ -2,8 +2,8 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActiveRemote::Serializers::Protobuf::Fields do
|
4
4
|
describe ".from_attributes" do
|
5
|
-
let(:ready_value) { {
|
6
|
-
let(:value) { {
|
5
|
+
let(:ready_value) { {records: [{name: "Cool Post", errors: [{message: "Boom!"}]}]} }
|
6
|
+
let(:value) { {records: {name: "Cool Post", errors: {message: "Boom!"}}} }
|
7
7
|
|
8
8
|
it "gets protobuf-ready fields from attributes" do
|
9
9
|
expect(described_class.from_attributes(Generic::Remote::Posts, value)).to eq ready_value
|
@@ -17,8 +17,8 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
17
17
|
let(:field) { Generic::Remote::Posts.get_field(:records) }
|
18
18
|
|
19
19
|
context "and the value is not an array" do
|
20
|
-
let(:ready_value) { [{
|
21
|
-
let(:value) { {
|
20
|
+
let(:ready_value) { [{name: "Cool Post", errors: [{message: "Boom!"}]}] }
|
21
|
+
let(:value) { {name: "Cool Post", errors: {message: "Boom!"}} }
|
22
22
|
|
23
23
|
it "gets protobuf-ready fields from the value" do
|
24
24
|
expect(described_class.from_attribute(field, value)).to eq ready_value
|
@@ -30,8 +30,8 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
30
30
|
let(:field) { Generic::Remote::Post.get_field(:category) }
|
31
31
|
|
32
32
|
context "and value is a hash" do
|
33
|
-
let(:ready_value) { {
|
34
|
-
let(:value) { {
|
33
|
+
let(:ready_value) { {name: "Film", errors: [{message: "Boom!"}]} }
|
34
|
+
let(:value) { {name: "Film", errors: {message: "Boom!"}} }
|
35
35
|
|
36
36
|
it "gets protobuf-ready fields from the value" do
|
37
37
|
expect(described_class.from_attribute(field, value)).to eq ready_value
|
@@ -61,7 +61,7 @@ describe ActiveRemote::Serializers::Protobuf::Field do
|
|
61
61
|
# typecasting.
|
62
62
|
#
|
63
63
|
context "when typecasting fields" do
|
64
|
-
let(:string_value) { double(:string, :
|
64
|
+
let(:string_value) { double(:string, to_s: "") }
|
65
65
|
|
66
66
|
def typecasts(field, conversion)
|
67
67
|
field = Serializer.get_field(field, true)
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe ActiveRemote::Validations do
|
4
4
|
let(:invalid_record) { ::Post.new }
|
5
|
-
let(:valid_record) { ::Post.new(:
|
5
|
+
let(:valid_record) { ::Post.new(name: "test") }
|
6
6
|
|
7
7
|
before { allow(valid_record).to receive(:create_or_update).and_return(true) }
|
8
8
|
before { allow(invalid_record).to receive(:create_or_update).and_return(true) }
|
@@ -18,9 +18,9 @@ class Author < ::ActiveRemote::Base
|
|
18
18
|
attribute :net_sales, :float
|
19
19
|
|
20
20
|
has_many :posts
|
21
|
-
has_many :user_posts, :
|
22
|
-
has_many :flagged_posts, :
|
23
|
-
has_many :bestseller_posts, :
|
21
|
+
has_many :user_posts, class_name: "::Post", scope: :user_guid
|
22
|
+
has_many :flagged_posts, class_name: "::Post"
|
23
|
+
has_many :bestseller_posts, class_name: "::Post", foreign_key: :bestseller_guid
|
24
24
|
|
25
25
|
belongs_to :category
|
26
26
|
end
|
@@ -13,7 +13,7 @@ class Category < ::ActiveRemote::Base
|
|
13
13
|
has_many :posts
|
14
14
|
|
15
15
|
has_one :author
|
16
|
-
has_one :senior_author, :
|
17
|
-
has_one :primary_editor, :
|
18
|
-
has_one :chief_editor, :
|
16
|
+
has_one :senior_author, class_name: "::Author"
|
17
|
+
has_one :primary_editor, class_name: "::Author", foreign_key: :editor_guid
|
18
|
+
has_one :chief_editor, class_name: "::Author", scope: :user_guid, foreign_key: :chief_editor_guid
|
19
19
|
end
|
@@ -6,7 +6,7 @@ require "support/protobuf/author.pb"
|
|
6
6
|
class DefaultAuthor < ::ActiveRemote::Base
|
7
7
|
service_class ::Generic::Remote::AuthorService
|
8
8
|
|
9
|
-
attribute :guid, :string, :
|
10
|
-
attribute :name, :string, :
|
11
|
-
attribute :books, :
|
9
|
+
attribute :guid, :string, default: lambda { 100 }
|
10
|
+
attribute :name, :string, default: "John Doe"
|
11
|
+
attribute :books, default: []
|
12
12
|
end
|
data/spec/support/models/post.rb
CHANGED
@@ -13,9 +13,9 @@ class Post < ::ActiveRemote::Base
|
|
13
13
|
attribute :bestseller_guid, :string
|
14
14
|
|
15
15
|
belongs_to :author
|
16
|
-
belongs_to :coauthor, :
|
17
|
-
belongs_to :bestseller, :
|
18
|
-
belongs_to :user, :
|
16
|
+
belongs_to :coauthor, class_name: "::Author"
|
17
|
+
belongs_to :bestseller, class_name: "::Author", foreign_key: :bestseller_guid
|
18
|
+
belongs_to :user, class_name: "::Author", scope: :user_guid
|
19
19
|
|
20
|
-
validates :name, :
|
20
|
+
validates :name, presence: true
|
21
21
|
end
|
@@ -1,16 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
##
|
4
2
|
# This file is auto-generated. DO NOT EDIT!
|
5
3
|
#
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
4
|
+
require "protobuf"
|
5
|
+
require "protobuf/rpc/service"
|
9
6
|
|
10
7
|
##
|
11
8
|
# Imports
|
12
9
|
#
|
13
|
-
require
|
10
|
+
require "error.pb"
|
14
11
|
|
15
12
|
module Generic
|
16
13
|
module Remote
|
@@ -20,9 +17,10 @@ module Generic
|
|
20
17
|
# Message Classes
|
21
18
|
#
|
22
19
|
class Author < ::Protobuf::Message; end
|
20
|
+
|
23
21
|
class Authors < ::Protobuf::Message; end
|
24
|
-
class AuthorRequest < ::Protobuf::Message; end
|
25
22
|
|
23
|
+
class AuthorRequest < ::Protobuf::Message; end
|
26
24
|
|
27
25
|
##
|
28
26
|
# Message Fields
|
@@ -43,7 +41,6 @@ module Generic
|
|
43
41
|
repeated :string, :name, 2
|
44
42
|
end
|
45
43
|
|
46
|
-
|
47
44
|
##
|
48
45
|
# Service Classes
|
49
46
|
#
|
@@ -57,8 +54,5 @@ module Generic
|
|
57
54
|
rpc :delete_all, ::Generic::Remote::Authors, ::Generic::Remote::Authors
|
58
55
|
rpc :destroy_all, ::Generic::Remote::Authors, ::Generic::Remote::Authors
|
59
56
|
end
|
60
|
-
|
61
57
|
end
|
62
|
-
|
63
58
|
end
|
64
|
-
|
@@ -1,16 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
##
|
4
2
|
# This file is auto-generated. DO NOT EDIT!
|
5
3
|
#
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
4
|
+
require "protobuf"
|
5
|
+
require "protobuf/rpc/service"
|
9
6
|
|
10
7
|
##
|
11
8
|
# Imports
|
12
9
|
#
|
13
|
-
require
|
10
|
+
require "error.pb"
|
14
11
|
|
15
12
|
module Generic
|
16
13
|
module Remote
|
@@ -20,9 +17,10 @@ module Generic
|
|
20
17
|
# Message Classes
|
21
18
|
#
|
22
19
|
class Category < ::Protobuf::Message; end
|
20
|
+
|
23
21
|
class Categories < ::Protobuf::Message; end
|
24
|
-
class CategoryRequest < ::Protobuf::Message; end
|
25
22
|
|
23
|
+
class CategoryRequest < ::Protobuf::Message; end
|
26
24
|
|
27
25
|
##
|
28
26
|
# Message Fields
|
@@ -46,7 +44,6 @@ module Generic
|
|
46
44
|
repeated :string, :name, 2
|
47
45
|
end
|
48
46
|
|
49
|
-
|
50
47
|
##
|
51
48
|
# Service Classes
|
52
49
|
#
|
@@ -60,8 +57,5 @@ module Generic
|
|
60
57
|
rpc :delete_all, ::Generic::Remote::Categories, ::Generic::Remote::Categories
|
61
58
|
rpc :destroy_all, ::Generic::Remote::Categories, ::Generic::Remote::Categories
|
62
59
|
end
|
63
|
-
|
64
60
|
end
|
65
|
-
|
66
61
|
end
|
67
|
-
|
@@ -1,9 +1,7 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
##
|
4
2
|
# This file is auto-generated. DO NOT EDIT!
|
5
3
|
#
|
6
|
-
require
|
4
|
+
require "protobuf"
|
7
5
|
|
8
6
|
module Generic
|
9
7
|
::Protobuf::Optionable.inject(self) { ::Google::Protobuf::FileOptions }
|
@@ -13,7 +11,6 @@ module Generic
|
|
13
11
|
#
|
14
12
|
class Error < ::Protobuf::Message; end
|
15
13
|
|
16
|
-
|
17
14
|
##
|
18
15
|
# Message Fields
|
19
16
|
#
|
@@ -21,6 +18,4 @@ module Generic
|
|
21
18
|
optional :string, :field, 1
|
22
19
|
optional :string, :message, 2
|
23
20
|
end
|
24
|
-
|
25
21
|
end
|
26
|
-
|