tessa 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tessa/model.rb +9 -1
- data/lib/tessa/version.rb +1 -1
- data/spec/tessa/model_spec.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 834d04ed4ba25a28ea451b5949d747bf38b8d3da
|
4
|
+
data.tar.gz: 2cf692ef3814562a77da8672a3e530d251a496e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83141404ec0a5e0ca3539ce50d95f6966431f92995f3901de681dfd6d17f5d3231fa6e5b2da0b67a4b87bbace5209e4ecc842e257763f0707003cf93c703f618
|
7
|
+
data.tar.gz: 1fc5949c63c52b4f43c79d75cd1038700327d276b007d99a66f380a667bdfc33ae0b878a8ad7c56626bfa8967b7e0bb20e0bdff245d7bfaa2012c668a28dee86
|
data/lib/tessa/model.rb
CHANGED
@@ -32,6 +32,14 @@ module Tessa
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def fetch_tessa_remote_assets(ids)
|
36
|
+
if [*ids].empty?
|
37
|
+
[] if ids.is_a?(Array)
|
38
|
+
else
|
39
|
+
Tessa::Asset.find(ids)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
35
43
|
end
|
36
44
|
|
37
45
|
module ClassMethods
|
@@ -45,7 +53,7 @@ module Tessa
|
|
45
53
|
else
|
46
54
|
instance_variable_set(
|
47
55
|
ivar,
|
48
|
-
|
56
|
+
fetch_tessa_remote_assets(field.id(on: self))
|
49
57
|
)
|
50
58
|
end
|
51
59
|
end
|
data/lib/tessa/version.rb
CHANGED
data/spec/tessa/model_spec.rb
CHANGED
@@ -256,10 +256,19 @@ RSpec.describe Tessa::Model do
|
|
256
256
|
end
|
257
257
|
|
258
258
|
it "caches the result" do
|
259
|
+
instance.file_ids = [1]
|
259
260
|
expect(Tessa::Asset).to receive(:find).and_return(:val).once
|
260
261
|
instance.file
|
261
262
|
instance.file
|
262
263
|
end
|
264
|
+
|
265
|
+
context "with no values" do
|
266
|
+
it "does not call find" do
|
267
|
+
instance.file_ids = []
|
268
|
+
expect(Tessa::Asset).not_to receive(:find)
|
269
|
+
expect(instance.file).to eq([])
|
270
|
+
end
|
271
|
+
end
|
263
272
|
end
|
264
273
|
|
265
274
|
context "with a singular typed field" do
|
@@ -275,10 +284,19 @@ RSpec.describe Tessa::Model do
|
|
275
284
|
end
|
276
285
|
|
277
286
|
it "caches the result" do
|
287
|
+
instance.file_id = 1
|
278
288
|
expect(Tessa::Asset).to receive(:find).and_return(:val).once
|
279
289
|
instance.file
|
280
290
|
instance.file
|
281
291
|
end
|
292
|
+
|
293
|
+
context "with nil value" do
|
294
|
+
it "does not call find" do
|
295
|
+
instance.file_id = nil
|
296
|
+
expect(Tessa::Asset).not_to receive(:find)
|
297
|
+
expect(instance.file).to be_nil
|
298
|
+
end
|
299
|
+
end
|
282
300
|
end
|
283
301
|
end
|
284
302
|
|