kt-paperclip 5.4.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +3 -0
  3. data/.hound.yml +27 -32
  4. data/.travis.yml +23 -2
  5. data/Appraisals +17 -0
  6. data/Gemfile +9 -7
  7. data/NEWS +21 -0
  8. data/README.md +27 -37
  9. data/Rakefile +29 -21
  10. data/UPGRADING +3 -3
  11. data/features/basic_integration.feature +4 -0
  12. data/features/migration.feature +10 -51
  13. data/features/step_definitions/attachment_steps.rb +12 -12
  14. data/features/step_definitions/html_steps.rb +5 -5
  15. data/features/step_definitions/rails_steps.rb +29 -9
  16. data/features/step_definitions/s3_steps.rb +3 -3
  17. data/features/step_definitions/web_steps.rb +5 -6
  18. data/features/support/env.rb +4 -4
  19. data/features/support/fakeweb.rb +3 -5
  20. data/features/support/file_helpers.rb +2 -2
  21. data/features/support/paths.rb +4 -4
  22. data/features/support/rails.rb +7 -7
  23. data/features/support/selectors.rb +1 -1
  24. data/gemfiles/4.2.gemfile +7 -4
  25. data/gemfiles/5.0.gemfile +7 -4
  26. data/gemfiles/5.1.gemfile +20 -0
  27. data/gemfiles/5.2.gemfile +20 -0
  28. data/gemfiles/6.0.gemfile +20 -0
  29. data/lib/generators/paperclip/paperclip_generator.rb +6 -8
  30. data/lib/paperclip/attachment.rb +102 -104
  31. data/lib/paperclip/attachment_registry.rb +2 -2
  32. data/lib/paperclip/file_command_content_type_detector.rb +1 -3
  33. data/lib/paperclip/filename_cleaner.rb +0 -1
  34. data/lib/paperclip/geometry.rb +18 -19
  35. data/lib/paperclip/geometry_detector_factory.rb +13 -16
  36. data/lib/paperclip/geometry_parser_factory.rb +5 -5
  37. data/lib/paperclip/glue.rb +3 -3
  38. data/lib/paperclip/has_attached_file.rb +5 -4
  39. data/lib/paperclip/helpers.rb +3 -3
  40. data/lib/paperclip/interpolations.rb +42 -38
  41. data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
  42. data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
  43. data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
  44. data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
  45. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
  46. data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
  47. data/lib/paperclip/io_adapters/registry.rb +1 -1
  48. data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
  49. data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
  50. data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
  51. data/lib/paperclip/logger.rb +1 -1
  52. data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
  53. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
  54. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
  55. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
  56. data/lib/paperclip/matchers.rb +4 -4
  57. data/lib/paperclip/media_type_spoof_detector.rb +13 -13
  58. data/lib/paperclip/missing_attachment_styles.rb +11 -6
  59. data/lib/paperclip/processor.rb +13 -6
  60. data/lib/paperclip/processor_helpers.rb +3 -1
  61. data/lib/paperclip/rails_environment.rb +1 -5
  62. data/lib/paperclip/railtie.rb +5 -5
  63. data/lib/paperclip/schema.rb +18 -14
  64. data/lib/paperclip/storage/filesystem.rb +5 -7
  65. data/lib/paperclip/storage/fog.rb +36 -32
  66. data/lib/paperclip/storage/s3.rb +67 -75
  67. data/lib/paperclip/style.rb +3 -6
  68. data/lib/paperclip/tempfile.rb +4 -5
  69. data/lib/paperclip/tempfile_factory.rb +0 -1
  70. data/lib/paperclip/thumbnail.rb +11 -11
  71. data/lib/paperclip/url_generator.rb +5 -12
  72. data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
  73. data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
  74. data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
  75. data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
  76. data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
  77. data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
  78. data/lib/paperclip/validators.rb +12 -13
  79. data/lib/paperclip/version.rb +1 -3
  80. data/lib/paperclip.rb +49 -48
  81. data/lib/tasks/paperclip.rake +23 -24
  82. data/paperclip.gemspec +29 -33
  83. data/shoulda_macros/paperclip.rb +16 -16
  84. data/spec/paperclip/attachment_definitions_spec.rb +5 -5
  85. data/spec/paperclip/attachment_processing_spec.rb +22 -23
  86. data/spec/paperclip/attachment_registry_spec.rb +15 -15
  87. data/spec/paperclip/attachment_spec.rb +238 -196
  88. data/spec/paperclip/content_type_detector_spec.rb +11 -12
  89. data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
  90. data/spec/paperclip/filename_cleaner_spec.rb +3 -4
  91. data/spec/paperclip/geometry_detector_spec.rb +7 -8
  92. data/spec/paperclip/geometry_parser_spec.rb +31 -31
  93. data/spec/paperclip/geometry_spec.rb +24 -24
  94. data/spec/paperclip/glue_spec.rb +3 -5
  95. data/spec/paperclip/has_attached_file_spec.rb +46 -126
  96. data/spec/paperclip/integration_spec.rb +111 -77
  97. data/spec/paperclip/interpolations_spec.rb +101 -93
  98. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
  99. data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
  100. data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
  101. data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
  102. data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
  103. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
  104. data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
  105. data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
  106. data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
  107. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
  108. data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
  109. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
  110. data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
  111. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
  112. data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
  113. data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
  114. data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
  115. data/spec/paperclip/meta_class_spec.rb +3 -3
  116. data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
  117. data/spec/paperclip/paperclip_spec.rb +15 -11
  118. data/spec/paperclip/plural_cache_spec.rb +8 -8
  119. data/spec/paperclip/processor_helpers_spec.rb +35 -35
  120. data/spec/paperclip/processor_spec.rb +8 -8
  121. data/spec/paperclip/rails_environment_spec.rb +7 -10
  122. data/spec/paperclip/rake_spec.rb +39 -39
  123. data/spec/paperclip/schema_spec.rb +57 -53
  124. data/spec/paperclip/storage/filesystem_spec.rb +6 -6
  125. data/spec/paperclip/storage/fog_spec.rb +76 -82
  126. data/spec/paperclip/storage/s3_live_spec.rb +22 -22
  127. data/spec/paperclip/storage/s3_spec.rb +585 -583
  128. data/spec/paperclip/style_spec.rb +67 -71
  129. data/spec/paperclip/tempfile_factory_spec.rb +5 -5
  130. data/spec/paperclip/thumbnail_spec.rb +68 -67
  131. data/spec/paperclip/url_generator_spec.rb +18 -29
  132. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
  133. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
  134. data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
  135. data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
  136. data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
  137. data/spec/paperclip/validators_spec.rb +40 -40
  138. data/spec/spec_helper.rb +21 -23
  139. data/spec/support/assertions.rb +8 -6
  140. data/spec/support/fake_model.rb +1 -2
  141. data/spec/support/fake_rails.rb +1 -1
  142. data/spec/support/matchers/exist.rb +1 -1
  143. data/spec/support/matchers/have_column.rb +1 -1
  144. data/spec/support/mock_url_generator_builder.rb +2 -3
  145. data/spec/support/model_reconstruction.rb +16 -12
  146. data/spec/support/reporting.rb +1 -1
  147. data/spec/support/test_data.rb +2 -2
  148. metadata +49 -105
  149. data/lib/kt-paperclip.rb +0 -1
  150. data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
4
4
  before do
@@ -8,17 +8,17 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
8
8
 
9
9
  def build_validator(options = {})
10
10
  @validator = Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(options.merge(
11
- attributes: :avatar
12
- ))
11
+ attributes: :avatar
12
+ ))
13
13
  end
14
14
 
15
15
  it "is on the attachment without being explicitly added" do
16
- assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :media_type_spoof_detection }
16
+ assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :media_type_spoof_detection }
17
17
  end
18
18
 
19
19
  it "is not on the attachment when explicitly rejected" do
20
20
  rebuild_model validate_media_type: false
21
- assert Dummy.validators_on(:avatar).none?{ |validator| validator.kind == :media_type_spoof_detection }
21
+ assert Dummy.validators_on(:avatar).none? { |validator| validator.kind == :media_type_spoof_detection }
22
22
  end
23
23
 
24
24
  it "returns default error message for spoofed media type" do
@@ -26,8 +26,8 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
26
26
  file = File.new(fixture_file("5k.png"), "rb")
27
27
  @dummy.avatar.assign(file)
28
28
 
29
- detector = mock("detector", :spoofed? => true)
30
- Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
29
+ detector = double("detector", spoofed?: true)
30
+ allow(Paperclip::MediaTypeSpoofDetector).to receive(:using).and_return(detector)
31
31
  @validator.validate(@dummy)
32
32
 
33
33
  assert_equal I18n.t("errors.messages.spoofed_media_type"), @dummy.errors[:avatar].first
@@ -37,16 +37,12 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
37
37
  build_validator
38
38
  file = File.new(fixture_file("5k.png"), "rb")
39
39
  @dummy.avatar.assign(file)
40
- Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(stub(:spoofed? => false))
41
-
40
+ expect(Paperclip::MediaTypeSpoofDetector).to receive(:using).once.and_return(double("detector", spoofed?: false))
42
41
  @dummy.valid?
43
-
44
- assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.once }
45
42
  end
46
43
 
47
44
  it "does not run when attachment is not dirty" do
48
- Paperclip::MediaTypeSpoofDetector.stubs(:using).never
45
+ expect(Paperclip::MediaTypeSpoofDetector).to_not receive(:using)
49
46
  @dummy.valid?
50
- assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.never }
51
47
  end
52
48
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Paperclip::Validators do
4
4
  context "using the helper" do
@@ -8,65 +8,65 @@ describe Paperclip::Validators do
8
8
  end
9
9
 
10
10
  it "adds the attachment_presence validator to the class" do
11
- assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
11
+ assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_presence }
12
12
  end
13
13
 
14
14
  it "adds the attachment_content_type validator to the class" do
15
- assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type }
15
+ assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_content_type }
16
16
  end
17
17
 
18
18
  it "adds the attachment_size validator to the class" do
19
- assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
19
+ assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_size }
20
20
  end
21
21
 
22
- it 'prevents you from attaching a file that violates that validation' do
23
- Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
22
+ it "prevents you from attaching a file that violates that validation" do
23
+ Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
24
24
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
25
25
  expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
26
- assert_raises(RuntimeError){ dummy.valid? }
26
+ assert_raises(RuntimeError) { dummy.valid? }
27
27
  end
28
28
  end
29
29
 
30
- context 'using the helper with array of validations' do
30
+ context "using the helper with array of validations" do
31
31
  before do
32
32
  rebuild_class
33
33
  Dummy.validates_attachment :avatar, file_type_ignorance: true, file_name: [
34
- { matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
35
- { matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
34
+ { matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
35
+ { matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
36
36
  ]
37
37
  end
38
38
 
39
- it 'adds the attachment_file_name validator to the class' do
40
- assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
39
+ it "adds the attachment_file_name validator to the class" do
40
+ assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_file_name }
41
41
  end
42
42
 
43
- it 'adds the attachment_file_name validator with two validations' do
44
- assert_equal 2, Dummy.validators_on(:avatar).select{ |validator| validator.kind == :attachment_file_name }.size
43
+ it "adds the attachment_file_name validator with two validations" do
44
+ assert_equal 2, Dummy.validators_on(:avatar).select { |validator| validator.kind == :attachment_file_name }.size
45
45
  end
46
46
 
47
- it 'prevents you from attaching a file that violates all of these validations' do
48
- Dummy.class_eval{ validate(:name) { raise 'DO NOT RUN THIS' } }
49
- dummy = Dummy.new(avatar: File.new(fixture_file('spaced file.png')))
47
+ it "prevents you from attaching a file that violates all of these validations" do
48
+ Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
49
+ dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.png")))
50
50
  expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
51
- assert_raises(RuntimeError){ dummy.valid? }
51
+ assert_raises(RuntimeError) { dummy.valid? }
52
52
  end
53
53
 
54
- it 'prevents you from attaching a file that violates only first of these validations' do
55
- Dummy.class_eval{ validate(:name) { raise 'DO NOT RUN THIS' } }
56
- dummy = Dummy.new(avatar: File.new(fixture_file('5k.png')))
54
+ it "prevents you from attaching a file that violates only first of these validations" do
55
+ Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
56
+ dummy = Dummy.new(avatar: File.new(fixture_file("5k.png")))
57
57
  expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
58
- assert_raises(RuntimeError){ dummy.valid? }
58
+ assert_raises(RuntimeError) { dummy.valid? }
59
59
  end
60
60
 
61
- it 'prevents you from attaching a file that violates only second of these validations' do
62
- Dummy.class_eval{ validate(:name) { raise 'DO NOT RUN THIS' } }
63
- dummy = Dummy.new(avatar: File.new(fixture_file('spaced file.jpg')))
61
+ it "prevents you from attaching a file that violates only second of these validations" do
62
+ Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
63
+ dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.jpg")))
64
64
  expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
65
- assert_raises(RuntimeError){ dummy.valid? }
65
+ assert_raises(RuntimeError) { dummy.valid? }
66
66
  end
67
67
 
68
- it 'allows you to attach a file that does not violate these validations' do
69
- dummy = Dummy.new(avatar: File.new(fixture_file('rotated.jpg')))
68
+ it "allows you to attach a file that does not violate these validations" do
69
+ dummy = Dummy.new(avatar: File.new(fixture_file("rotated.jpg")))
70
70
  expect(dummy.errors.full_messages).to be_empty
71
71
  assert dummy.valid?
72
72
  end
@@ -76,9 +76,9 @@ describe Paperclip::Validators do
76
76
  before do
77
77
  rebuild_class
78
78
  Dummy.validates_attachment :avatar, presence: true,
79
- content_type: { content_type: "image/jpeg" },
80
- size: { in: 0..10240 },
81
- if: :title_present?
79
+ content_type: { content_type: "image/jpeg" },
80
+ size: { in: 0..10240 },
81
+ if: :title_present?
82
82
  end
83
83
 
84
84
  it "validates the attachment if title is present" do
@@ -102,20 +102,20 @@ describe Paperclip::Validators do
102
102
  end
103
103
  end
104
104
 
105
- context 'with no other validations on the Dummy#avatar attachment' do
105
+ context "with no other validations on the Dummy#avatar attachment" do
106
106
  before do
107
107
  reset_class("Dummy")
108
108
  Dummy.has_attached_file :avatar
109
109
  Paperclip.reset_duplicate_clash_check!
110
110
  end
111
111
 
112
- it 'raises an error when no content_type validation exists' do
112
+ it "raises an error when no content_type validation exists" do
113
113
  assert_raises(Paperclip::Errors::MissingRequiredValidatorError) do
114
114
  Dummy.new(avatar: File.new(fixture_file("12k.png")))
115
115
  end
116
116
  end
117
117
 
118
- it 'does not raise an error when a content_type validation exists' do
118
+ it "does not raise an error when a content_type validation exists" do
119
119
  Dummy.validates_attachment :avatar, content_type: { content_type: "image/jpeg" }
120
120
 
121
121
  assert_nothing_raised do
@@ -123,18 +123,18 @@ describe Paperclip::Validators do
123
123
  end
124
124
  end
125
125
 
126
- it 'does not raise an error when a content_type validation exists using validates_with' do
127
- Dummy.validates_with Paperclip::Validators::AttachmentContentTypeValidator, attributes: :attachment, content_type: 'images/jpeg'
126
+ it "does not raise an error when a content_type validation exists using validates_with" do
127
+ Dummy.validates_with Paperclip::Validators::AttachmentContentTypeValidator, attributes: :attachment, content_type: "images/jpeg"
128
128
 
129
129
  assert_nothing_raised do
130
130
  Dummy.new(avatar: File.new(fixture_file("12k.png")))
131
131
  end
132
132
  end
133
133
 
134
- it 'does not raise an error when an inherited validator is used' do
134
+ it "does not raise an error when an inherited validator is used" do
135
135
  class MyValidator < Paperclip::Validators::AttachmentContentTypeValidator
136
136
  def initialize(options)
137
- options[:content_type] = "images/jpeg" unless options.has_key?(:content_type)
137
+ options[:content_type] = "images/jpeg" unless options.key?(:content_type)
138
138
  super
139
139
  end
140
140
  end
@@ -145,7 +145,7 @@ describe Paperclip::Validators do
145
145
  end
146
146
  end
147
147
 
148
- it 'does not raise an error when a file_name validation exists' do
148
+ it "does not raise an error when a file_name validation exists" do
149
149
  Dummy.validates_attachment :avatar, file_name: { matches: /png$/ }
150
150
 
151
151
  assert_nothing_raised do
@@ -153,7 +153,7 @@ describe Paperclip::Validators do
153
153
  end
154
154
  end
155
155
 
156
- it 'does not raise an error when a the validation has been explicitly rejected' do
156
+ it "does not raise an error when a the validation has been explicitly rejected" do
157
157
  Dummy.validates_attachment :avatar, file_type_ignorance: true
158
158
 
159
159
  assert_nothing_raised do
data/spec/spec_helper.rb CHANGED
@@ -1,36 +1,35 @@
1
- require 'rubygems'
2
- require 'rspec'
3
- require 'active_record'
4
- require 'active_record/version'
5
- require 'active_support'
6
- require 'active_support/core_ext'
7
- require 'mocha/api'
8
- require 'bourne'
9
- require 'ostruct'
10
- require 'pathname'
11
- require 'activerecord-import'
12
-
13
- ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "active_record"
4
+ require "active_record/version"
5
+ require "active_support"
6
+ require "active_support/core_ext"
7
+ require "ostruct"
8
+ require "pathname"
9
+ require "activerecord-import"
10
+ require "yaml"
11
+
12
+ ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), "..")))
14
13
 
15
14
  puts "Testing against version #{ActiveRecord::VERSION::STRING}"
16
15
 
17
- $LOAD_PATH << File.join(ROOT, 'lib')
18
- $LOAD_PATH << File.join(ROOT, 'lib', 'paperclip')
19
- require File.join(ROOT, 'lib', 'paperclip.rb')
16
+ $LOAD_PATH << File.join(ROOT, "lib")
17
+ $LOAD_PATH << File.join(ROOT, "lib", "paperclip")
18
+ require File.join(ROOT, "lib", "paperclip.rb")
20
19
 
21
20
  FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
22
- config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
21
+ config = YAML::safe_load(IO.read(File.dirname(__FILE__) + "/database.yml"))
23
22
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
24
- ActiveRecord::Base.establish_connection(config['test'])
23
+ ActiveRecord::Base.establish_connection(config["test"])
25
24
  if ActiveRecord::VERSION::STRING >= "4.2" &&
26
- ActiveRecord::VERSION::STRING < "5.0"
25
+ ActiveRecord::VERSION::STRING < "5.0"
27
26
  ActiveRecord::Base.raise_in_transactional_callbacks = true
28
27
  end
29
28
  Paperclip.options[:logger] = ActiveRecord::Base.logger
30
29
 
31
- Dir[File.join(ROOT, 'spec', 'support', '**', '*.rb')].each{|f| require f }
30
+ Dir[File.join(ROOT, "spec", "support", "**", "*.rb")].each { |f| require f }
32
31
 
33
- Rails = FakeRails.new('test', Pathname.new(ROOT).join('tmp'))
32
+ Rails = FakeRails.new("test", Pathname.new(ROOT).join("tmp"))
34
33
  ActiveSupport::Deprecation.silenced = true
35
34
 
36
35
  RSpec.configure do |config|
@@ -39,8 +38,7 @@ RSpec.configure do |config|
39
38
  config.include TestData
40
39
  config.include Reporting
41
40
  config.extend VersionHelper
42
- config.extend ConditionalFilterHelper
43
- config.mock_framework = :mocha
41
+
44
42
  config.before(:all) do
45
43
  rebuild_model
46
44
  end
@@ -51,8 +51,8 @@ module Assertions
51
51
  url = "http:#{url}" unless url =~ /http/
52
52
  Net::HTTP.get_response(URI.parse(url)) do |response|
53
53
  assert_equal "200",
54
- response.code,
55
- "Expected HTTP response code 200, got #{response.code}"
54
+ response.code,
55
+ "Expected HTTP response code 200, got #{response.code}"
56
56
  end
57
57
  end
58
58
 
@@ -60,7 +60,7 @@ module Assertions
60
60
  url = "http:#{url}" unless url =~ /http/
61
61
  Net::HTTP.get_response(URI.parse(url)) do |response|
62
62
  assert_equal "404", response.code,
63
- "Expected HTTP response code 404, got #{response.code}"
63
+ "Expected HTTP response code 404, got #{response.code}"
64
64
  end
65
65
  end
66
66
 
@@ -68,14 +68,16 @@ module Assertions
68
68
  url = "http:#{url}" unless url =~ /http/
69
69
  Net::HTTP.get_response(URI.parse(url)) do |response|
70
70
  assert_equal "403", response.code,
71
- "Expected HTTP response code 403, got #{response.code}"
71
+ "Expected HTTP response code 403, got #{response.code}"
72
72
  end
73
73
  end
74
74
 
75
75
  def assert_frame_dimensions(range, frames)
76
76
  frames.each_with_index do |frame, frame_index|
77
- frame.split('x').each_with_index do |dimension, dimension_index |
78
- assert range.include?(dimension.to_i), "Frame #{frame_index}[#{dimension_index}] should have been within #{range.inspect}, but was #{dimension}"
77
+ frame.split("x").each_with_index do |dimension, dimension_index|
78
+ assert range.include?(dimension.to_i),
79
+ "Frame #{frame_index}[#{dimension_index}] should have been within #{range.inspect},
80
+ but was #{dimension}"
79
81
  end
80
82
  end
81
83
  end
@@ -12,8 +12,7 @@ class FakeModel
12
12
  @errors ||= []
13
13
  end
14
14
 
15
- def run_paperclip_callbacks name, *args
16
- end
15
+ def run_paperclip_callbacks(name, *args); end
17
16
 
18
17
  def valid?
19
18
  errors.empty?
@@ -6,7 +6,7 @@ class FakeRails
6
6
 
7
7
  attr_accessor :env, :root
8
8
 
9
- def const_defined?(const)
9
+ def const_defined?(_const)
10
10
  false
11
11
  end
12
12
  end
@@ -1,4 +1,4 @@
1
- RSpec::Matchers.define :exist do |expected|
1
+ RSpec::Matchers.define :exist do |_expected|
2
2
  match do |actual|
3
3
  File.exist?(actual)
4
4
  end
@@ -4,7 +4,7 @@ RSpec::Matchers.define :have_column do |column_name|
4
4
  end
5
5
 
6
6
  match do |columns|
7
- column = columns.detect{|column| column.name == column_name }
7
+ column = columns.detect { |column| column.name == column_name }
8
8
  column && column.default.to_s == @default.to_s
9
9
  end
10
10
 
@@ -1,6 +1,5 @@
1
1
  class MockUrlGeneratorBuilder
2
- def initializer
3
- end
2
+ def initializer; end
4
3
 
5
4
  def new(attachment)
6
5
  @attachment = attachment
@@ -16,7 +15,7 @@ class MockUrlGeneratorBuilder
16
15
 
17
16
  def has_generated_url_with_options?(options)
18
17
  # options.is_a_subhash_of(@generated_url_with_options)
19
- options.inject(true) do |acc,(k,v)|
18
+ options.inject(true) do |acc, (k, v)|
20
19
  acc && @generated_url_with_options[k] == v
21
20
  end
22
21
  end
@@ -1,7 +1,11 @@
1
1
  module ModelReconstruction
2
- def reset_class class_name
3
- ActiveRecord::Base.send(:include, Paperclip::Glue)
4
- Object.send(:remove_const, class_name) rescue nil
2
+ def reset_class(class_name)
3
+ ActiveRecord::Base.include Paperclip::Glue
4
+ begin
5
+ Object.send(:remove_const, class_name)
6
+ rescue StandardError
7
+ nil
8
+ end
5
9
  klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
6
10
 
7
11
  klass.class_eval do
@@ -22,29 +26,29 @@ module ModelReconstruction
22
26
  klass
23
27
  end
24
28
 
25
- def reset_table table_name, &block
26
- block ||= lambda { |table| true }
27
- ActiveRecord::Base.connection.create_table :dummies, **{force: true}, &block
29
+ def reset_table(_table_name, &block)
30
+ block ||= lambda { |_table| true }
31
+ ActiveRecord::Base.connection.create_table :dummies, { force: true }, &block
28
32
  end
29
33
 
30
- def modify_table table_name, &block
34
+ def modify_table(&block)
31
35
  ActiveRecord::Base.connection.change_table :dummies, &block
32
36
  end
33
37
 
34
- def rebuild_model options = {}
35
- ActiveRecord::Base.connection.create_table :dummies, **{force: true} do |table|
38
+ def rebuild_model(options = {})
39
+ ActiveRecord::Base.connection.create_table :dummies, force: true do |table|
36
40
  table.column :title, :string
37
41
  table.column :other, :string
38
42
  table.column :avatar_file_name, :string
39
43
  table.column :avatar_content_type, :string
40
- table.column :avatar_file_size, :integer
44
+ table.column :avatar_file_size, :bigint
41
45
  table.column :avatar_updated_at, :datetime
42
46
  table.column :avatar_fingerprint, :string
43
47
  end
44
48
  rebuild_class options
45
49
  end
46
50
 
47
- def rebuild_class options = {}
51
+ def rebuild_class(options = {})
48
52
  reset_class("Dummy").tap do |klass|
49
53
  klass.has_attached_file :avatar, options
50
54
  klass.do_not_validate_attachment_file_type :avatar
@@ -52,7 +56,7 @@ module ModelReconstruction
52
56
  end
53
57
  end
54
58
 
55
- def rebuild_meta_class_of obj, options = {}
59
+ def rebuild_meta_class_of(obj, options = {})
56
60
  meta_class_of(obj).tap do |metaklass|
57
61
  metaklass.has_attached_file :avatar, options
58
62
  metaklass.do_not_validate_attachment_file_type :avatar
@@ -1,7 +1,7 @@
1
1
  module Reporting
2
2
  def silence_stream(stream)
3
3
  old_stream = stream.dup
4
- stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
4
+ stream.reopen(RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ ? "NUL:" : "/dev/null")
5
5
  stream.sync = true
6
6
  yield
7
7
  ensure
@@ -1,5 +1,5 @@
1
1
  module TestData
2
- def attachment(options={})
2
+ def attachment(options = {})
3
3
  Paperclip::Attachment.new(:avatar, FakeModel.new, options)
4
4
  end
5
5
 
@@ -8,6 +8,6 @@ module TestData
8
8
  end
9
9
 
10
10
  def fixture_file(filename)
11
- File.join(File.dirname(__FILE__), 'fixtures', filename)
11
+ File.join(File.dirname(__FILE__), "fixtures", filename)
12
12
  end
13
13
  end