Skip to content
This repository
Browse code

fixed wrong permissions ('private' and 'public-read') into the right

ones (:private and :public_read) in the s3_test
completed test for lambda permission value
  • Loading branch information...
commit 3a6ca7d9c7ba6a6ccd751bb1a10721e3798b5b66 1 parent 1571290
momolog authored October 20, 2011
6  lib/paperclip/storage/s3.rb
@@ -81,9 +81,9 @@ def self.extended base
81 81
           @s3_permissions = set_permissions(@options.s3_permissions)
82 82
           @s3_protocol    = @options.s3_protocol    ||
83 83
             Proc.new do |style, attachment|
84  
-              permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
85  
-              permission = permission.call(attachment, style) if permission.is_a?(Proc)
86  
-              permission == :public_read ? 'http' : 'https'
  84
+              permission  = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
  85
+              permission  = permission.call(attachment, style) if permission.is_a?(Proc)
  86
+              (permission == :public_read) ? 'http' : 'https'
87 87
             end
88 88
           @s3_headers     = @options.s3_headers     || {}
89 89
 
54  test/storage/s3_test.rb
@@ -509,7 +509,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
509 509
   end
510 510
 
511 511
   context "S3 Permissions" do
512  
-    context "defaults to public-read" do
  512
+    context "defaults to :public_read" do
513 513
       setup do
514 514
         rebuild_model :storage => :s3,
515 515
                       :bucket => "testing",
@@ -556,7 +556,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
556 556
                         'access_key_id' => "12345",
557 557
                         'secret_access_key' => "54321"
558 558
                       },
559  
-                      :s3_permissions => 'private'
  559
+                      :s3_permissions => :private
560 560
       end
561 561
 
562 562
       context "when assigned" do
@@ -575,7 +575,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
575 575
                                                    anything,
576 576
                                                    'testing',
577 577
                                                    :content_type => 'image/png',
578  
-                                                   :access => 'private')
  578
+                                                   :access => :private)
579 579
             @dummy.save
580 580
           end
581 581
 
@@ -599,8 +599,8 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
599 599
                         'secret_access_key' => "54321"
600 600
                       },
601 601
                       :s3_permissions => {
602  
-                        :original => 'private',
603  
-                        :thumb => 'public-read'
  602
+                        :original => :private,
  603
+                        :thumb => :public_read
604 604
                       }
605 605
       end
606 606
 
@@ -621,7 +621,7 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
621 621
                                                     anything,
622 622
                                                     'testing',
623 623
                                                     :content_type => 'image/png',
624  
-                                                    :access => style == :thumb ? 'public-read' : 'private')
  624
+                                                    :access => style == :thumb ? :public_read : :private)
625 625
             end
626 626
             @dummy.save
627 627
           end
@@ -635,17 +635,21 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
635 635
 
636 636
     context "proc permission set" do
637 637
       setup do
638  
-        rebuild_model :storage => :s3,
639  
-                      :bucket => "testing",
640  
-                      :path => ":attachment/:style/:basename.:extension",
641  
-                      :styles => {
642  
-                         :thumb => "80x80>"
643  
-                      },
644  
-                      :s3_credentials => {
645  
-                        'access_key_id' => "12345",
646  
-                        'secret_access_key' => "54321"
647  
-                      },
648  
-                      :s3_permissions => lambda{|attachment, style| attachment.instance.private_attachment? && style.to_sym != :thumb ? 'private' : 'public-read' }
  638
+        rebuild_model(
  639
+          :storage => :s3,
  640
+          :bucket => "testing",
  641
+          :path => ":attachment/:style/:basename.:extension",
  642
+          :styles => {
  643
+             :thumb => "80x80>"
  644
+          },
  645
+          :s3_credentials => {
  646
+            'access_key_id' => "12345",
  647
+            'secret_access_key' => "54321"
  648
+          },
  649
+          :s3_permissions => lambda {|attachment, style|
  650
+            attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
  651
+          }
  652
+        )
649 653
       end
650 654
 
651 655
       context "when assigned" do
@@ -662,18 +666,20 @@ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
662 666
           setup do
663 667
             AWS::S3::Base.stubs(:establish_connection!)
664 668
             [:thumb, :original].each do |style|
665  
-              AWS::S3::S3Object.expects(:store).with("avatars/#{style}/5k.png",
666  
-                                                    anything,
667  
-                                                    'testing',
668  
-                                                    :content_type => 'image/png',
669  
-                                                    :access => style == :thumb ? 'public-read' : 'private')
  669
+              AWS::S3::S3Object.expects(:store).with(
  670
+                "avatars/#{style}/5k.png",
  671
+                anything,
  672
+                'testing',
  673
+                :content_type => 'image/png',
  674
+                :access => style == :thumb ? :public_read : :private
  675
+              )
670 676
             end
671 677
             @dummy.save
672 678
           end
673 679
 
674 680
           should "succeed" do
675  
-            assert_equal 0, @dummy.avatar.url()       =~ /^https:/
676  
-            assert_equal 0, @dummy.avatar.url(:thumb) =~ /^http:/
  681
+            assert @dummy.avatar.url().include?       "https://"
  682
+            assert @dummy.avatar.url(:thumb).include? "http://"
677 683
           end
678 684
         end
679 685
       end

0 notes on commit 3a6ca7d

Please sign in to comment.
Something went wrong with that request. Please try again.