saviour 0.5.6 → 0.5.7

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: '084a405456f0b11741e0f8a92a96a85620b26aca9209b53835acfecebaf13fdc'
4
- data.tar.gz: 20e26cc51b5d6867907c9f656169d9929a4d3e3fe081c22d9cb28ec972557149
3
+ metadata.gz: 2c4a0898f2a80dfb611406f5d9ad72a6abdd8a1dc36716013f7d6c375041a603
4
+ data.tar.gz: b394cc24a4e380a64948026543489c2f9f40cdc91023d6009642b351e3162dea
5
5
  SHA512:
6
- metadata.gz: edffce475e7dc22aca7fc71c2a96867eff9ad24d4c4fd1284420247c00dac571630a5117345900fb03288ebd7d97cff81bf395cfa71a2da029b2f71aab434164
7
- data.tar.gz: 7a58495b5e89f4b04724c0364d90f25885dff7105b3b0cdf175296b2125d699c364e4986812d91d21e4946f135dc68e92cddf8a3eea7e6aedbe65a87dd2d009e
6
+ metadata.gz: 33b0babd6aac01fda54898026e70fb717b65819c7cbddfc721baa6c0ec5f2bff19b05edbe7b465ff972e3c9ce14db9a9a8ceee180f073d92f92b8c7741fc3748
7
+ data.tar.gz: ac423bdfc6ed48c368ca92e6e4aeca395ceb51ae4d14d363971b27d656777e8974c5514a6db959ca89154c95c5a8fc484cdad26e478198ea17775abda466250a
data/lib/saviour/file.rb CHANGED
@@ -66,6 +66,10 @@ module Saviour
66
66
  new_file
67
67
  end
68
68
 
69
+ def reload
70
+ @model.instance_variable_set("@__uploader_#{@attached_as}", nil)
71
+ end
72
+
69
73
  alias_method :url, :public_url
70
74
 
71
75
  def assign(object)
@@ -52,6 +52,10 @@ module Saviour
52
52
  send(attach_as).assign(value)
53
53
  end
54
54
 
55
+ define_method("#{attach_as}?") do
56
+ send(attach_as).present?
57
+ end
58
+
55
59
  define_method("#{attach_as}_changed?") do
56
60
  send(attach_as).changed?
57
61
  end
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "saving a new file" do
3
+ describe "CRUD" do
4
4
  before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
5
5
 
6
6
  let(:uploader) {
@@ -233,4 +233,22 @@ describe "saving a new file" do
233
233
  expect(Saviour::Config.storage.read(a[:file])).to eq Saviour::Config.storage.read(b[:file])
234
234
  end
235
235
  end
236
+
237
+ describe "presence" do
238
+ it "false when no assigned file" do
239
+ a = klass.create!
240
+ expect(a.file?).to be_falsey
241
+ end
242
+
243
+ it "true when no persisted but assigned" do
244
+ a = klass.create!
245
+ a.file = Saviour::StringSource.new("contents", "file.txt")
246
+ expect(a.file?).to be_truthy
247
+ end
248
+
249
+ it "true when persisted and assigned" do
250
+ a = klass.create! file: Saviour::StringSource.new("contents", "file.txt")
251
+ expect(a.file?).to be_truthy
252
+ end
253
+ end
236
254
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "reload model" do
3
+ describe "reload" do
4
4
  before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
5
5
 
6
- context "updates the Saviour::File instance" do
6
+ describe "updates the Saviour::File instances on the model" do
7
7
  it do
8
8
  uploader = Class.new(Saviour::BaseUploader) { store_dir { "/store/dir" } }
9
9
  klass = Class.new(Test) { include Saviour::Model }
@@ -21,4 +21,20 @@ describe "reload model" do
21
21
  end
22
22
  end
23
23
  end
24
+
25
+ it "reloads the file instance" do
26
+ uploader = Class.new(Saviour::BaseUploader) { store_dir { "/store/dir" } }
27
+ klass = Class.new(Test) { include Saviour::Model }
28
+ klass.attach_file :file, uploader
29
+ a = klass.create!
30
+
31
+ expect(a.file.present?).to be_falsey
32
+ Saviour::Config.storage.write "contents", "file.txt"
33
+ a.update_columns(file: "file.txt")
34
+ expect(a.file.present?).to be_falsey
35
+
36
+ a.file.reload
37
+ expect(a.file.present?).to be_truthy
38
+ expect(a.file.read).to eq "contents"
39
+ end
24
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saviour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord