active_remote 7.1.0 → 7.2.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/.rspec +1 -1
- data/.standard.yml +2 -1
- data/{CHANGES.md → CHANGELOG.md} +10 -4
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +13 -8
- data/lib/active_remote/association.rb +8 -13
- data/lib/active_remote/attribute_methods.rb +1 -1
- data/lib/active_remote/base.rb +2 -4
- data/lib/active_remote/dirty.rb +0 -32
- data/lib/active_remote/version.rb +1 -1
- metadata +18 -186
- data/.github/workflows/main.yml +0 -41
- data/.gitignore +0 -13
- data/Gemfile +0 -4
- data/LICENSE +0 -22
- data/active_remote.gemspec +0 -38
- data/bin/benchmark +0 -43
- data/bin/console +0 -10
- data/spec/lib/active_remote/association_spec.rb +0 -257
- data/spec/lib/active_remote/base_spec.rb +0 -10
- data/spec/lib/active_remote/dirty_spec.rb +0 -93
- data/spec/lib/active_remote/dsl_spec.rb +0 -85
- data/spec/lib/active_remote/errors_spec.rb +0 -31
- data/spec/lib/active_remote/integration_spec.rb +0 -111
- data/spec/lib/active_remote/persistence_spec.rb +0 -416
- data/spec/lib/active_remote/primary_key_spec.rb +0 -49
- data/spec/lib/active_remote/query_attribute_spec.rb +0 -43
- data/spec/lib/active_remote/rpc_adapters/protobuf_adapter_spec.rb +0 -24
- data/spec/lib/active_remote/rpc_spec.rb +0 -86
- data/spec/lib/active_remote/scope_keys_spec.rb +0 -42
- data/spec/lib/active_remote/search_spec.rb +0 -114
- data/spec/lib/active_remote/serialization_spec.rb +0 -33
- data/spec/lib/active_remote/serializers/protobuf_spec.rb +0 -89
- data/spec/lib/active_remote/validations_spec.rb +0 -56
- data/spec/spec_helper.rb +0 -29
- data/spec/support/definitions/author.proto +0 -30
- data/spec/support/definitions/category.proto +0 -33
- data/spec/support/definitions/error.proto +0 -6
- data/spec/support/definitions/post.proto +0 -35
- data/spec/support/definitions/serializer.proto +0 -23
- data/spec/support/definitions/tag.proto +0 -30
- data/spec/support/helpers.rb +0 -35
- data/spec/support/models/author.rb +0 -26
- data/spec/support/models/category.rb +0 -19
- data/spec/support/models/default_author.rb +0 -12
- data/spec/support/models/message_with_options.rb +0 -11
- data/spec/support/models/no_attributes.rb +0 -2
- data/spec/support/models/post.rb +0 -21
- data/spec/support/models/tag.rb +0 -22
- data/spec/support/models.rb +0 -7
- data/spec/support/protobuf/author.pb.rb +0 -58
- data/spec/support/protobuf/category.pb.rb +0 -61
- data/spec/support/protobuf/error.pb.rb +0 -21
- data/spec/support/protobuf/post.pb.rb +0 -63
- data/spec/support/protobuf/serializer.pb.rb +0 -36
- data/spec/support/protobuf/tag.pb.rb +0 -58
- data/spec/support/protobuf.rb +0 -5
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ::ActiveRemote::Integration do
|
|
4
|
-
let(:guid) { "GUID-derp" }
|
|
5
|
-
let(:tag) { ::Tag.new(guid: guid) }
|
|
6
|
-
|
|
7
|
-
subject { tag }
|
|
8
|
-
|
|
9
|
-
context ".to_param" do
|
|
10
|
-
specify { expect(::Tag).to respond_to(:to_param) }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
context "#to_param" do
|
|
14
|
-
specify { expect(subject).to respond_to(:to_param) }
|
|
15
|
-
|
|
16
|
-
it "returns the guid if the guid is present (by default)" do
|
|
17
|
-
expect(tag.to_param).to eq(guid)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "#cache_key" do
|
|
22
|
-
specify { expect(subject).to respond_to(:cache_key) }
|
|
23
|
-
|
|
24
|
-
it "sets 'new' as the identifier when the record has not been persisted" do
|
|
25
|
-
expect(tag).to receive(:new_record?).and_return(true)
|
|
26
|
-
expect(tag.cache_key).to match(/tags\/new/)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "sets the cache_key to the class/guid as a default" do
|
|
30
|
-
expect(tag).to receive(:new_record?).and_return(false)
|
|
31
|
-
expect(tag.cache_key).to eq("tags/#{guid}")
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "adds the 'updated_at' attribute to the cache_key if updated_at is present" do
|
|
35
|
-
::ActiveRemote.config.default_cache_key_updated_at = true
|
|
36
|
-
twenty_o_one_one = tag.updated_at = DateTime.new(2001, 0o1, 0o1)
|
|
37
|
-
expect(tag).to receive(:new_record?).and_return(false)
|
|
38
|
-
expect(tag.cache_key).to eq("tags/#{guid}-#{twenty_o_one_one.to_fs(:usec)}")
|
|
39
|
-
tag.updated_at = nil
|
|
40
|
-
::ActiveRemote.config.default_cache_key_updated_at = false
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "defaults the cache updated_at to false" do
|
|
44
|
-
expect(::ActiveRemote.config.default_cache_key_updated_at?).to be_falsey
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "#cache_key_with_version" do
|
|
49
|
-
let(:tag) { ::Tag.new(guid: guid, updated_at: ::DateTime.current) }
|
|
50
|
-
|
|
51
|
-
specify { expect(subject).to respond_to(:cache_key_with_version) }
|
|
52
|
-
|
|
53
|
-
context "when cache versioning is enabled" do
|
|
54
|
-
around do |example|
|
|
55
|
-
cache_versioning_value = ::Tag.cache_versioning
|
|
56
|
-
::Tag.cache_versioning = true
|
|
57
|
-
example.run
|
|
58
|
-
::Tag.cache_versioning = cache_versioning_value
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "returns a cache key with the version" do
|
|
62
|
-
expect(tag.cache_version).to be_present
|
|
63
|
-
expect(tag.cache_key_with_version).to eq("#{tag.cache_key}-#{tag.cache_version}")
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context "when cache versioning is not enabled" do
|
|
68
|
-
around do |example|
|
|
69
|
-
cache_versioning_value = ::Tag.cache_versioning
|
|
70
|
-
::Tag.cache_versioning = false
|
|
71
|
-
example.run
|
|
72
|
-
::Tag.cache_versioning = cache_versioning_value
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "returns a cache key without the version" do
|
|
76
|
-
expect(tag.cache_key_with_version).to eq(tag.cache_key)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
describe "#cache_version" do
|
|
82
|
-
specify { expect(subject).to respond_to(:cache_version) }
|
|
83
|
-
|
|
84
|
-
context "when cache versioning is enabled" do
|
|
85
|
-
around do |example|
|
|
86
|
-
cache_versioning_value = ::Tag.cache_versioning
|
|
87
|
-
::Tag.cache_versioning = true
|
|
88
|
-
example.run
|
|
89
|
-
::Tag.cache_versioning = cache_versioning_value
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "returns a cache version" do
|
|
93
|
-
tag.updated_at = DateTime.new(2001, 0o1, 0o1)
|
|
94
|
-
expect(tag.cache_version).to eq(tag.updated_at.utc.to_fs(:usec))
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "when cache versioning is not enabled" do
|
|
99
|
-
around do |example|
|
|
100
|
-
cache_versioning_value = ::Tag.cache_versioning
|
|
101
|
-
::Tag.cache_versioning = false
|
|
102
|
-
example.run
|
|
103
|
-
::Tag.cache_versioning = cache_versioning_value
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "returns nil" do
|
|
107
|
-
expect(tag.cache_version).to be_nil
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ::ActiveRemote::Persistence do
|
|
4
|
-
let(:response_without_errors) { ::HashWithIndifferentAccess.new(errors: []) }
|
|
5
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
|
6
|
-
|
|
7
|
-
subject { ::Tag.new }
|
|
8
|
-
|
|
9
|
-
before {
|
|
10
|
-
allow(rpc).to receive(:execute).and_return(response_without_errors)
|
|
11
|
-
allow(Tag).to receive(:rpc).and_return(rpc)
|
|
12
|
-
}
|
|
13
|
-
after { allow(::Tag).to receive(:rpc).and_call_original }
|
|
14
|
-
|
|
15
|
-
describe ".create" do
|
|
16
|
-
it "runs create callbacks" do
|
|
17
|
-
expect_any_instance_of(Tag).to receive(:after_create_callback)
|
|
18
|
-
Tag.create(name: "foo")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "initializes and saves a new record" do
|
|
22
|
-
expect_any_instance_of(Tag).to receive(:save)
|
|
23
|
-
Tag.create(name: "foo")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "returns a new record" do
|
|
27
|
-
value = Tag.create(name: "foo")
|
|
28
|
-
expect(value).to be_a(Tag)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe ".create!" do
|
|
33
|
-
it "initializes and saves a new record" do
|
|
34
|
-
expect_any_instance_of(Tag).to receive(:save!)
|
|
35
|
-
Tag.create!(name: "foo")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "when the record has errors" do
|
|
39
|
-
before { allow_any_instance_of(Tag).to receive(:save!).and_raise(ActiveRemote::ActiveRemoteError) }
|
|
40
|
-
|
|
41
|
-
it "raises an exception" do
|
|
42
|
-
expect { Tag.create!(name: "foo") }.to raise_error(ActiveRemote::ActiveRemoteError)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe "#delete" do
|
|
48
|
-
it "deletes a remote record" do
|
|
49
|
-
expect(rpc).to receive(:execute).with(:delete, subject.scope_key_hash)
|
|
50
|
-
subject.delete
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "when the record doesn't have errors" do
|
|
54
|
-
it "freezes the record" do
|
|
55
|
-
subject.delete
|
|
56
|
-
expect(subject.frozen?).to be_truthy
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "when the response has errors" do
|
|
61
|
-
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
|
62
|
-
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
|
63
|
-
|
|
64
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
65
|
-
|
|
66
|
-
it "adds the errors to the record" do
|
|
67
|
-
subject.delete
|
|
68
|
-
expect(subject.has_errors?).to be_truthy
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "returns false" do
|
|
72
|
-
expect(subject.delete).to be_falsey
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "#delete!" do
|
|
78
|
-
it "deletes a remote record" do
|
|
79
|
-
expect(rpc).to receive(:execute).with(:delete, subject.scope_key_hash)
|
|
80
|
-
subject.delete!
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "when an error occurs" do
|
|
84
|
-
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
|
85
|
-
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
|
86
|
-
|
|
87
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
88
|
-
|
|
89
|
-
it "raises an exception" do
|
|
90
|
-
expect { subject.delete! }.to raise_error(ActiveRemote::ActiveRemoteError)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe "#destroy" do
|
|
96
|
-
it "destroys a remote record" do
|
|
97
|
-
expect(rpc).to receive(:execute).with(:destroy, subject.scope_key_hash)
|
|
98
|
-
subject.destroy
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
context "when the record doesn't have errors" do
|
|
102
|
-
it "freezes the record" do
|
|
103
|
-
subject.destroy
|
|
104
|
-
expect(subject.frozen?).to be_truthy
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "when the response has errors" do
|
|
109
|
-
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
|
110
|
-
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
|
111
|
-
|
|
112
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
113
|
-
|
|
114
|
-
it "adds the errors to the record" do
|
|
115
|
-
subject.destroy
|
|
116
|
-
expect(subject.has_errors?).to be_truthy
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "returns false" do
|
|
120
|
-
expect(subject.destroy).to be_falsey
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
describe "#destroy!" do
|
|
126
|
-
it "destroys a remote record" do
|
|
127
|
-
expect(rpc).to receive(:execute).with(:destroy, subject.scope_key_hash)
|
|
128
|
-
subject.destroy!
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
context "when an error occurs" do
|
|
132
|
-
let(:error) { Generic::Error.new(field: "name", message: "Boom!") }
|
|
133
|
-
let(:response) { Generic::Remote::Tag.new(errors: [error]) }
|
|
134
|
-
|
|
135
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
136
|
-
|
|
137
|
-
it "raises an exception" do
|
|
138
|
-
expect { subject.destroy! }.to raise_error(ActiveRemote::ActiveRemoteError)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe "#has_errors?" do
|
|
144
|
-
context "when errors are not present" do
|
|
145
|
-
before { subject.errors.clear }
|
|
146
|
-
|
|
147
|
-
its(:has_errors?) { should be_falsey }
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "when errors are present" do
|
|
151
|
-
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
|
152
|
-
|
|
153
|
-
its(:has_errors?) { should be_truthy }
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
describe "#new_record?" do
|
|
158
|
-
context "when the record is created through instantiate" do
|
|
159
|
-
subject { Tag.instantiate(guid: "foo") }
|
|
160
|
-
|
|
161
|
-
its(:new_record?) { should be_falsey }
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
context "when the record is persisted" do
|
|
165
|
-
subject { Tag.allocate.instantiate(guid: "foo") }
|
|
166
|
-
|
|
167
|
-
its(:new_record?) { should be_falsey }
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
context "when the record is not persisted" do
|
|
171
|
-
subject { Tag.new }
|
|
172
|
-
|
|
173
|
-
its(:new_record?) { should be_truthy }
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe "#persisted?" do
|
|
178
|
-
context "when the record is persisted" do
|
|
179
|
-
subject { Tag.allocate.instantiate(guid: "foo") }
|
|
180
|
-
|
|
181
|
-
its(:persisted?) { should be_truthy }
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "when the record is not persisted" do
|
|
185
|
-
subject { Tag.new }
|
|
186
|
-
|
|
187
|
-
its(:persisted?) { should be_falsey }
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe "#readonly?" do
|
|
192
|
-
context "when the record is created through instantiate with options[:readonly]" do
|
|
193
|
-
subject { Tag.instantiate({guid: "foo"}, readonly: true) }
|
|
194
|
-
|
|
195
|
-
its(:new_record?) { should be_falsey }
|
|
196
|
-
its(:readonly?) { should be_truthy }
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
describe "#remote" do
|
|
201
|
-
let(:response) { ::Generic::Remote::Tag.new(guid: tag.guid, name: "bar") }
|
|
202
|
-
let(:rpc) { ::ActiveRemote::RPCAdapters::ProtobufAdapter.new(::Tag.service_class, ::Tag.endpoints) }
|
|
203
|
-
let(:tag) { ::Tag.new(guid: SecureRandom.uuid) }
|
|
204
|
-
|
|
205
|
-
subject { tag }
|
|
206
|
-
|
|
207
|
-
before do
|
|
208
|
-
allow(::Tag).to receive(:rpc).and_return(rpc)
|
|
209
|
-
allow(rpc).to receive(:execute).and_return(response)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "calls the given RPC method with default args" do
|
|
213
|
-
expect(::Tag.rpc).to receive(:execute).with(:remote_method, tag.scope_key_hash)
|
|
214
|
-
tag.remote(:remote_method)
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
it "updates the attributes from the response" do
|
|
218
|
-
expect { tag.remote(:remote_method) }.to change { tag.name }.to(response.name)
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
it "returns true" do
|
|
222
|
-
expect(tag.remote(:remote_method)).to be(true)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
context "when request args are given" do
|
|
226
|
-
it "calls the given RPC method with default args" do
|
|
227
|
-
attributes = {guid: tag.guid, name: "foo"}
|
|
228
|
-
expect(::Tag.rpc).to receive(:execute).with(:remote_method, attributes)
|
|
229
|
-
tag.remote(:remote_method, attributes)
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
context "when response does not respond to errors" do
|
|
234
|
-
it "returns true" do
|
|
235
|
-
allow(rpc).to receive(:execute).and_return(double(:response, to_hash: {}))
|
|
236
|
-
expect(tag.remote(:remote_method)).to be(true)
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
context "when errors are returned" do
|
|
241
|
-
let(:response) {
|
|
242
|
-
::Generic::Remote::Tag.new(guid: tag.guid, name: "bar", errors: [{field: "name", message: "message"}])
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
it "adds errors from the response" do
|
|
246
|
-
expect { tag.remote(:remote_method) }.to change { tag.has_errors? }.to(true)
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
it "returns false" do
|
|
250
|
-
expect(tag.remote(:remote_method)).to be(false)
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
describe "#save" do
|
|
256
|
-
it "runs save callbacks" do
|
|
257
|
-
allow(subject).to receive(:run_callbacks).with(:validation).and_return(true)
|
|
258
|
-
expect(subject).to receive(:run_callbacks).with(:save)
|
|
259
|
-
subject.save
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
context "when the record is new" do
|
|
263
|
-
subject { Tag.new }
|
|
264
|
-
|
|
265
|
-
it "creates the record" do
|
|
266
|
-
expected_attributes = subject.attributes
|
|
267
|
-
expect(rpc).to receive(:execute).with(:create, expected_attributes)
|
|
268
|
-
subject.save
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
context "when the record is not new" do
|
|
273
|
-
let(:attributes) { {"guid" => "foo"} }
|
|
274
|
-
|
|
275
|
-
subject { Tag.allocate.instantiate(attributes) }
|
|
276
|
-
|
|
277
|
-
it "updates the record" do
|
|
278
|
-
expect(rpc).to receive(:execute).with(:update, attributes)
|
|
279
|
-
subject.save
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
context "when the record is saved" do
|
|
284
|
-
it "returns true" do
|
|
285
|
-
allow(subject).to receive(:has_errors?) { false }
|
|
286
|
-
expect(subject.save).to be_truthy
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
context "when the record is not saved" do
|
|
291
|
-
it "returns false" do
|
|
292
|
-
allow(subject).to receive(:has_errors?) { true }
|
|
293
|
-
expect(subject.save).to be_falsey
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
context "when the record has errors before the save" do
|
|
298
|
-
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
|
299
|
-
|
|
300
|
-
it "clears the errors before the save" do
|
|
301
|
-
expect(subject.errors).not_to be_empty
|
|
302
|
-
expect(subject.save).to be_truthy
|
|
303
|
-
expect(subject.errors).to be_empty
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
describe "#save!" do
|
|
309
|
-
context "when the record is saved" do
|
|
310
|
-
it "returns true" do
|
|
311
|
-
allow(subject).to receive(:save).and_return(true)
|
|
312
|
-
expect(subject.save!).to be_truthy
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
context "when the record is not saved" do
|
|
317
|
-
let(:errors) {
|
|
318
|
-
[Generic::Error.new(field: "name", message: "Error one!"),
|
|
319
|
-
Generic::Error.new(field: "name", message: "Error two!")]
|
|
320
|
-
}
|
|
321
|
-
let(:response) { Generic::Remote::Tag.new(errors: errors) }
|
|
322
|
-
before { allow(rpc).to receive(:execute).and_return(response) }
|
|
323
|
-
|
|
324
|
-
it "raises an exception" do
|
|
325
|
-
expect { subject.save! }
|
|
326
|
-
.to raise_error(ActiveRemote::RemoteRecordNotSaved, "Name Error one!, Name Error two!")
|
|
327
|
-
end
|
|
328
|
-
end
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
describe "#success?" do
|
|
332
|
-
context "when errors are present" do
|
|
333
|
-
before { subject.errors.add(:base, :invalid, message: "Boom!") }
|
|
334
|
-
|
|
335
|
-
its(:success?) { should be_falsey }
|
|
336
|
-
end
|
|
337
|
-
|
|
338
|
-
context "when errors are not present" do
|
|
339
|
-
before { subject.errors.clear }
|
|
340
|
-
|
|
341
|
-
its(:success?) { should be_truthy }
|
|
342
|
-
end
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
describe "#update_attribute" do
|
|
346
|
-
let(:tag) { Tag.allocate.instantiate(guid: "123") }
|
|
347
|
-
|
|
348
|
-
it "runs update callbacks" do
|
|
349
|
-
expect(tag).to receive(:after_update_callback)
|
|
350
|
-
tag.update_attribute(:name, "foo")
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
it "updates a remote record" do
|
|
354
|
-
expect(rpc).to receive(:execute).with(:update, {"name" => "foo", "guid" => "123"})
|
|
355
|
-
tag.update_attribute(:name, "foo")
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
before { allow(subject).to receive(:save) }
|
|
359
|
-
after { allow(subject).to receive(:save).and_call_original }
|
|
360
|
-
|
|
361
|
-
it "assigns new attributes" do
|
|
362
|
-
expect(subject).to receive(:name=).with("foo")
|
|
363
|
-
subject.update_attribute(:name, "foo")
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
it "saves the record" do
|
|
367
|
-
expect(subject).to receive(:save)
|
|
368
|
-
subject.update_attribute(:name, "foo")
|
|
369
|
-
end
|
|
370
|
-
end
|
|
371
|
-
|
|
372
|
-
describe "#update_attributes" do
|
|
373
|
-
let(:attributes) { HashWithIndifferentAccess.new(name: "bar") }
|
|
374
|
-
let(:tag) { Tag.allocate.instantiate(guid: "123") }
|
|
375
|
-
|
|
376
|
-
it "runs update callbacks" do
|
|
377
|
-
expect(tag).to receive(:after_update_callback)
|
|
378
|
-
tag.update({})
|
|
379
|
-
end
|
|
380
|
-
|
|
381
|
-
it "updates a remote record" do
|
|
382
|
-
expect(rpc).to receive(:execute).with(:update, tag.scope_key_hash)
|
|
383
|
-
tag.update({})
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
before { allow(subject).to receive(:save) }
|
|
387
|
-
after { allow(subject).to receive(:save).and_call_original }
|
|
388
|
-
|
|
389
|
-
it "assigns new attributes" do
|
|
390
|
-
expect(subject).to receive(:assign_attributes).with(attributes)
|
|
391
|
-
subject.update(attributes)
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
it "saves the record" do
|
|
395
|
-
expect(subject).to receive(:save)
|
|
396
|
-
subject.update(attributes)
|
|
397
|
-
end
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
describe "#update_attributes!" do
|
|
401
|
-
let(:attributes) { HashWithIndifferentAccess.new(name: "bar") }
|
|
402
|
-
|
|
403
|
-
before { allow(subject).to receive(:save!) }
|
|
404
|
-
after { allow(subject).to receive(:save!).and_call_original }
|
|
405
|
-
|
|
406
|
-
it "assigns new attributes" do
|
|
407
|
-
expect(subject).to receive(:assign_attributes).with(attributes)
|
|
408
|
-
subject.update!(attributes)
|
|
409
|
-
end
|
|
410
|
-
|
|
411
|
-
it "saves! the record" do
|
|
412
|
-
expect(subject).to receive(:save!)
|
|
413
|
-
subject.update!(attributes)
|
|
414
|
-
end
|
|
415
|
-
end
|
|
416
|
-
end
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::PrimaryKey do
|
|
4
|
-
let(:tag) { Tag.new(id: "1234", guid: "TAG-123", user_guid: "USR-123") }
|
|
5
|
-
|
|
6
|
-
after { Tag.instance_variable_set :@primary_key, nil }
|
|
7
|
-
|
|
8
|
-
describe ".default_primary_key" do
|
|
9
|
-
it "returns array of :guid" do
|
|
10
|
-
expect(Tag.default_primary_key).to eq(:guid)
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "primary_key" do
|
|
15
|
-
context "when no arguments are passed" do
|
|
16
|
-
it "returns default primary key" do
|
|
17
|
-
expect(Tag.primary_key).to eq(:guid)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "when arguments are passed" do
|
|
22
|
-
let(:specified_primary_key) { :name }
|
|
23
|
-
|
|
24
|
-
it "returns the given primary key" do
|
|
25
|
-
expect(Tag.primary_key(specified_primary_key)).to eq(specified_primary_key)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "#primary_key" do
|
|
31
|
-
it "returns the primary key for the class" do
|
|
32
|
-
expect(Tag.new.primary_key).to eq Tag.primary_key
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe "#to_key" do
|
|
37
|
-
context "when no primary key is specified and default of guid does not exist" do
|
|
38
|
-
it "returns nil" do
|
|
39
|
-
expect(NoAttributes.new.to_key).to eq nil
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when no primary key is specified, but default of guid exists" do
|
|
44
|
-
it "returns guid in array" do
|
|
45
|
-
expect(Tag.new(guid: "TAG-123").to_key).to eq ["TAG-123"]
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ::ActiveRemote::QueryAttributes do
|
|
4
|
-
subject { ::Author.new }
|
|
5
|
-
|
|
6
|
-
describe "#query_attribute" do
|
|
7
|
-
it "is false when the attribute is false" do
|
|
8
|
-
subject.writes_fiction = false
|
|
9
|
-
expect(subject.writes_fiction?).to eq false
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "is true when the attribute is true" do
|
|
13
|
-
subject.writes_fiction = true
|
|
14
|
-
expect(subject.writes_fiction?).to eq true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "is false when the attribute is nil" do
|
|
18
|
-
subject.name = nil
|
|
19
|
-
expect(subject.name?).to eq false
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "is false when the attribute is an empty string" do
|
|
23
|
-
subject.name = ""
|
|
24
|
-
expect(subject.name?).to eq false
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "is true when the attribute is a non-empty string" do
|
|
28
|
-
subject.name = "Chris"
|
|
29
|
-
expect(subject.name?).to eq true
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# This behavior varies from ActiveRecord, so we test it explicitly
|
|
33
|
-
it "is true when the attribute is 0" do
|
|
34
|
-
subject.age = 0
|
|
35
|
-
expect(subject.age?).to eq true
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "is true when the attribute is 1" do
|
|
39
|
-
subject.age = 1
|
|
40
|
-
expect(subject.age?).to eq true
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe ActiveRemote::RPCAdapters::ProtobufAdapter do
|
|
4
|
-
let(:adapter) { ActiveRemote::RPCAdapters::ProtobufAdapter.new(Tag.service_class, Tag.endpoints) }
|
|
5
|
-
let(:client) { double(:client) }
|
|
6
|
-
|
|
7
|
-
subject { adapter }
|
|
8
|
-
|
|
9
|
-
# The Protobuf RPC client relies on method missing and delegations
|
|
10
|
-
# Provide a client double to make it possible to add expectations that specific methods are called
|
|
11
|
-
before { allow(adapter).to receive(:client).and_return(client) }
|
|
12
|
-
|
|
13
|
-
describe "#execute" do
|
|
14
|
-
context "when a custom endpoint is defined" do
|
|
15
|
-
before { adapter.endpoints[:create] = :register }
|
|
16
|
-
after { adapter.endpoints[:create] = :create }
|
|
17
|
-
|
|
18
|
-
it "calls the custom endpoint" do
|
|
19
|
-
expect(adapter.client).to receive(:register)
|
|
20
|
-
adapter.execute(:create, name: "foo")
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|