paperclip-permanent_records 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +32 -0
- data/.rubocop_todo.yml +45 -0
- data/.travis.yml +24 -0
- data/Appraisals +29 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +20 -0
- data/gemfiles/rails_4.2_pc_4.1.gemfile +8 -0
- data/gemfiles/rails_4.2_pc_4.2.gemfile +8 -0
- data/gemfiles/rails_4.2_pc_5.0.gemfile +8 -0
- data/gemfiles/rails_4.2_pc_5.1.gemfile +8 -0
- data/gemfiles/rails_5.0_pc_5.0.gemfile +8 -0
- data/gemfiles/rails_5.1_pc_5.1.gemfile +8 -0
- data/lib/paperclip/permanent_records/active_record.rb +28 -0
- data/lib/paperclip/permanent_records/gem_helper.rb +26 -0
- data/lib/paperclip/permanent_records/gem_tasks.rb +2 -0
- data/lib/paperclip/permanent_records/paperclip_patch.rb +22 -0
- data/lib/paperclip/permanent_records/version.rb +5 -0
- data/lib/paperclip/permanent_records.rb +15 -0
- data/paperclip-permanent_records.gemspec +34 -0
- data/spec/data/models.rb +17 -0
- data/spec/data/schema.rb +29 -0
- data/spec/data/test.png +0 -0
- data/spec/paperclip/permanent_records_spec.rb +108 -0
- data/spec/spec_helper.rb +55 -0
- metadata +232 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3bdbba54470c8648d6c9142341358a972517d28
|
4
|
+
data.tar.gz: c08220d8ac31b12ac11bc89c58ac102eae0429fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0889073c9419ff4a7dbeba7dca791e7b54058154b596509ae007f8beaa4124c041d5ddcb923a77336743b7b3f770e229863f3d0f9d41035748d8361e3a963ff2
|
7
|
+
data.tar.gz: 9db4b49baf4aad4b0a27ada9f2768e635eb34fc7a4d4e2583928f48e474f79656b642d4e4cd99c6ca3f78544a9034da6510cbdc067b48a01dd01b94d8928ae25
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
inherit_from: .rubocop_todo.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Include:
|
7
|
+
- 'Appraisals'
|
8
|
+
- '**/*.gemspec'
|
9
|
+
- '**/*.rake'
|
10
|
+
- '**/*.gemfile'
|
11
|
+
- '**/Gemfile'
|
12
|
+
- '**/Rakefile'
|
13
|
+
- '**/Capfile'
|
14
|
+
TargetRubyVersion: 2.2
|
15
|
+
|
16
|
+
Layout/AlignHash:
|
17
|
+
EnforcedColonStyle: 'table'
|
18
|
+
|
19
|
+
Layout/AlignParameters:
|
20
|
+
EnforcedStyle: 'with_fixed_indentation'
|
21
|
+
|
22
|
+
Layout/DotPosition:
|
23
|
+
EnforcedStyle: 'trailing'
|
24
|
+
|
25
|
+
Layout/SpaceInsideHashLiteralBraces:
|
26
|
+
EnforcedStyle: 'no_space'
|
27
|
+
|
28
|
+
Metrics/LineLength:
|
29
|
+
Max: 120
|
30
|
+
|
31
|
+
Naming/VariableNumber:
|
32
|
+
EnforcedStyle: 'snake_case'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-01-18 16:08:39 +0100 using RuboCop version 0.52.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 3
|
10
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Max: 82
|
13
|
+
|
14
|
+
# Offense count: 4
|
15
|
+
# Configuration parameters: Prefixes.
|
16
|
+
# Prefixes: when, with, without
|
17
|
+
RSpec/ContextWording:
|
18
|
+
Exclude:
|
19
|
+
- 'spec/paperclip/permanent_records_spec.rb'
|
20
|
+
|
21
|
+
# Offense count: 2
|
22
|
+
# Configuration parameters: Max.
|
23
|
+
RSpec/ExampleLength:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/paperclip/permanent_records_spec.rb'
|
26
|
+
|
27
|
+
# Offense count: 4
|
28
|
+
# Configuration parameters: AggregateFailuresByDefault.
|
29
|
+
RSpec/MultipleExpectations:
|
30
|
+
Max: 4
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
# Configuration parameters: Max.
|
34
|
+
RSpec/NestedGroups:
|
35
|
+
Exclude:
|
36
|
+
- 'spec/paperclip/permanent_records_spec.rb'
|
37
|
+
|
38
|
+
# Offense count: 3
|
39
|
+
Style/Documentation:
|
40
|
+
Exclude:
|
41
|
+
- 'spec/**/*'
|
42
|
+
- 'test/**/*'
|
43
|
+
- 'lib/paperclip/permanent_records.rb'
|
44
|
+
- 'lib/paperclip/permanent_records/active_record.rb'
|
45
|
+
- 'lib/paperclip/permanent_records/paperclip_patch.rb'
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.9
|
4
|
+
- 2.3.5
|
5
|
+
- 2.4.3
|
6
|
+
- 2.5.0
|
7
|
+
script: "bundle exec rake spec"
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/rails_4.2_pc_4.1.gemfile
|
10
|
+
- gemfiles/rails_4.2_pc_4.2.gemfile
|
11
|
+
- gemfiles/rails_4.2_pc_5.0.gemfile
|
12
|
+
- gemfiles/rails_4.2_pc_5.1.gemfile
|
13
|
+
- gemfiles/rails_5.0_pc_5.0.gemfile
|
14
|
+
- gemfiles/rails_5.1_pc_5.1.gemfile
|
15
|
+
matrix:
|
16
|
+
exclude:
|
17
|
+
- rvm: 2.5.0
|
18
|
+
gemfile: gemfiles/rails_4.2_pc_4.1.gemfile
|
19
|
+
- rvm: 2.5.0
|
20
|
+
gemfile: gemfiles/rails_4.2_pc_4.2.gemfile
|
21
|
+
- rvm: 2.5.0
|
22
|
+
gemfile: gemfiles/rails_4.2_pc_5.0.gemfile
|
23
|
+
- rvm: 2.5.0
|
24
|
+
gemfile: gemfiles/rails_4.2_pc_5.1.gemfile
|
data/Appraisals
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
appraise 'rails_4.2_pc_4.1' do
|
2
|
+
gem 'rails', '~> 4.2.0'
|
3
|
+
gem 'paperclip', '~> 4.1.1'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails_4.2_pc_4.2' do
|
7
|
+
gem 'rails', '~> 4.2.0'
|
8
|
+
gem 'paperclip', '~> 4.2.4'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'rails_4.2_pc_5.0' do
|
12
|
+
gem 'rails', '~> 4.2.0'
|
13
|
+
gem 'paperclip', '~> 5.0.0'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'rails_4.2_pc_5.1' do
|
17
|
+
gem 'rails', '~> 4.2.0'
|
18
|
+
gem 'paperclip', '~> 5.1.0'
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise 'rails_5.0_pc_5.0' do
|
22
|
+
gem 'rails', '~> 5.0.0'
|
23
|
+
gem 'paperclip', '~> 5.0.0'
|
24
|
+
end
|
25
|
+
|
26
|
+
appraise 'rails_5.1_pc_5.1' do
|
27
|
+
gem 'rails', '~> 5.1.0'
|
28
|
+
gem 'paperclip', '~> 5.1.0'
|
29
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# 0.4.0 (2018-01-18)
|
2
|
+
|
3
|
+
* Remove support for rails < 4.2
|
4
|
+
* Remove support for ruby 2.1
|
5
|
+
* Test with rails 5.0 and 5.1
|
6
|
+
* Test on ruby 2.4 and 2.5
|
7
|
+
* Update permanent_records dependency to at least 4.2.7 (currenly the latest)
|
8
|
+
* paperclip: update patch to its 5.1.0 counterpart, test with 5.0 and 5.1
|
9
|
+
* Don't trigger ActiveRecord loading on requiring this gem
|
10
|
+
* Dev dependencies: update rake and rubocop/rubocop-rspec (+ some code style fixes)
|
11
|
+
|
12
|
+
# 0.3.0 (2018-01-17)
|
13
|
+
|
14
|
+
* Remove support for rails < 4.0 and paperclip < 4.1
|
15
|
+
* Remove support for ruby 1.9 and 2.0
|
16
|
+
* Test on ruby 2.1 and 2.3
|
17
|
+
* Test with paperclip 4.2
|
18
|
+
* Dev dependencies: update versions, add rubocop (+ lots of code style fixes), fix definitions
|
19
|
+
|
20
|
+
# 0.2.0 (2015-03-11)
|
21
|
+
|
22
|
+
* Update permanent_records dependency from 3.2 to 3.3
|
23
|
+
|
24
|
+
# 0.1.0 (2015-02-12)
|
25
|
+
|
26
|
+
Initial version.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015-2018 emjot GmbH & Co. KG
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Paperclip::PermanentRecords
|
2
|
+
|
3
|
+
When using permanent_records, paperclip attachments should only be deleted
|
4
|
+
when the model is really destroyed.
|
5
|
+
|
6
|
+
See [paperclip #804](https://github.com/thoughtbot/paperclip/issues/804#issuecomment-4946231).
|
7
|
+
|
8
|
+
## Compatibility
|
9
|
+
|
10
|
+
* rails 4.2: works with paperclip 4.1 - 5.1 and ruby 2.2 - 2.4.
|
11
|
+
* rails 5.0 - 5.1 : works with paperclip 5.0 - 5.1 and ruby 2.2 - 2.5.
|
12
|
+
* all tested with permanent_records 4.2.7.
|
13
|
+
|
14
|
+
Please see `.travis.yml` and `Appraisals` for what combinations have actually been tested. Usage with other versions
|
15
|
+
might cause data loss.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'paperclip-permanent_records'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install paperclip-permanent_records
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Nothing to do, this should just work.
|
36
|
+
|
37
|
+
## How does it work?
|
38
|
+
|
39
|
+
This gem does basically two things:
|
40
|
+
|
41
|
+
* prevent paperclip from marking attachments to be deleted in paperclip's `before_destroy` callback(s)
|
42
|
+
(by patching paperclip)
|
43
|
+
* mark attachments to be deleted in the model's `destroy` method
|
44
|
+
(depending on whether the model is actually destroyed or only deleted)
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
Code style: Please use rubocop before you commit (`bundle exec rubocop`) and fix any warnings.
|
49
|
+
|
50
|
+
To setup tests, make sure all the ruby versions defined in `.travis.yml` are installed on your system.
|
51
|
+
Use `bundle exec appraisal generate` to generate the gemfiles if you change them in `Appraisals` and `.travis.yml`.
|
52
|
+
|
53
|
+
Run tests via:
|
54
|
+
|
55
|
+
* `rake wwtd` for all combinations of ruby/rails/paperclip versions
|
56
|
+
* `rake wwtd:local` for all rails/paperclip versions, but only on current ruby
|
57
|
+
* `rake spec` (or e.g. `bundle exec rspec spec --format documentation`) with main Gemfile and only on current ruby
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'paperclip/permanent_records/gem_tasks'
|
3
|
+
require 'appraisal'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'wwtd/tasks'
|
6
|
+
|
7
|
+
desc 'Default: run all tests with all supported versions'
|
8
|
+
task default: :all
|
9
|
+
|
10
|
+
desc 'Run tests with all supported versions.'
|
11
|
+
task all: ['appraisal:install'] do
|
12
|
+
exec('rake appraisal spec')
|
13
|
+
end
|
14
|
+
|
15
|
+
task local: 'wwtd:local' # run all gemfiles with local ruby
|
16
|
+
|
17
|
+
desc 'Run all tests'
|
18
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
19
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module PermanentRecords
|
3
|
+
module ActiveRecord
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def destroy(force = nil)
|
7
|
+
if paperclip_attachments? && # only when we have paperclip attachments,
|
8
|
+
(!is_permanent? || # if model does not support "safe deletion"
|
9
|
+
::PermanentRecords.should_force_destroy?(force)) # or if model supports "safe deletion" but it is forced
|
10
|
+
schedule_attachments_for_deletion # => delete the attachments
|
11
|
+
end
|
12
|
+
|
13
|
+
super(force)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def paperclip_attachments?
|
19
|
+
self.class.respond_to?(:attachment_definitions)
|
20
|
+
end
|
21
|
+
|
22
|
+
# (this contains what each of the before_destroy callbacks originally did)
|
23
|
+
def schedule_attachments_for_deletion
|
24
|
+
self.class.attachment_definitions.each_key { |name| send(name).send(:queue_all_for_delete) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module PermanentRecords
|
3
|
+
# Like Bundler::GemHelper, but without the 'release' task
|
4
|
+
# (would need to be implemented for release on gems.emjot.de)
|
5
|
+
class GemHelper < Bundler::GemHelper
|
6
|
+
def install
|
7
|
+
built_gem_path = nil
|
8
|
+
desc "Build #{name}-#{version}.gem into the pkg directory."
|
9
|
+
task 'build' do
|
10
|
+
built_gem_path = build_gem
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Build and install #{name}-#{version}.gem into system gems."
|
14
|
+
task 'install' => 'build' do
|
15
|
+
install_gem(built_gem_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
GemHelper.instance = self
|
19
|
+
end
|
20
|
+
|
21
|
+
def version_tag
|
22
|
+
version.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Patch for paperclip >= 3.5.0 (based on 5.1.0)
|
2
|
+
|
3
|
+
module Paperclip
|
4
|
+
class HasAttachedFile
|
5
|
+
private
|
6
|
+
|
7
|
+
# Overwrite so it doesn't add a :before_destroy filter - we want to handle that in
|
8
|
+
# {Paperclip::PermanentRecords::ActiveRecord#destroy} instead
|
9
|
+
def add_active_record_callbacks
|
10
|
+
name = @name
|
11
|
+
@klass.send(:after_save) { send(name).send(:save) }
|
12
|
+
# @klass.send(:before_destroy) { send(name).send(:queue_all_for_delete) }
|
13
|
+
if @klass.respond_to?(:after_commit)
|
14
|
+
@klass.send(:after_commit, on: :destroy) do
|
15
|
+
send(name).send(:flush_deletes)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@klass.send(:after_destroy) { send(name).send(:flush_deletes) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'paperclip/permanent_records/version'
|
2
|
+
|
3
|
+
require 'paperclip'
|
4
|
+
require 'permanent_records'
|
5
|
+
require 'paperclip/permanent_records/active_record'
|
6
|
+
|
7
|
+
module Paperclip
|
8
|
+
module PermanentRecords
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
::ActiveRecord::Base.send :include, Paperclip::PermanentRecords::ActiveRecord
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'paperclip/permanent_records/paperclip_patch'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'paperclip/permanent_records/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'paperclip-permanent_records'
|
7
|
+
spec.version = Paperclip::PermanentRecords::VERSION
|
8
|
+
spec.authors = ['Maximilian Herold']
|
9
|
+
spec.email = ['herold@emjot.de']
|
10
|
+
spec.summary = 'Make paperclip attachments work with permanent_records'
|
11
|
+
spec.description = 'Make paperclip attachments work with permanent_records'
|
12
|
+
spec.homepage = ''
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.required_ruby_version = '>= 2.2'
|
21
|
+
|
22
|
+
spec.add_dependency 'activerecord', '>= 4.2'
|
23
|
+
spec.add_dependency 'paperclip', '>= 4.1'
|
24
|
+
spec.add_dependency 'permanent_records', '>= 4.2.7'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'appraisal', '~> 2.2'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
28
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
29
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.7'
|
30
|
+
spec.add_development_dependency 'rubocop'
|
31
|
+
spec.add_development_dependency 'rubocop-rspec'
|
32
|
+
spec.add_development_dependency 'sqlite3'
|
33
|
+
spec.add_development_dependency 'wwtd', '~> 1.3'
|
34
|
+
end
|
data/spec/data/models.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
has_attached_file :image,
|
3
|
+
url: '/system/:test_env_number/:class/:attachment/:id/:style-:fingerprint.:extension'
|
4
|
+
validates_attachment :image, content_type: {content_type: ['image/png']}
|
5
|
+
end
|
6
|
+
|
7
|
+
class PermanentPost < ActiveRecord::Base
|
8
|
+
has_attached_file :image,
|
9
|
+
url: '/system/:test_env_number/:class/:attachment/:id/:style-:fingerprint.:extension'
|
10
|
+
validates_attachment :image, content_type: {content_type: ['image/png']}
|
11
|
+
end
|
12
|
+
|
13
|
+
class Uid < ActiveRecord::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
class PermanentUid < ActiveRecord::Base
|
17
|
+
end
|
data/spec/data/schema.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
2
|
+
|
3
|
+
ActiveRecord::Schema.define do
|
4
|
+
create_table :permanent_posts, force: true do |t|
|
5
|
+
t.string :image_file_name
|
6
|
+
t.integer :image_file_size
|
7
|
+
t.string :image_content_type
|
8
|
+
t.string :image_fingerprint
|
9
|
+
t.timestamp :image_updated_at
|
10
|
+
t.timestamp :deleted_at
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :posts, force: true do |t|
|
14
|
+
t.string :image_file_name
|
15
|
+
t.integer :image_file_size
|
16
|
+
t.string :image_content_type
|
17
|
+
t.string :image_fingerprint
|
18
|
+
t.timestamp :image_updated_at
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :permanent_uids, force: true do |t|
|
22
|
+
t.integer :uid
|
23
|
+
t.timestamp :deleted_at
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :uids, force: true do |t|
|
27
|
+
t.integer :uid
|
28
|
+
end
|
29
|
+
end
|
data/spec/data/test.png
ADDED
Binary file
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Paperclip::PermanentRecords do
|
4
|
+
before do
|
5
|
+
stub_const('Rails', instance_double('Rails'))
|
6
|
+
allow(Rails).to receive(:root).and_return(ROOT.join('tmp'))
|
7
|
+
allow(Rails).to receive(:env).and_return('test')
|
8
|
+
allow(Rails).to receive(:const_defined?).with(:Railtie).and_return(false)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:test_image_dir) do
|
12
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..', 'data'))
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:test_image_file) do
|
16
|
+
File.new(File.join(test_image_dir, 'test.png'))
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#destroy' do
|
20
|
+
context 'on a permanent model with attachments' do
|
21
|
+
let!(:model) { PermanentPost.create!(image: test_image_file) }
|
22
|
+
let!(:file_path) { model.image.path }
|
23
|
+
|
24
|
+
it 'soft-deletes the model' do
|
25
|
+
expect { model.destroy }.to change(model, :deleted?).from(false).to(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'keeps the model' do
|
29
|
+
expect(model.destroy).not_to be_destroyed
|
30
|
+
end
|
31
|
+
|
32
|
+
it "keeps the attachments' files" do
|
33
|
+
model.destroy
|
34
|
+
expect(model).to be_image
|
35
|
+
expect(File).to be_exist(file_path)
|
36
|
+
|
37
|
+
# should still be okay even after saving again
|
38
|
+
model.save!
|
39
|
+
expect(model).to be_image
|
40
|
+
expect(File).to be_exist(file_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "keeps the attachments' files after revive" do
|
44
|
+
model.destroy.revive
|
45
|
+
expect(model).to be_image
|
46
|
+
expect(File).to be_exist(file_path)
|
47
|
+
|
48
|
+
# should still be okay even after saving again
|
49
|
+
model.save!
|
50
|
+
expect(model).to be_image
|
51
|
+
expect(File).to be_exist(file_path)
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with :force option' do
|
55
|
+
it 'destroys the model' do
|
56
|
+
expect(model.destroy(:force)).to be_destroyed
|
57
|
+
end
|
58
|
+
|
59
|
+
it "deletes the attachments' files" do
|
60
|
+
model.destroy(:force)
|
61
|
+
expect(model).not_to be_image
|
62
|
+
expect(File).not_to be_exist(file_path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'on a permanent model without attachments' do
|
68
|
+
let!(:model) { PermanentUid.create!(uid: 99) }
|
69
|
+
|
70
|
+
it 'soft-deletes the model' do
|
71
|
+
expect { model.destroy }.to change(model, :deleted?).from(false).to(true)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'keeps the model' do
|
75
|
+
expect(model.destroy).not_to be_destroyed
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'with :force option' do
|
79
|
+
it 'destroys the model' do
|
80
|
+
expect(model.destroy(:force)).to be_destroyed
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'on a regular model with attachments' do
|
86
|
+
let!(:model) { Post.create!(image: test_image_file) }
|
87
|
+
let!(:file_path) { model.image.path }
|
88
|
+
|
89
|
+
it 'destroys the model' do
|
90
|
+
expect { model.destroy }.to change(Post, :count).from(1).to(0)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "deletes the attachments' files" do
|
94
|
+
model.destroy
|
95
|
+
expect(model).not_to be_image
|
96
|
+
expect(File).not_to be_exist(file_path)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'on a regular model without attachments' do
|
101
|
+
let!(:model) { Uid.create!(uid: 99) }
|
102
|
+
|
103
|
+
it 'destroys the model' do
|
104
|
+
expect { model.destroy }.to change(Uid, :count).from(1).to(0)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
6
|
+
TEST_ASSETS_PATH = Pathname.new(ROOT).join('tmp', 'public')
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.expect_with :rspec do |expectations|
|
10
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.mock_with :rspec do |mocks|
|
14
|
+
mocks.verify_partial_doubles = true
|
15
|
+
end
|
16
|
+
|
17
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
18
|
+
config.filter_run_when_matching :focus
|
19
|
+
config.example_status_persistence_file_path = 'spec/examples.txt'
|
20
|
+
config.disable_monkey_patching!
|
21
|
+
|
22
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
23
|
+
|
24
|
+
config.profile_examples = 2
|
25
|
+
config.order = :random
|
26
|
+
Kernel.srand config.seed
|
27
|
+
|
28
|
+
config.after(:suite) do
|
29
|
+
FileUtils.rm_rf TEST_ASSETS_PATH if File.exist?(TEST_ASSETS_PATH)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'active_record'
|
34
|
+
require 'active_support'
|
35
|
+
require 'paperclip/permanent_records'
|
36
|
+
|
37
|
+
ActiveRecord::Base.send(:include, Paperclip::Glue)
|
38
|
+
|
39
|
+
Paperclip.interpolates(:test_env_number) do |_, _|
|
40
|
+
ENV['TEST_ENV_NUMBER'].presence || '0'
|
41
|
+
end
|
42
|
+
|
43
|
+
# set up models
|
44
|
+
require 'fileutils'
|
45
|
+
require 'logger'
|
46
|
+
tmpdir = File.join(File.dirname(__FILE__), '../tmp')
|
47
|
+
FileUtils.mkdir(tmpdir) unless File.exist?(tmpdir)
|
48
|
+
log = File.expand_path(File.join(tmpdir, 'permanent_records_test.log'))
|
49
|
+
FileUtils.touch(log) unless File.exist?(log)
|
50
|
+
ActiveRecord::Base.logger = Logger.new(log)
|
51
|
+
ActiveRecord::LogSubscriber.attach_to(:active_record)
|
52
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
53
|
+
require File.expand_path('../data/schema', __FILE__)
|
54
|
+
require File.expand_path('../data/models', __FILE__)
|
55
|
+
I18n.locale = I18n.default_locale = :en
|
metadata
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-permanent_records
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maximilian Herold
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: paperclip
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: permanent_records
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: appraisal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.15'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.15'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.7'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: wwtd
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.3'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.3'
|
167
|
+
description: Make paperclip attachments work with permanent_records
|
168
|
+
email:
|
169
|
+
- herold@emjot.de
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rspec"
|
176
|
+
- ".rubocop.yml"
|
177
|
+
- ".rubocop_todo.yml"
|
178
|
+
- ".travis.yml"
|
179
|
+
- Appraisals
|
180
|
+
- CHANGELOG.md
|
181
|
+
- Gemfile
|
182
|
+
- LICENSE.txt
|
183
|
+
- README.md
|
184
|
+
- Rakefile
|
185
|
+
- gemfiles/rails_4.2_pc_4.1.gemfile
|
186
|
+
- gemfiles/rails_4.2_pc_4.2.gemfile
|
187
|
+
- gemfiles/rails_4.2_pc_5.0.gemfile
|
188
|
+
- gemfiles/rails_4.2_pc_5.1.gemfile
|
189
|
+
- gemfiles/rails_5.0_pc_5.0.gemfile
|
190
|
+
- gemfiles/rails_5.1_pc_5.1.gemfile
|
191
|
+
- lib/paperclip/permanent_records.rb
|
192
|
+
- lib/paperclip/permanent_records/active_record.rb
|
193
|
+
- lib/paperclip/permanent_records/gem_helper.rb
|
194
|
+
- lib/paperclip/permanent_records/gem_tasks.rb
|
195
|
+
- lib/paperclip/permanent_records/paperclip_patch.rb
|
196
|
+
- lib/paperclip/permanent_records/version.rb
|
197
|
+
- paperclip-permanent_records.gemspec
|
198
|
+
- spec/data/models.rb
|
199
|
+
- spec/data/schema.rb
|
200
|
+
- spec/data/test.png
|
201
|
+
- spec/paperclip/permanent_records_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
homepage: ''
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
metadata: {}
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '2.2'
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubyforge_project:
|
223
|
+
rubygems_version: 2.6.14
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: Make paperclip attachments work with permanent_records
|
227
|
+
test_files:
|
228
|
+
- spec/data/models.rb
|
229
|
+
- spec/data/schema.rb
|
230
|
+
- spec/data/test.png
|
231
|
+
- spec/paperclip/permanent_records_spec.rb
|
232
|
+
- spec/spec_helper.rb
|