saviour 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3759ef570763d52959c2939288131c3065fac5018e2abe0465b7098eb2572180
4
- data.tar.gz: b5b51017fdc09079ad4c086340d9eba67e66e282ae86cc5d745cc4038ccc5c2f
3
+ metadata.gz: d28e5f8f325721c27a7f763b9733070cf20e3dce6a9acfa7253249a7995ae51c
4
+ data.tar.gz: d5d81ed8993b2c848d4746e85bd9686c291dff58d61bd3f7eebbdc7f6099246f
5
5
  SHA512:
6
- metadata.gz: 56e95d8e497c5c1284fc0bc8e89fc182dcf8b044cc8d100e2925152816dacd4ce45ece02ef3253e75dd424c53d8afb73e44ceaa35f23f93d0c00ef9be7c242ef
7
- data.tar.gz: 3477c312dd0f3d630ce43cbefc519f7db74c9b8b9d45c1f6f6b708ee0fb3038642fe8cc4ac220b198b3303d0f5dc55d6b9f3008ac357de2888cfd71ce6fa1295
6
+ metadata.gz: 7ac2b201f3aad2cdd39cb8092d0becdc9d1833f508971f3a33d1d460a9abf83199d6ed9caab807ec72217191adee0585c5cbb53162d3c87e92d46dd34491fd98
7
+ data.tar.gz: 6ee49e6b551deadf44596066c96a89bcb0dab781e0d7693b99c9af9687b6584bf8b4da58319ce0917cf12c85010aa83b04ae74262cba96b065d272c3e1148ac2
data/lib/saviour/file.rb CHANGED
@@ -19,7 +19,8 @@ module Saviour
19
19
  end
20
20
 
21
21
  def read
22
- persisted? && Config.storage.read(@persisted_path)
22
+ return nil unless persisted?
23
+ Config.storage.read(@persisted_path)
23
24
  end
24
25
 
25
26
  def delete
@@ -30,7 +31,8 @@ module Saviour
30
31
  end
31
32
 
32
33
  def public_url
33
- persisted? && Config.storage.public_url(@persisted_path)
34
+ return nil unless persisted?
35
+ Config.storage.public_url(@persisted_path)
34
36
  end
35
37
 
36
38
  def ==(another_file)
data/lib/saviour/model.rb CHANGED
@@ -13,7 +13,7 @@ module Saviour
13
13
  end
14
14
  end
15
15
 
16
- def reload
16
+ def reload(*args)
17
17
  self.class.attached_files.each do |attach_as|
18
18
  instance_variable_set("@__uploader_#{attach_as}", nil)
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.4.11"
2
+ VERSION = "0.4.12"
3
3
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Introspection of attached files" do
4
+ before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
5
+
6
+ let(:uploader) {
7
+ Class.new(Saviour::BaseUploader) do
8
+ store_dir { "/store/dir" }
9
+ end
10
+ }
11
+
12
+ let(:uploader_for_version) {
13
+ Class.new(Saviour::BaseUploader) do
14
+ store_dir { "/store/dir" }
15
+
16
+ process do |contents, filename|
17
+ [contents, "new_#{filename}"]
18
+ end
19
+ end
20
+ }
21
+
22
+ let(:klass) {
23
+ a = Class.new(Test) { include Saviour::Model }
24
+ a.attach_file :file, uploader
25
+ a.attach_file :file_thumb, uploader_for_version, follow: :file
26
+ a
27
+ }
28
+
29
+ describe "Model.attached_files" do
30
+ it "includes a mapping of the currently attached files" do
31
+ expect(klass.attached_files).to eq([:file, :file_thumb])
32
+ end
33
+ end
34
+
35
+ describe "Model.attached_followers_per_leader" do
36
+ it "is a hash of attachments and followers" do
37
+ expect(klass.attached_followers_per_leader).to eq({ file: [:file_thumb] })
38
+ end
39
+ end
40
+ end
@@ -16,7 +16,7 @@ describe "reload model" do
16
16
  expect(a.file.exists?).to be_truthy
17
17
  expect(b.file.exists?).to be_falsey
18
18
 
19
- b.reload
19
+ b.reload(lock: false)
20
20
  expect(b.file.exists?).to be_truthy
21
21
  end
22
22
  end
@@ -204,4 +204,18 @@ describe Saviour::File do
204
204
  expect(a).to_not eq b
205
205
  end
206
206
  end
207
+
208
+ describe "#read" do
209
+ it "returns nil when there's no file persisted" do
210
+ a = Saviour::File.new(uploader_klass, dummy_class.new, :file)
211
+ expect(a.read).to be_nil
212
+ end
213
+ end
214
+
215
+ describe "#public_url" do
216
+ it "returns nil when there's no file persisted" do
217
+ a = Saviour::File.new(uploader_klass, dummy_class.new, :file)
218
+ expect(a.public_url).to be_nil
219
+ end
220
+ end
207
221
  end
@@ -9,21 +9,6 @@ describe Saviour do
9
9
  }.to raise_error(Saviour::NoActiveRecordDetected)
10
10
  end
11
11
 
12
- describe ".attached_files" do
13
- it "includes a mapping of the currently attached files" do
14
- uploader = Class.new(Saviour::BaseUploader) do
15
- store_dir { "/store/dir" }
16
- end
17
-
18
- klass = Class.new(Test) do
19
- include Saviour::Model
20
- attach_file :file, uploader
21
- end
22
-
23
- expect(klass.attached_files).to eq([:file])
24
- end
25
- end
26
-
27
12
  it "doens't mess with default File constant" do
28
13
  # Constant lookup in ruby works by lexical scope, so we can't create classes dynamically like above.
29
14
  expect(TestForSaviourFileResolution.new.foo).to be_falsey
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saviour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
@@ -190,6 +190,7 @@ files:
190
190
  - spec/feature/dirty_spec.rb
191
191
  - spec/feature/follow_file_spec.rb
192
192
  - spec/feature/halt_processor_spec.rb
193
+ - spec/feature/introspection_spec.rb
193
194
  - spec/feature/memory_usage_spec.rb
194
195
  - spec/feature/original_assigned_file_is_not_modified_spec.rb
195
196
  - spec/feature/persisted_path_spec.rb