saviour 0.6.0 → 0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9031d0f7f9624571c39792d2953c5eb11f50f7edd7f4c7117bf7951166c43b8
4
- data.tar.gz: 3ef5fac874948c7b1a330b756c25c88c357108e08237ab940f4e0cb0d71ff55e
3
+ metadata.gz: 0121fbeb0549f71c53b630c648c3791c3b47c48accb0839c2d887490ade48868
4
+ data.tar.gz: 1494bc8c02a203fc199117210e43d0a5e694b6766774799d85a8cd34049f0c87
5
5
  SHA512:
6
- metadata.gz: aa7d00ae67fe68da25c4eb9652813b9a6f0d751a0ddf9729efe43c6dcfd5af2ffa8b7db14e9bb9dcc06b8c5a4cf8bcea503c3394abf2d5e82e8213b6d0f3589f
7
- data.tar.gz: 348f05edc2b3f0d5185412f741e5d9aedecfdff44430833aaed0ab7221a70fc6c834d4489d0ff8c1bd01c06c20fb1bd56a3b996b6d3c75cdd15471c911159636
6
+ metadata.gz: b8a223b8b404728287418c24391db7320332ed09a931fffb550a024948d12a335187df393f85defa26fbd3e943dc18c2f49cf6467d743d066c42a21b57212211
7
+ data.tar.gz: d8c1ab1f0b7f72e2d376391c62fd166b708182bb2733a13ffef2310fdc6c1b8d5152b5364ca5837b2b7da09d46e770d276b42dc65fc234f00d0bc0d1748f02be
@@ -49,7 +49,7 @@ module Saviour
49
49
  end
50
50
 
51
51
  @new_path = @file.write(
52
- before_write: ->(path) { dup_file.call if @current_path == path }
52
+ before_write: ->(path) { dup_file.call if @current_path == path }
53
53
  )
54
54
 
55
55
  return unless @new_path
@@ -112,22 +112,22 @@ module Saviour
112
112
  end
113
113
 
114
114
  def update!
115
- process_upload(FileUpdater)
115
+ process_upload(FileUpdater, touch: true)
116
116
  end
117
117
 
118
118
  private
119
119
 
120
- def process_upload(klass)
120
+ def process_upload(klass, touch: false)
121
121
  persistence_layer = @persistence_klass.new(@model)
122
122
 
123
123
  uploaders = attached_files.map do |column|
124
124
  next unless @model.send(column).changed?
125
125
 
126
126
  klass.new(
127
- persistence_layer.read(column),
128
- @model.send(column),
129
- column,
130
- ActiveRecord::Base.connection
127
+ persistence_layer.read(column),
128
+ @model.send(column),
129
+ column,
130
+ ActiveRecord::Base.connection
131
131
  )
132
132
  end.compact
133
133
 
@@ -161,6 +161,11 @@ module Saviour
161
161
  end
162
162
  end
163
163
 
164
+ if attrs.length > 0 && touch && @model.class.record_timestamps
165
+ touches = @model.class.send(:timestamp_attributes_for_update_in_model).map { |x| [x, Time.current] }.to_h
166
+ attrs.merge!(touches)
167
+ end
168
+
164
169
  persistence_layer.write_attrs(attrs) if attrs.length > 0
165
170
  end
166
171
 
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -117,8 +117,8 @@ describe "CRUD" do
117
117
  expected_query = %Q{UPDATE "tests" SET "file" = '/store/dir/file.txt', "file_thumb" = '/store/dir/file.txt'}
118
118
  expect_to_yield_queries(count: 2, including: [expected_query]) do
119
119
  klass.create!(
120
- file: Saviour::StringSource.new("foo", "file.txt"),
121
- file_thumb: Saviour::StringSource.new("foo", "file.txt")
120
+ file: Saviour::StringSource.new("foo", "file.txt"),
121
+ file_thumb: Saviour::StringSource.new("foo", "file.txt")
122
122
  )
123
123
  end
124
124
  end
@@ -188,6 +188,31 @@ describe "CRUD" do
188
188
  end
189
189
  end
190
190
 
191
+ describe "touch updated_at" do
192
+ it "touches updated_at if the model has it" do
193
+ time = Time.now - 4.years
194
+ a = klass.create! updated_at: time
195
+ a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt")
196
+
197
+ expect(a.updated_at).to be > time + 2.years
198
+ end
199
+
200
+ context do
201
+ let(:klass) {
202
+ a = Class.new(TestNoTimestamp) { include Saviour::Model }
203
+ a.attach_file :file, uploader
204
+ a
205
+ }
206
+
207
+ it "works with models that do not have updated_at" do
208
+ a = klass.create!
209
+ expect(a).not_to respond_to(:updated_at)
210
+ a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt")
211
+ expect(a.file.read).to eq "foo"
212
+ end
213
+ end
214
+ end
215
+
191
216
  context do
192
217
  let(:klass) {
193
218
  a = Class.new(Test) { include Saviour::Model }
@@ -202,8 +227,8 @@ describe "CRUD" do
202
227
  expected_query = %Q{UPDATE "tests" SET "file" = '/store/dir/file.txt', "file_thumb" = '/store/dir/file.txt'}
203
228
  expect_to_yield_queries(count: 1, including: [expected_query]) do
204
229
  a.update_attributes!(
205
- file: Saviour::StringSource.new("foo", "file.txt"),
206
- file_thumb: Saviour::StringSource.new("foo", "file.txt")
230
+ file: Saviour::StringSource.new("foo", "file.txt"),
231
+ file_thumb: Saviour::StringSource.new("foo", "file.txt")
207
232
  )
208
233
  end
209
234
  end
@@ -55,7 +55,6 @@ describe "stash data on process" do
55
55
  store_dir { "/store/dir" }
56
56
 
57
57
  process_with_file do |file, filename|
58
- # same ':size' key in the stash
59
58
  stash(size: File.size(file.path))
60
59
 
61
60
  [file, filename]
@@ -2,6 +2,10 @@ class Test < ActiveRecord::Base
2
2
 
3
3
  end
4
4
 
5
+ class TestNoTimestamp < ActiveRecord::Base
6
+
7
+ end
8
+
5
9
  # Constant lookup in ruby works by lexical scope, so we can't create classes dynamically to test this.
6
10
  class TestForSaviourFileResolution < Test
7
11
  include Saviour::Model
@@ -10,4 +10,9 @@ ActiveRecord::Schema.define do
10
10
  t.integer :size_file_thumb
11
11
  t.timestamps null: false
12
12
  end
13
+
14
+ create_table :test_no_timestamps do |t|
15
+ t.string :file
16
+ t.string :name
17
+ end
13
18
  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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord