paperclip 5.0.0.beta1 → 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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +10 -4
  3. data/NEWS +22 -1
  4. data/README.md +49 -45
  5. data/UPGRADING +3 -0
  6. data/features/migration.feature +0 -24
  7. data/features/step_definitions/rails_steps.rb +0 -6
  8. data/features/step_definitions/s3_steps.rb +2 -6
  9. data/gemfiles/5.0.awsv2.0.gemfile +1 -1
  10. data/gemfiles/5.0.awsv2.1.gemfile +1 -1
  11. data/gemfiles/5.0.awsv2.gemfile +1 -6
  12. data/lib/paperclip/attachment.rb +3 -2
  13. data/lib/paperclip/content_type_detector.rb +3 -2
  14. data/lib/paperclip/errors.rb +3 -1
  15. data/lib/paperclip/helpers.rb +14 -10
  16. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  17. data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
  18. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  19. data/lib/paperclip/schema.rb +1 -6
  20. data/lib/paperclip/storage/fog.rb +9 -6
  21. data/lib/paperclip/storage/s3.rb +16 -38
  22. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  23. data/lib/paperclip/version.rb +3 -1
  24. data/lib/paperclip.rb +2 -1
  25. data/lib/tasks/paperclip.rake +1 -1
  26. data/paperclip.gemspec +1 -2
  27. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  28. data/spec/paperclip/attachment_spec.rb +1 -4
  29. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
  30. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
  31. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  32. data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
  33. data/spec/paperclip/paperclip_spec.rb +3 -1
  34. data/spec/paperclip/storage/fog_spec.rb +10 -0
  35. data/spec/paperclip/storage/s3_spec.rb +92 -215
  36. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  37. data/spec/paperclip/validators_spec.rb +1 -0
  38. metadata +10 -8
  39. data/cucumber/paperclip_steps.rb +0 -6
@@ -3,15 +3,11 @@ require 'aws-sdk'
3
3
 
4
4
  describe Paperclip::Storage::S3 do
5
5
  before do
6
- if defined?(::Aws)
7
- Aws.config[:stub_responses] = true
8
- else
9
- AWS.stub!
10
- end
6
+ Aws.config[:stub_responses] = true
11
7
  end
12
8
 
13
9
  def aws2_add_region
14
- defined?(::Aws) ? { s3_region: 'us-east-1' } : {}
10
+ { s3_region: 'us-east-1' }
15
11
  end
16
12
 
17
13
  context "Parsing S3 credentials" do
@@ -244,20 +240,12 @@ describe Paperclip::Storage::S3 do
244
240
  # if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
245
241
  context "s3_host_name" do
246
242
  before do
247
- if defined?(::Aws)
248
- rebuild_model storage: :s3,
249
- s3_credentials: {},
250
- bucket: "bucket",
251
- path: ":attachment/:basename:dotextension",
252
- s3_host_name: "s3-ap-northeast-1.amazonaws.com",
253
- s3_region: "ap-northeast-1"
254
- else
255
- rebuild_model storage: :s3,
256
- s3_credentials: {},
257
- bucket: "bucket",
258
- path: ":attachment/:basename:dotextension",
259
- s3_host_name: "s3-ap-northeast-1.amazonaws.com"
260
- end
243
+ rebuild_model storage: :s3,
244
+ s3_credentials: {},
245
+ bucket: "bucket",
246
+ path: ":attachment/:basename:dotextension",
247
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com",
248
+ s3_region: "ap-northeast-1"
261
249
  @dummy = Dummy.new
262
250
  @dummy.avatar = stringy_file
263
251
  @dummy.stubs(:new_record?).returns(false)
@@ -269,9 +257,7 @@ describe Paperclip::Storage::S3 do
269
257
 
270
258
  it "uses the S3 bucket with the correct host name" do
271
259
  assert_equal "s3-ap-northeast-1.amazonaws.com",
272
- (defined?(::Aws) ?
273
- @dummy.avatar.s3_bucket.client.config.endpoint.host :
274
- @dummy.avatar.s3_bucket.config.s3_endpoint)
260
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
275
261
  end
276
262
  end
277
263
 
@@ -361,13 +347,12 @@ describe Paperclip::Storage::S3 do
361
347
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
362
348
  @dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
363
349
 
364
- object.expects((defined?(::Aws) ? :upload_file : :write))
350
+ object.expects(:upload_file)
365
351
  .with(anything, content_type: 'image/png',
366
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
367
-
368
- object.expects((defined?(::Aws) ? :upload_file : :write))
352
+ acl: :"public-read")
353
+ object.expects(:upload_file)
369
354
  .with(anything, content_type: 'image/png',
370
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
355
+ acl: :"public-read",
371
356
  cache_control: 'max-age=31557600')
372
357
  @dummy.save
373
358
  end
@@ -554,11 +539,7 @@ describe Paperclip::Storage::S3 do
554
539
  object = stub
555
540
  @dummy.avatar.stubs(:s3_object).returns(object)
556
541
 
557
- if defined?(::Aws)
558
- object.expects(:presigned_url).with(:get, expires_in: 3600)
559
- else
560
- object.expects(:url_for).with(:read, expires: 3600, secure: true)
561
- end
542
+ object.expects(:presigned_url).with(:get, expires_in: 3600)
562
543
  @dummy.avatar.expiring_url
563
544
  end
564
545
  end
@@ -572,15 +553,9 @@ describe Paperclip::Storage::S3 do
572
553
 
573
554
  object = stub
574
555
  @dummy.avatar.stubs(:s3_object).returns(object)
575
- if defined?(::Aws)
576
- object.expects(:presigned_url)
577
- .with(:get, expires_in: 3600,
578
- response_content_disposition: "inline")
579
- else
580
- object.expects(:url_for)
581
- .with(:read, expires: 3600, secure: true,
582
- response_content_disposition: "inline")
583
- end
556
+ object.expects(:presigned_url)
557
+ .with(:get, expires_in: 3600,
558
+ response_content_disposition: "inline")
584
559
  @dummy.avatar.expiring_url
585
560
  end
586
561
  end
@@ -601,14 +576,8 @@ describe Paperclip::Storage::S3 do
601
576
 
602
577
  object = stub
603
578
  @dummy.avatar.stubs(:s3_object).returns(object)
604
- if defined?(::Aws)
605
- object.expects(:presigned_url)
606
- .with(:get, expires_in: 3600, response_content_type: "image/png")
607
- else
608
- object.expects(:url_for)
609
- .with(:read, expires: 3600, secure: true,
610
- response_content_type: "image/png")
611
- end
579
+ object.expects(:presigned_url)
580
+ .with(:get, expires_in: 3600, response_content_type: "image/png")
612
581
  @dummy.avatar.expiring_url
613
582
  end
614
583
  end
@@ -655,22 +624,14 @@ describe Paperclip::Storage::S3 do
655
624
  it "generates a url for the thumb" do
656
625
  object = stub
657
626
  @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
658
- if defined?(::Aws)
659
- object.expects(:presigned_url).with(:get, expires_in: 1800)
660
- else
661
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
662
- end
627
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
663
628
  @dummy.avatar.expiring_url(1800, :thumb)
664
629
  end
665
630
 
666
631
  it "generates a url for the default style" do
667
632
  object = stub
668
633
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
669
- if defined?(::Aws)
670
- object.expects(:presigned_url).with(:get, expires_in: 1800)
671
- else
672
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
673
- end
634
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
674
635
  @dummy.avatar.expiring_url(1800)
675
636
  end
676
637
  end
@@ -703,65 +664,42 @@ describe Paperclip::Storage::S3 do
703
664
  # for aws-sdk-v2 the bucket.name is determined by the :s3_region
704
665
  context "Parsing S3 credentials with a s3_host_name in them" do
705
666
  before do
706
- if defined?(::Aws)
707
- rebuild_model storage: :s3,
708
- bucket: 'testing',
709
- s3_credentials: {
710
- production: {
711
- s3_region: "world-end",
712
- s3_host_name: "s3-world-end.amazonaws.com" },
713
- development: {
714
- s3_region: "ap-northeast-1",
715
- s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
716
- }
717
- else
718
- rebuild_model storage: :s3,
719
- bucket: 'testing',
720
- s3_credentials: {
721
- production: { s3_host_name: "s3-world-end.amazonaws.com" },
722
- development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
723
- }
724
- end
667
+ rebuild_model storage: :s3,
668
+ bucket: 'testing',
669
+ s3_credentials: {
670
+ production: {
671
+ s3_region: "world-end",
672
+ s3_host_name: "s3-world-end.amazonaws.com" },
673
+ development: {
674
+ s3_region: "ap-northeast-1",
675
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com" },
676
+ test: {
677
+ s3_region: "" }
678
+ }
725
679
  @dummy = Dummy.new
726
680
  end
727
681
 
728
682
  it "gets the right s3_host_name in production" do
729
683
  rails_env("production") do
730
684
  assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
731
- if defined?(::Aws)
732
- assert_match %r{^s3.world-end.amazonaws.com},
733
- @dummy.avatar.s3_bucket.client.config.endpoint.host
734
- else
735
- assert_match %r{^s3-world-end.amazonaws.com},
736
- @dummy.avatar.s3_bucket.config.s3_endpoint
737
- end
685
+ assert_match %r{^s3.world-end.amazonaws.com},
686
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
738
687
  end
739
688
  end
740
689
 
741
690
  it "gets the right s3_host_name in development" do
742
691
  rails_env("development") do
743
692
  assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
744
- if defined?(::Aws)
745
- assert_match %r{^s3-ap-northeast-1.amazonaws.com},
746
- @dummy.avatar.s3_bucket.client.config.endpoint.host
747
- else
748
- assert_match %r{^s3-ap-northeast-1.amazonaws.com},
749
- @dummy.avatar.s3_bucket.config.s3_endpoint
750
- end
693
+ assert_match %r{^s3-ap-northeast-1.amazonaws.com},
694
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
751
695
  end
752
696
  end
753
697
 
754
698
  it "gets the right s3_host_name if the key does not exist" do
755
699
  rails_env("test") do
756
700
  assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
757
- if defined?(::Aws)
758
- # :s3_region is *required* for aws-sdk-v2
759
- assert_raises(Aws::Errors::MissingRegionError) do
760
- @dummy.avatar.s3_bucket.client.config.endpoint.host
761
- end
762
- else
763
- assert_match %r{^s3.amazonaws.com},
764
- @dummy.avatar.s3_bucket.config.s3_endpoint
701
+ assert_raises(Aws::Errors::MissingRegionError) do
702
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
765
703
  end
766
704
  end
767
705
  end
@@ -804,22 +742,14 @@ describe Paperclip::Storage::S3 do
804
742
 
805
743
  it "is rewound after flush_writes" do
806
744
  @dummy.avatar.instance_eval "def after_flush_writes; end"
807
- if defined?(::Aws)
808
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
809
- else
810
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
811
- end
745
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
812
746
  files = @dummy.avatar.queued_for_write.values.each(&:read)
813
747
  @dummy.save
814
748
  assert files.none?(&:eof?), "Expect all the files to be rewound."
815
749
  end
816
750
 
817
751
  it "is removed after after_flush_writes" do
818
- if defined?(::Aws)
819
- @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
820
- else
821
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
822
- end
752
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
823
753
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
824
754
  @dummy.save
825
755
  assert paths.none?{ |path| File.exist?(path) },
@@ -828,17 +758,10 @@ describe Paperclip::Storage::S3 do
828
758
 
829
759
  it "will retry to save again but back off on SlowDown" do
830
760
  @dummy.avatar.stubs(:sleep)
831
- if defined?(::Aws)
832
- Aws::S3::Object.any_instance.stubs(:upload_file).
833
- raises(Aws::S3::Errors::SlowDown.new(stub,
834
- stub(status: 503, body: "")))
835
- expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
836
- else
837
- AWS::S3::S3Object.any_instance.stubs(:write).
838
- raises(AWS::S3::Errors::SlowDown.new(stub,
839
- stub(status: 503, body: "")))
840
- expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
841
- end
761
+ Aws::S3::Object.any_instance.stubs(:upload_file).
762
+ raises(Aws::S3::Errors::SlowDown.new(stub,
763
+ stub(status: 503, body: "")))
764
+ expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
842
765
  expect(@dummy.avatar).to have_received(:sleep).with(1)
843
766
  expect(@dummy.avatar).to have_received(:sleep).with(2)
844
767
  expect(@dummy.avatar).to have_received(:sleep).with(4)
@@ -850,9 +773,8 @@ describe Paperclip::Storage::S3 do
850
773
  before do
851
774
  object = stub
852
775
  @dummy.avatar.stubs(:s3_object).returns(object)
853
- object.expects((defined?(::Aws) ? :upload_file : :write))
854
- .with(anything, content_type: 'image/png',
855
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
776
+ object.expects(:upload_file)
777
+ .with(anything, content_type: 'image/png', acl: :"public-read")
856
778
  @dummy.save
857
779
  end
858
780
 
@@ -863,21 +785,11 @@ describe Paperclip::Storage::S3 do
863
785
 
864
786
  context "and saved without a bucket" do
865
787
  before do
866
- if defined?(::Aws)
867
- Aws::S3::Bucket.any_instance.expects(:create)
868
- Aws::S3::Object.any_instance.stubs(:upload_file).
869
- raises(Aws::S3::Errors::NoSuchBucket
870
- .new(stub,
871
- stub(status: 404, body: "<foo/>"))).then.returns(nil)
872
- else
873
- AWS::S3::BucketCollection.any_instance.expects(:create)
874
- .with("testing")
875
- AWS::S3::S3Object.any_instance.stubs(:write).
876
- raises(AWS::S3::Errors::NoSuchBucket.new(stub,
877
- stub(status: 404,
878
- body: "<foo/>"))).
879
- then.returns(nil)
880
- end
788
+ Aws::S3::Bucket.any_instance.expects(:create)
789
+ Aws::S3::Object.any_instance.stubs(:upload_file).
790
+ raises(Aws::S3::Errors::NoSuchBucket
791
+ .new(stub,
792
+ stub(status: 404, body: "<foo/>"))).then.returns(nil)
881
793
  @dummy.save
882
794
  end
883
795
 
@@ -888,13 +800,8 @@ describe Paperclip::Storage::S3 do
888
800
 
889
801
  context "and remove" do
890
802
  before do
891
- if defined?(::Aws)
892
- Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
893
- Aws::S3::Object.any_instance.stubs(:delete)
894
- else
895
- AWS::S3::S3Object.any_instance.stubs(:exists?).returns(true)
896
- AWS::S3::S3Object.any_instance.stubs(:delete)
897
- end
803
+ Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
804
+ Aws::S3::Object.any_instance.stubs(:delete)
898
805
  @dummy.destroy
899
806
  end
900
807
 
@@ -905,14 +812,9 @@ describe Paperclip::Storage::S3 do
905
812
 
906
813
  context 'that the file were missing' do
907
814
  before do
908
- if defined?(::Aws)
909
- Aws::S3::Object.any_instance.stubs(:exists?)
910
- .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
911
- "object exists?"))
912
- else
913
- AWS::S3::S3Object.any_instance.stubs(:exists?)
914
- .raises(AWS::Errors::Base)
915
- end
815
+ Aws::S3::Object.any_instance.stubs(:exists?)
816
+ .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
817
+ "object exists?"))
916
818
  end
917
819
 
918
820
  it 'returns false on exists?' do
@@ -956,28 +858,16 @@ describe Paperclip::Storage::S3 do
956
858
  before do
957
859
  class DummyCredentialProvider; end
958
860
 
959
- if defined?(::Aws)
960
- rebuild_model (aws2_add_region).merge storage: :s3,
961
- bucket: "testing",
962
- s3_credentials: {
963
- credentials: DummyCredentialProvider.new
964
- }
965
- else
966
- rebuild_model storage: :s3,
967
- bucket: "testing",
968
- s3_credentials: {
969
- credential_provider: DummyCredentialProvider.new
970
- }
971
- end
861
+ rebuild_model (aws2_add_region).merge storage: :s3,
862
+ bucket: "testing",
863
+ s3_credentials: {
864
+ credentials: DummyCredentialProvider.new
865
+ }
972
866
  @dummy = Dummy.new
973
867
  end
974
868
 
975
869
  it "sets the credential-provider" do
976
- if defined?(::Aws)
977
- expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
978
- else
979
- expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
980
- end
870
+ expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
981
871
  end
982
872
  end
983
873
 
@@ -1032,10 +922,10 @@ describe Paperclip::Storage::S3 do
1032
922
  object = stub
1033
923
  @dummy.avatar.stubs(:s3_object).returns(object)
1034
924
 
1035
- object.expects((defined?(::Aws) ? :upload_file : :write))
925
+ object.expects(:upload_file)
1036
926
  .with(anything,
1037
927
  content_type: 'image/png',
1038
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
928
+ acl: :"public-read",
1039
929
  cache_control: 'max-age=31557600')
1040
930
  @dummy.save
1041
931
  end
@@ -1073,10 +963,10 @@ describe Paperclip::Storage::S3 do
1073
963
  object = stub
1074
964
  @dummy.avatar.stubs(:s3_object).returns(object)
1075
965
 
1076
- object.expects((defined?(::Aws) ? :upload_file : :write))
966
+ object.expects(:upload_file)
1077
967
  .with(anything,
1078
968
  content_type: 'image/png',
1079
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
969
+ acl: :"public-read",
1080
970
  metadata: { "color" => "red" })
1081
971
  @dummy.save
1082
972
  end
@@ -1114,10 +1004,10 @@ describe Paperclip::Storage::S3 do
1114
1004
  object = stub
1115
1005
  @dummy.avatar.stubs(:s3_object).returns(object)
1116
1006
 
1117
- object.expects((defined?(::Aws) ? :upload_file : :write))
1007
+ object.expects(:upload_file)
1118
1008
  .with(anything,
1119
1009
  content_type: 'image/png',
1120
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1010
+ acl: :"public-read",
1121
1011
  metadata: { "color" => "red" })
1122
1012
  @dummy.save
1123
1013
  end
@@ -1156,10 +1046,10 @@ describe Paperclip::Storage::S3 do
1156
1046
  object = stub
1157
1047
  @dummy.avatar.stubs(:s3_object).returns(object)
1158
1048
 
1159
- object.expects((defined?(::Aws) ? :upload_file : :write))
1049
+ object.expects(:upload_file)
1160
1050
  .with(anything,
1161
1051
  content_type: 'image/png',
1162
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1052
+ acl: :"public-read",
1163
1053
  storage_class: "reduced_redundancy")
1164
1054
  @dummy.save
1165
1055
  end
@@ -1205,11 +1095,11 @@ describe Paperclip::Storage::S3 do
1205
1095
 
1206
1096
  expected_options = {
1207
1097
  :content_type => "image/png",
1208
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION
1098
+ acl: :"public-read"
1209
1099
  }
1210
1100
  expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
1211
1101
 
1212
- object.expects((defined?(::Aws) ? :upload_file : :write))
1102
+ object.expects(:upload_file)
1213
1103
  .with(anything, expected_options)
1214
1104
  end
1215
1105
  @dummy.save
@@ -1252,9 +1142,9 @@ describe Paperclip::Storage::S3 do
1252
1142
  [:thumb, :original].each do |style|
1253
1143
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1254
1144
 
1255
- object.expects((defined?(::Aws) ? :upload_file : :write))
1145
+ object.expects(:upload_file)
1256
1146
  .with(anything, :content_type => "image/png",
1257
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION,
1147
+ acl: :"public-read",
1258
1148
  :storage_class => :reduced_redundancy)
1259
1149
  end
1260
1150
  @dummy.save
@@ -1295,9 +1185,8 @@ describe Paperclip::Storage::S3 do
1295
1185
  object = stub
1296
1186
  @dummy.avatar.stubs(:s3_object).returns(object)
1297
1187
 
1298
- object.expects((defined?(::Aws) ? :upload_file : :write))
1299
- .with(anything, :content_type => "image/png",
1300
- :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION)
1188
+ object.expects(:upload_file)
1189
+ .with(anything, :content_type => "image/png", acl: :"public-read")
1301
1190
  @dummy.save
1302
1191
  end
1303
1192
 
@@ -1335,9 +1224,9 @@ describe Paperclip::Storage::S3 do
1335
1224
  object = stub
1336
1225
  @dummy.avatar.stubs(:s3_object).returns(object)
1337
1226
 
1338
- object.expects((defined?(::Aws) ? :upload_file : :write))
1227
+ object.expects(:upload_file)
1339
1228
  .with(anything, content_type: "image/png",
1340
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1229
+ acl: :"public-read",
1341
1230
  server_side_encryption: :aes256)
1342
1231
  @dummy.save
1343
1232
  end
@@ -1375,10 +1264,10 @@ describe Paperclip::Storage::S3 do
1375
1264
  object = stub
1376
1265
  @dummy.avatar.stubs(:s3_object).returns(object)
1377
1266
 
1378
- object.expects((defined?(::Aws) ? :upload_file : :write))
1267
+ object.expects(:upload_file)
1379
1268
  .with(anything,
1380
1269
  content_type: "image/png",
1381
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1270
+ acl: :"public-read",
1382
1271
  storage_class: :reduced_redundancy)
1383
1272
  @dummy.save
1384
1273
  end
@@ -1409,14 +1298,10 @@ describe Paperclip::Storage::S3 do
1409
1298
  assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
1410
1299
 
1411
1300
  assert_equal 'pathname_key',
1412
- (defined?(::Aws) ?
1413
- @dummy.avatar.s3_bucket.client.config.access_key_id :
1414
- @dummy.avatar.s3_bucket.config.access_key_id)
1301
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1415
1302
 
1416
1303
  assert_equal 'pathname_secret',
1417
- (defined?(::Aws) ?
1418
- @dummy.avatar.s3_bucket.client.config.secret_access_key :
1419
- @dummy.avatar.s3_bucket.config.secret_access_key)
1304
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1420
1305
  end
1421
1306
  end
1422
1307
 
@@ -1440,14 +1325,10 @@ describe Paperclip::Storage::S3 do
1440
1325
  assert_equal 'env_bucket', @dummy.avatar.bucket_name
1441
1326
 
1442
1327
  assert_equal 'env_key',
1443
- (defined?(::Aws) ?
1444
- @dummy.avatar.s3_bucket.client.config.access_key_id :
1445
- @dummy.avatar.s3_bucket.config.access_key_id)
1328
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1446
1329
 
1447
1330
  assert_equal 'env_secret',
1448
- (defined?(::Aws) ?
1449
- @dummy.avatar.s3_bucket.client.config.secret_access_key :
1450
- @dummy.avatar.s3_bucket.config.secret_access_key)
1331
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1451
1332
  end
1452
1333
  end
1453
1334
 
@@ -1477,10 +1358,8 @@ describe Paperclip::Storage::S3 do
1477
1358
  object = stub
1478
1359
  @dummy.avatar.stubs(:s3_object).returns(object)
1479
1360
 
1480
- object.expects((defined?(::Aws) ? :upload_file : :write))
1481
- .with(anything,
1482
- content_type: "image/png",
1483
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
1361
+ object.expects(:upload_file)
1362
+ .with(anything, content_type: "image/png", acl: :"public-read")
1484
1363
  @dummy.save
1485
1364
  end
1486
1365
 
@@ -1517,7 +1396,7 @@ describe Paperclip::Storage::S3 do
1517
1396
  object = stub
1518
1397
  @dummy.avatar.stubs(:s3_object).returns(object)
1519
1398
 
1520
- object.expects((defined?(::Aws) ? :upload_file : :write))
1399
+ object.expects(:upload_file)
1521
1400
  .with(anything, content_type: "image/png", acl: :private)
1522
1401
  @dummy.save
1523
1402
  end
@@ -1562,7 +1441,7 @@ describe Paperclip::Storage::S3 do
1562
1441
  object = stub
1563
1442
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1564
1443
 
1565
- object.expects((defined?(::Aws) ? :upload_file : :write))
1444
+ object.expects(:upload_file)
1566
1445
  .with(anything,
1567
1446
  content_type: "image/png",
1568
1447
  acl: style == :thumb ? :public_read : :private)
@@ -1591,7 +1470,7 @@ describe Paperclip::Storage::S3 do
1591
1470
  'secret_access_key' => "54321"
1592
1471
  },
1593
1472
  s3_permissions: lambda {|attachment, style|
1594
- attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : Paperclip::Storage::S3::DEFAULT_PERMISSION
1473
+ attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
1595
1474
  }
1596
1475
  )
1597
1476
  end
@@ -1656,10 +1535,10 @@ describe Paperclip::Storage::S3 do
1656
1535
  object = stub
1657
1536
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1658
1537
 
1659
- object.expects((defined?(::Aws) ? :upload_file : :write))
1538
+ object.expects(:upload_file)
1660
1539
  .with(anything,
1661
1540
  content_type: "image/png",
1662
- acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1541
+ acl: :"public-read",
1663
1542
  content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1664
1543
  end
1665
1544
  @dummy.save
@@ -1691,7 +1570,6 @@ describe Paperclip::Storage::S3 do
1691
1570
  end
1692
1571
  end
1693
1572
 
1694
-
1695
1573
  private
1696
1574
 
1697
1575
  def rails_env(env)
@@ -1702,5 +1580,4 @@ describe Paperclip::Storage::S3 do
1702
1580
  Rails.env = stored_env
1703
1581
  end
1704
1582
  end
1705
-
1706
1583
  end
@@ -12,14 +12,6 @@ describe Paperclip::Validators::AttachmentSizeValidator do
12
12
  ))
13
13
  end
14
14
 
15
- def self.storage_units
16
- if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
17
- { 5120 => '5 KB', 10240 => '10 KB' }
18
- else
19
- { 5120 => '5120 Bytes', 10240 => '10240 Bytes' }
20
- end
21
- end
22
-
23
15
  def self.should_allow_attachment_file_size(size)
24
16
  context "when the attachment size is #{size}" do
25
17
  it "adds error to dummy object" do
@@ -158,8 +150,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
158
150
  message: "is invalid. (Between %{min} and %{max} please.)"
159
151
  end
160
152
 
161
- should_not_allow_attachment_file_size 11.kilobytes,
162
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
153
+ should_not_allow_attachment_file_size(
154
+ 11.kilobytes,
155
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
156
+ )
163
157
  end
164
158
 
165
159
  context "given :less_than and :greater_than" do
@@ -169,8 +163,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
169
163
  message: "is invalid. (Between %{min} and %{max} please.)"
170
164
  end
171
165
 
172
- should_not_allow_attachment_file_size 11.kilobytes,
173
- message: "is invalid. (Between #{storage_units[5120]} and #{storage_units[10240]} please.)"
166
+ should_not_allow_attachment_file_size(
167
+ 11.kilobytes,
168
+ message: "is invalid. (Between 5 KB and 10 KB please.)"
169
+ )
174
170
  end
175
171
  end
176
172
 
@@ -181,10 +177,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
181
177
  less_than: 10.kilobytes
182
178
  end
183
179
 
184
- should_not_allow_attachment_file_size 11.kilobytes,
185
- message: "must be less than #{storage_units[10240]}"
186
- should_not_allow_attachment_file_size 4.kilobytes,
187
- message: "must be greater than #{storage_units[5120]}"
180
+ should_not_allow_attachment_file_size(
181
+ 11.kilobytes,
182
+ message: "must be less than 10 KB"
183
+ )
184
+
185
+ should_not_allow_attachment_file_size(
186
+ 4.kilobytes,
187
+ message: "must be greater than 5 KB"
188
+ )
188
189
  end
189
190
 
190
191
  context "given a size range" do
@@ -192,10 +193,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
192
193
  build_validator in: (5.kilobytes..10.kilobytes)
193
194
  end
194
195
 
195
- should_not_allow_attachment_file_size 11.kilobytes,
196
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
197
- should_not_allow_attachment_file_size 4.kilobytes,
198
- message: "must be in between #{storage_units[5120]} and #{storage_units[10240]}"
196
+ should_not_allow_attachment_file_size(
197
+ 11.kilobytes,
198
+ message: "must be in between 5 KB and 10 KB"
199
+ )
200
+
201
+ should_not_allow_attachment_file_size(
202
+ 4.kilobytes,
203
+ message: "must be in between 5 KB and 10 KB"
204
+ )
199
205
  end
200
206
  end
201
207
 
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Paperclip::Validators do
4
4
  context "using the helper" do
5
5
  before do
6
+ rebuild_class
6
7
  Dummy.validates_attachment :avatar, presence: true, content_type: { content_type: "image/jpeg" }, size: { in: 0..10240 }
7
8
  end
8
9