paperclip 4.3.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -13
  3. data/Appraisals +22 -9
  4. data/CONTRIBUTING.md +16 -5
  5. data/Gemfile +2 -8
  6. data/LICENSE +1 -1
  7. data/NEWS +49 -2
  8. data/README.md +126 -102
  9. data/UPGRADING +12 -9
  10. data/features/basic_integration.feature +1 -0
  11. data/features/migration.feature +0 -24
  12. data/features/step_definitions/attachment_steps.rb +20 -20
  13. data/features/step_definitions/html_steps.rb +2 -2
  14. data/features/step_definitions/rails_steps.rb +11 -17
  15. data/features/step_definitions/s3_steps.rb +2 -2
  16. data/features/step_definitions/web_steps.rb +1 -103
  17. data/features/support/file_helpers.rb +2 -2
  18. data/gemfiles/4.2.awsv2.0.gemfile +17 -0
  19. data/gemfiles/4.2.awsv2.1.gemfile +17 -0
  20. data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -1
  21. data/gemfiles/5.0.awsv2.0.gemfile +17 -0
  22. data/gemfiles/5.0.awsv2.1.gemfile +17 -0
  23. data/gemfiles/{4.1.gemfile → 5.0.awsv2.gemfile} +2 -2
  24. data/lib/paperclip/attachment.rb +18 -17
  25. data/lib/paperclip/attachment_registry.rb +2 -1
  26. data/lib/paperclip/callbacks.rb +8 -6
  27. data/lib/paperclip/content_type_detector.rb +3 -2
  28. data/lib/paperclip/errors.rb +3 -1
  29. data/lib/paperclip/geometry_parser_factory.rb +1 -1
  30. data/lib/paperclip/glue.rb +1 -1
  31. data/lib/paperclip/has_attached_file.rb +7 -1
  32. data/lib/paperclip/helpers.rb +14 -10
  33. data/lib/paperclip/interpolations/plural_cache.rb +6 -5
  34. data/lib/paperclip/interpolations.rb +18 -13
  35. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  36. data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
  37. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  38. data/lib/paperclip/media_type_spoof_detector.rb +1 -1
  39. data/lib/paperclip/rails_environment.rb +1 -1
  40. data/lib/paperclip/schema.rb +3 -9
  41. data/lib/paperclip/storage/fog.rb +17 -8
  42. data/lib/paperclip/storage/s3.rb +51 -49
  43. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  44. data/lib/paperclip/version.rb +3 -1
  45. data/lib/paperclip.rb +2 -1
  46. data/lib/tasks/paperclip.rake +1 -1
  47. data/paperclip.gemspec +15 -11
  48. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  49. data/spec/paperclip/attachment_registry_spec.rb +28 -0
  50. data/spec/paperclip/attachment_spec.rb +36 -14
  51. data/spec/paperclip/geometry_spec.rb +1 -1
  52. data/spec/paperclip/glue_spec.rb +44 -0
  53. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  54. data/spec/paperclip/integration_spec.rb +4 -3
  55. data/spec/paperclip/interpolations_spec.rb +14 -4
  56. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
  57. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
  58. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  59. data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
  60. data/spec/paperclip/paperclip_spec.rb +3 -28
  61. data/spec/paperclip/plural_cache_spec.rb +17 -16
  62. data/spec/paperclip/storage/fog_spec.rb +31 -1
  63. data/spec/paperclip/storage/s3_live_spec.rb +8 -4
  64. data/spec/paperclip/storage/s3_spec.rb +213 -156
  65. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  66. data/spec/paperclip/validators_spec.rb +3 -3
  67. data/spec/spec_helper.rb +6 -1
  68. data/spec/support/assertions.rb +7 -0
  69. data/spec/support/model_reconstruction.rb +9 -1
  70. data/spec/support/reporting.rb +11 -0
  71. metadata +74 -47
  72. data/cucumber/paperclip_steps.rb +0 -6
  73. data/gemfiles/3.2.gemfile +0 -20
  74. data/lib/paperclip/locales/de.yml +0 -18
  75. data/lib/paperclip/locales/es.yml +0 -18
  76. data/lib/paperclip/locales/ja.yml +0 -18
  77. data/lib/paperclip/locales/pt-BR.yml +0 -18
  78. data/lib/paperclip/locales/zh-CN.yml +0 -18
  79. data/lib/paperclip/locales/zh-HK.yml +0 -18
  80. data/lib/paperclip/locales/zh-TW.yml +0 -18
  81. data/spec/support/rails_helpers.rb +0 -7
@@ -10,7 +10,7 @@ end
10
10
  World(AttachmentHelpers)
11
11
 
12
12
  When /^I modify my attachment definition to:$/ do |definition|
13
- content = in_current_dir { File.read("app/models/user.rb") }
13
+ content = cd(".") { File.read("app/models/user.rb") }
14
14
  name = content[/has_attached_file :\w+/][/:\w+/]
15
15
  content.gsub!(/has_attached_file.+end/m, <<-FILE)
16
16
  #{definition}
@@ -19,7 +19,7 @@ When /^I modify my attachment definition to:$/ do |definition|
19
19
  FILE
20
20
 
21
21
  write_file "app/models/user.rb", content
22
- in_current_dir { FileUtils.rm_rf ".rbx" }
22
+ cd(".") { FileUtils.rm_rf ".rbx" }
23
23
  end
24
24
 
25
25
  When /^I upload the fixture "([^"]*)"$/ do |filename|
@@ -27,20 +27,20 @@ When /^I upload the fixture "([^"]*)"$/ do |filename|
27
27
  end
28
28
 
29
29
  Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
30
- in_current_dir do
30
+ cd(".") do
31
31
  geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
32
- geometry.should == dimension
32
+ expect(geometry).to eq(dimension)
33
33
  end
34
34
  end
35
35
 
36
36
  Then /^the attachment "([^"]*)" should exist$/ do |filename|
37
- in_current_dir do
38
- File.exist?(attachment_path(filename)).should be
37
+ cd(".") do
38
+ expect(File.exist?(attachment_path(filename))).to be true
39
39
  end
40
40
  end
41
41
 
42
42
  When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
43
- in_current_dir do
43
+ cd(".") do
44
44
  require 'fileutils'
45
45
  FileUtils.rm_f attachment_path(attachment_filename)
46
46
  FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
@@ -48,7 +48,7 @@ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachme
48
48
  end
49
49
 
50
50
  Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
51
- in_current_dir do
51
+ cd(".") do
52
52
  begin
53
53
  # Use mime/types/columnar if available, for reduced memory usage
54
54
  require "mime/types/columnar"
@@ -57,32 +57,33 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)"
57
57
  end
58
58
 
59
59
  attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip
60
- attachment_content_type.should == MIME::Types.type_for(filename).first.content_type
60
+ expected = MIME::Types.type_for(filename).first.content_type
61
+ expect(attachment_content_type).to eq(expected)
61
62
  end
62
63
  end
63
64
 
64
65
  Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
65
- in_current_dir do
66
+ cd(".") do
66
67
  attachment_file_name = `bundle exec #{runner_command} "puts User.last.attachment_file_name"`.strip
67
- attachment_file_name.should == File.name(fixture_path(filename)).to_s
68
+ expect(attachment_file_name).to eq(File.name(fixture_path(filename)).to_s)
68
69
  end
69
70
  end
70
71
 
71
72
  Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
72
- in_current_dir do
73
+ cd(".") do
73
74
  attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip
74
- attachment_file_size.should == File.size(fixture_path(filename)).to_s
75
+ expect(attachment_file_size).to eq(File.size(fixture_path(filename)).to_s)
75
76
  end
76
77
  end
77
78
 
78
79
  Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
79
- in_current_dir do
80
- check_file_presence([attachment_path(filename)], !not_exist)
80
+ cd(".") do
81
+ expect(attachment_path(filename)).not_to be_an_existing_file
81
82
  end
82
83
  end
83
84
 
84
85
  Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
85
- in_current_dir do
86
+ cd(".") do
86
87
  columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
87
88
  expect_columns = [
88
89
  ["#{attachment_name}_file_name", :string],
@@ -90,13 +91,12 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
90
91
  ["#{attachment_name}_file_size", :integer],
91
92
  ["#{attachment_name}_updated_at", :datetime]
92
93
  ]
93
-
94
- expect_columns.all?{ |column| columns.include? column }.should eq true
94
+ expect(columns).to include(*expect_columns)
95
95
  end
96
96
  end
97
97
 
98
98
  Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
99
- in_current_dir do
99
+ cd(".") do
100
100
  columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
101
101
  expect_columns = [
102
102
  ["#{attachment_name}_file_name", :string],
@@ -105,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
105
105
  ["#{attachment_name}_updated_at", :datetime]
106
106
  ]
107
107
 
108
- expect_columns.none?{ |column| columns.include? column }.should eq true
108
+ expect(columns).not_to include(*expect_columns)
109
109
  end
110
110
  end
@@ -1,5 +1,5 @@
1
1
  Then %r{I should see an image with a path of "([^"]*)"} do |path|
2
- page.should have_css("img[src^='#{path}']")
2
+ expect(page).to have_css("img[src^='#{path}']")
3
3
  end
4
4
 
5
5
  Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
@@ -11,5 +11,5 @@ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
11
11
  page.body
12
12
  end
13
13
  actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
14
- actual.should == expected
14
+ expect(actual).to eq(expected)
15
15
  end
@@ -24,7 +24,7 @@ Given /^I generate a new rails application$/ do
24
24
  end
25
25
 
26
26
  Given "I fix the application.rb for 3.0.12" do
27
- in_current_dir do
27
+ cd(".") do
28
28
  File.open("config/application.rb", "a") do |f|
29
29
  f << "ActionController::Base.config.relative_url_root = ''"
30
30
  end
@@ -32,7 +32,7 @@ Given "I fix the application.rb for 3.0.12" do
32
32
  end
33
33
 
34
34
  Given "I allow the attachment to be submitted" do
35
- in_current_dir do
35
+ cd(".") do
36
36
  transform_file("app/controllers/users_controller.rb") do |content|
37
37
  content.gsub("params.require(:user).permit(:name)",
38
38
  "params.require(:user).permit!")
@@ -41,7 +41,7 @@ Given "I allow the attachment to be submitted" do
41
41
  end
42
42
 
43
43
  Given "I remove turbolinks" do
44
- in_current_dir do
44
+ cd(".") do
45
45
  transform_file("app/assets/javascripts/application.js") do |content|
46
46
  content.gsub("//= require turbolinks", "")
47
47
  end
@@ -70,7 +70,7 @@ def attach_attachment(name, definition = nil)
70
70
  snippet += definition
71
71
  end
72
72
  snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
73
- in_current_dir do
73
+ cd(".") do
74
74
  transform_file("app/models/user.rb") do |content|
75
75
  content.sub(/end\Z/, "#{snippet}\nend")
76
76
  end
@@ -78,7 +78,7 @@ def attach_attachment(name, definition = nil)
78
78
  end
79
79
 
80
80
  Given "I empty the application.js file" do
81
- in_current_dir do
81
+ cd(".") do
82
82
  transform_file("app/assets/javascripts/application.js") do |content|
83
83
  ""
84
84
  end
@@ -128,7 +128,7 @@ end
128
128
 
129
129
  Given /^I add this snippet to the User model:$/ do |snippet|
130
130
  file_name = "app/models/user.rb"
131
- in_current_dir do
131
+ cd(".") do
132
132
  content = File.read(file_name)
133
133
  File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
134
134
  end
@@ -136,14 +136,14 @@ end
136
136
 
137
137
  Given /^I add this snippet to config\/application.rb:$/ do |snippet|
138
138
  file_name = "config/application.rb"
139
- in_current_dir do
139
+ cd(".") do
140
140
  content = File.read(file_name)
141
141
  File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
142
142
  end
143
143
  end
144
144
 
145
145
  Given /^I start the rails application$/ do
146
- in_current_dir do
146
+ cd(".") do
147
147
  require "./config/environment"
148
148
  require "capybara/rails"
149
149
  end
@@ -154,7 +154,7 @@ Given /^I reload my application$/ do
154
154
  end
155
155
 
156
156
  When /^I turn off class caching$/ do
157
- in_current_dir do
157
+ cd(".") do
158
158
  file = "config/environments/test.rb"
159
159
  config = IO.read(file)
160
160
  config.gsub!(%r{^\s*config.cache_classes.*$},
@@ -166,7 +166,7 @@ end
166
166
  Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
167
167
  expected = IO.read(path)
168
168
  actual = read_from_web(web_file)
169
- actual.should == expected
169
+ expect(actual).to eq(expected)
170
170
  end
171
171
 
172
172
  When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
@@ -190,15 +190,9 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
190
190
  comment_out_gem_in_gemfile gemname
191
191
  end
192
192
 
193
- Given /^I am using Rails newer than ([\d\.]+)$/ do |version|
194
- if framework_version < version
195
- pending "Not supported in Rails < #{version}"
196
- end
197
- end
198
-
199
193
  Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
200
194
  filename = "#{directory}/#{processor}.rb"
201
- in_current_dir do
195
+ cd(".") do
202
196
  FileUtils.mkdir_p directory
203
197
  File.open(filename, "w") do |f|
204
198
  f.write(<<-CLASS)
@@ -1,11 +1,11 @@
1
1
  When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
2
2
  definition = Paperclip::AttachmentRegistry.definitions_for(User)[field.downcase.to_sym]
3
- path = "https://paperclip.s3.amazonaws.com#{definition[:path]}"
3
+ path = "https://paperclip.s3-us-west-2.amazonaws.com#{definition[:path]}"
4
4
  path.gsub!(':filename', File.basename(file_path))
5
5
  path.gsub!(/:([^\/\.]+)/) do |match|
6
6
  "([^\/\.]+)"
7
7
  end
8
- FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
8
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "<xml></xml>")
9
9
  step "I attach the file \"#{file_path}\" to \"#{field}\""
10
10
  end
11
11
 
@@ -103,107 +103,5 @@ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
103
103
  end
104
104
 
105
105
  Then /^(?:|I )should see "([^"]*)"$/ do |text|
106
- if page.respond_to? :should
107
- page.should have_content(text)
108
- else
109
- assert page.has_content?(text)
110
- end
111
- end
112
-
113
- Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
114
- regexp = Regexp.new(regexp)
115
-
116
- if page.respond_to? :should
117
- page.should have_xpath('//*', :text => regexp)
118
- else
119
- assert page.has_xpath?('//*', :text => regexp)
120
- end
121
- end
122
-
123
- Then /^(?:|I )should not see "([^"]*)"$/ do |text|
124
- if page.respond_to? :should
125
- page.should have_no_content(text)
126
- else
127
- assert page.has_no_content?(text)
128
- end
129
- end
130
-
131
- Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
132
- regexp = Regexp.new(regexp)
133
-
134
- if page.respond_to? :should
135
- page.should have_no_xpath('//*', :text => regexp)
136
- else
137
- assert page.has_no_xpath?('//*', :text => regexp)
138
- end
139
- end
140
-
141
- Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
142
- with_scope(parent) do
143
- field = find_field(field)
144
- if field.value.respond_to? :should
145
- field.value.should =~ /#{value}/
146
- else
147
- assert_match(/#{value}/, field.value)
148
- end
149
- end
150
- end
151
-
152
- Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
153
- with_scope(parent) do
154
- field = find_field(field)
155
- if field.value.respond_to? :should_not
156
- field.value.should_not =~ /#{value}/
157
- else
158
- assert_no_match(/#{value}/, field.value)
159
- end
160
- end
161
- end
162
-
163
- Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
164
- with_scope(parent) do
165
- field_checked = find_field(label)['checked']
166
- if field_checked.respond_to? :should
167
- field_checked.should eq true
168
- else
169
- assert field_checked
170
- end
171
- end
172
- end
173
-
174
- Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
175
- with_scope(parent) do
176
- field_checked = find_field(label)['checked']
177
- if field_checked.respond_to? :should
178
- field_checked.should eq false
179
- else
180
- assert !field_checked
181
- end
182
- end
183
- end
184
-
185
- Then /^(?:|I )should be on (.+)$/ do |page_name|
186
- current_path = URI.parse(current_url).path
187
- if current_path.respond_to? :should
188
- current_path.should == path_to(page_name)
189
- else
190
- assert_equal path_to(page_name), current_path
191
- end
192
- end
193
-
194
- Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
195
- query = URI.parse(current_url).query
196
- actual_params = query ? CGI.parse(query) : {}
197
- expected_params = {}
198
- expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
199
-
200
- if actual_params.respond_to? :should
201
- actual_params.should == expected_params
202
- else
203
- assert_equal expected_params, actual_params
204
- end
205
- end
206
-
207
- Then /^show me the page$/ do
208
- save_and_open_page
106
+ expect(page).to have_content(text)
209
107
  end
@@ -1,6 +1,6 @@
1
1
  module FileHelpers
2
2
  def append_to(path, contents)
3
- in_current_dir do
3
+ cd(".") do
4
4
  File.open(path, "a") do |file|
5
5
  file.puts
6
6
  file.puts contents
@@ -13,7 +13,7 @@ module FileHelpers
13
13
  end
14
14
 
15
15
  def comment_out_gem_in_gemfile(gemname)
16
- in_current_dir do
16
+ cd(".") do
17
17
  gemfile = File.read("Gemfile")
18
18
  gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
19
19
  File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "~> 4.2.0"
8
+ gem "aws-sdk", "~> 2.0.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "~> 4.2.0"
8
+ gem "aws-sdk", "~> 2.1.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types", ">= 1.16", "< 4"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -9,7 +9,7 @@ gem "rubysl", :platforms => :rbx
9
9
  gem "racc", :platforms => :rbx
10
10
  gem "pry"
11
11
  gem "rails", "~> 4.2.0"
12
- gem "paperclip", :path => "../"
12
+ gem "aws-sdk", "~> 2.0"
13
13
 
14
14
  group :development, :test do
15
15
  gem "mime-types", "~> 1.16"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "5.0.0"
8
+ gem "aws-sdk", "~> 2.0.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types", ">= 1.16", "< 4"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -0,0 +1,17 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.8", :platforms => :ruby
6
+ gem "pry"
7
+ gem "rails", "5.0.0"
8
+ gem "aws-sdk", "~> 2.1.0"
9
+
10
+ group :development, :test do
11
+ gem "activerecord-import"
12
+ gem "mime-types"
13
+ gem "builder"
14
+ gem "rubocop", :require => false
15
+ end
16
+
17
+ gemspec :path => "../"
@@ -8,8 +8,8 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
8
8
  gem "rubysl", :platforms => :rbx
9
9
  gem "racc", :platforms => :rbx
10
10
  gem "pry"
11
- gem "rails", "~> 4.1.0"
12
- gem "paperclip", :path => "../"
11
+ gem "rails", "~> 5.0.0"
12
+ gem "aws-sdk", "~> 2.0"
13
13
 
14
14
  group :development, :test do
15
15
  gem "mime-types", "~> 1.16"
@@ -2,6 +2,7 @@
2
2
  require 'uri'
3
3
  require 'paperclip/url_generator'
4
4
  require 'active_support/deprecation'
5
+ require 'active_support/core_ext/string/inflections'
5
6
 
6
7
  module Paperclip
7
8
  # The Attachment class manages the files for a given attachment. It saves
@@ -49,7 +50,8 @@ module Paperclip
49
50
  # +url+ - a relative URL of the attachment. This is interpolated using +interpolator+
50
51
  # +path+ - where on the filesystem to store the attachment. This is interpolated using +interpolator+
51
52
  # +styles+ - a hash of options for processing the attachment. See +has_attached_file+ for the details
52
- # +only_process+ - style args to be run through the post-processor. This defaults to the empty list
53
+ # +only_process+ - style args to be run through the post-processor. This defaults to the empty list (which is
54
+ # a special case that indicates all styles should be processed)
53
55
  # +default_url+ - a URL for the missing image
54
56
  # +default_style+ - the style to use when an argument is not specified e.g. #url, #path
55
57
  # +storage+ - the storage mechanism. Defaults to :filesystem
@@ -68,7 +70,8 @@ module Paperclip
68
70
  # +url_generator+ - the object used to generate URLs, using the interpolator. Defaults to Paperclip::UrlGenerator
69
71
  # +escape_url+ - Perform URI escaping to URLs. Defaults to true
70
72
  def initialize(name, instance, options = {})
71
- @name = name
73
+ @name = name.to_sym
74
+ @name_string = name.to_s
72
75
  @instance = instance
73
76
 
74
77
  options = self.class.default_options.deep_merge(options)
@@ -137,8 +140,6 @@ module Paperclip
137
140
  # +#for(style_name, options_hash)+
138
141
 
139
142
  def url(style_name = default_style, options = {})
140
- return nil if @instance.new_record?
141
-
142
143
  if options == true || options == false # Backwards compatibility.
143
144
  @url_generator.for(style_name, default_options.merge(:timestamp => options))
144
145
  else
@@ -323,7 +324,7 @@ module Paperclip
323
324
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@options[:hash_digest]).new, @options[:hash_secret], data)
324
325
  end
325
326
 
326
- # This method really shouldn't be called that often. It's expected use is
327
+ # This method really shouldn't be called that often. Its expected use is
327
328
  # in the paperclip:refresh rake task and that's it. It will regenerate all
328
329
  # thumbnails forcefully, by reobtaining the original file and going through
329
330
  # the post-process again.
@@ -348,7 +349,7 @@ module Paperclip
348
349
 
349
350
  # Returns true if a file has been assigned.
350
351
  def file?
351
- !original_filename.blank?
352
+ original_filename.present?
352
353
  end
353
354
 
354
355
  alias :present? :file?
@@ -367,7 +368,7 @@ module Paperclip
367
368
  # instance_write(:file_name, "me.jpg") will write "me.jpg" to the instance's
368
369
  # "avatar_file_name" field (assuming the attachment is called avatar).
369
370
  def instance_write(attr, value)
370
- setter = :"#{name}_#{attr}="
371
+ setter = :"#{@name_string}_#{attr}="
371
372
  if instance.respond_to?(setter)
372
373
  instance.send(setter, value)
373
374
  end
@@ -376,7 +377,7 @@ module Paperclip
376
377
  # Reads the attachment-specific attribute on the instance. See instance_write
377
378
  # for more details.
378
379
  def instance_read(attr)
379
- getter = :"#{name}_#{attr}"
380
+ getter = :"#{@name_string}_#{attr}"
380
381
  if instance.respond_to?(getter)
381
382
  instance.send(getter)
382
383
  end
@@ -404,8 +405,8 @@ module Paperclip
404
405
 
405
406
  def ensure_required_accessors! #:nodoc:
406
407
  %w(file_name).each do |field|
407
- unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=")
408
- raise Paperclip::Error.new("#{@instance.class} model missing required attr_accessor for '#{name}_#{field}'")
408
+ unless @instance.respond_to?("#{@name_string}_#{field}") && @instance.respond_to?("#{@name_string}_#{field}=")
409
+ raise Paperclip::Error.new("#{@instance.class} model missing required attr_accessor for '#{@name_string}_#{field}'")
409
410
  end
410
411
  end
411
412
  end
@@ -427,7 +428,7 @@ module Paperclip
427
428
  def assign_attributes
428
429
  @queued_for_write[:original] = @file
429
430
  assign_file_information
430
- assign_fingerprint(@file.fingerprint)
431
+ assign_fingerprint { @file.fingerprint }
431
432
  assign_timestamps
432
433
  end
433
434
 
@@ -437,9 +438,9 @@ module Paperclip
437
438
  instance_write(:file_size, @file.size)
438
439
  end
439
440
 
440
- def assign_fingerprint(fingerprint)
441
+ def assign_fingerprint
441
442
  if instance_respond_to?(:fingerprint)
442
- instance_write(:fingerprint, fingerprint)
443
+ instance_write(:fingerprint, yield)
443
444
  end
444
445
  end
445
446
 
@@ -465,7 +466,7 @@ module Paperclip
465
466
 
466
467
  def reset_file_if_original_reprocessed
467
468
  instance_write(:file_size, @queued_for_write[:original].size)
468
- assign_fingerprint(@queued_for_write[:original].fingerprint)
469
+ assign_fingerprint { @queued_for_write[:original].fingerprint }
469
470
  reset_updater
470
471
  end
471
472
 
@@ -501,7 +502,7 @@ module Paperclip
501
502
 
502
503
  instance.run_paperclip_callbacks(:post_process) do
503
504
  instance.run_paperclip_callbacks(:"#{name}_post_process") do
504
- unless @options[:check_validity_before_processing] && instance.errors.any?
505
+ if !@options[:check_validity_before_processing] || !instance.errors.any?
505
506
  post_process_styles(*style_args)
506
507
  end
507
508
  end
@@ -522,7 +523,7 @@ module Paperclip
522
523
 
523
524
  @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
524
525
  file = Paperclip.processor(processor).make(file, style.processor_options, self)
525
- intermediate_files << file
526
+ intermediate_files << file unless file == @queued_for_write[:original]
526
527
  file
527
528
  end
528
529
 
@@ -587,7 +588,7 @@ module Paperclip
587
588
 
588
589
  # You can either specifiy :restricted_characters or you can define your own
589
590
  # :filename_cleaner object. This object needs to respond to #call and takes
590
- # the filename that will be cleaned. It should return the cleaned filenme.
591
+ # the filename that will be cleaned. It should return the cleaned filename.
591
592
  def filename_cleaner
592
593
  @options[:filename_cleaner] || FilenameCleaner.new(@options[:restricted_characters])
593
594
  end
@@ -51,7 +51,8 @@ module Paperclip
51
51
  end
52
52
 
53
53
  def definitions_for(klass)
54
- klass.ancestors.each_with_object({}) do |ancestor, inherited_definitions|
54
+ parent_classes = klass.ancestors.reverse
55
+ parent_classes.each_with_object({}) do |ancestor, inherited_definitions|
55
56
  inherited_definitions.deep_merge! @attachments[ancestor]
56
57
  end
57
58
  end
@@ -7,7 +7,7 @@ module Paperclip
7
7
 
8
8
  module Defining
9
9
  def define_paperclip_callbacks(*callbacks)
10
- define_callbacks(*[callbacks, {:terminator => callback_terminator}].flatten)
10
+ define_callbacks(*[callbacks, { terminator: hasta_la_vista_baby }].flatten)
11
11
  callbacks.each do |callback|
12
12
  eval <<-end_callbacks
13
13
  def before_#{callback}(*args, &blk)
@@ -22,11 +22,13 @@ module Paperclip
22
22
 
23
23
  private
24
24
 
25
- def callback_terminator
26
- if ::ActiveSupport::VERSION::STRING >= '4.1'
27
- lambda { |target, result| result == false }
28
- else
29
- 'result == false'
25
+ def hasta_la_vista_baby
26
+ lambda do |_, result|
27
+ if result.respond_to?(:call)
28
+ result.call == false
29
+ else
30
+ result == false
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -67,8 +67,9 @@ module Paperclip
67
67
  end
68
68
 
69
69
  def type_from_mime_magic
70
- @type_from_mime_magic ||=
71
- MimeMagic.by_magic(File.open(@filepath)).try(:type)
70
+ @type_from_mime_magic ||= File.open(@filepath) do |file|
71
+ MimeMagic.by_magic(file).try(:type)
72
+ end
72
73
  end
73
74
 
74
75
  def type_from_file_command