kt-paperclip 5.4.0 → 7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/custom.md +10 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.hound.yml +3 -1055
- data/.rubocop.yml +1061 -1
- data/.travis.yml +23 -4
- data/Appraisals +23 -0
- data/CONTRIBUTING.md +4 -5
- data/Gemfile +10 -7
- data/NEWS +52 -0
- data/README.md +58 -46
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +23 -13
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/gemfiles/6.1.gemfile +21 -0
- data/gemfiles/7.0.gemfile +21 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +103 -105
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +10 -5
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +21 -9
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +16 -12
- data/lib/paperclip/storage/filesystem.rb +6 -8
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +68 -76
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -5
- data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
- data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +28 -11
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +16 -17
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +18 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +58 -37
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +90 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +29 -6
- data/spec/paperclip/storage/fog_spec.rb +122 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +649 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -19
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +61 -46
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/fixtures/aws_s3.yml +13 -0
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +58 -106
- data/spec/support/conditional_filter_helper.rb +0 -5
data/spec/paperclip/rake_spec.rb
CHANGED
@@ -1,102 +1,102 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
load
|
1
|
+
require "spec_helper"
|
2
|
+
require "rake"
|
3
|
+
load "./lib/tasks/paperclip.rake"
|
4
4
|
|
5
5
|
describe Rake do
|
6
6
|
context "calling `rake paperclip:refresh:thumbnails`" do
|
7
7
|
before do
|
8
8
|
rebuild_model
|
9
|
-
Paperclip::Task.
|
9
|
+
allow(Paperclip::Task).to receive(:obtain_class).and_return("Dummy")
|
10
10
|
@bogus_instance = Dummy.new
|
11
|
-
@bogus_instance.id =
|
12
|
-
@bogus_instance.avatar.
|
11
|
+
@bogus_instance.id = "some_id"
|
12
|
+
allow(@bogus_instance.avatar).to receive(:reprocess!)
|
13
13
|
@valid_instance = Dummy.new
|
14
|
-
@valid_instance.avatar.
|
15
|
-
Paperclip::Task.
|
16
|
-
Paperclip.
|
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
17
|
end
|
18
18
|
context "when there is an exception in reprocess!" do
|
19
19
|
before do
|
20
|
-
@bogus_instance.avatar.
|
20
|
+
allow(@bogus_instance.avatar).to receive(:reprocess!).and_raise
|
21
21
|
end
|
22
22
|
|
23
23
|
it "catches the exception" do
|
24
24
|
assert_nothing_raised do
|
25
|
-
::Rake::Task[
|
25
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
it "continues to the next instance" do
|
30
|
-
@valid_instance.avatar.
|
31
|
-
::Rake::Task[
|
30
|
+
expect(@valid_instance.avatar).to receive(:reprocess!)
|
31
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
32
32
|
end
|
33
33
|
|
34
34
|
it "prints the exception" do
|
35
|
-
exception_msg =
|
36
|
-
@bogus_instance.avatar.
|
37
|
-
Paperclip::Task.
|
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
38
|
str.match exception_msg
|
39
39
|
end
|
40
|
-
::Rake::Task[
|
40
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
41
41
|
end
|
42
42
|
|
43
43
|
it "prints the class name" do
|
44
|
-
Paperclip::Task.
|
45
|
-
str.match
|
44
|
+
expect(Paperclip::Task).to receive(:log_error) do |str|
|
45
|
+
str.match "Dummy"
|
46
46
|
end
|
47
|
-
::Rake::Task[
|
47
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
48
48
|
end
|
49
49
|
|
50
50
|
it "prints the instance ID" do
|
51
|
-
Paperclip::Task.
|
51
|
+
expect(Paperclip::Task).to receive(:log_error) do |str|
|
52
52
|
str.match "ID #{@bogus_instance.id}"
|
53
53
|
end
|
54
|
-
::Rake::Task[
|
54
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
context "when there is an error in reprocess!" do
|
59
59
|
before do
|
60
|
-
@errors =
|
61
|
-
@errors.
|
62
|
-
@errors.
|
63
|
-
@bogus_instance.
|
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
64
|
end
|
65
65
|
|
66
66
|
it "continues to the next instance" do
|
67
|
-
@valid_instance.avatar.
|
68
|
-
::Rake::Task[
|
67
|
+
expect(@valid_instance.avatar).to receive(:reprocess!)
|
68
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
69
69
|
end
|
70
70
|
|
71
71
|
it "prints the error" do
|
72
|
-
error_msg =
|
73
|
-
@errors.
|
74
|
-
Paperclip::Task.
|
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
75
|
str.match error_msg
|
76
76
|
end
|
77
|
-
::Rake::Task[
|
77
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
78
78
|
end
|
79
79
|
|
80
80
|
it "prints the class name" do
|
81
|
-
Paperclip::Task.
|
82
|
-
str.match
|
81
|
+
expect(Paperclip::Task).to receive(:log_error) do |str|
|
82
|
+
str.match "Dummy"
|
83
83
|
end
|
84
|
-
::Rake::Task[
|
84
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
85
85
|
end
|
86
86
|
|
87
87
|
it "prints the instance ID" do
|
88
|
-
Paperclip::Task.
|
88
|
+
expect(Paperclip::Task).to receive(:log_error) do |str|
|
89
89
|
str.match "ID #{@bogus_instance.id}"
|
90
90
|
end
|
91
|
-
::Rake::Task[
|
91
|
+
::Rake::Task["paperclip:refresh:thumbnails"].execute
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
context "Paperclip::Task.log_error method" do
|
97
97
|
it "prints its argument to STDERR" do
|
98
|
-
msg =
|
99
|
-
$stderr.
|
98
|
+
msg = "Some Message"
|
99
|
+
expect($stderr).to receive(:puts).with(msg)
|
100
100
|
Paperclip::Task.log_error(msg)
|
101
101
|
end
|
102
102
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "paperclip/schema"
|
3
|
+
require "active_support/testing/deprecation"
|
4
4
|
|
5
5
|
describe Paperclip::Schema do
|
6
6
|
include ActiveSupport::Testing::Deprecation
|
@@ -10,7 +10,11 @@ describe Paperclip::Schema do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
after do
|
13
|
-
|
13
|
+
begin
|
14
|
+
Dummy.connection.drop_table :dummies
|
15
|
+
rescue StandardError
|
16
|
+
nil
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
context "within table definition" do
|
@@ -25,12 +29,12 @@ describe Paperclip::Schema do
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
32
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
29
33
|
|
30
|
-
expect(columns).to include([
|
31
|
-
expect(columns).to include([
|
32
|
-
expect(columns).to include([
|
33
|
-
expect(columns).to include([
|
34
|
+
expect(columns).to include(["avatar_file_name", "varchar"])
|
35
|
+
expect(columns).to include(["avatar_content_type", "varchar"])
|
36
|
+
expect(columns).to include(["avatar_file_size", "bigint"])
|
37
|
+
expect(columns).to include(["avatar_updated_at", "datetime"])
|
34
38
|
end
|
35
39
|
|
36
40
|
it "displays deprecation warning" do
|
@@ -50,19 +54,19 @@ describe Paperclip::Schema do
|
|
50
54
|
end
|
51
55
|
|
52
56
|
it "creates attachment columns" do
|
53
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
57
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
54
58
|
|
55
|
-
expect(columns).to include([
|
56
|
-
expect(columns).to include([
|
57
|
-
expect(columns).to include([
|
58
|
-
expect(columns).to include([
|
59
|
+
expect(columns).to include(["avatar_file_name", "varchar"])
|
60
|
+
expect(columns).to include(["avatar_content_type", "varchar"])
|
61
|
+
expect(columns).to include(["avatar_file_size", "bigint"])
|
62
|
+
expect(columns).to include(["avatar_updated_at", "datetime"])
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
62
66
|
context "using #attachment with options" do
|
63
67
|
before do
|
64
68
|
Dummy.connection.create_table :dummies, force: true do |t|
|
65
|
-
t.attachment :avatar, default: 1, file_name: { default:
|
69
|
+
t.attachment :avatar, default: 1, file_name: { default: "default" }
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
@@ -89,18 +93,18 @@ describe Paperclip::Schema do
|
|
89
93
|
end
|
90
94
|
|
91
95
|
it "creates attachment columns" do
|
92
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
96
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
93
97
|
|
94
|
-
expect(columns).to include([
|
95
|
-
expect(columns).to include([
|
96
|
-
expect(columns).to include([
|
97
|
-
expect(columns).to include([
|
98
|
+
expect(columns).to include(["avatar_file_name", "varchar"])
|
99
|
+
expect(columns).to include(["avatar_content_type", "varchar"])
|
100
|
+
expect(columns).to include(["avatar_file_size", "bigint"])
|
101
|
+
expect(columns).to include(["avatar_updated_at", "datetime"])
|
98
102
|
end
|
99
103
|
end
|
100
104
|
|
101
105
|
context "with single attachment and options" do
|
102
106
|
before do
|
103
|
-
Dummy.connection.add_attachment :dummies, :avatar, default:
|
107
|
+
Dummy.connection.add_attachment :dummies, :avatar, default: "1", file_name: { default: "default" }
|
104
108
|
end
|
105
109
|
|
106
110
|
it "sets defaults on columns" do
|
@@ -119,22 +123,22 @@ describe Paperclip::Schema do
|
|
119
123
|
end
|
120
124
|
|
121
125
|
it "creates attachment columns" do
|
122
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
126
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
123
127
|
|
124
|
-
expect(columns).to include([
|
125
|
-
expect(columns).to include([
|
126
|
-
expect(columns).to include([
|
127
|
-
expect(columns).to include([
|
128
|
-
expect(columns).to include([
|
129
|
-
expect(columns).to include([
|
130
|
-
expect(columns).to include([
|
131
|
-
expect(columns).to include([
|
128
|
+
expect(columns).to include(["avatar_file_name", "varchar"])
|
129
|
+
expect(columns).to include(["avatar_content_type", "varchar"])
|
130
|
+
expect(columns).to include(["avatar_file_size", "bigint"])
|
131
|
+
expect(columns).to include(["avatar_updated_at", "datetime"])
|
132
|
+
expect(columns).to include(["photo_file_name", "varchar"])
|
133
|
+
expect(columns).to include(["photo_content_type", "varchar"])
|
134
|
+
expect(columns).to include(["photo_file_size", "bigint"])
|
135
|
+
expect(columns).to include(["photo_updated_at", "datetime"])
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
135
139
|
context "with multiple attachments and options" do
|
136
140
|
before do
|
137
|
-
Dummy.connection.add_attachment :dummies, :avatar, :photo, default:
|
141
|
+
Dummy.connection.add_attachment :dummies, :avatar, :photo, default: "1", file_name: { default: "default" }
|
138
142
|
end
|
139
143
|
|
140
144
|
it "sets defaults on columns" do
|
@@ -164,7 +168,7 @@ describe Paperclip::Schema do
|
|
164
168
|
Dummy.connection.change_table :dummies do |t|
|
165
169
|
t.column :avatar_file_name, :string
|
166
170
|
t.column :avatar_content_type, :string
|
167
|
-
t.column :avatar_file_size, :
|
171
|
+
t.column :avatar_file_size, :bigint
|
168
172
|
t.column :avatar_updated_at, :datetime
|
169
173
|
end
|
170
174
|
end
|
@@ -178,12 +182,12 @@ describe Paperclip::Schema do
|
|
178
182
|
Dummy.connection.drop_attached_file :dummies, :avatar
|
179
183
|
end
|
180
184
|
|
181
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
185
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
182
186
|
|
183
|
-
expect(columns).to_not include([
|
184
|
-
expect(columns).to_not include([
|
185
|
-
expect(columns).to_not include([
|
186
|
-
expect(columns).to_not include([
|
187
|
+
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
188
|
+
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
189
|
+
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
190
|
+
expect(columns).to_not include(["avatar_updated_at", "datetime"])
|
187
191
|
end
|
188
192
|
|
189
193
|
it "displays a deprecation warning" do
|
@@ -200,12 +204,12 @@ describe Paperclip::Schema do
|
|
200
204
|
end
|
201
205
|
|
202
206
|
it "removes the attachment columns" do
|
203
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
207
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
204
208
|
|
205
|
-
expect(columns).to_not include([
|
206
|
-
expect(columns).to_not include([
|
207
|
-
expect(columns).to_not include([
|
208
|
-
expect(columns).to_not include([
|
209
|
+
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
210
|
+
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
211
|
+
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
212
|
+
expect(columns).to_not include(["avatar_updated_at", "datetime"])
|
209
213
|
end
|
210
214
|
end
|
211
215
|
|
@@ -214,7 +218,7 @@ describe Paperclip::Schema do
|
|
214
218
|
Dummy.connection.change_table :dummies do |t|
|
215
219
|
t.column :photo_file_name, :string
|
216
220
|
t.column :photo_content_type, :string
|
217
|
-
t.column :photo_file_size, :
|
221
|
+
t.column :photo_file_size, :bigint
|
218
222
|
t.column :photo_updated_at, :datetime
|
219
223
|
end
|
220
224
|
|
@@ -222,16 +226,16 @@ describe Paperclip::Schema do
|
|
222
226
|
end
|
223
227
|
|
224
228
|
it "removes the attachment columns" do
|
225
|
-
columns = Dummy.columns.map{ |column| [column.name, column.
|
226
|
-
|
227
|
-
expect(columns).to_not include([
|
228
|
-
expect(columns).to_not include([
|
229
|
-
expect(columns).to_not include([
|
230
|
-
expect(columns).to_not include([
|
231
|
-
expect(columns).to_not include([
|
232
|
-
expect(columns).to_not include([
|
233
|
-
expect(columns).to_not include([
|
234
|
-
expect(columns).to_not include([
|
229
|
+
columns = Dummy.columns.map { |column| [column.name, column.sql_type] }
|
230
|
+
|
231
|
+
expect(columns).to_not include(["avatar_file_name", "varchar"])
|
232
|
+
expect(columns).to_not include(["avatar_content_type", "varchar"])
|
233
|
+
expect(columns).to_not include(["avatar_file_size", "bigint"])
|
234
|
+
expect(columns).to_not include(["avatar_updated_at", "datetime"])
|
235
|
+
expect(columns).to_not include(["photo_file_name", "varchar"])
|
236
|
+
expect(columns).to_not include(["photo_content_type", "varchar"])
|
237
|
+
expect(columns).to_not include(["photo_file_size", "bigint"])
|
238
|
+
expect(columns).to_not include(["photo_updated_at", "datetime"])
|
235
239
|
end
|
236
240
|
end
|
237
241
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Storage::Filesystem do
|
4
4
|
context "Filesystem" do
|
@@ -7,7 +7,7 @@ describe Paperclip::Storage::Filesystem do
|
|
7
7
|
rebuild_model styles: { thumbnail: "25x25#" }
|
8
8
|
@dummy = Dummy.create!
|
9
9
|
|
10
|
-
@file = File.open(fixture_file(
|
10
|
+
@file = File.open(fixture_file("5k.png"))
|
11
11
|
@dummy.avatar = @file
|
12
12
|
end
|
13
13
|
|
@@ -38,17 +38,40 @@ describe Paperclip::Storage::Filesystem do
|
|
38
38
|
it "is removed after after_flush_writes" do
|
39
39
|
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
40
40
|
@dummy.save
|
41
|
-
assert paths.none?{ |path| File.exist?(path) },
|
42
|
-
|
41
|
+
assert paths.none? { |path| File.exist?(path) },
|
42
|
+
"Expect all the files to be deleted."
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it "copies the file to a known location with copy_to_local_file" do
|
46
46
|
tempfile = Tempfile.new("known_location")
|
47
47
|
@dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
48
48
|
tempfile.rewind
|
49
49
|
assert_equal @file.read, tempfile.read
|
50
50
|
tempfile.close
|
51
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
|
52
75
|
end
|
53
76
|
|
54
77
|
context "with file that has space in file name" do
|
@@ -56,7 +79,7 @@ describe Paperclip::Storage::Filesystem do
|
|
56
79
|
rebuild_model styles: { thumbnail: "25x25#" }
|
57
80
|
@dummy = Dummy.create!
|
58
81
|
|
59
|
-
@file = File.open(fixture_file(
|
82
|
+
@file = File.open(fixture_file("spaced file.png"))
|
60
83
|
@dummy.avatar = @file
|
61
84
|
@dummy.save
|
62
85
|
end
|