saviour 0.4.2 → 0.4.3
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/.travis.yml +11 -8
- data/gemfiles/5.1.gemfile +9 -0
- data/lib/saviour/file.rb +22 -0
- data/lib/saviour/version.rb +1 -1
- data/spec/feature/dirty_spec.rb +36 -0
- data/spec/models/file_spec.rb +44 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 319d2711e341ea64600303c886f98cba1d698946
|
4
|
+
data.tar.gz: 2d48a9c86baa03ade58dd34b5932735080120b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d49c6f41a7ab74b67e52b99e85e13c6c653c7fce639231835ba9ca1cbd6991213231558505ea9d42be51d0b173226a144d5657779ef36570e3960ad156b4ddb
|
7
|
+
data.tar.gz: 4aad76005e7bb31d153a8e135816ac255cd2e812cd1af00360147c1122c1eba54f296d70f5cd363f139fa858f3fd3c2f6db61c27eff4826a5dfc23afe1833963
|
data/.travis.yml
CHANGED
@@ -2,16 +2,17 @@ language: ruby
|
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
- 2.1.
|
6
|
-
- 2.2.
|
7
|
-
- 2.3.
|
8
|
-
- 2.4.
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.8
|
7
|
+
- 2.3.5
|
8
|
+
- 2.4.2
|
9
9
|
|
10
10
|
gemfile:
|
11
11
|
- gemfiles/4.0.gemfile
|
12
12
|
- gemfiles/4.1.gemfile
|
13
13
|
- gemfiles/4.2.gemfile
|
14
14
|
- gemfiles/5.0.gemfile
|
15
|
+
- gemfiles/5.1.gemfile
|
15
16
|
|
16
17
|
addons:
|
17
18
|
code_climate:
|
@@ -22,12 +23,14 @@ after_success:
|
|
22
23
|
|
23
24
|
matrix:
|
24
25
|
exclude:
|
25
|
-
# rails 5 requires 2.2+
|
26
|
-
- rvm: 2.1.
|
26
|
+
# rails 5+ requires 2.2+
|
27
|
+
- rvm: 2.1.10
|
27
28
|
gemfile: gemfiles/5.0.gemfile
|
29
|
+
- rvm: 2.1.10
|
30
|
+
gemfile: gemfiles/5.1.gemfile
|
28
31
|
|
29
32
|
# Arel support for ruby 2.4 starts in 4.2
|
30
|
-
- rvm: 2.4.
|
33
|
+
- rvm: 2.4.2
|
31
34
|
gemfile: gemfiles/4.0.gemfile
|
32
|
-
- rvm: 2.4.
|
35
|
+
- rvm: 2.4.2
|
33
36
|
gemfile: gemfiles/4.1.gemfile
|
data/lib/saviour/file.rb
CHANGED
@@ -29,6 +29,23 @@ module Saviour
|
|
29
29
|
persisted? && Config.storage.public_url(@persisted_path)
|
30
30
|
end
|
31
31
|
|
32
|
+
def ==(another_file)
|
33
|
+
return false unless another_file.is_a?(Saviour::File)
|
34
|
+
return false unless another_file.persisted? == persisted?
|
35
|
+
|
36
|
+
if persisted?
|
37
|
+
another_file.persisted_path == persisted_path
|
38
|
+
else
|
39
|
+
another_file.instance_variable_get("@source") == @source
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def clone
|
44
|
+
new_file = Saviour::File.new(@uploader_klass, @model, @attached_as)
|
45
|
+
new_file.set_path!(@persisted_path)
|
46
|
+
new_file
|
47
|
+
end
|
48
|
+
|
32
49
|
alias_method :url, :public_url
|
33
50
|
|
34
51
|
def assign(object)
|
@@ -39,6 +56,11 @@ module Saviour
|
|
39
56
|
|
40
57
|
@source_data = nil
|
41
58
|
@source = object
|
59
|
+
|
60
|
+
if changed? && @model.respond_to?("#{@attached_as}_will_change!")
|
61
|
+
@model.send "#{@attached_as}_will_change!"
|
62
|
+
end
|
63
|
+
|
42
64
|
@persisted_path = nil if object
|
43
65
|
|
44
66
|
object
|
data/lib/saviour/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "dirty model" 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
|
+
context "provides changes and previous file" do
|
7
|
+
it do
|
8
|
+
uploader = Class.new(Saviour::BaseUploader) { store_dir { "/store/dir" } }
|
9
|
+
klass = Class.new(Test) { include Saviour::Model }
|
10
|
+
klass.attach_file :file, uploader
|
11
|
+
a = klass.create!
|
12
|
+
|
13
|
+
with_test_file("example.xml") do |xml_file|
|
14
|
+
with_test_file("camaloon.jpg") do |jpg_file|
|
15
|
+
a.update_attributes! file: xml_file
|
16
|
+
|
17
|
+
expect(a.changed_attributes).to eq({})
|
18
|
+
|
19
|
+
expect(a.file.exists?).to be_truthy
|
20
|
+
expect(a.file_changed?).to be_falsey
|
21
|
+
expect(a.file.persisted?).to be_truthy
|
22
|
+
|
23
|
+
a.file = jpg_file
|
24
|
+
expect(a.file.persisted?).to be_falsey
|
25
|
+
|
26
|
+
expect(a.file_changed?).to be_truthy
|
27
|
+
expect(a.file_was).to_not eq(a.file)
|
28
|
+
expect(a.file_was.url).to match /\.xml$/
|
29
|
+
expect(a.file_was.persisted?).to be_truthy
|
30
|
+
|
31
|
+
expect(a.changed_attributes).to include("file" => a.file_was)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/models/file_spec.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Saviour::File do
|
4
|
+
class ComparableStringIO < StringIO
|
5
|
+
def ==(a)
|
6
|
+
a.is_a?(ComparableStringIO) && a.read == read
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
let(:mocked_storage) {
|
5
11
|
Class.new {
|
6
12
|
def write(content, filename)
|
@@ -188,4 +194,42 @@ describe Saviour::File do
|
|
188
194
|
expect(file).not_to be_blank
|
189
195
|
end
|
190
196
|
end
|
197
|
+
|
198
|
+
describe "#clone" do
|
199
|
+
it "returns a cloned instance pointing to the same stored file" do
|
200
|
+
file = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
201
|
+
file.set_path! "/path/dummy.jpg"
|
202
|
+
|
203
|
+
new_file = file.clone
|
204
|
+
expect(new_file.persisted_path).to eq "/path/dummy.jpg"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "#==" do
|
209
|
+
it "compares by object persisted path if persisted" do
|
210
|
+
a = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
211
|
+
a.set_path! "/path/dummy.jpg"
|
212
|
+
|
213
|
+
b = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
214
|
+
b.set_path! "/path/dummy.jpg"
|
215
|
+
|
216
|
+
expect(a).to eq b
|
217
|
+
|
218
|
+
b.set_path! "/path/dummy2.jpg"
|
219
|
+
expect(a).to_not eq b
|
220
|
+
end
|
221
|
+
|
222
|
+
it "compares by content if not persisted" do
|
223
|
+
a = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
224
|
+
a.assign(ComparableStringIO.new("content"))
|
225
|
+
|
226
|
+
b = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
227
|
+
b.assign(ComparableStringIO.new("content"))
|
228
|
+
|
229
|
+
expect(a).to eq b
|
230
|
+
|
231
|
+
b.assign(ComparableStringIO.new("another content"))
|
232
|
+
expect(a).to_not eq b
|
233
|
+
end
|
234
|
+
end
|
191
235
|
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.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- gemfiles/4.1.gemfile
|
155
155
|
- gemfiles/4.2.gemfile
|
156
156
|
- gemfiles/5.0.gemfile
|
157
|
+
- gemfiles/5.1.gemfile
|
157
158
|
- lib/saviour.rb
|
158
159
|
- lib/saviour/base_uploader.rb
|
159
160
|
- lib/saviour/config.rb
|
@@ -175,6 +176,7 @@ files:
|
|
175
176
|
- spec/feature/access_to_model_and_mounted_as_spec.rb
|
176
177
|
- spec/feature/allow_overriding_attached_as_method.rb
|
177
178
|
- spec/feature/crud_workflows_spec.rb
|
179
|
+
- spec/feature/dirty_spec.rb
|
178
180
|
- spec/feature/follow_file_spec.rb
|
179
181
|
- spec/feature/persisted_path_spec.rb
|
180
182
|
- spec/feature/reload_model_spec.rb
|