spec/paperclip/storage/fog_spec.rb in kt-paperclip-4.4.0 vs spec/paperclip/storage/fog_spec.rb in kt-paperclip-5.4.0

- old
+ new

@@ -181,10 +181,17 @@ assert_equal @connection.directories.get(@fog_directory).files.get(@dummy.avatar.path).body, tempfile.read tempfile.close end + it 'is able to be handled when missing while copying to a local file' do + tempfile = Tempfile.new("known_location") + tempfile.binmode + assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path) + tempfile.close + end + it "passes the content type to the Fog::Storage::AWS::Files instance" do Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash| hash[:content_type] end @dummy.save @@ -269,10 +276,26 @@ assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public] assert_equal false, @dummy.avatar.fog_public end end + context "with fog_public as a proc" do + let(:proc) { ->(attachment) { !attachment } } + + before do + rebuild_model(@options.merge(fog_public: proc)) + @dummy = Dummy.new + @dummy.avatar = StringIO.new(".") + @dummy.save + end + + it "sets the @fog_public instance variable to false" do + assert_equal proc, @dummy.avatar.instance_variable_get("@options")[:fog_public] + assert_equal false, @dummy.avatar.fog_public + end + end + context "with styles set and fog_public set to false" do before do rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" })) @file = File.new(fixture_file('5k.png'), 'rb') @dummy = Dummy.new @@ -421,9 +444,12 @@ it "has created the bucket" do assert @connection.directories.get(@dynamic_fog_directory).inspect end + it "provides an url using dynamic bucket name" do + assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url) + end end context "with a proc for the fog_host evaluating a model method" do before do rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))