jr-paperclip 8.0.1 → 8.0.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/NEWS +9 -0
- data/lib/paperclip/thumbnail.rb +18 -15
- data/lib/paperclip/version.rb +1 -1
- metadata +3 -245
- data/.github/FUNDING.yml +0 -3
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -18
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- data/.github/workflows/reviewdog.yml +0 -23
- data/.github/workflows/tests.yml +0 -56
- data/.gitignore +0 -19
- data/.qlty/.gitignore +0 -7
- data/.qlty/qlty.toml +0 -89
- data/Appraisals +0 -29
- data/Gemfile +0 -18
- data/bin/console +0 -11
- data/features/basic_integration.feature +0 -112
- data/features/migration.feature +0 -29
- data/features/rake_tasks.feature +0 -62
- data/features/step_definitions/attachment_steps.rb +0 -138
- data/features/step_definitions/html_steps.rb +0 -15
- data/features/step_definitions/rails_steps.rb +0 -271
- data/features/step_definitions/s3_steps.rb +0 -16
- data/features/step_definitions/web_steps.rb +0 -106
- data/features/support/env.rb +0 -12
- data/features/support/file_helpers.rb +0 -34
- data/features/support/fixtures/boot_config.txt +0 -15
- data/features/support/fixtures/gemfile.txt +0 -5
- data/features/support/fixtures/preinitializer.txt +0 -20
- data/features/support/paths.rb +0 -28
- data/features/support/rails.rb +0 -39
- data/features/support/selectors.rb +0 -19
- data/features/support/webmock_setup.rb +0 -8
- data/gemfiles/7.0.gemfile +0 -21
- data/gemfiles/7.1.gemfile +0 -21
- data/gemfiles/7.2.gemfile +0 -21
- data/gemfiles/8.0.gemfile +0 -21
- data/gemfiles/8.1.gemfile +0 -21
- data/paperclip.gemspec +0 -52
- data/spec/database.yml +0 -4
- data/spec/paperclip/attachment_definitions_spec.rb +0 -313
- data/spec/paperclip/attachment_processing_spec.rb +0 -79
- data/spec/paperclip/attachment_registry_spec.rb +0 -158
- data/spec/paperclip/attachment_spec.rb +0 -1617
- data/spec/paperclip/content_type_detector_spec.rb +0 -58
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -40
- data/spec/paperclip/filename_cleaner_spec.rb +0 -13
- data/spec/paperclip/geometry_detector_spec.rb +0 -96
- data/spec/paperclip/geometry_parser_spec.rb +0 -73
- data/spec/paperclip/geometry_spec.rb +0 -270
- data/spec/paperclip/glue_spec.rb +0 -63
- data/spec/paperclip/has_attached_file_spec.rb +0 -78
- data/spec/paperclip/helpers_spec.rb +0 -49
- data/spec/paperclip/integration_spec.rb +0 -702
- data/spec/paperclip/interpolations_spec.rb +0 -270
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +0 -160
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +0 -167
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +0 -88
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +0 -17
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +0 -134
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +0 -142
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +0 -8
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +0 -25
- data/spec/paperclip/io_adapters/registry_spec.rb +0 -35
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +0 -64
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +0 -146
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +0 -231
- data/spec/paperclip/lazy_thumbnail_compatibility_spec.rb +0 -266
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +0 -19
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +0 -108
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +0 -69
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +0 -88
- data/spec/paperclip/media_type_spoof_detector_spec.rb +0 -126
- data/spec/paperclip/meta_class_spec.rb +0 -30
- data/spec/paperclip/migration_guide_example_spec.rb +0 -44
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +0 -88
- data/spec/paperclip/paperclip_spec.rb +0 -196
- data/spec/paperclip/plural_cache_spec.rb +0 -37
- data/spec/paperclip/processor_helpers_spec.rb +0 -57
- data/spec/paperclip/processor_spec.rb +0 -60
- data/spec/paperclip/rails_environment_spec.rb +0 -30
- data/spec/paperclip/rake_spec.rb +0 -103
- data/spec/paperclip/schema_spec.rb +0 -298
- data/spec/paperclip/storage/filesystem_spec.rb +0 -102
- data/spec/paperclip/storage/fog_spec.rb +0 -606
- data/spec/paperclip/storage/s3_live_spec.rb +0 -188
- data/spec/paperclip/storage/s3_spec.rb +0 -1974
- data/spec/paperclip/style_spec.rb +0 -309
- data/spec/paperclip/tempfile_factory_spec.rb +0 -33
- data/spec/paperclip/tempfile_spec.rb +0 -35
- data/spec/paperclip/thumbnail_custom_options_spec.rb +0 -225
- data/spec/paperclip/thumbnail_loader_options_spec.rb +0 -53
- data/spec/paperclip/thumbnail_security_spec.rb +0 -42
- data/spec/paperclip/thumbnail_spec.rb +0 -1460
- data/spec/paperclip/url_generator_spec.rb +0 -231
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +0 -410
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +0 -249
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +0 -85
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +0 -325
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +0 -48
- data/spec/paperclip/validators_spec.rb +0 -179
- data/spec/spec_helper.rb +0 -52
- data/spec/support/assertions.rb +0 -84
- data/spec/support/fake_model.rb +0 -24
- data/spec/support/fake_rails.rb +0 -12
- data/spec/support/fixtures/12k.png +0 -0
- data/spec/support/fixtures/50x50.png +0 -0
- data/spec/support/fixtures/5k.png +0 -0
- data/spec/support/fixtures/animated +0 -0
- data/spec/support/fixtures/animated.gif +0 -0
- data/spec/support/fixtures/animated.unknown +0 -0
- data/spec/support/fixtures/aws_s3.yml +0 -13
- data/spec/support/fixtures/bad.png +0 -1
- data/spec/support/fixtures/empty.html +0 -1
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/fixtures/fog.yml +0 -8
- data/spec/support/fixtures/rotated.jpg +0 -0
- data/spec/support/fixtures/s3.yml +0 -8
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/spec/support/fixtures/spaced file.png +0 -0
- data/spec/support/fixtures/text.txt +0 -1
- data/spec/support/fixtures/twopage.pdf +0 -0
- data/spec/support/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +0 -5
- data/spec/support/matchers/exist.rb +0 -5
- data/spec/support/matchers/have_column.rb +0 -23
- data/spec/support/mock_attachment.rb +0 -24
- data/spec/support/mock_interpolator.rb +0 -24
- data/spec/support/mock_url_generator_builder.rb +0 -26
- data/spec/support/model_reconstruction.rb +0 -72
- data/spec/support/reporting.rb +0 -11
- data/spec/support/test_data.rb +0 -13
- data/spec/support/version_helper.rb +0 -9
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Processor do
|
|
4
|
-
it "instantiates and call #make when sent #make to the class" do
|
|
5
|
-
processor = double
|
|
6
|
-
expect(processor).to receive(:make)
|
|
7
|
-
expect(Paperclip::Processor).to receive(:new).with(:one, :two, :three).and_return(processor)
|
|
8
|
-
Paperclip::Processor.make(:one, :two, :three)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context "Calling #convert" do
|
|
12
|
-
it "runs the convert command with Terrapin" do
|
|
13
|
-
Paperclip.options[:log_command] = false
|
|
14
|
-
allow(Paperclip).to receive(:imagemagick7?).and_return(false)
|
|
15
|
-
Paperclip.options[:is_windows] = false
|
|
16
|
-
expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", {}).and_return(double(run: nil))
|
|
17
|
-
Paperclip::Processor.new("filename").convert("stuff")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "runs the magick convert command when ImageMagick 7 is present" do
|
|
21
|
-
Paperclip.options[:log_command] = false
|
|
22
|
-
allow(Paperclip).to receive(:imagemagick7?).and_return(true)
|
|
23
|
-
expect(Terrapin::CommandLine).to receive(:new).with("magick", "stuff", {}).and_return(double(run: nil))
|
|
24
|
-
Paperclip::Processor.new("filename").convert("stuff")
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "Calling #identify" do
|
|
29
|
-
it "runs the identify command" do
|
|
30
|
-
Paperclip.options[:log_command] = false
|
|
31
|
-
allow(Paperclip).to receive(:imagemagick7?).and_return(false)
|
|
32
|
-
Paperclip.options[:is_windows] = false
|
|
33
|
-
expect(Terrapin::CommandLine).to receive(:new).with("identify", "stuff", {}).and_return(double(run: nil))
|
|
34
|
-
Paperclip::Processor.new("filename").identify("stuff")
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "runs the magick identify command when ImageMagick 7 is present" do
|
|
38
|
-
Paperclip.options[:log_command] = false
|
|
39
|
-
allow(Paperclip).to receive(:imagemagick7?).and_return(true)
|
|
40
|
-
expect(Terrapin::CommandLine).to receive(:new).with("magick identify", "stuff", {}).and_return(double(run: nil))
|
|
41
|
-
Paperclip::Processor.new("filename").identify("stuff")
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context "Calling #vips" do
|
|
46
|
-
it "runs the vips command with Paperclip.run" do
|
|
47
|
-
Paperclip.options[:log_command] = false
|
|
48
|
-
expect(Paperclip).to receive(:run).with("vips", "stuff", { :some => "args" })
|
|
49
|
-
Paperclip::Processor.new("filename").vips("stuff", { :some => "args" })
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context "Calling #vipsheader" do
|
|
54
|
-
it "runs the vipsheader command with Paperclip.run" do
|
|
55
|
-
Paperclip.options[:log_command] = false
|
|
56
|
-
expect(Paperclip).to receive(:run).with("vipsheader", "stuff", { :some => "args" })
|
|
57
|
-
Paperclip::Processor.new("filename").vipsheader("stuff", { :some => "args" })
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::RailsEnvironment do
|
|
4
|
-
it "returns nil when Rails isn't defined" do
|
|
5
|
-
resetting_rails_to(nil) do
|
|
6
|
-
expect(Paperclip::RailsEnvironment.get).to be_nil
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "returns nil when Rails.env isn't defined" do
|
|
11
|
-
resetting_rails_to({}) do
|
|
12
|
-
expect(Paperclip::RailsEnvironment.get).to be_nil
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "returns the value of Rails.env if it is set" do
|
|
17
|
-
resetting_rails_to(OpenStruct.new(env: "foo")) do
|
|
18
|
-
expect(Paperclip::RailsEnvironment.get).to eq "foo"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def resetting_rails_to(new_value)
|
|
23
|
-
previous_rails = Object.send(:remove_const, "Rails")
|
|
24
|
-
Object.const_set("Rails", new_value) unless new_value.nil?
|
|
25
|
-
yield
|
|
26
|
-
ensure
|
|
27
|
-
Object.send(:remove_const, "Rails") if Object.const_defined?("Rails")
|
|
28
|
-
Object.const_set("Rails", previous_rails)
|
|
29
|
-
end
|
|
30
|
-
end
|
data/spec/paperclip/rake_spec.rb
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "rake"
|
|
3
|
-
load "./lib/tasks/paperclip.rake"
|
|
4
|
-
|
|
5
|
-
describe Rake do
|
|
6
|
-
context "calling `rake paperclip:refresh:thumbnails`" do
|
|
7
|
-
before do
|
|
8
|
-
rebuild_model
|
|
9
|
-
allow(Paperclip::Task).to receive(:obtain_class).and_return("Dummy")
|
|
10
|
-
@bogus_instance = Dummy.new
|
|
11
|
-
@bogus_instance.id = "some_id"
|
|
12
|
-
allow(@bogus_instance.avatar).to receive(:reprocess!)
|
|
13
|
-
@valid_instance = Dummy.new
|
|
14
|
-
allow(@valid_instance.avatar).to receive(:reprocess!)
|
|
15
|
-
allow(Paperclip::Task).to receive(:log_error)
|
|
16
|
-
allow(Paperclip).to receive(:each_instance_with_attachment).and_yield(@bogus_instance).and_yield(@valid_instance)
|
|
17
|
-
end
|
|
18
|
-
context "when there is an exception in reprocess!" do
|
|
19
|
-
before do
|
|
20
|
-
allow(@bogus_instance.avatar).to receive(:reprocess!).and_raise
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "catches the exception" do
|
|
24
|
-
assert_nothing_raised do
|
|
25
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "continues to the next instance" do
|
|
30
|
-
expect(@valid_instance.avatar).to receive(:reprocess!)
|
|
31
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "prints the exception" do
|
|
35
|
-
exception_msg = "Some Exception"
|
|
36
|
-
allow(@bogus_instance.avatar).to receive(:reprocess!).and_raise(exception_msg)
|
|
37
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
38
|
-
str.match exception_msg
|
|
39
|
-
end
|
|
40
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "prints the class name" do
|
|
44
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
45
|
-
str.match "Dummy"
|
|
46
|
-
end
|
|
47
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "prints the instance ID" do
|
|
51
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
52
|
-
str.match "ID #{@bogus_instance.id}"
|
|
53
|
-
end
|
|
54
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context "when there is an error in reprocess!" do
|
|
59
|
-
before do
|
|
60
|
-
@errors = double("errors")
|
|
61
|
-
allow(@errors).to receive(:full_messages).and_return([""])
|
|
62
|
-
allow(@errors).to receive(:blank?).and_return(false)
|
|
63
|
-
allow(@bogus_instance).to receive(:errors).and_return(@errors)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "continues to the next instance" do
|
|
67
|
-
expect(@valid_instance.avatar).to receive(:reprocess!)
|
|
68
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "prints the error" do
|
|
72
|
-
error_msg = "Some Error"
|
|
73
|
-
allow(@errors).to receive(:full_messages).and_return([error_msg])
|
|
74
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
75
|
-
str.match error_msg
|
|
76
|
-
end
|
|
77
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "prints the class name" do
|
|
81
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
82
|
-
str.match "Dummy"
|
|
83
|
-
end
|
|
84
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "prints the instance ID" do
|
|
88
|
-
expect(Paperclip::Task).to receive(:log_error) do |str|
|
|
89
|
-
str.match "ID #{@bogus_instance.id}"
|
|
90
|
-
end
|
|
91
|
-
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context "Paperclip::Task.log_error method" do
|
|
97
|
-
it "prints its argument to STDERR" do
|
|
98
|
-
msg = "Some Message"
|
|
99
|
-
expect($stderr).to receive(:puts).with(msg)
|
|
100
|
-
Paperclip::Task.log_error(msg)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "paperclip/schema"
|
|
3
|
-
require "active_support/testing/deprecation"
|
|
4
|
-
|
|
5
|
-
describe Paperclip::Schema do
|
|
6
|
-
include ActiveSupport::Testing::Deprecation
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
rebuild_class
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
after do
|
|
13
|
-
begin
|
|
14
|
-
ActiveRecord::Migration.drop_table :dummies
|
|
15
|
-
rescue StandardError
|
|
16
|
-
nil
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Helper to check datetime column (Rails 7+ uses datetime(6) precision by default)
|
|
21
|
-
def expect_datetime_column(columns, column_name)
|
|
22
|
-
datetime_column = columns.find { |col| col[0] == column_name }
|
|
23
|
-
expect(datetime_column).to be_present
|
|
24
|
-
expect(datetime_column[1]).to match(/^datetime/)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Helper to enable deprecation warnings for testing
|
|
28
|
-
def with_deprecation_warnings_enabled
|
|
29
|
-
if ActiveSupport::Deprecation.respond_to?(:silenced=)
|
|
30
|
-
old_silenced = ActiveSupport::Deprecation.silenced
|
|
31
|
-
ActiveSupport::Deprecation.silenced = false
|
|
32
|
-
yield
|
|
33
|
-
ActiveSupport::Deprecation.silenced = old_silenced
|
|
34
|
-
elsif defined?(ActiveSupport.deprecator)
|
|
35
|
-
old_behavior = ActiveSupport.deprecator.behavior
|
|
36
|
-
ActiveSupport.deprecator.behavior = :stderr
|
|
37
|
-
yield
|
|
38
|
-
ActiveSupport.deprecator.behavior = old_behavior
|
|
39
|
-
else
|
|
40
|
-
yield
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "within table definition" do
|
|
45
|
-
context "using #has_attached_file" do
|
|
46
|
-
it "creates attachment columns" do
|
|
47
|
-
ActiveRecord::Migration.create_table :dummies, force: true do |t|
|
|
48
|
-
if ActiveSupport::Deprecation.respond_to?(:silence)
|
|
49
|
-
ActiveSupport::Deprecation.silence do
|
|
50
|
-
t.has_attached_file :avatar
|
|
51
|
-
end
|
|
52
|
-
elsif defined?(ActiveSupport.deprecator)
|
|
53
|
-
ActiveSupport.deprecator.silence do
|
|
54
|
-
t.has_attached_file :avatar
|
|
55
|
-
end
|
|
56
|
-
else
|
|
57
|
-
t.has_attached_file :avatar
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
62
|
-
|
|
63
|
-
expect(columns).to include(["avatar_file_name", "varchar"])
|
|
64
|
-
expect(columns).to include(["avatar_content_type", "varchar"])
|
|
65
|
-
expect(columns).to include(["avatar_file_size", "bigint"])
|
|
66
|
-
expect_datetime_column(columns, "avatar_updated_at")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "displays deprecation warning" do
|
|
70
|
-
with_deprecation_warnings_enabled do
|
|
71
|
-
ActiveRecord::Migration.create_table :dummies, force: true do |t|
|
|
72
|
-
deprecator = defined?(ActiveSupport.deprecator) ? ActiveSupport.deprecator : ActiveSupport::Deprecation
|
|
73
|
-
assert_deprecated(nil, deprecator) do
|
|
74
|
-
t.has_attached_file :avatar
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
context "using #attachment" do
|
|
82
|
-
before do
|
|
83
|
-
ActiveRecord::Migration.create_table :dummies, force: true do |t|
|
|
84
|
-
t.attachment :avatar
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "creates attachment columns" do
|
|
89
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
90
|
-
|
|
91
|
-
expect(columns).to include(["avatar_file_name", "varchar"])
|
|
92
|
-
expect(columns).to include(["avatar_content_type", "varchar"])
|
|
93
|
-
expect(columns).to include(["avatar_file_size", "bigint"])
|
|
94
|
-
expect_datetime_column(columns, "avatar_updated_at")
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "using #attachment with options" do
|
|
99
|
-
before do
|
|
100
|
-
ActiveRecord::Migration.create_table :dummies, force: true do |t|
|
|
101
|
-
t.attachment :avatar, default: 1, file_name: { default: "default" }
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "sets defaults on columns" do
|
|
106
|
-
defaults_columns = ["avatar_file_name", "avatar_content_type", "avatar_file_size"]
|
|
107
|
-
columns = Dummy.columns.select { |e| defaults_columns.include? e.name }
|
|
108
|
-
|
|
109
|
-
expect(columns).to have_column("avatar_file_name").with_default("default")
|
|
110
|
-
expect(columns).to have_column("avatar_content_type").with_default("1")
|
|
111
|
-
expect(columns).to have_column("avatar_file_size").with_default(1)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context "within schema statement" do
|
|
117
|
-
before do
|
|
118
|
-
ActiveRecord::Migration.create_table :dummies, force: true
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
context "migrating up" do
|
|
122
|
-
context "with single attachment" do
|
|
123
|
-
before do
|
|
124
|
-
ActiveRecord::Migration.add_attachment :dummies, :avatar
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it "creates attachment columns" do
|
|
128
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
129
|
-
|
|
130
|
-
expect(columns).to include(["avatar_file_name", "varchar"])
|
|
131
|
-
expect(columns).to include(["avatar_content_type", "varchar"])
|
|
132
|
-
expect(columns).to include(["avatar_file_size", "bigint"])
|
|
133
|
-
expect_datetime_column(columns, "avatar_updated_at")
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "with single attachment and options" do
|
|
138
|
-
before do
|
|
139
|
-
ActiveRecord::Migration.add_attachment :dummies, :avatar, default: "1", file_name: { default: "default" }
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "sets defaults on columns" do
|
|
143
|
-
defaults_columns = ["avatar_file_name", "avatar_content_type", "avatar_file_size"]
|
|
144
|
-
columns = Dummy.columns.select { |e| defaults_columns.include? e.name }
|
|
145
|
-
|
|
146
|
-
expect(columns).to have_column("avatar_file_name").with_default("default")
|
|
147
|
-
expect(columns).to have_column("avatar_content_type").with_default("1")
|
|
148
|
-
expect(columns).to have_column("avatar_file_size").with_default(1)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context "with multiple attachments" do
|
|
153
|
-
before do
|
|
154
|
-
ActiveRecord::Migration.add_attachment :dummies, :avatar, :photo
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "creates attachment columns" do
|
|
158
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
159
|
-
|
|
160
|
-
expect(columns).to include(["avatar_file_name", "varchar"])
|
|
161
|
-
expect(columns).to include(["avatar_content_type", "varchar"])
|
|
162
|
-
expect(columns).to include(["avatar_file_size", "bigint"])
|
|
163
|
-
expect_datetime_column(columns, "avatar_updated_at")
|
|
164
|
-
expect(columns).to include(["photo_file_name", "varchar"])
|
|
165
|
-
expect(columns).to include(["photo_content_type", "varchar"])
|
|
166
|
-
expect(columns).to include(["photo_file_size", "bigint"])
|
|
167
|
-
expect_datetime_column(columns, "photo_updated_at")
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
context "with multiple attachments and options" do
|
|
172
|
-
before do
|
|
173
|
-
ActiveRecord::Migration.add_attachment :dummies, :avatar, :photo, default: "1", file_name: { default: "default" }
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it "sets defaults on columns" do
|
|
177
|
-
defaults_columns = ["avatar_file_name", "avatar_content_type", "avatar_file_size", "photo_file_name", "photo_content_type", "photo_file_size"]
|
|
178
|
-
columns = Dummy.columns.select { |e| defaults_columns.include? e.name }
|
|
179
|
-
|
|
180
|
-
expect(columns).to have_column("avatar_file_name").with_default("default")
|
|
181
|
-
expect(columns).to have_column("avatar_content_type").with_default("1")
|
|
182
|
-
expect(columns).to have_column("avatar_file_size").with_default(1)
|
|
183
|
-
expect(columns).to have_column("photo_file_name").with_default("default")
|
|
184
|
-
expect(columns).to have_column("photo_content_type").with_default("1")
|
|
185
|
-
expect(columns).to have_column("photo_file_size").with_default(1)
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
context "with no attachment" do
|
|
190
|
-
it "raises an error" do
|
|
191
|
-
assert_raises ArgumentError do
|
|
192
|
-
ActiveRecord::Migration.add_attachment :dummies
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
context "migrating down" do
|
|
199
|
-
before do
|
|
200
|
-
ActiveRecord::Migration.change_table :dummies do |t|
|
|
201
|
-
t.column :avatar_file_name, :string
|
|
202
|
-
t.column :avatar_content_type, :string
|
|
203
|
-
t.column :avatar_file_size, :bigint
|
|
204
|
-
t.column :avatar_updated_at, :datetime
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
# Helper to check datetime column is NOT present
|
|
209
|
-
def expect_no_datetime_column(columns, column_name)
|
|
210
|
-
datetime_column = columns.find { |col| col[0] == column_name }
|
|
211
|
-
expect(datetime_column).to be_nil
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
context "using #drop_attached_file" do
|
|
215
|
-
it "removes the attachment columns" do
|
|
216
|
-
if ActiveSupport::Deprecation.respond_to?(:silence)
|
|
217
|
-
ActiveSupport::Deprecation.silence do
|
|
218
|
-
ActiveRecord::Migration.drop_attached_file :dummies, :avatar
|
|
219
|
-
end
|
|
220
|
-
elsif defined?(ActiveSupport.deprecator)
|
|
221
|
-
ActiveSupport.deprecator.silence do
|
|
222
|
-
ActiveRecord::Migration.drop_attached_file :dummies, :avatar
|
|
223
|
-
end
|
|
224
|
-
else
|
|
225
|
-
ActiveRecord::Migration.drop_attached_file :dummies, :avatar
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
229
|
-
|
|
230
|
-
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
|
231
|
-
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
|
232
|
-
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
|
233
|
-
expect_no_datetime_column(columns, "avatar_updated_at")
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
it "displays a deprecation warning" do
|
|
237
|
-
with_deprecation_warnings_enabled do
|
|
238
|
-
deprecator = defined?(ActiveSupport.deprecator) ? ActiveSupport.deprecator : ActiveSupport::Deprecation
|
|
239
|
-
assert_deprecated(nil, deprecator) do
|
|
240
|
-
ActiveRecord::Migration.drop_attached_file :dummies, :avatar
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
context "using #remove_attachment" do
|
|
247
|
-
context "with single attachment" do
|
|
248
|
-
before do
|
|
249
|
-
ActiveRecord::Migration.remove_attachment :dummies, :avatar
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it "removes the attachment columns" do
|
|
253
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
254
|
-
|
|
255
|
-
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
|
256
|
-
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
|
257
|
-
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
|
258
|
-
expect_no_datetime_column(columns, "avatar_updated_at")
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
context "with multiple attachments" do
|
|
263
|
-
before do
|
|
264
|
-
ActiveRecord::Migration.change_table :dummies do |t|
|
|
265
|
-
t.column :photo_file_name, :string
|
|
266
|
-
t.column :photo_content_type, :string
|
|
267
|
-
t.column :photo_file_size, :bigint
|
|
268
|
-
t.column :photo_updated_at, :datetime
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
ActiveRecord::Migration.remove_attachment :dummies, :avatar, :photo
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it "removes the attachment columns" do
|
|
275
|
-
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
|
276
|
-
|
|
277
|
-
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
|
278
|
-
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
|
279
|
-
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
|
280
|
-
expect_no_datetime_column(columns, "avatar_updated_at")
|
|
281
|
-
expect(columns).to_not include(["photo_file_name", "varchar"])
|
|
282
|
-
expect(columns).to_not include(["photo_content_type", "varchar"])
|
|
283
|
-
expect(columns).to_not include(["photo_file_size", "bigint"])
|
|
284
|
-
expect_no_datetime_column(columns, "photo_updated_at")
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
context "with no attachment" do
|
|
289
|
-
it "raises an error" do
|
|
290
|
-
assert_raises ArgumentError do
|
|
291
|
-
ActiveRecord::Migration.remove_attachment :dummies
|
|
292
|
-
end
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
end
|
|
298
|
-
end
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe Paperclip::Storage::Filesystem do
|
|
4
|
-
context "Filesystem" do
|
|
5
|
-
context "normal file" do
|
|
6
|
-
before do
|
|
7
|
-
rebuild_model styles: { thumbnail: "25x25#" }
|
|
8
|
-
@dummy = Dummy.create!
|
|
9
|
-
|
|
10
|
-
@file = File.open(fixture_file("5k.png"))
|
|
11
|
-
@dummy.avatar = @file
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after { @file.close }
|
|
15
|
-
|
|
16
|
-
it "allows file assignment" do
|
|
17
|
-
assert @dummy.save
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "stores the original" do
|
|
21
|
-
@dummy.save
|
|
22
|
-
assert_file_exists(@dummy.avatar.path)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "stores the thumbnail" do
|
|
26
|
-
@dummy.save
|
|
27
|
-
assert_file_exists(@dummy.avatar.path(:thumbnail))
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "is rewinded after flush_writes" do
|
|
31
|
-
@dummy.avatar.instance_eval "def after_flush_writes; end"
|
|
32
|
-
|
|
33
|
-
files = @dummy.avatar.queued_for_write.values
|
|
34
|
-
@dummy.save
|
|
35
|
-
assert files.none?(&:eof?), "Expect all the files to be rewinded."
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "is removed after after_flush_writes" do
|
|
39
|
-
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
|
40
|
-
@dummy.save
|
|
41
|
-
assert paths.none? { |path| File.exist?(path) },
|
|
42
|
-
"Expect all the files to be deleted."
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "copies the file to a known location with copy_to_local_file" do
|
|
46
|
-
tempfile = Tempfile.new("known_location")
|
|
47
|
-
@dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
|
48
|
-
tempfile.rewind
|
|
49
|
-
assert_equal @file.read, tempfile.read
|
|
50
|
-
tempfile.close
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "only issues a delete call once for each unique attachment style when nullifying attachment" do
|
|
54
|
-
@dummy.save
|
|
55
|
-
@dummy.avatar.clear(:thumbnail)
|
|
56
|
-
@dummy.avatar = nil
|
|
57
|
-
assert_equal 3, @dummy.avatar.queued_for_delete.size
|
|
58
|
-
|
|
59
|
-
expect(FileUtils).to receive(:rm).twice
|
|
60
|
-
@dummy.save
|
|
61
|
-
|
|
62
|
-
FileUtils.rm_rf("tmp")
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "only issues a delete call once for each unique attachment style when destroying model" do
|
|
66
|
-
@dummy.save
|
|
67
|
-
@dummy.avatar.clear(:thumbnail)
|
|
68
|
-
assert_equal 1, @dummy.avatar.queued_for_delete.size
|
|
69
|
-
|
|
70
|
-
expect(FileUtils).to receive(:rm).twice
|
|
71
|
-
@dummy.destroy
|
|
72
|
-
|
|
73
|
-
FileUtils.rm_rf("tmp")
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "with file that has space in file name" do
|
|
78
|
-
before do
|
|
79
|
-
rebuild_model styles: { thumbnail: "25x25#" }
|
|
80
|
-
@dummy = Dummy.create!
|
|
81
|
-
|
|
82
|
-
@file = File.open(fixture_file("spaced file.png"))
|
|
83
|
-
@dummy.avatar = @file
|
|
84
|
-
@dummy.save
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
after { @file.close }
|
|
88
|
-
|
|
89
|
-
it "stores the file" do
|
|
90
|
-
assert_file_exists(@dummy.avatar.path)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "returns a replaced version for path" do
|
|
94
|
-
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "returns a replaced version for url" do
|
|
98
|
-
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|