Commit 71727f49 by Jon Yurek

Give all spec names the correct tense

parent 244bb201
...@@ -7,7 +7,7 @@ describe 'Attachment Processing' do ...@@ -7,7 +7,7 @@ describe 'Attachment Processing' do
rebuild_class rebuild_class
end end
it 'process attachments given a valid assignment' do it 'processes attachments given a valid assignment' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, content_type: "image/png" Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
instance = Dummy.new instance = Dummy.new
...@@ -17,7 +17,7 @@ describe 'Attachment Processing' do ...@@ -17,7 +17,7 @@ describe 'Attachment Processing' do
attachment.assign(file) attachment.assign(file)
end end
it 'not process attachments given an invalid assignment with :not' do it 'does not process attachments given an invalid assignment with :not' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, not: "image/png" Dummy.validates_attachment_content_type :avatar, not: "image/png"
instance = Dummy.new instance = Dummy.new
...@@ -27,7 +27,7 @@ describe 'Attachment Processing' do ...@@ -27,7 +27,7 @@ describe 'Attachment Processing' do
attachment.assign(file) attachment.assign(file)
end end
it 'not process attachments given an invalid assignment with :content_type' do it 'does not process attachments given an invalid assignment with :content_type' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff" Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff"
instance = Dummy.new instance = Dummy.new
...@@ -37,7 +37,7 @@ describe 'Attachment Processing' do ...@@ -37,7 +37,7 @@ describe 'Attachment Processing' do
attachment.assign(file) attachment.assign(file)
end end
it 'when validation :if clause returns false, allow what would be an invalid assignment' do it 'allows what would be an invalid assignment when validation :if clause returns false' do
invalid_assignment = File.new(fixture_file("5k.png")) invalid_assignment = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda{false} Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda{false}
instance = Dummy.new instance = Dummy.new
...@@ -49,7 +49,7 @@ describe 'Attachment Processing' do ...@@ -49,7 +49,7 @@ describe 'Attachment Processing' do
end end
context 'using validates_attachment' do context 'using validates_attachment' do
it 'process attachments given a valid assignment' do it 'processes attachments given a valid assignment' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"} Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"}
instance = Dummy.new instance = Dummy.new
...@@ -59,7 +59,7 @@ describe 'Attachment Processing' do ...@@ -59,7 +59,7 @@ describe 'Attachment Processing' do
attachment.assign(file) attachment.assign(file)
end end
it 'not process attachments given an invalid assignment with :not' do it 'does not process attachments given an invalid assignment with :not' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment :avatar, content_type: {not: "image/png"} Dummy.validates_attachment :avatar, content_type: {not: "image/png"}
instance = Dummy.new instance = Dummy.new
...@@ -69,7 +69,7 @@ describe 'Attachment Processing' do ...@@ -69,7 +69,7 @@ describe 'Attachment Processing' do
attachment.assign(file) attachment.assign(file)
end end
it 'not process attachments given an invalid assignment with :content_type' do it 'does not process attachments given an invalid assignment with :content_type' do
file = File.new(fixture_file("5k.png")) file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment :avatar, content_type: {content_type: "image/tiff"} Dummy.validates_attachment :avatar, content_type: {content_type: "image/tiff"}
instance = Dummy.new instance = Dummy.new
......
...@@ -6,14 +6,14 @@ describe 'Attachment Registry' do ...@@ -6,14 +6,14 @@ describe 'Attachment Registry' do
end end
context '.names_for' do context '.names_for' do
it 'include attachment names for the given class' do it 'includes attachment names for the given class' do
foo = Class.new foo = Class.new
Paperclip::AttachmentRegistry.register(foo, :avatar, {}) Paperclip::AttachmentRegistry.register(foo, :avatar, {})
assert_equal [:avatar], Paperclip::AttachmentRegistry.names_for(foo) assert_equal [:avatar], Paperclip::AttachmentRegistry.names_for(foo)
end end
it 'not include attachment names for other classes' do it 'does not include attachment names for other classes' do
foo = Class.new foo = Class.new
bar = Class.new bar = Class.new
Paperclip::AttachmentRegistry.register(foo, :avatar, {}) Paperclip::AttachmentRegistry.register(foo, :avatar, {})
...@@ -22,13 +22,13 @@ describe 'Attachment Registry' do ...@@ -22,13 +22,13 @@ describe 'Attachment Registry' do
assert_equal [:lover], Paperclip::AttachmentRegistry.names_for(bar) assert_equal [:lover], Paperclip::AttachmentRegistry.names_for(bar)
end end
it 'produce the empty array for a missing key' do it 'produces the empty array for a missing key' do
assert_empty Paperclip::AttachmentRegistry.names_for(Class.new) assert_empty Paperclip::AttachmentRegistry.names_for(Class.new)
end end
end end
context '.each_definition' do context '.each_definition' do
it 'call the block with the class, attachment name, and options' do it 'calls the block with the class, attachment name, and options' do
foo = Class.new foo = Class.new
expected_accumulations = [ expected_accumulations = [
[foo, :avatar, { yo: 'greeting' }], [foo, :avatar, { yo: 'greeting' }],
...@@ -48,7 +48,7 @@ describe 'Attachment Registry' do ...@@ -48,7 +48,7 @@ describe 'Attachment Registry' do
end end
context '.definitions_for' do context '.definitions_for' do
it 'produce the attachment name and options' do it 'produces the attachment name and options' do
expected_definitions = { expected_definitions = {
avatar: { yo: 'greeting' }, avatar: { yo: 'greeting' },
greeter: { ciao: 'greeting' } greeter: { ciao: 'greeting' }
...@@ -62,7 +62,7 @@ describe 'Attachment Registry' do ...@@ -62,7 +62,7 @@ describe 'Attachment Registry' do
assert_equal expected_definitions, definitions assert_equal expected_definitions, definitions
end end
it "produce defintions for subclasses" do it "produces defintions for subclasses" do
expected_definitions = { avatar: { yo: 'greeting' } } expected_definitions = { avatar: { yo: 'greeting' } }
Foo = Class.new Foo = Class.new
Bar = Class.new(Foo) Bar = Class.new(Foo)
...@@ -75,7 +75,7 @@ describe 'Attachment Registry' do ...@@ -75,7 +75,7 @@ describe 'Attachment Registry' do
end end
context '.clear' do context '.clear' do
it 'remove all of the existing attachment definitions' do it 'removes all of the existing attachment definitions' do
foo = Class.new foo = Class.new
Paperclip::AttachmentRegistry.register(foo, :greeter, { ciao: 'greeting' }) Paperclip::AttachmentRegistry.register(foo, :greeter, { ciao: 'greeting' })
......
...@@ -31,7 +31,7 @@ describe Paperclip::Attachment do ...@@ -31,7 +31,7 @@ describe Paperclip::Attachment do
file.close file.close
end end
it "not delete styles that don't get reprocessed" do it "does not delete styles that don't get reprocessed" do
file = File.new(fixture_file("50x50.png"), 'rb') file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class styles: { rebuild_class styles: {
small: '100x>', small: '100x>',
...@@ -65,7 +65,7 @@ describe Paperclip::Attachment do ...@@ -65,7 +65,7 @@ describe Paperclip::Attachment do
Paperclip::Attachment.default_options.merge!(@old_default_options) Paperclip::Attachment.default_options.merge!(@old_default_options)
end end
it "deep merge when it is overridden" do it "deep merges when it is overridden" do
new_options = { convert_options: { thumb: "-thumbnailize" } } new_options = { convert_options: { thumb: "-thumbnailize" } }
attachment = Paperclip::Attachment.new(:name, :instance, new_options) attachment = Paperclip::Attachment.new(:name, :instance, new_options)
...@@ -84,7 +84,7 @@ describe Paperclip::Attachment do ...@@ -84,7 +84,7 @@ describe Paperclip::Attachment do
expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: false, escape: true)).to be_true expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: false, escape: true)).to be_true
end end
it "pass the style and options through to the URL generator on #url" do it "passes the style and options through to the URL generator on #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder) attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder)
...@@ -92,7 +92,7 @@ describe Paperclip::Attachment do ...@@ -92,7 +92,7 @@ describe Paperclip::Attachment do
expect(mock_url_generator_builder.has_generated_url_with_options?(options: :values)).to be_true expect(mock_url_generator_builder.has_generated_url_with_options?(options: :values)).to be_true
end end
it "pass default options through when #url is given one argument" do it "passes default options through when #url is given one argument" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -103,7 +103,7 @@ describe Paperclip::Attachment do ...@@ -103,7 +103,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true) assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end end
it "pass default style and options through when #url is given no arguments" do it "passes default style and options through when #url is given no arguments" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -116,7 +116,7 @@ describe Paperclip::Attachment do ...@@ -116,7 +116,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_style_name?('default style') assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
end end
it "pass the option timestamp: true if :use_timestamp is true and :timestamp is not passed" do it "passes the option timestamp: true if :use_timestamp is true and :timestamp is not passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -127,7 +127,7 @@ describe Paperclip::Attachment do ...@@ -127,7 +127,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true) assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end end
it "pass the option timestamp: false if :use_timestamp is false and :timestamp is not passed" do it "passes the option timestamp: false if :use_timestamp is false and :timestamp is not passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -138,7 +138,7 @@ describe Paperclip::Attachment do ...@@ -138,7 +138,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: false) assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: false)
end end
it "not change the :timestamp if :timestamp is passed" do it "does not change the :timestamp if :timestamp is passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -149,7 +149,7 @@ describe Paperclip::Attachment do ...@@ -149,7 +149,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true) assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end end
it "render JSON as default style" do it "renders JSON as default style" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -160,7 +160,7 @@ describe Paperclip::Attachment do ...@@ -160,7 +160,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_style_name?('default style') assert mock_url_generator_builder.has_generated_url_with_style_name?('default style')
end end
it "pass the option escape: true if :escape_url is true and :escape is not passed" do it "passes the option escape: true if :escape_url is true and :escape is not passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -171,7 +171,7 @@ describe Paperclip::Attachment do ...@@ -171,7 +171,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true) assert mock_url_generator_builder.has_generated_url_with_options?(escape: true)
end end
it "pass the option escape: false if :escape_url is false and :escape is not passed" do it "passes the option escape: false if :escape_url is false and :escape is not passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, attachment = Paperclip::Attachment.new(:name,
:instance, :instance,
...@@ -182,7 +182,7 @@ describe Paperclip::Attachment do ...@@ -182,7 +182,7 @@ describe Paperclip::Attachment do
assert mock_url_generator_builder.has_generated_url_with_options?(escape: false) assert mock_url_generator_builder.has_generated_url_with_options?(escape: false)
end end
it "return the path based on the url by default" do it "returns the path based on the url by default" do
@attachment = attachment url: "/:class/:id/:basename" @attachment = attachment url: "/:class/:id/:basename"
@model = @attachment.instance @model = @attachment.instance
@model.id = 1234 @model.id = 1234
...@@ -190,7 +190,7 @@ describe Paperclip::Attachment do ...@@ -190,7 +190,7 @@ describe Paperclip::Attachment do
assert_equal "#{Rails.root}/public/fake_models/1234/fake", @attachment.path assert_equal "#{Rails.root}/public/fake_models/1234/fake", @attachment.path
end end
it "default to a path that scales" do it "defaults to a path that scales" do
avatar_attachment = attachment avatar_attachment = attachment
model = avatar_attachment.instance model = avatar_attachment.instance
model.id = 1234 model.id = 1234
...@@ -199,7 +199,7 @@ describe Paperclip::Attachment do ...@@ -199,7 +199,7 @@ describe Paperclip::Attachment do
assert_equal expected_path, avatar_attachment.path assert_equal expected_path, avatar_attachment.path
end end
it "render JSON as the URL to the attachment" do it "renders JSON as the URL to the attachment" do
avatar_attachment = attachment avatar_attachment = attachment
model = avatar_attachment.instance model = avatar_attachment.instance
model.id = 1234 model.id = 1234
...@@ -207,7 +207,7 @@ describe Paperclip::Attachment do ...@@ -207,7 +207,7 @@ describe Paperclip::Attachment do
assert_equal attachment.url, attachment.as_json assert_equal attachment.url, attachment.as_json
end end
it "render JSON from the model when requested by :methods" do it "renders JSON from the model when requested by :methods" do
rebuild_model rebuild_model
dummy = Dummy.new dummy = Dummy.new
dummy.id = 1234 dummy.id = 1234
...@@ -235,7 +235,7 @@ describe Paperclip::Attachment do ...@@ -235,7 +235,7 @@ describe Paperclip::Attachment do
Paperclip::Attachment.default_options.merge! @old_default_options Paperclip::Attachment.default_options.merge! @old_default_options
end end
it "be overrideable" do it "is overrideable" do
Paperclip::Attachment.default_options.merge!(@new_default_options) Paperclip::Attachment.default_options.merge!(@new_default_options)
@new_default_options.keys.each do |key| @new_default_options.keys.each do |key|
assert_equal @new_default_options[key], assert_equal @new_default_options[key],
...@@ -248,7 +248,7 @@ describe Paperclip::Attachment do ...@@ -248,7 +248,7 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "return false when asked exists?" do it "returns false when asked exists?" do
assert !@dummy.avatar.exists? assert !@dummy.avatar.exists?
end end
end end
...@@ -260,7 +260,7 @@ describe Paperclip::Attachment do ...@@ -260,7 +260,7 @@ describe Paperclip::Attachment do
end end
Paperclip::Attachment.default_options.keys.each do |key| Paperclip::Attachment.default_options.keys.each do |key|
it "be the default_options for #{key}" do it "is the default_options for #{key}" do
assert_equal @old_default_options[key], assert_equal @old_default_options[key],
@attachment.instance_variable_get("@options")[key], @attachment.instance_variable_get("@options")[key],
key.to_s key.to_s
...@@ -275,7 +275,7 @@ describe Paperclip::Attachment do ...@@ -275,7 +275,7 @@ describe Paperclip::Attachment do
end end
Paperclip::Attachment.default_options.keys.each do |key| Paperclip::Attachment.default_options.keys.each do |key|
it "be the new default_options for #{key}" do it "is the new default_options for #{key}" do
assert_equal @new_default_options[key], assert_equal @new_default_options[key],
@attachment.instance_variable_get("@options")[key], @attachment.instance_variable_get("@options")[key],
key.to_s key.to_s
...@@ -296,7 +296,7 @@ describe Paperclip::Attachment do ...@@ -296,7 +296,7 @@ describe Paperclip::Attachment do
after { @file.close } after { @file.close }
it "make sure that they are interpolated correctly" do it "makes sure that they are interpolated correctly" do
assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path assert_equal "1024.omg/1024-bbq/1024what/000/001/024.wtf", @dummy.avatar.path
end end
end end
...@@ -317,7 +317,7 @@ describe Paperclip::Attachment do ...@@ -317,7 +317,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "return a time in the default zone" do it "returns a time in the default zone" do
assert_equal @dummy.avatar_updated_at.in_time_zone(@zone_default).to_s, @dummy.avatar.path assert_equal @dummy.avatar_updated_at.in_time_zone(@zone_default).to_s, @dummy.avatar.path
end end
end end
...@@ -329,7 +329,7 @@ describe Paperclip::Attachment do ...@@ -329,7 +329,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "return a time in the per-thread zone" do it "returns a time in the per-thread zone" do
assert_equal @dummy.avatar_updated_at.in_time_zone(@zone).to_s, @dummy.avatar.path assert_equal @dummy.avatar_updated_at.in_time_zone(@zone).to_s, @dummy.avatar.path
end end
end end
...@@ -340,7 +340,7 @@ describe Paperclip::Attachment do ...@@ -340,7 +340,7 @@ describe Paperclip::Attachment do
@file = StringIO.new("...\n") @file = StringIO.new("...\n")
end end
it "raise if no secret is provided" do it "raises if no secret is provided" do
rebuild_model path: ":hash" rebuild_model path: ":hash"
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
@attachment.assign @file @attachment.assign @file
...@@ -359,14 +359,14 @@ describe Paperclip::Attachment do ...@@ -359,14 +359,14 @@ describe Paperclip::Attachment do
@attachment.assign @file @attachment.assign @file
end end
it "result in the correct interpolation" do it "results in the correct interpolation" do
assert_equal "dummies/avatars/original/data.txt", assert_equal "dummies/avatars/original/data.txt",
@attachment.send(:interpolate, @attachment.options[:hash_data]) @attachment.send(:interpolate, @attachment.options[:hash_data])
assert_equal "dummies/avatars/thumb/data.txt", assert_equal "dummies/avatars/thumb/data.txt",
@attachment.send(:interpolate, @attachment.options[:hash_data], :thumb) @attachment.send(:interpolate, @attachment.options[:hash_data], :thumb)
end end
it "result in a correct hash" do it "results in a correct hash" do
assert_equal "e1079a5c34ddbd197ebd0280d07952d98a57fb30", @attachment.path assert_equal "e1079a5c34ddbd197ebd0280d07952d98a57fb30", @attachment.path
assert_equal "d740189bd3e49ef226fab84c8d45f7ae4126d043", @attachment.path(:thumb) assert_equal "d740189bd3e49ef226fab84c8d45f7ae4126d043", @attachment.path(:thumb)
end end
...@@ -385,7 +385,7 @@ describe Paperclip::Attachment do ...@@ -385,7 +385,7 @@ describe Paperclip::Attachment do
Rails.stubs(:env).returns(@rails_env) Rails.stubs(:env).returns(@rails_env)
end end
it "return the proper path" do it "returns the proper path" do
assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path
end end
end end
...@@ -399,7 +399,7 @@ describe Paperclip::Attachment do ...@@ -399,7 +399,7 @@ describe Paperclip::Attachment do
@file = File.open(fixture_file("5k.png")) @file = File.open(fixture_file("5k.png"))
@file.stubs(:original_filename).returns("file.png") @file.stubs(:original_filename).returns("file.png")
end end
it "return the right extension for the path" do it "returns the right extension for the path" do
@attachment.assign(@file) @attachment.assign(@file)
assert_equal "file.jpg", @attachment.path assert_equal "file.jpg", @attachment.path
end end
...@@ -419,11 +419,11 @@ describe Paperclip::Attachment do ...@@ -419,11 +419,11 @@ describe Paperclip::Attachment do
@dummy.avatar @dummy.avatar
end end
it "report the correct options when sent #extra_options_for(:thumb)" do it "reports the correct options when sent #extra_options_for(:thumb)" do
assert_equal "-thumbnailize -do_stuff", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect assert_equal "-thumbnailize -do_stuff", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
end end
it "report the correct options when sent #extra_options_for(:large)" do it "reports the correct options when sent #extra_options_for(:large)" do
assert_equal "-do_stuff", @dummy.avatar.send(:extra_options_for, :large) assert_equal "-do_stuff", @dummy.avatar.send(:extra_options_for, :large)
end end
end end
...@@ -442,11 +442,11 @@ describe Paperclip::Attachment do ...@@ -442,11 +442,11 @@ describe Paperclip::Attachment do
@dummy.avatar @dummy.avatar
end end
it "report the correct options when sent #extra_source_file_options_for(:thumb)" do it "reports the correct options when sent #extra_source_file_options_for(:thumb)" do
assert_equal "-depth 8 -density 400", @dummy.avatar.send(:extra_source_file_options_for, :thumb), @dummy.avatar.source_file_options.inspect assert_equal "-depth 8 -density 400", @dummy.avatar.send(:extra_source_file_options_for, :thumb), @dummy.avatar.source_file_options.inspect
end end
it "report the correct options when sent #extra_source_file_options_for(:large)" do it "reports the correct options when sent #extra_source_file_options_for(:large)" do
assert_equal "-density 400", @dummy.avatar.send(:extra_source_file_options_for, :large) assert_equal "-density 400", @dummy.avatar.send(:extra_source_file_options_for, :large)
end end
end end
...@@ -462,7 +462,7 @@ describe Paperclip::Attachment do ...@@ -462,7 +462,7 @@ describe Paperclip::Attachment do
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
end end
it "only process the provided style" do it "only processes the provided style" do
@attachment.expects(:post_process).with(:thumb) @attachment.expects(:post_process).with(:thumb)
@attachment.expects(:post_process).with(:large).never @attachment.expects(:post_process).with(:large).never
@attachment.assign(@file) @attachment.assign(@file)
...@@ -481,7 +481,7 @@ describe Paperclip::Attachment do ...@@ -481,7 +481,7 @@ describe Paperclip::Attachment do
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
end end
it "only process the provided style" do it "only processes the provided style" do
@attachment.expects(:post_process).with(:thumb) @attachment.expects(:post_process).with(:thumb)
@attachment.expects(:post_process).with(:large).never @attachment.expects(:post_process).with(:large).never
@attachment.assign(@file) @attachment.assign(@file)
...@@ -506,11 +506,11 @@ describe Paperclip::Attachment do ...@@ -506,11 +506,11 @@ describe Paperclip::Attachment do
@dummy.avatar @dummy.avatar
end end
it "report the correct options when sent #extra_options_for(:thumb)" do it "reports the correct options when sent #extra_options_for(:thumb)" do
assert_equal "-thumb -all", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect assert_equal "-thumb -all", @dummy.avatar.send(:extra_options_for, :thumb), @dummy.avatar.convert_options.inspect
end end
it "report the correct options when sent #extra_options_for(:large)" do it "reports the correct options when sent #extra_options_for(:large)" do
assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large) assert_equal "-all", @dummy.avatar.send(:extra_options_for, :large)
end end
end end
...@@ -528,7 +528,7 @@ describe Paperclip::Attachment do ...@@ -528,7 +528,7 @@ describe Paperclip::Attachment do
after { @file.close } after { @file.close }
it "return correct path" do it "returns correct path" do
assert_equal "path/a.png", @dummyA.avatar.path assert_equal "path/a.png", @dummyA.avatar.path
assert_equal "path/b.png", @dummyB.avatar.path assert_equal "path/b.png", @dummyB.avatar.path
end end
...@@ -541,7 +541,7 @@ describe Paperclip::Attachment do ...@@ -541,7 +541,7 @@ describe Paperclip::Attachment do
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
end end
it "have the correct geometry" do it "has the correct geometry" do
assert_equal "50x50#", @attachment.styles[:thumb][:geometry] assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end end
end end
...@@ -553,7 +553,7 @@ describe Paperclip::Attachment do ...@@ -553,7 +553,7 @@ describe Paperclip::Attachment do
@dummy = Dummy.new(other: 'a') @dummy = Dummy.new(other: 'a')
end end
it "have the correct styles for the assigned instance values" do it "has the correct styles for the assigned instance values" do
assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry] assert_equal "50x50#", @dummy.avatar.styles[:thumb][:geometry]
assert_nil @dummy.avatar.styles[:large] assert_nil @dummy.avatar.styles[:large]
...@@ -582,7 +582,7 @@ describe Paperclip::Attachment do ...@@ -582,7 +582,7 @@ describe Paperclip::Attachment do
@attachment.assign(@file) @attachment.assign(@file)
end end
it "have the correct geometry" do it "has the correct geometry" do
assert_equal "50x50#", @attachment.styles[:normal][:geometry] assert_equal "50x50#", @attachment.styles[:normal][:geometry]
end end
end end
...@@ -600,7 +600,7 @@ describe Paperclip::Attachment do ...@@ -600,7 +600,7 @@ describe Paperclip::Attachment do
end end
[:processors, :whiny, :convert_options, :geometry, :format].each do |field| [:processors, :whiny, :convert_options, :geometry, :format].each do |field|
it "have the same #{field} field" do it "has the same #{field} field" do
assert_equal @attachment.styles[:normal][field], @attachment.styles[:hash][field] assert_equal @attachment.styles[:normal][field], @attachment.styles[:hash][field]
end end
end end
...@@ -621,7 +621,7 @@ describe Paperclip::Attachment do ...@@ -621,7 +621,7 @@ describe Paperclip::Attachment do
@attachment.assign(StringIO.new(".")) @attachment.assign(StringIO.new("."))
end end
it "have the correct processors" do it "has the correct processors" do
assert_equal [ :test ], @attachment.styles[:normal][:processors] assert_equal [ :test ], @attachment.styles[:normal][:processors]
end end
end end
...@@ -637,7 +637,7 @@ describe Paperclip::Attachment do ...@@ -637,7 +637,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "correctly forward processing error message to the instance" do it "correctly forwards processing error message to the instance" do
@dummy.valid? @dummy.valid?
assert_contains @dummy.errors.full_messages, "Avatar cannot be processed." assert_contains @dummy.errors.full_messages, "Avatar cannot be processed."
end end
...@@ -656,7 +656,7 @@ describe Paperclip::Attachment do ...@@ -656,7 +656,7 @@ describe Paperclip::Attachment do
end end
context "when assigned" do context "when assigned" do
it "call #make on all specified processors" do it "calls #make on all specified processors" do
Paperclip::Thumbnail.stubs(:make).with(any_parameters).returns(@file) Paperclip::Thumbnail.stubs(:make).with(any_parameters).returns(@file)
Paperclip::Test.stubs(:make).with(any_parameters).returns(@file) Paperclip::Test.stubs(:make).with(any_parameters).returns(@file)
...@@ -666,8 +666,9 @@ describe Paperclip::Attachment do ...@@ -666,8 +666,9 @@ describe Paperclip::Attachment do
expect(Paperclip::Test).to have_received(:make) expect(Paperclip::Test).to have_received(:make)
end end
it "call #make with the right parameters passed as second argument" do it "calls #make with the right parameters passed as second argument" do
expected_params = @style_params[:once].merge({ expected_params = @style_params[:once].merge({
style: :once,
processors: [:thumbnail, :test], processors: [:thumbnail, :test],
whiny: true, whiny: true,
convert_options: "", convert_options: "",
...@@ -680,7 +681,7 @@ describe Paperclip::Attachment do ...@@ -680,7 +681,7 @@ describe Paperclip::Attachment do
expect(Paperclip::Thumbnail).to have_received(:make).with(anything, expected_params, anything) expect(Paperclip::Thumbnail).to have_received(:make).with(anything, expected_params, anything)
end end
it "call #make with attachment passed as third argument" do it "calls #make with attachment passed as third argument" do
Paperclip::Test.expects(:make).returns(@file) Paperclip::Test.expects(:make).returns(@file)
@dummy.avatar = @file @dummy.avatar = @file
...@@ -690,13 +691,13 @@ describe Paperclip::Attachment do ...@@ -690,13 +691,13 @@ describe Paperclip::Attachment do
end end
end end
it "include the filesystem module when loading the filesystem storage" do it "includes the filesystem module when loading the filesystem storage" do
rebuild_model storage: :filesystem rebuild_model storage: :filesystem
@dummy = Dummy.new @dummy = Dummy.new
assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem) assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
end end
it "include the filesystem module even if capitalization is wrong" do it "includes the filesystem module even if capitalization is wrong" do
rebuild_model storage: :FileSystem rebuild_model storage: :FileSystem
@dummy = Dummy.new @dummy = Dummy.new
assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem) assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
...@@ -706,7 +707,7 @@ describe Paperclip::Attachment do ...@@ -706,7 +707,7 @@ describe Paperclip::Attachment do
assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem) assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
end end
it "convert underscored storage name to camelcase" do it "converts underscored storage name to camelcase" do
rebuild_model storage: :not_here rebuild_model storage: :not_here
@dummy = Dummy.new @dummy = Dummy.new
exception = assert_raises(Paperclip::Errors::StorageMethodNotFound, /NotHere/) do exception = assert_raises(Paperclip::Errors::StorageMethodNotFound, /NotHere/) do
...@@ -714,7 +715,7 @@ describe Paperclip::Attachment do ...@@ -714,7 +715,7 @@ describe Paperclip::Attachment do
end end
end end
it "raise an error if you try to include a storage module that doesn't exist" do it "raises an error if you try to include a storage module that doesn't exist" do
rebuild_model storage: :not_here rebuild_model storage: :not_here
@dummy = Dummy.new @dummy = Dummy.new
assert_raises(Paperclip::Errors::StorageMethodNotFound) do assert_raises(Paperclip::Errors::StorageMethodNotFound) do
...@@ -728,7 +729,7 @@ describe Paperclip::Attachment do ...@@ -728,7 +729,7 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
@file = StringIO.new("...") @file = StringIO.new("...")
end end
it "raise when assigned to" do it "raises when assigned to" do
assert_raises(RuntimeError){ @dummy.avatar = @file } assert_raises(RuntimeError){ @dummy.avatar = @file }
end end
end end
...@@ -739,7 +740,7 @@ describe Paperclip::Attachment do ...@@ -739,7 +740,7 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
@file = StringIO.new("...") @file = StringIO.new("...")
end end
it "not raise when assigned to" do it "does not raise when assigned to" do
@dummy.avatar = @file @dummy.avatar = @file
end end
end end
...@@ -764,7 +765,7 @@ describe Paperclip::Attachment do ...@@ -764,7 +765,7 @@ describe Paperclip::Attachment do
@attachment = @dummy.avatar @attachment = @dummy.avatar
end end
it "call the defined callbacks when assigned" do it "calls the defined callbacks when assigned" do
@dummy.expects(:do_before_avatar).with() @dummy.expects(:do_before_avatar).with()
@dummy.expects(:do_after_avatar).with() @dummy.expects(:do_after_avatar).with()
@dummy.expects(:do_before_all).with() @dummy.expects(:do_before_all).with()
...@@ -773,7 +774,7 @@ describe Paperclip::Attachment do ...@@ -773,7 +774,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "not cancel the processing if a before_post_process returns nil" do it "does not cancel the processing if a before_post_process returns nil" do
@dummy.expects(:do_before_avatar).with().returns(nil) @dummy.expects(:do_before_avatar).with().returns(nil)
@dummy.expects(:do_after_avatar).with() @dummy.expects(:do_after_avatar).with()
@dummy.expects(:do_before_all).with().returns(nil) @dummy.expects(:do_before_all).with().returns(nil)
...@@ -782,7 +783,7 @@ describe Paperclip::Attachment do ...@@ -782,7 +783,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "cancel the processing if a before_post_process returns false" do it "cancels the processing if a before_post_process returns false" do
@dummy.expects(:do_before_avatar).never @dummy.expects(:do_before_avatar).never
@dummy.expects(:do_after_avatar).never @dummy.expects(:do_after_avatar).never
@dummy.expects(:do_before_all).with().returns(false) @dummy.expects(:do_before_all).with().returns(false)
...@@ -791,7 +792,7 @@ describe Paperclip::Attachment do ...@@ -791,7 +792,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "cancel the processing if a before_avatar_post_process returns false" do it "cancels the processing if a before_avatar_post_process returns false" do
@dummy.expects(:do_before_avatar).with().returns(false) @dummy.expects(:do_before_avatar).with().returns(false)
@dummy.expects(:do_after_avatar) @dummy.expects(:do_after_avatar)
@dummy.expects(:do_before_all).with().returns(true) @dummy.expects(:do_before_all).with().returns(true)
...@@ -809,11 +810,11 @@ describe Paperclip::Attachment do ...@@ -809,11 +810,11 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "strip whitespace from original_filename field" do it "strips whitespace from original_filename field" do
assert_equal "5k.png", @dummy.avatar.original_filename assert_equal "5k.png", @dummy.avatar.original_filename
end end
it "strip whitespace from content_type field" do it "strips whitespace from content_type field" do
assert_equal "image/png", @dummy.avatar.instance.avatar_content_type assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
end end
end end
...@@ -826,7 +827,7 @@ describe Paperclip::Attachment do ...@@ -826,7 +827,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "make sure the content_type is a string" do it "makes sure the content_type is a string" do
assert_equal "image/png", @dummy.avatar.instance.avatar_content_type assert_equal "image/png", @dummy.avatar.instance.avatar_content_type
end end
end end
...@@ -840,7 +841,7 @@ describe Paperclip::Attachment do ...@@ -840,7 +841,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "not remove strange letters" do it "does not remove strange letters" do
assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename assert_equal "sheep_say_bæ.png", @dummy.avatar.original_filename
end end
end end
...@@ -866,7 +867,7 @@ describe Paperclip::Attachment do ...@@ -866,7 +867,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "convert special character into underscore" do it "converts special character into underscore" do
assert_equal "_filename.png", @dummy.avatar.original_filename assert_equal "_filename.png", @dummy.avatar.original_filename
end end
end end
...@@ -878,7 +879,7 @@ describe Paperclip::Attachment do ...@@ -878,7 +879,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "convert special character into underscore" do it "converts special character into underscore" do
assert_equal "filename.png_", @dummy.avatar.original_filename assert_equal "filename.png_", @dummy.avatar.original_filename
end end
end end
...@@ -890,7 +891,7 @@ describe Paperclip::Attachment do ...@@ -890,7 +891,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "convert special character into underscore" do it "converts special character into underscore" do
assert_equal "file_name.png", @dummy.avatar.original_filename assert_equal "file_name.png", @dummy.avatar.original_filename
end end
end end
...@@ -917,7 +918,7 @@ describe Paperclip::Attachment do ...@@ -917,7 +918,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "match and convert that character" do it "matches and converts that character" do
assert_equal "g___d.png", @dummy.avatar.original_filename assert_equal "g___d.png", @dummy.avatar.original_filename
end end
end end
...@@ -931,7 +932,7 @@ describe Paperclip::Attachment do ...@@ -931,7 +932,7 @@ describe Paperclip::Attachment do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "ignore and return the original file name" do it "ignores and returns the original file name" do
assert_equal "goood.png", @dummy.avatar.original_filename assert_equal "goood.png", @dummy.avatar.original_filename
end end
end end
...@@ -946,7 +947,7 @@ describe Paperclip::Attachment do ...@@ -946,7 +947,7 @@ describe Paperclip::Attachment do
Paperclip::Attachment.default_options.merge! @old_defaults Paperclip::Attachment.default_options.merge! @old_defaults
end end
it 'call the given proc and take the result as cleaned filename' do it 'calls the given proc and take the result as cleaned filename' do
Paperclip::Attachment.default_options[:filename_cleaner] = lambda do |str| Paperclip::Attachment.default_options[:filename_cleaner] = lambda do |str|
"from_proc_#{str}" "from_proc_#{str}"
end end
...@@ -957,7 +958,7 @@ describe Paperclip::Attachment do ...@@ -957,7 +958,7 @@ describe Paperclip::Attachment do
assert_equal "from_proc_goood.png", @dummy.avatar.original_filename assert_equal "from_proc_goood.png", @dummy.avatar.original_filename
end end
it 'call the given object and take the result as the cleaned filename' do it 'calls the given object and take the result as the cleaned filename' do
class MyCleaner class MyCleaner
def call(filename) def call(filename)
"foo" "foo"
...@@ -1001,12 +1002,12 @@ describe Paperclip::Attachment do ...@@ -1001,12 +1002,12 @@ describe Paperclip::Attachment do
Paperclip::Attachment.default_options.merge!(@old_defaults) Paperclip::Attachment.default_options.merge!(@old_defaults)
end end
it "should have matching to_s and url methods" do it "has matching to_s and url methods" do
assert_equal @attachment.to_s, @attachment.url assert_equal @attachment.to_s, @attachment.url
assert_equal @attachment.to_s(:small), @attachment.url(:small) assert_equal @attachment.to_s(:small), @attachment.url(:small)
end end
it "have matching expiring_url and url methods when using the filesystem storage" do it "has matching expiring_url and url methods when using the filesystem storage" do
assert_equal @attachment.expiring_url, @attachment.url assert_equal @attachment.expiring_url, @attachment.url
end end
end end
...@@ -1031,34 +1032,34 @@ describe Paperclip::Attachment do ...@@ -1031,34 +1032,34 @@ describe Paperclip::Attachment do
Paperclip::Attachment.default_options.merge!(@old_defaults) Paperclip::Attachment.default_options.merge!(@old_defaults)
end end
it "raise if there are not the correct columns when you try to assign" do it "raises if there are not the correct columns when you try to assign" do
@other_attachment = Paperclip::Attachment.new(:not_here, @instance) @other_attachment = Paperclip::Attachment.new(:not_here, @instance)
assert_raises(Paperclip::Error) do assert_raises(Paperclip::Error) do
@other_attachment.assign(@file) @other_attachment.assign(@file)
end end
end end
it 'clear out the previous assignment when assigned nil' do it 'clears out the previous assignment when assigned nil' do
@attachment.assign(@file) @attachment.assign(@file)
@attachment.queued_for_write[:original] @attachment.queued_for_write[:original]
@attachment.assign(nil) @attachment.assign(nil)
assert_nil @attachment.queued_for_write[:original] assert_nil @attachment.queued_for_write[:original]
end end
it 'not do anything when it is assigned an empty string' do it 'does not do anything when it is assigned an empty string' do
@attachment.assign(@file) @attachment.assign(@file)
original_file = @attachment.queued_for_write[:original] original_file = @attachment.queued_for_write[:original]
@attachment.assign("") @attachment.assign("")
assert_equal original_file, @attachment.queued_for_write[:original] assert_equal original_file, @attachment.queued_for_write[:original]
end end
it "return nil as path when no file assigned" do it "returns nil as path when no file assigned" do
assert_equal nil, @attachment.path assert_equal nil, @attachment.path
assert_equal nil, @attachment.path(:blah) assert_equal nil, @attachment.path(:blah)
end end
context "with a file assigned but not saved yet" do context "with a file assigned but not saved yet" do
it "clear out any attached files" do it "clears out any attached files" do
@attachment.assign(@file) @attachment.assign(@file)
assert !@attachment.queued_for_write.blank? assert !@attachment.queued_for_write.blank?
@attachment.clear @attachment.clear
...@@ -1077,11 +1078,11 @@ describe Paperclip::Attachment do ...@@ -1077,11 +1078,11 @@ describe Paperclip::Attachment do
@attachment.stubs(:instance_read).with(:updated_at).returns(dtnow) @attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
end end
it "return the proper path when filename has a single .'s" do it "returns the proper path when filename has a single .'s" do
assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.png"), File.expand_path(@attachment.path) assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.png"), File.expand_path(@attachment.path)
end end
it "return the proper path when filename has multiple .'s" do it "returns the proper path when filename has multiple .'s" do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png") @attachment.stubs(:instance_read).with(:file_name).returns("5k.old.png")
assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path) assert_equal File.expand_path("tmp/avatars/dummies/original/#{@instance.id}/5k.old.png"), File.expand_path(@attachment.path)
end end
...@@ -1106,7 +1107,7 @@ describe Paperclip::Attachment do ...@@ -1106,7 +1107,7 @@ describe Paperclip::Attachment do
@attachment.assign(@file) @attachment.assign(@file)
end end
it "be dirty" do it "is dirty" do
assert @attachment.dirty? assert @attachment.dirty?
end end
...@@ -1115,13 +1116,13 @@ describe Paperclip::Attachment do ...@@ -1115,13 +1116,13 @@ describe Paperclip::Attachment do
@attachment.save @attachment.save
end end
it "commit the files to disk" do it "commits the files to disk" do
[:large, :medium, :small].each do |style| [:large, :medium, :small].each do |style|
expect(@attachment.path(style)).to exist expect(@attachment.path(style)).to exist
end end
end end
it "save the files as the right formats and sizes" do it "saves the files as the right formats and sizes" do
[[:large, 400, 61, "PNG"], [[:large, 400, 61, "PNG"],
[:medium, 100, 15, "GIF"], [:medium, 100, 15, "GIF"],
[:small, 32, 32, "JPEG"]].each do |style| [:small, 32, 32, "JPEG"]].each do |style|
...@@ -1141,7 +1142,7 @@ describe Paperclip::Attachment do ...@@ -1141,7 +1142,7 @@ describe Paperclip::Attachment do
end end
end end
it "delete the files after assigning nil" do it "deletes the files after assigning nil" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1152,7 +1153,7 @@ describe Paperclip::Attachment do ...@@ -1152,7 +1153,7 @@ describe Paperclip::Attachment do
@existing_names.each{|f| assert_file_not_exists(f) } @existing_names.each{|f| assert_file_not_exists(f) }
end end
it "delete the files when you call #clear and #save" do it "deletes the files when you call #clear and #save" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1163,7 +1164,7 @@ describe Paperclip::Attachment do ...@@ -1163,7 +1164,7 @@ describe Paperclip::Attachment do
@existing_names.each{|f| assert_file_not_exists(f) } @existing_names.each{|f| assert_file_not_exists(f) }
end end
it "delete the files when you call #delete" do it "deletes the files when you call #delete" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1178,7 +1179,7 @@ describe Paperclip::Attachment do ...@@ -1178,7 +1179,7 @@ describe Paperclip::Attachment do
@attachment.options[:keep_old_files] = true @attachment.options[:keep_old_files] = true
end end
it "keep the files after assigning nil" do it "keeps the files after assigning nil" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1189,7 +1190,7 @@ describe Paperclip::Attachment do ...@@ -1189,7 +1190,7 @@ describe Paperclip::Attachment do
@existing_names.each{|f| assert_file_exists(f) } @existing_names.each{|f| assert_file_exists(f) }
end end
it "keep the files when you call #clear and #save" do it "keeps the files when you call #clear and #save" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1200,7 +1201,7 @@ describe Paperclip::Attachment do ...@@ -1200,7 +1201,7 @@ describe Paperclip::Attachment do
@existing_names.each{|f| assert_file_exists(f) } @existing_names.each{|f| assert_file_exists(f) }
end end
it "keep the files when you call #delete" do it "keeps the files when you call #delete" do
@attachment.expects(:instance_write).with(:file_name, nil) @attachment.expects(:instance_write).with(:file_name, nil)
@attachment.expects(:instance_write).with(:content_type, nil) @attachment.expects(:instance_write).with(:content_type, nil)
@attachment.expects(:instance_write).with(:file_size, nil) @attachment.expects(:instance_write).with(:file_size, nil)
...@@ -1221,7 +1222,7 @@ describe Paperclip::Attachment do ...@@ -1221,7 +1222,7 @@ describe Paperclip::Attachment do
rebuild_model storage: :not_here rebuild_model storage: :not_here
end end
it "not be able to find the module" do it "is not able to find the module" do
assert_raises(Paperclip::Errors::StorageMethodNotFound){ Dummy.new.avatar } assert_raises(Paperclip::Errors::StorageMethodNotFound){ Dummy.new.avatar }
end end
end end
...@@ -1239,16 +1240,16 @@ describe Paperclip::Attachment do ...@@ -1239,16 +1240,16 @@ describe Paperclip::Attachment do
after { @file.close } after { @file.close }
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "not return the time when sent #avatar_updated_at" do it "does not return the time when sent #avatar_updated_at" do
@dummy.avatar = @file @dummy.avatar = @file
assert_nil @dummy.avatar.updated_at assert_nil @dummy.avatar.updated_at
end end
it "return the right value when sent #avatar_file_size" do it "returns the right value when sent #avatar_file_size" do
@dummy.avatar = @file @dummy.avatar = @file
assert_equal File.size(@file), @dummy.avatar.size assert_equal File.size(@file), @dummy.avatar.size
end end
...@@ -1260,18 +1261,18 @@ describe Paperclip::Attachment do ...@@ -1260,18 +1261,18 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "return the creation time when sent #avatar_created_at" do it "returns the creation time when sent #avatar_created_at" do
now = Time.now now = Time.now
Time.stubs(:now).returns(now) Time.stubs(:now).returns(now)
@dummy.avatar = @file @dummy.avatar = @file
assert_equal now.to_i, @dummy.avatar.created_at assert_equal now.to_i, @dummy.avatar.created_at
end end
it "return the creation time when sent #avatar_created_at and the entry has been updated" do it "returns the creation time when sent #avatar_created_at and the entry has been updated" do
creation = 2.hours.ago creation = 2.hours.ago
now = Time.now now = Time.now
Time.stubs(:now).returns(creation) Time.stubs(:now).returns(creation)
...@@ -1282,7 +1283,7 @@ describe Paperclip::Attachment do ...@@ -1282,7 +1283,7 @@ describe Paperclip::Attachment do
assert_not_equal now.to_i, @dummy.avatar.created_at assert_not_equal now.to_i, @dummy.avatar.created_at
end end
it "set changed? to true on attachment assignment" do it "sets changed? to true on attachment assignment" do
@dummy.avatar = @file @dummy.avatar = @file
@dummy.save! @dummy.save!
@dummy.avatar = @file @dummy.avatar = @file
...@@ -1297,11 +1298,11 @@ describe Paperclip::Attachment do ...@@ -1297,11 +1298,11 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "return the right value when sent #avatar_updated_at" do it "returns the right value when sent #avatar_updated_at" do
now = Time.now now = Time.now
Time.stubs(:now).returns(now) Time.stubs(:now).returns(now)
@dummy.avatar = @file @dummy.avatar = @file
...@@ -1309,7 +1310,7 @@ describe Paperclip::Attachment do ...@@ -1309,7 +1310,7 @@ describe Paperclip::Attachment do
end end
end end
it "not calculate fingerprint" do it "does not calculate fingerprint" do
@dummy.avatar = @file @dummy.avatar = @file
assert_nil @dummy.avatar.fingerprint assert_nil @dummy.avatar.fingerprint
end end
...@@ -1321,11 +1322,11 @@ describe Paperclip::Attachment do ...@@ -1321,11 +1322,11 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "return the right value when sent #avatar_content_type" do it "returns the right value when sent #avatar_content_type" do
@dummy.avatar = @file @dummy.avatar = @file
assert_equal "image/png", @dummy.avatar.content_type assert_equal "image/png", @dummy.avatar.content_type
end end
...@@ -1338,16 +1339,16 @@ describe Paperclip::Attachment do ...@@ -1338,16 +1339,16 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "return the right value when sent #avatar_file_size" do it "returns the right value when sent #avatar_file_size" do
@dummy.avatar = @file @dummy.avatar = @file
assert_equal File.size(@file), @dummy.avatar.size assert_equal File.size(@file), @dummy.avatar.size
end end
it "return the right value when saved, reloaded, and sent #avatar_file_size" do it "returns the right value when saved, reloaded, and sent #avatar_file_size" do
@dummy.avatar = @file @dummy.avatar = @file
@dummy.save @dummy.save
@dummy = Dummy.find(@dummy.id) @dummy = Dummy.find(@dummy.id)
...@@ -1362,16 +1363,16 @@ describe Paperclip::Attachment do ...@@ -1362,16 +1363,16 @@ describe Paperclip::Attachment do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not error when assigned an attachment" do it "does not error when assigned an attachment" do
assert_nothing_raised { @dummy.avatar = @file } assert_nothing_raised { @dummy.avatar = @file }
end end
it "return the right value when sent #avatar_fingerprint" do it "returns the right value when sent #avatar_fingerprint" do
@dummy.avatar = @file @dummy.avatar = @file
assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.avatar_fingerprint assert_equal 'aec488126c3b33c08a10c3fa303acf27', @dummy.avatar_fingerprint
end end
it "return the right value when saved, reloaded, and sent #avatar_fingerprint" do it "returns the right value when saved, reloaded, and sent #avatar_fingerprint" do
@dummy.avatar = @file @dummy.avatar = @file
@dummy.save @dummy.save
@dummy = Dummy.find(@dummy.id) @dummy = Dummy.find(@dummy.id)
...@@ -1393,18 +1394,18 @@ describe Paperclip::Attachment do ...@@ -1393,18 +1394,18 @@ describe Paperclip::Attachment do
after { @file.close } after { @file.close }
it "not delete the files from storage when attachment is destroyed" do it "does not delete the files from storage when attachment is destroyed" do
@attachment.destroy @attachment.destroy
assert_file_exists(@path) assert_file_exists(@path)
end end
it "clear out attachment data when attachment is destroyed" do it "clears out attachment data when attachment is destroyed" do
@attachment.destroy @attachment.destroy
assert !@attachment.exists? assert !@attachment.exists?
assert_nil @dummy.avatar_file_name assert_nil @dummy.avatar_file_name
end end
it "not delete the file when model is destroyed" do it "does not delete the file when model is destroyed" do
@dummy.destroy @dummy.destroy
assert_file_exists(@path) assert_file_exists(@path)
end end
...@@ -1423,7 +1424,7 @@ describe Paperclip::Attachment do ...@@ -1423,7 +1424,7 @@ describe Paperclip::Attachment do
after { @file.close } after { @file.close }
it "not be deleted when the model fails to destroy" do it "is not deleted when the model fails to destroy" do
@dummy.stubs(:destroy).raises(Exception) @dummy.stubs(:destroy).raises(Exception)
assert_raises Exception do assert_raises Exception do
...@@ -1433,12 +1434,12 @@ describe Paperclip::Attachment do ...@@ -1433,12 +1434,12 @@ describe Paperclip::Attachment do
assert_file_exists(@path) assert_file_exists(@path)
end end
it "be deleted when the model is destroyed" do it "is deleted when the model is destroyed" do
@dummy.destroy @dummy.destroy
assert_file_not_exists(@path) assert_file_not_exists(@path)
end end
it "not be deleted when transaction rollbacks after model is destroyed" do it "is not deleted when transaction rollbacks after model is destroyed" do
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@dummy.destroy @dummy.destroy
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::ContentTypeDetector do describe Paperclip::ContentTypeDetector do
it 'give a sensible default when the name is empty' do it 'gives a sensible default when the name is empty' do
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
end end
it 'return the empty content type when the file is empty' do it 'returns the empty content type when the file is empty' do
tempfile = Tempfile.new("empty") tempfile = Tempfile.new("empty")
assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect assert_equal "inode/x-empty", Paperclip::ContentTypeDetector.new(tempfile.path).detect
tempfile.close tempfile.close
end end
it 'return content type of file if it is an acceptable type' do it 'returns content type of file if it is an acceptable type' do
MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')]) MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')])
Paperclip.stubs(:run).returns("video/mp4") Paperclip.stubs(:run).returns("video/mp4")
@filename = "my_file.mp4" @filename = "my_file.mp4"
assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
end end
it 'find the right type in the list via the file command' do it 'finds the right type in the list via the file command' do
@filename = "#{Dir.tmpdir}/something.hahalolnotreal" @filename = "#{Dir.tmpdir}/something.hahalolnotreal"
File.open(@filename, "w+") do |file| File.open(@filename, "w+") do |file|
file.puts "This is a text file." file.puts "This is a text file."
...@@ -28,12 +28,12 @@ describe Paperclip::ContentTypeDetector do ...@@ -28,12 +28,12 @@ describe Paperclip::ContentTypeDetector do
FileUtils.rm @filename FileUtils.rm @filename
end end
it 'return a sensible default if something is wrong, like the file is gone' do it 'returns a sensible default if something is wrong, like the file is gone' do
@filename = "/path/to/nothing" @filename = "/path/to/nothing"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end end
it 'return a sensible default when the file command is missing' do it 'returns a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new) Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
@filename = "/path/to/something" @filename = "/path/to/something"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::FileCommandContentTypeDetector do describe Paperclip::FileCommandContentTypeDetector do
it 'return a content type based on the content of the file' do it 'returns a content type based on the content of the file' do
tempfile = Tempfile.new("something") tempfile = Tempfile.new("something")
tempfile.write("This is a file.") tempfile.write("This is a file.")
tempfile.rewind tempfile.rewind
...@@ -11,14 +11,14 @@ describe Paperclip::FileCommandContentTypeDetector do ...@@ -11,14 +11,14 @@ describe Paperclip::FileCommandContentTypeDetector do
tempfile.close tempfile.close
end end
it 'return a sensible default when the file command is missing' do it 'returns a sensible default when the file command is missing' do
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new) Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
@filename = "/path/to/something" @filename = "/path/to/something"
assert_equal "application/octet-stream", assert_equal "application/octet-stream",
Paperclip::FileCommandContentTypeDetector.new(@filename).detect Paperclip::FileCommandContentTypeDetector.new(@filename).detect
end end
it 'return a sensible default on the odd chance that run returns nil' do it 'returns a sensible default on the odd chance that run returns nil' do
Paperclip.stubs(:run).returns(nil) Paperclip.stubs(:run).returns(nil)
assert_equal "application/octet-stream", assert_equal "application/octet-stream",
Paperclip::FileCommandContentTypeDetector.new("windows").detect Paperclip::FileCommandContentTypeDetector.new("windows").detect
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
require 'spec_helper' require 'spec_helper'
describe Paperclip::FilenameCleaner do describe Paperclip::FilenameCleaner do
it 'convert invalid characters to underscores' do it 'converts invalid characters to underscores' do
cleaner = Paperclip::FilenameCleaner.new(/[aeiou]/) cleaner = Paperclip::FilenameCleaner.new(/[aeiou]/)
expect(cleaner.call("baseball")).to eq "b_s_b_ll" expect(cleaner.call("baseball")).to eq "b_s_b_ll"
end end
it 'not convert anything if the character regex is nil' do it 'does not convert anything if the character regex is nil' do
cleaner = Paperclip::FilenameCleaner.new(nil) cleaner = Paperclip::FilenameCleaner.new(nil)
expect(cleaner.call("baseball")).to eq "baseball" expect(cleaner.call("baseball")).to eq "baseball"
end end
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::GeometryDetector do describe Paperclip::GeometryDetector do
it 'identify an image and extract its dimensions' do it 'identifies an image and extract its dimensions' do
Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(make: :correct)) Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(make: :correct))
file = fixture_file("5k.png") file = fixture_file("5k.png")
factory = Paperclip::GeometryDetector.new(file) factory = Paperclip::GeometryDetector.new(file)
...@@ -11,7 +11,7 @@ describe Paperclip::GeometryDetector do ...@@ -11,7 +11,7 @@ describe Paperclip::GeometryDetector do
expect(output).to eq :correct expect(output).to eq :correct
end end
it 'identify an image and extract its dimensions and orientation' do it 'identifies an image and extract its dimensions and orientation' do
Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(make: :correct)) Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(make: :correct))
file = fixture_file("rotated.jpg") file = fixture_file("rotated.jpg")
factory = Paperclip::GeometryDetector.new(file) factory = Paperclip::GeometryDetector.new(file)
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::GeometryParser do describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions with no orientation' do it 'identifies an image and extract its dimensions with no orientation' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
height: '73', height: '73',
width: '434', width: '434',
...@@ -15,7 +15,7 @@ describe Paperclip::GeometryParser do ...@@ -15,7 +15,7 @@ describe Paperclip::GeometryParser do
assert_equal :correct, output assert_equal :correct, output
end end
it 'identify an image and extract its dimensions with an empty orientation' do it 'identifies an image and extract its dimensions with an empty orientation' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
height: '73', height: '73',
width: '434', width: '434',
...@@ -29,7 +29,7 @@ describe Paperclip::GeometryParser do ...@@ -29,7 +29,7 @@ describe Paperclip::GeometryParser do
assert_equal :correct, output assert_equal :correct, output
end end
it 'identify an image and extract its dimensions and orientation' do it 'identifies an image and extract its dimensions and orientation' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
height: '200', height: '200',
width: '300', width: '300',
...@@ -43,7 +43,7 @@ describe Paperclip::GeometryParser do ...@@ -43,7 +43,7 @@ describe Paperclip::GeometryParser do
assert_equal :correct, output assert_equal :correct, output
end end
it 'identify an image and extract its dimensions and modifier' do it 'identifies an image and extract its dimensions and modifier' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
height: '64', height: '64',
width: '64', width: '64',
...@@ -57,7 +57,7 @@ describe Paperclip::GeometryParser do ...@@ -57,7 +57,7 @@ describe Paperclip::GeometryParser do
assert_equal :correct, output assert_equal :correct, output
end end
it 'identify an image and extract its dimensions, orientation, and modifier' do it 'identifies an image and extract its dimensions, orientation, and modifier' do
Paperclip::Geometry.stubs(:new).with( Paperclip::Geometry.stubs(:new).with(
height: '50', height: '50',
width: '100', width: '100',
......
...@@ -2,54 +2,54 @@ require 'spec_helper' ...@@ -2,54 +2,54 @@ require 'spec_helper'
describe Paperclip::Geometry do describe Paperclip::Geometry do
context "Paperclip::Geometry" do context "Paperclip::Geometry" do
it "correctly report its given dimensions" do it "correctly reports its given dimensions" do
assert @geo = Paperclip::Geometry.new(1024, 768) assert @geo = Paperclip::Geometry.new(1024, 768)
assert_equal 1024, @geo.width assert_equal 1024, @geo.width
assert_equal 768, @geo.height assert_equal 768, @geo.height
end end
it "set height to 0 if height dimension is missing" do it "sets height to 0 if height dimension is missing" do
assert @geo = Paperclip::Geometry.new(1024) assert @geo = Paperclip::Geometry.new(1024)
assert_equal 1024, @geo.width assert_equal 1024, @geo.width
assert_equal 0, @geo.height assert_equal 0, @geo.height
end end
it "set width to 0 if width dimension is missing" do it "sets width to 0 if width dimension is missing" do
assert @geo = Paperclip::Geometry.new(nil, 768) assert @geo = Paperclip::Geometry.new(nil, 768)
assert_equal 0, @geo.width assert_equal 0, @geo.width
assert_equal 768, @geo.height assert_equal 768, @geo.height
end end
it "be generated from a WxH-formatted string" do it "is generated from a WxH-formatted string" do
assert @geo = Paperclip::Geometry.parse("800x600") assert @geo = Paperclip::Geometry.parse("800x600")
assert_equal 800, @geo.width assert_equal 800, @geo.width
assert_equal 600, @geo.height assert_equal 600, @geo.height
end end
it "be generated from a xH-formatted string" do it "is generated from a xH-formatted string" do
assert @geo = Paperclip::Geometry.parse("x600") assert @geo = Paperclip::Geometry.parse("x600")
assert_equal 0, @geo.width assert_equal 0, @geo.width
assert_equal 600, @geo.height assert_equal 600, @geo.height
end end
it "be generated from a Wx-formatted string" do it "is generated from a Wx-formatted string" do
assert @geo = Paperclip::Geometry.parse("800x") assert @geo = Paperclip::Geometry.parse("800x")
assert_equal 800, @geo.width assert_equal 800, @geo.width
assert_equal 0, @geo.height assert_equal 0, @geo.height
end end
it "be generated from a W-formatted string" do it "is generated from a W-formatted string" do
assert @geo = Paperclip::Geometry.parse("800") assert @geo = Paperclip::Geometry.parse("800")
assert_equal 800, @geo.width assert_equal 800, @geo.width
assert_equal 0, @geo.height assert_equal 0, @geo.height
end end
it "ensure the modifier is nil if not present" do it "ensures the modifier is nil if not present" do
assert @geo = Paperclip::Geometry.parse("123x456") assert @geo = Paperclip::Geometry.parse("123x456")
assert_nil @geo.modifier assert_nil @geo.modifier
end end
it "recognize an EXIF orientation and not rotate with auto_orient if not necessary" do it "recognizes an EXIF orientation and not rotate with auto_orient if not necessary" do
geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 1) geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 1)
assert geo assert geo
assert_equal 1024, geo.width assert_equal 1024, geo.width
...@@ -61,7 +61,7 @@ describe Paperclip::Geometry do ...@@ -61,7 +61,7 @@ describe Paperclip::Geometry do
assert_equal 768, geo.height assert_equal 768, geo.height
end end
it "recognize an EXIF orientation and rotate with auto_orient if necessary" do it "recognizes an EXIF orientation and rotate with auto_orient if necessary" do
geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 6) geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 6)
assert geo assert geo
assert_equal 1024, geo.width assert_equal 1024, geo.width
...@@ -73,7 +73,7 @@ describe Paperclip::Geometry do ...@@ -73,7 +73,7 @@ describe Paperclip::Geometry do
assert_equal 1024, geo.height assert_equal 1024, geo.height
end end
it "treat x and X the same in geometries" do it "treats x and X the same in geometries" do
@lower = Paperclip::Geometry.parse("123x456") @lower = Paperclip::Geometry.parse("123x456")
@upper = Paperclip::Geometry.parse("123X456") @upper = Paperclip::Geometry.parse("123X456")
assert_equal 123, @lower.width assert_equal 123, @lower.width
...@@ -83,46 +83,46 @@ describe Paperclip::Geometry do ...@@ -83,46 +83,46 @@ describe Paperclip::Geometry do
end end
['>', '<', '#', '@', '%', '^', '!', nil].each do |mod| ['>', '<', '#', '@', '%', '^', '!', nil].each do |mod|
it "ensure the modifier #{description} is preserved" do it "ensures the modifier #{description} is preserved" do
assert @geo = Paperclip::Geometry.parse("123x456#{mod}") assert @geo = Paperclip::Geometry.parse("123x456#{mod}")
assert_equal mod, @geo.modifier assert_equal mod, @geo.modifier
assert_equal "123x456#{mod}", @geo.to_s assert_equal "123x456#{mod}", @geo.to_s
end end
it "ensure the modifier #{description} is preserved with no height" do it "ensures the modifier #{description} is preserved with no height" do
assert @geo = Paperclip::Geometry.parse("123x#{mod}") assert @geo = Paperclip::Geometry.parse("123x#{mod}")
assert_equal mod, @geo.modifier assert_equal mod, @geo.modifier
assert_equal "123#{mod}", @geo.to_s assert_equal "123#{mod}", @geo.to_s
end end
end end
it "make sure the modifier gets passed during transformation_to" do it "makes sure the modifier gets passed during transformation_to" do
assert @src = Paperclip::Geometry.parse("123x456") assert @src = Paperclip::Geometry.parse("123x456")
assert @dst = Paperclip::Geometry.parse("123x456>") assert @dst = Paperclip::Geometry.parse("123x456>")
assert_equal ["123x456>", nil], @src.transformation_to(@dst) assert_equal ["123x456>", nil], @src.transformation_to(@dst)
end end
it "generate correct ImageMagick formatting string for W-formatted string" do it "generates correct ImageMagick formatting string for W-formatted string" do
assert @geo = Paperclip::Geometry.parse("800") assert @geo = Paperclip::Geometry.parse("800")
assert_equal "800", @geo.to_s assert_equal "800", @geo.to_s
end end
it "generate correct ImageMagick formatting string for Wx-formatted string" do it "generates correct ImageMagick formatting string for Wx-formatted string" do
assert @geo = Paperclip::Geometry.parse("800x") assert @geo = Paperclip::Geometry.parse("800x")
assert_equal "800", @geo.to_s assert_equal "800", @geo.to_s
end end
it "generate correct ImageMagick formatting string for xH-formatted string" do it "generates correct ImageMagick formatting string for xH-formatted string" do
assert @geo = Paperclip::Geometry.parse("x600") assert @geo = Paperclip::Geometry.parse("x600")
assert_equal "x600", @geo.to_s assert_equal "x600", @geo.to_s
end end
it "generate correct ImageMagick formatting string for WxH-formatted string" do it "generates correct ImageMagick formatting string for WxH-formatted string" do
assert @geo = Paperclip::Geometry.parse("800x600") assert @geo = Paperclip::Geometry.parse("800x600")
assert_equal "800x600", @geo.to_s assert_equal "800x600", @geo.to_s
end end
it "be generated from a file" do it "is generated from a file" do
file = fixture_file("5k.png") file = fixture_file("5k.png")
file = File.new(file, 'rb') file = File.new(file, 'rb')
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) } assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
...@@ -130,14 +130,14 @@ describe Paperclip::Geometry do ...@@ -130,14 +130,14 @@ describe Paperclip::Geometry do
assert_equal 434, @geo.width assert_equal 434, @geo.width
end end
it "be generated from a file path" do it "is generated from a file path" do
file = fixture_file("5k.png") file = fixture_file("5k.png")
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) } assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
assert_equal 66, @geo.height assert_equal 66, @geo.height
assert_equal 434, @geo.width assert_equal 434, @geo.width
end end
it 'calculate an EXIF-rotated image dimensions from a path' do it 'calculates an EXIF-rotated image dimensions from a path' do
file = fixture_file("rotated.jpg") file = fixture_file("rotated.jpg")
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) } assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
@geo.auto_orient @geo.auto_orient
...@@ -145,28 +145,28 @@ describe Paperclip::Geometry do ...@@ -145,28 +145,28 @@ describe Paperclip::Geometry do
assert_equal 200, @geo.width assert_equal 200, @geo.width
end end
it "not generate from a bad file" do it "does not generate from a bad file" do
file = "/home/This File Does Not Exist.omg" file = "/home/This File Does Not Exist.omg"
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError) expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
end end
it "not generate from a blank filename" do it "does not generate from a blank filename" do
file = "" file = ""
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError) expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
end end
it "not generate from a nil file" do it "does not generate from a nil file" do
file = nil file = nil
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError) expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
end end
it "not generate from a file with no path" do it "does not generate from a file with no path" do
file = mock("file", path: "") file = mock("file", path: "")
file.stubs(:respond_to?).with(:path).returns(true) file.stubs(:respond_to?).with(:path).returns(true)
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError) expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
end end
it "let us know when a command isn't found versus a processing error" do it "lets us know when a command isn't found versus a processing error" do
old_path = ENV['PATH'] old_path = ENV['PATH']
begin begin
ENV['PATH'] = '' ENV['PATH'] = ''
...@@ -187,27 +187,27 @@ describe Paperclip::Geometry do ...@@ -187,27 +187,27 @@ describe Paperclip::Geometry do
@geo = Paperclip::Geometry.new(args[1], args[2]) @geo = Paperclip::Geometry.new(args[1], args[2])
end end
it "#{args[3] ? "" : "not"} be vertical" do it "is #{args[3]s ? "" : "not"} vertical" do
assert_equal args[3], @geo.vertical? assert_equal args[3], @geo.vertical?
end end
it "#{args[4] ? "" : "not"} be horizontal" do it "is #{args[4] ? "" : "not"} horizontal" do
assert_equal args[4], @geo.horizontal? assert_equal args[4], @geo.horizontal?
end end
it "#{args[5] ? "" : "not"} be square" do it "is #{args[5] ? "" : "not"} square" do
assert_equal args[5], @geo.square? assert_equal args[5], @geo.square?
end end
it "report that #{args[6]} is the larger dimension" do it "reports that #{args[6]} is the larger dimension" do
assert_equal args[6], @geo.larger assert_equal args[6], @geo.larger
end end
it "report that #{args[7]} is the smaller dimension" do it "reports that #{args[7]} is the smaller dimension" do
assert_equal args[7], @geo.smaller assert_equal args[7], @geo.smaller
end end
it "have an aspect ratio of #{args[8]}" do it "has an aspect ratio of #{args[8]}" do
expect(@geo.aspect).to be_within(0.0001).of(args[8]) expect(@geo.aspect).to be_within(0.0001).of(args[8])
end end
end end
...@@ -223,11 +223,11 @@ describe Paperclip::Geometry do ...@@ -223,11 +223,11 @@ describe Paperclip::Geometry do
@scale, @crop = @geo.transformation_to @dst, true @scale, @crop = @geo.transformation_to @dst, true
end end
it "be able to return the correct scaling transformation geometry #{args[2]}" do it "is able to return the correct scaling transformation geometry #{args[2]}" do
assert_equal args[2], @scale assert_equal args[2], @scale
end end
it "be able to return the correct crop transformation geometry #{args[3]}" do it "is able to return the correct crop transformation geometry #{args[3]}" do
assert_equal args[3], @crop assert_equal args[3], @crop
end end
end end
...@@ -242,10 +242,10 @@ describe Paperclip::Geometry do ...@@ -242,10 +242,10 @@ describe Paperclip::Geometry do
@source = Paperclip::Geometry.parse original_size @source = Paperclip::Geometry.parse original_size
@new_geometry = @source.resize_to size @new_geometry = @source.resize_to size
end end
it "have #{dimensions.first} width" do it "has #{dimensions.first} width" do
assert_equal dimensions.first, @new_geometry.width assert_equal dimensions.first, @new_geometry.width
end end
it "have #{dimensions.last} height" do it "has #{dimensions.last} height" do
assert_equal dimensions.last, @new_geometry.height assert_equal dimensions.last, @new_geometry.height
end end
end end
......
...@@ -2,43 +2,43 @@ require 'spec_helper' ...@@ -2,43 +2,43 @@ require 'spec_helper'
describe Paperclip::HasAttachedFile do describe Paperclip::HasAttachedFile do
context '#define_on' do context '#define_on' do
it 'define a setter on the class object' do it 'defines a setter on the class object' do
assert_adding_attachment('avatar').defines_method('avatar=') assert_adding_attachment('avatar').defines_method('avatar=')
end end
it 'define a getter on the class object' do it 'defines a getter on the class object' do
assert_adding_attachment('avatar').defines_method('avatar') assert_adding_attachment('avatar').defines_method('avatar')
end end
it 'define a query on the class object' do it 'defines a query on the class object' do
assert_adding_attachment('avatar').defines_method('avatar?') assert_adding_attachment('avatar').defines_method('avatar?')
end end
it 'define a method on the class to get all of its attachments' do it 'defines a method on the class to get all of its attachments' do
assert_adding_attachment('avatar').defines_class_method('attachment_definitions') assert_adding_attachment('avatar').defines_class_method('attachment_definitions')
end end
it 'flush errors as part of validations' do it 'flushes errors as part of validations' do
assert_adding_attachment('avatar').defines_validation assert_adding_attachment('avatar').defines_validation
end end
it 'register the attachment with Paperclip::AttachmentRegistry' do it 'registers the attachment with Paperclip::AttachmentRegistry' do
assert_adding_attachment('avatar').registers_attachment assert_adding_attachment('avatar').registers_attachment
end end
it 'define an after_save callback' do it 'defines an after_save callback' do
assert_adding_attachment('avatar').defines_callback('after_save') assert_adding_attachment('avatar').defines_callback('after_save')
end end
it 'define a before_destroy callback' do it 'defines a before_destroy callback' do
assert_adding_attachment('avatar').defines_callback('before_destroy') assert_adding_attachment('avatar').defines_callback('before_destroy')
end end
it 'define an after_commit callback' do it 'defines an after_commit callback' do
assert_adding_attachment('avatar').defines_callback('after_commit') assert_adding_attachment('avatar').defines_callback('after_commit')
end end
it 'define the Paperclip-specific callbacks' do it 'defines the Paperclip-specific callbacks' do
assert_adding_attachment('avatar').defines_callback('define_paperclip_callbacks') assert_adding_attachment('avatar').defines_callback('define_paperclip_callbacks')
end end
end end
......
...@@ -14,7 +14,7 @@ describe 'Paperclip' do ...@@ -14,7 +14,7 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "not exceed the open file limit" do it "does not exceed the open file limit" do
assert_nothing_raised do assert_nothing_raised do
Dummy.all.each { |dummy| dummy.avatar } Dummy.all.each { |dummy| dummy.avatar }
end end
...@@ -32,14 +32,14 @@ describe 'Paperclip' do ...@@ -32,14 +32,14 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "create its thumbnails properly" do it "creates its thumbnails properly" do
assert_match(/\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`) assert_match(/\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`)
end end
context 'reprocessing with unreadable original' do context 'reprocessing with unreadable original' do
before { File.chmod(0000, @dummy.avatar.path) } before { File.chmod(0000, @dummy.avatar.path) }
it "not raise an error" do it "does not raise an error" do
assert_nothing_raised do assert_nothing_raised do
silence_stream(STDERR) do silence_stream(STDERR) do
@dummy.avatar.reprocess! @dummy.avatar.reprocess!
...@@ -47,7 +47,7 @@ describe 'Paperclip' do ...@@ -47,7 +47,7 @@ describe 'Paperclip' do
end end
end end
it "return false" do it "returns false" do
silence_stream(STDERR) do silence_stream(STDERR) do
assert !@dummy.avatar.reprocess! assert !@dummy.avatar.reprocess!
end end
...@@ -67,12 +67,12 @@ describe 'Paperclip' do ...@@ -67,12 +67,12 @@ describe 'Paperclip' do
@d2.save @d2.save
end end
it "create its thumbnails properly" do it "creates its thumbnails properly" do
assert_match(/\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"`) assert_match(/\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"`)
assert_match(/\b50x50\b/, `identify "#{@dummy.avatar.path(:dynamic)}"`) assert_match(/\b50x50\b/, `identify "#{@dummy.avatar.path(:dynamic)}"`)
end end
it "change the timestamp" do it "changes the timestamp" do
assert_not_equal @original_timestamp, @d2.avatar_updated_at assert_not_equal @original_timestamp, @d2.avatar_updated_at
end end
end end
...@@ -90,14 +90,14 @@ describe 'Paperclip' do ...@@ -90,14 +90,14 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "not create the thumbnails upon saving when post-processing is disabled" do it "does not create the thumbnails upon saving when post-processing is disabled" do
@dummy.avatar.post_processing = false @dummy.avatar.post_processing = false
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save assert @dummy.save
assert_file_not_exists @thumb_path assert_file_not_exists @thumb_path
end end
it "create the thumbnails upon saving when post_processing is enabled" do it "creates the thumbnails upon saving when post_processing is enabled" do
@dummy.avatar.post_processing = true @dummy.avatar.post_processing = true
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save assert @dummy.save
...@@ -123,7 +123,7 @@ describe 'Paperclip' do ...@@ -123,7 +123,7 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "allow us to create all thumbnails in one go" do it "allows us to create all thumbnails in one go" do
assert_file_not_exists(@thumb_small_path) assert_file_not_exists(@thumb_small_path)
assert_file_not_exists(@thumb_large_path) assert_file_not_exists(@thumb_large_path)
...@@ -133,7 +133,7 @@ describe 'Paperclip' do ...@@ -133,7 +133,7 @@ describe 'Paperclip' do
assert_file_exists(@thumb_large_path) assert_file_exists(@thumb_large_path)
end end
it "allow us to selectively create each thumbnail" do it "allows us to selectively create each thumbnail" do
assert_file_not_exists(@thumb_small_path) assert_file_not_exists(@thumb_small_path)
assert_file_not_exists(@thumb_large_path) assert_file_not_exists(@thumb_large_path)
...@@ -154,7 +154,7 @@ describe 'Paperclip' do ...@@ -154,7 +154,7 @@ describe 'Paperclip' do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "report the file size of the processed file and not the original" do it "reports the file size of the processed file and not the original" do
assert_not_equal File.size(@file.path), @dummy.avatar.size assert_not_equal File.size(@file.path), @dummy.avatar.size
end end
...@@ -179,7 +179,7 @@ describe 'Paperclip' do ...@@ -179,7 +179,7 @@ describe 'Paperclip' do
@saved_path = @dummy.avatar.path(:large) @saved_path = @dummy.avatar.path(:large)
end end
it "have a large file in the right place" do it "has a large file in the right place" do
assert_file_exists(@dummy.avatar.path(:large)) assert_file_exists(@dummy.avatar.path(:large))
end end
...@@ -189,18 +189,18 @@ describe 'Paperclip' do ...@@ -189,18 +189,18 @@ describe 'Paperclip' do
@dummy.save @dummy.save
end end
it "not have a large file in the right place anymore" do it "does not have a large file in the right place anymore" do
assert_file_not_exists(@saved_path) assert_file_not_exists(@saved_path)
end end
it "not have its next two parent directories" do it "does not have its next two parent directories" do
assert_file_not_exists(File.dirname(@saved_path)) assert_file_not_exists(File.dirname(@saved_path))
assert_file_not_exists(File.dirname(File.dirname(@saved_path))) assert_file_not_exists(File.dirname(File.dirname(@saved_path)))
end end
end end
context 'and deleted where the delete fails' do context 'and deleted where the delete fails' do
it "not die if an unexpected SystemCallError happens" do it "does not die if an unexpected SystemCallError happens" do
FileUtils.stubs(:rmdir).raises(Errno::EPIPE) FileUtils.stubs(:rmdir).raises(Errno::EPIPE)
assert_nothing_raised do assert_nothing_raised do
@dummy.avatar.clear @dummy.avatar.clear
...@@ -225,7 +225,7 @@ describe 'Paperclip' do ...@@ -225,7 +225,7 @@ describe 'Paperclip' do
@file.close @file.close
end end
it "respect the current umask" do it "respects the current umask" do
@dummy.avatar = @file @dummy.avatar = @file
@dummy.save @dummy.save
assert_equal 0666&~umask, 0666&File.stat(@dummy.avatar.path).mode assert_equal 0666&~umask, 0666&File.stat(@dummy.avatar.path).mode
...@@ -245,7 +245,7 @@ describe 'Paperclip' do ...@@ -245,7 +245,7 @@ describe 'Paperclip' do
@file.close @file.close
end end
it "respect the current perms" do it "respects the current perms" do
@dummy.avatar = @file @dummy.avatar = @file
@dummy.save @dummy.save
assert_equal perms, File.stat(@dummy.avatar.path).mode & 0777 assert_equal perms, File.stat(@dummy.avatar.path).mode & 0777
...@@ -253,7 +253,7 @@ describe 'Paperclip' do ...@@ -253,7 +253,7 @@ describe 'Paperclip' do
end end
end end
it "skip chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)" do it "skips chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)" do
FileUtils.expects(:chmod).never FileUtils.expects(:chmod).never
rebuild_model override_file_permissions: false rebuild_model override_file_permissions: false
...@@ -281,7 +281,7 @@ describe 'Paperclip' do ...@@ -281,7 +281,7 @@ describe 'Paperclip' do
after { [@file, @bad_file].each(&:close) } after { [@file, @bad_file].each(&:close) }
it "write and delete its files" do it "writes and delete its files" do
[["434x66", :original], [["434x66", :original],
["300x46", :large], ["300x46", :large],
["100x15", :medium], ["100x15", :medium],
...@@ -319,7 +319,7 @@ describe 'Paperclip' do ...@@ -319,7 +319,7 @@ describe 'Paperclip' do
assert_nil @d2.avatar_file_name assert_nil @d2.avatar_file_name
end end
it "work exactly the same when new as when reloaded" do it "works exactly the same when new as when reloaded" do
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
assert_equal @dummy.avatar_file_name, @d2.avatar_file_name assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
...@@ -337,18 +337,18 @@ describe 'Paperclip' do ...@@ -337,18 +337,18 @@ describe 'Paperclip' do
end end
end end
it "not abide things that don't have adapters" do it "does not abide things that don't have adapters" do
assert_raises(Paperclip::AdapterRegistry::NoHandlerError) do assert_raises(Paperclip::AdapterRegistry::NoHandlerError) do
@dummy.avatar = "not a file" @dummy.avatar = "not a file"
end end
end end
it "not be ok with bad files" do it "is not ok with bad files" do
@dummy.avatar = @bad_file @dummy.avatar = @bad_file
assert ! @dummy.valid? assert ! @dummy.valid?
end end
it "know the difference between good files, bad files, and not files when validating" do it "knows the difference between good files, bad files, and not files when validating" do
Dummy.validates_attachment_presence :avatar Dummy.validates_attachment_presence :avatar
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
@d2.avatar = @file @d2.avatar = @file
...@@ -357,7 +357,7 @@ describe 'Paperclip' do ...@@ -357,7 +357,7 @@ describe 'Paperclip' do
assert ! @d2.valid? assert ! @d2.valid?
end end
it "be able to reload without saving and not have the file disappear" do it "is able to reload without saving and not have the file disappear" do
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save, @dummy.errors.full_messages.inspect assert @dummy.save, @dummy.errors.full_messages.inspect
@dummy.avatar.clear @dummy.avatar.clear
...@@ -376,7 +376,7 @@ describe 'Paperclip' do ...@@ -376,7 +376,7 @@ describe 'Paperclip' do
after { @file2.close } after { @file2.close }
it "work when assigned a file" do it "works when assigned a file" do
assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`, assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
`identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"` `identify -format "%wx%h" "#{@dummy2.avatar.path(:original)}"`
...@@ -403,7 +403,7 @@ describe 'Paperclip' do ...@@ -403,7 +403,7 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "should not error when saving" do it "does not error when saving" do
@dummy.save! @dummy.save!
end end
end end
...@@ -425,7 +425,7 @@ describe 'Paperclip' do ...@@ -425,7 +425,7 @@ describe 'Paperclip' do
@file.close @file.close
end end
it "be accessible" do it "is accessible" do
assert_file_exists(@dummy.avatar.path(:original)) assert_file_exists(@dummy.avatar.path(:original))
assert_file_exists(@dummy.avatar.path(:thumb)) assert_file_exists(@dummy.avatar.path(:thumb))
end end
...@@ -439,7 +439,7 @@ describe 'Paperclip' do ...@@ -439,7 +439,7 @@ describe 'Paperclip' do
@dummy.reload @dummy.reload
end end
it "make all the styles accessible" do it "makes all the styles accessible" do
assert_file_exists(@dummy.avatar.path(:original)) assert_file_exists(@dummy.avatar.path(:original))
assert_file_exists(@dummy.avatar.path(:thumb)) assert_file_exists(@dummy.avatar.path(:thumb))
assert_file_exists(@dummy.avatar.path(:mini)) assert_file_exists(@dummy.avatar.path(:mini))
...@@ -513,16 +513,16 @@ describe 'Paperclip' do ...@@ -513,16 +513,16 @@ describe 'Paperclip' do
@d2.save @d2.save
end end
it "have the same name as the old file" do it "has the same name as the old file" do
assert_equal @d2.avatar.original_filename, @dummy.avatar.original_filename assert_equal @d2.avatar.original_filename, @dummy.avatar.original_filename
end end
end end
it "have the same contents as the original" do it "has the same contents as the original" do
assert_equal @file.read, @files_on_s3[:original].read assert_equal @file.read, @files_on_s3[:original].read
end end
it "write and delete its files" do it "writes and delete its files" do
[["434x66", :original], [["434x66", :original],
["300x46", :large], ["300x46", :large],
["100x15", :medium], ["100x15", :medium],
...@@ -554,7 +554,7 @@ describe 'Paperclip' do ...@@ -554,7 +554,7 @@ describe 'Paperclip' do
assert_nil @d2.avatar_file_name assert_nil @d2.avatar_file_name
end end
it "work exactly the same when new as when reloaded" do it "works exactly the same when new as when reloaded" do
@d2 = Dummy.find(@dummy.id) @d2 = Dummy.find(@dummy.id)
assert_equal @dummy.avatar_file_name, @d2.avatar_file_name assert_equal @dummy.avatar_file_name, @d2.avatar_file_name
...@@ -578,7 +578,7 @@ describe 'Paperclip' do ...@@ -578,7 +578,7 @@ describe 'Paperclip' do
end end
end end
it "know the difference between good files, bad files, and nil" do it "knows the difference between good files, bad files, and nil" do
@dummy.avatar = @bad_file @dummy.avatar = @bad_file
assert ! @dummy.valid? assert ! @dummy.valid?
@dummy.avatar = nil @dummy.avatar = nil
...@@ -594,7 +594,7 @@ describe 'Paperclip' do ...@@ -594,7 +594,7 @@ describe 'Paperclip' do
assert ! @d2.valid? assert ! @d2.valid?
end end
it "be able to reload without saving and not have the file disappear" do it "is able to reload without saving and not have the file disappear" do
@dummy.avatar = @file @dummy.avatar = @file
assert @dummy.save assert @dummy.save
@dummy.avatar = nil @dummy.avatar = nil
...@@ -603,17 +603,17 @@ describe 'Paperclip' do ...@@ -603,17 +603,17 @@ describe 'Paperclip' do
assert_equal "5k.png", @dummy.avatar_file_name assert_equal "5k.png", @dummy.avatar_file_name
end end
it "have the right content type" do it "has the right content type" do
headers = s3_headers_for(@dummy.avatar, :original) headers = s3_headers_for(@dummy.avatar, :original)
assert_equal 'image/png', headers['content-type'] assert_equal 'image/png', headers['content-type']
end end
it "have the right style-specific headers" do it "has the right style-specific headers" do
headers = s3_headers_for(@dummy.avatar, :custom) headers = s3_headers_for(@dummy.avatar, :custom)
assert_equal 'max-age=31557600', headers['cache-control'] assert_equal 'max-age=31557600', headers['cache-control']
end end
it "have the right style-specific metadata" do it "has the right style-specific metadata" do
headers = s3_headers_for(@dummy.avatar, :custom) headers = s3_headers_for(@dummy.avatar, :custom)
assert_equal 'bar', headers['x-amz-meta-foo'] assert_equal 'bar', headers['x-amz-meta-foo']
end end
...@@ -624,7 +624,7 @@ describe 'Paperclip' do ...@@ -624,7 +624,7 @@ describe 'Paperclip' do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "not raise any error" do it "does not raise any error" do
@dummy.save! @dummy.save!
end end
end end
...@@ -639,7 +639,7 @@ describe 'Paperclip' do ...@@ -639,7 +639,7 @@ describe 'Paperclip' do
after { @file.close } after { @file.close }
it "succeed when original attachment is a file" do it "succeeds when original attachment is a file" do
original = Dummy.new original = Dummy.new
original.avatar = @file original.avatar = @file
assert original.save assert original.save
...@@ -651,7 +651,7 @@ describe 'Paperclip' do ...@@ -651,7 +651,7 @@ describe 'Paperclip' do
assert copy.avatar.present? assert copy.avatar.present?
end end
it "succeed when original attachment is empty" do it "succeeds when original attachment is empty" do
original = Dummy.create! original = Dummy.create!
copy = Dummy.new copy = Dummy.new
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::Interpolations do describe Paperclip::Interpolations do
it "return all methods but the infrastructure when sent #all" do it "returns all methods but the infrastructure when sent #all" do
methods = Paperclip::Interpolations.all methods = Paperclip::Interpolations.all
assert ! methods.include?(:[]) assert ! methods.include?(:[])
assert ! methods.include?(:[]=) assert ! methods.include?(:[]=)
...@@ -11,39 +11,39 @@ describe Paperclip::Interpolations do ...@@ -11,39 +11,39 @@ describe Paperclip::Interpolations do
end end
end end
it "return the Rails.root" do it "returns the Rails.root" do
assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style) assert_equal Rails.root, Paperclip::Interpolations.rails_root(:attachment, :style)
end end
it "return the Rails.env" do it "returns the Rails.env" do
assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style) assert_equal Rails.env, Paperclip::Interpolations.rails_env(:attachment, :style)
end end
it "return the class of the Interpolations module when called with no params" do it "returns the class of the Interpolations module when called with no params" do
assert_equal Module, Paperclip::Interpolations.class assert_equal Module, Paperclip::Interpolations.class
end end
it "return the class of the instance" do it "returns the class of the instance" do
attachment = mock attachment = mock
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
attachment.expects(:class).returns("Thing") attachment.expects(:class).returns("Thing")
assert_equal "things", Paperclip::Interpolations.class(attachment, :style) assert_equal "things", Paperclip::Interpolations.class(attachment, :style)
end end
it "return the basename of the file" do it "returns the basename of the file" do
attachment = mock attachment = mock
attachment.expects(:original_filename).returns("one.jpg").times(2) attachment.expects(:original_filename).returns("one.jpg").times(2)
assert_equal "one", Paperclip::Interpolations.basename(attachment, :style) assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
end end
it "return the extension of the file" do it "returns the extension of the file" do
attachment = mock attachment = mock
attachment.expects(:original_filename).returns("one.jpg") attachment.expects(:original_filename).returns("one.jpg")
attachment.expects(:styles).returns({}) attachment.expects(:styles).returns({})
assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style) assert_equal "jpg", Paperclip::Interpolations.extension(attachment, :style)
end end
it "return the extension of the file as the format if defined in the style" do it "returns the extension of the file as the format if defined in the style" do
attachment = mock attachment = mock
attachment.expects(:original_filename).never attachment.expects(:original_filename).never
attachment.expects(:styles).twice.returns({style: {format: "png"}}) attachment.expects(:styles).twice.returns({style: {format: "png"}})
...@@ -53,7 +53,7 @@ describe Paperclip::Interpolations do ...@@ -53,7 +53,7 @@ describe Paperclip::Interpolations do
end end
end end
it "return the extension of the file based on the content type" do it "returns the extension of the file based on the content type" do
attachment = mock attachment = mock
attachment.expects(:content_type).returns('image/jpeg') attachment.expects(:content_type).returns('image/jpeg')
attachment.expects(:styles).returns({}) attachment.expects(:styles).returns({})
...@@ -62,7 +62,7 @@ describe Paperclip::Interpolations do ...@@ -62,7 +62,7 @@ describe Paperclip::Interpolations do
assert_equal "jpeg", interpolations.content_type_extension(attachment, :style) assert_equal "jpeg", interpolations.content_type_extension(attachment, :style)
end end
it "return the original extension of the file if it matches a content type extension" do it "returns the original extension of the file if it matches a content type extension" do
attachment = mock attachment = mock
attachment.expects(:content_type).returns('image/jpeg') attachment.expects(:content_type).returns('image/jpeg')
attachment.expects(:styles).returns({}) attachment.expects(:styles).returns({})
...@@ -71,7 +71,7 @@ describe Paperclip::Interpolations do ...@@ -71,7 +71,7 @@ describe Paperclip::Interpolations do
assert_equal "jpe", interpolations.content_type_extension(attachment, :style) assert_equal "jpe", interpolations.content_type_extension(attachment, :style)
end end
it "return the latter half of the content type of the extension if no match found" do it "returns the latter half of the content type of the extension if no match found" do
attachment = mock attachment = mock
attachment.expects(:content_type).at_least_once().returns('not/found') attachment.expects(:content_type).at_least_once().returns('not/found')
attachment.expects(:styles).returns({}) attachment.expects(:styles).returns({})
...@@ -80,7 +80,7 @@ describe Paperclip::Interpolations do ...@@ -80,7 +80,7 @@ describe Paperclip::Interpolations do
assert_equal "found", interpolations.content_type_extension(attachment, :style) assert_equal "found", interpolations.content_type_extension(attachment, :style)
end end
it "return the format if defined in the style, ignoring the content type" do it "returns the format if defined in the style, ignoring the content type" do
attachment = mock attachment = mock
attachment.expects(:content_type).returns('image/jpeg') attachment.expects(:content_type).returns('image/jpeg')
attachment.expects(:styles).returns({style: {format: "png"}}) attachment.expects(:styles).returns({style: {format: "png"}})
...@@ -89,78 +89,78 @@ describe Paperclip::Interpolations do ...@@ -89,78 +89,78 @@ describe Paperclip::Interpolations do
assert_equal "png", interpolations.content_type_extension(attachment, :style) assert_equal "png", interpolations.content_type_extension(attachment, :style)
end end
it "be able to handle numeric style names" do it "is able to handle numeric style names" do
attachment = mock( attachment = mock(
styles: {:"4" => {format: :expected_extension}} styles: {:"4" => {format: :expected_extension}}
) )
assert_equal :expected_extension, Paperclip::Interpolations.extension(attachment, 4) assert_equal :expected_extension, Paperclip::Interpolations.extension(attachment, 4)
end end
it "return the #to_param of the attachment" do it "returns the #to_param of the attachment" do
attachment = mock attachment = mock
attachment.expects(:to_param).returns("23-awesome") attachment.expects(:to_param).returns("23-awesome")
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_equal "23-awesome", Paperclip::Interpolations.param(attachment, :style) assert_equal "23-awesome", Paperclip::Interpolations.param(attachment, :style)
end end
it "return the id of the attachment" do it "returns the id of the attachment" do
attachment = mock attachment = mock
attachment.expects(:id).returns(23) attachment.expects(:id).returns(23)
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_equal 23, Paperclip::Interpolations.id(attachment, :style) assert_equal 23, Paperclip::Interpolations.id(attachment, :style)
end end
it "return nil for attachments to new records" do it "returns nil for attachments to new records" do
attachment = mock attachment = mock
attachment.expects(:id).returns(nil) attachment.expects(:id).returns(nil)
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_nil Paperclip::Interpolations.id(attachment, :style) assert_nil Paperclip::Interpolations.id(attachment, :style)
end end
it "return the partitioned id of the attachment when the id is an integer" do it "returns the partitioned id of the attachment when the id is an integer" do
attachment = mock attachment = mock
attachment.expects(:id).returns(23) attachment.expects(:id).returns(23)
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style) assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
end end
it "return the partitioned id of the attachment when the id is a string" do it "returns the partitioned id of the attachment when the id is a string" do
attachment = mock attachment = mock
attachment.expects(:id).returns("32fnj23oio2f") attachment.expects(:id).returns("32fnj23oio2f")
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_equal "32f/nj2/3oi", Paperclip::Interpolations.id_partition(attachment, :style) assert_equal "32f/nj2/3oi", Paperclip::Interpolations.id_partition(attachment, :style)
end end
it "return nil for the partitioned id of an attachment to a new record (when the id is nil)" do it "returns nil for the partitioned id of an attachment to a new record (when the id is nil)" do
attachment = mock attachment = mock
attachment.expects(:id).returns(nil) attachment.expects(:id).returns(nil)
attachment.expects(:instance).returns(attachment) attachment.expects(:instance).returns(attachment)
assert_nil Paperclip::Interpolations.id_partition(attachment, :style) assert_nil Paperclip::Interpolations.id_partition(attachment, :style)
end end
it "return the name of the attachment" do it "returns the name of the attachment" do
attachment = mock attachment = mock
attachment.expects(:name).returns("file") attachment.expects(:name).returns("file")
assert_equal "files", Paperclip::Interpolations.attachment(attachment, :style) assert_equal "files", Paperclip::Interpolations.attachment(attachment, :style)
end end
it "return the style" do it "returns the style" do
assert_equal :style, Paperclip::Interpolations.style(:attachment, :style) assert_equal :style, Paperclip::Interpolations.style(:attachment, :style)
end end
it "return the default style" do it "returns the default style" do
attachment = mock attachment = mock
attachment.expects(:default_style).returns(:default_style) attachment.expects(:default_style).returns(:default_style)
assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil) assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil)
end end
it "reinterpolate :url" do it "reinterpolates :url" do
attachment = mock attachment = mock
attachment.expects(:url).with(:style, timestamp: false, escape: false).returns("1234") attachment.expects(:url).with(:style, timestamp: false, escape: false).returns("1234")
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style) assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
end end
it "raise if infinite loop detcted reinterpolating :url" do it "raises if infinite loop detcted reinterpolating :url" do
attachment = Object.new attachment = Object.new
class << attachment class << attachment
def url(*args) def url(*args)
...@@ -170,35 +170,35 @@ describe Paperclip::Interpolations do ...@@ -170,35 +170,35 @@ describe Paperclip::Interpolations do
assert_raises(Paperclip::Errors::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) } assert_raises(Paperclip::Errors::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
end end
it "return the filename as basename.extension" do it "returns the filename as basename.extension" do
attachment = mock attachment = mock
attachment.expects(:styles).returns({}) attachment.expects(:styles).returns({})
attachment.expects(:original_filename).returns("one.jpg").times(3) attachment.expects(:original_filename).returns("one.jpg").times(3)
assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style) assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style)
end end
it "return the filename as basename.extension when format supplied" do it "returns the filename as basename.extension when format supplied" do
attachment = mock attachment = mock
attachment.expects(:styles).returns({style: {format: :png}}) attachment.expects(:styles).returns({style: {format: :png}})
attachment.expects(:original_filename).returns("one.jpg").times(2) attachment.expects(:original_filename).returns("one.jpg").times(2)
assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style) assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
end end
it "return the filename as basename when extension is blank" do it "returns the filename as basename when extension is blank" do
attachment = mock attachment = mock
attachment.stubs(:styles).returns({}) attachment.stubs(:styles).returns({})
attachment.stubs(:original_filename).returns("one") attachment.stubs(:original_filename).returns("one")
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style) assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
end end
it "return the basename when the extension contains regexp special characters" do it "returns the basename when the extension contains regexp special characters" do
attachment = mock attachment = mock
attachment.stubs(:styles).returns({}) attachment.stubs(:styles).returns({})
attachment.stubs(:original_filename).returns("one.ab)") attachment.stubs(:original_filename).returns("one.ab)")
assert_equal "one", Paperclip::Interpolations.basename(attachment, :style) assert_equal "one", Paperclip::Interpolations.basename(attachment, :style)
end end
it "return the timestamp" do it "returns the timestamp" do
now = Time.now now = Time.now
zone = 'UTC' zone = 'UTC'
attachment = mock attachment = mock
...@@ -207,28 +207,28 @@ describe Paperclip::Interpolations do ...@@ -207,28 +207,28 @@ describe Paperclip::Interpolations do
assert_equal now.in_time_zone(zone).to_s, Paperclip::Interpolations.timestamp(attachment, :style) assert_equal now.in_time_zone(zone).to_s, Paperclip::Interpolations.timestamp(attachment, :style)
end end
it "return updated_at" do it "returns updated_at" do
attachment = mock attachment = mock
seconds_since_epoch = 1234567890 seconds_since_epoch = 1234567890
attachment.expects(:updated_at).returns(seconds_since_epoch) attachment.expects(:updated_at).returns(seconds_since_epoch)
assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style) assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
end end
it "return attachment's hash when passing both arguments" do it "returns attachment's hash when passing both arguments" do
attachment = mock attachment = mock
fake_hash = "a_wicked_secure_hash" fake_hash = "a_wicked_secure_hash"
attachment.expects(:hash_key).returns(fake_hash) attachment.expects(:hash_key).returns(fake_hash)
assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style) assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
end end
it "return Object#hash when passing no argument" do it "returns Object#hash when passing no argument" do
attachment = mock attachment = mock
fake_hash = "a_wicked_secure_hash" fake_hash = "a_wicked_secure_hash"
attachment.expects(:hash_key).never.returns(fake_hash) attachment.expects(:hash_key).never.returns(fake_hash)
assert_not_equal fake_hash, Paperclip::Interpolations.hash assert_not_equal fake_hash, Paperclip::Interpolations.hash
end end
it "call all expected interpolations with the given arguments" do it "calls all expected interpolations with the given arguments" do
Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234) Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments") Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
Paperclip::Interpolations.expects(:notreal).never Paperclip::Interpolations.expects(:notreal).never
......
...@@ -16,13 +16,13 @@ describe Paperclip::AbstractAdapter do ...@@ -16,13 +16,13 @@ describe Paperclip::AbstractAdapter do
Paperclip.stubs(:run).returns("image/png\n") Paperclip.stubs(:run).returns("image/png\n")
end end
it "return the content type without newline" do it "returns the content type without newline" do
assert_equal "image/png", @adapter.content_type assert_equal "image/png", @adapter.content_type
end end
end end
context "nil?" do context "nil?" do
it "return false" do it "returns false" do
assert !TestAdapter.new.nil? assert !TestAdapter.new.nil?
end end
end end
...@@ -34,7 +34,7 @@ describe Paperclip::AbstractAdapter do ...@@ -34,7 +34,7 @@ describe Paperclip::AbstractAdapter do
end end
[:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink].each do |method| [:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink].each do |method|
it "delegate #{method} to @tempfile" do it "delegates #{method} to @tempfile" do
@adapter.tempfile.stubs(method) @adapter.tempfile.stubs(method)
@adapter.public_send(method) @adapter.public_send(method)
assert_received @adapter.tempfile, method assert_received @adapter.tempfile, method
...@@ -42,18 +42,18 @@ describe Paperclip::AbstractAdapter do ...@@ -42,18 +42,18 @@ describe Paperclip::AbstractAdapter do
end end
end end
it 'get rid of slashes and colons in filenames' do it 'gets rid of slashes and colons in filenames' do
@adapter = TestAdapter.new @adapter = TestAdapter.new
@adapter.original_filename = "awesome/file:name.png" @adapter.original_filename = "awesome/file:name.png"
assert_equal "awesome_file_name.png", @adapter.original_filename assert_equal "awesome_file_name.png", @adapter.original_filename
end end
it 'be an assignment' do it 'is an assignment' do
assert TestAdapter.new.assignment? assert TestAdapter.new.assignment?
end end
it 'not be nil' do it 'is not nil' do
assert !TestAdapter.new.nil? assert !TestAdapter.new.nil?
end end
end end
...@@ -21,32 +21,32 @@ describe Paperclip::AttachmentAdapter do ...@@ -21,32 +21,32 @@ describe Paperclip::AttachmentAdapter do
@subject.close @subject.close
end end
it "get the right filename" do it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
it "force binmode on tempfile" do it "forces binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode? assert @subject.instance_variable_get("@tempfile").binmode?
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "get the file's size" do it "gets the file's size" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert ! @subject.nil? assert ! @subject.nil?
end end
it "generate a MD5 hash of the contents" do it "generates a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.path).to_s expected = Digest::MD5.file(@file.path).to_s
assert_equal expected, @subject.fingerprint assert_equal expected, @subject.fingerprint
end end
it "read the contents of the file" do it "reads the contents of the file" do
expected = @file.read expected = @file.read
actual = @subject.read actual = @subject.read
assert expected.length > 0 assert expected.length > 0
...@@ -72,11 +72,11 @@ describe Paperclip::AttachmentAdapter do ...@@ -72,11 +72,11 @@ describe Paperclip::AttachmentAdapter do
@subject.close @subject.close
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
assert_equal 'image_restricted.gif', @subject.original_filename assert_equal 'image_restricted.gif', @subject.original_filename
end end
end end
...@@ -101,32 +101,32 @@ describe Paperclip::AttachmentAdapter do ...@@ -101,32 +101,32 @@ describe Paperclip::AttachmentAdapter do
@subject.close @subject.close
end end
it "get the original filename" do it "gets the original filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
it "force binmode on tempfile" do it "forces binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode? assert @subject.instance_variable_get("@tempfile").binmode?
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "get the thumbnail's file size" do it "gets the thumbnail's file size" do
assert_equal @thumb.size, @subject.size assert_equal @thumb.size, @subject.size
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert ! @subject.nil? assert ! @subject.nil?
end end
it "generate a MD5 hash of the contents" do it "generates a MD5 hash of the contents" do
expected = Digest::MD5.file(@thumb.path).to_s expected = Digest::MD5.file(@thumb.path).to_s
assert_equal expected, @subject.fingerprint assert_equal expected, @subject.fingerprint
end end
it "read the contents of the thumbnail" do it "reads the contents of the thumbnail" do
@thumb.rewind @thumb.rewind
expected = @thumb.read expected = @thumb.read
actual = @subject.read actual = @subject.read
......
...@@ -7,7 +7,7 @@ describe Paperclip::DataUriAdapter do ...@@ -7,7 +7,7 @@ describe Paperclip::DataUriAdapter do
end end
end end
it 'allow a missing mime-type' do it 'allows a missing mime-type' do
adapter = Paperclip.io_adapters.for("data:;base64,#{original_base64_content}") adapter = Paperclip.io_adapters.for("data:;base64,#{original_base64_content}")
assert_equal Paperclip::DataUriAdapter, adapter.class assert_equal Paperclip::DataUriAdapter, adapter.class
end end
...@@ -22,46 +22,46 @@ describe Paperclip::DataUriAdapter do ...@@ -22,46 +22,46 @@ describe Paperclip::DataUriAdapter do
assert_equal "data.png", @subject.original_filename assert_equal "data.png", @subject.original_filename
end end
it "return a content type" do it "returns a content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "return the size of the data" do it "returns the size of the data" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
end end
it "generate a correct MD5 hash of the contents" do it "generates a correct MD5 hash of the contents" do
assert_equal( assert_equal(
Digest::MD5.hexdigest(Base64.decode64(original_base64_content)), Digest::MD5.hexdigest(Base64.decode64(original_base64_content)),
@subject.fingerprint @subject.fingerprint
) )
end end
it "generate correct fingerprint after read" do it "generates correct fingerprint after read" do
fingerprint = Digest::MD5.hexdigest(@subject.read) fingerprint = Digest::MD5.hexdigest(@subject.read)
assert_equal fingerprint, @subject.fingerprint assert_equal fingerprint, @subject.fingerprint
end end
it "generate same fingerprint" do it "generates same fingerprint" do
assert_equal @subject.fingerprint, @subject.fingerprint assert_equal @subject.fingerprint, @subject.fingerprint
end end
it 'accept a content_type' do it 'accepts a content_type' do
@subject.content_type = 'image/png' @subject.content_type = 'image/png'
assert_equal 'image/png', @subject.content_type assert_equal 'image/png', @subject.content_type
end end
it 'accept an original_filename' do it 'accepts an original_filename' do
@subject.original_filename = 'image.png' @subject.original_filename = 'image.png'
assert_equal 'image.png', @subject.original_filename assert_equal 'image.png', @subject.original_filename
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
@subject.original_filename = 'image:restricted.png' @subject.original_filename = 'image:restricted.png'
assert_equal 'image_restricted.png', @subject.original_filename assert_equal 'image_restricted.png', @subject.original_filename
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
@subject.original_filename = 'image:restricted.png' @subject.original_filename = 'image:restricted.png'
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
......
...@@ -6,11 +6,11 @@ describe Paperclip::EmptyStringAdapter do ...@@ -6,11 +6,11 @@ describe Paperclip::EmptyStringAdapter do
@subject = Paperclip.io_adapters.for('') @subject = Paperclip.io_adapters.for('')
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert !@subject.nil? assert !@subject.nil?
end end
it 'return false for a call to assignment?' do it 'returns false for a call to assignment?' do
assert !@subject.assignment? assert !@subject.assignment?
end end
end end
......
...@@ -18,36 +18,36 @@ describe Paperclip::FileAdapter do ...@@ -18,36 +18,36 @@ describe Paperclip::FileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "get the right filename" do it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
it "force binmode on tempfile" do it "forces binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode? assert @subject.instance_variable_get("@tempfile").binmode?
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "return content type as a string" do it "returns content type as a string" do
expect(@subject.content_type).to be_a String expect(@subject.content_type).to be_a String
end end
it "get the file's size" do it "gets the file's size" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert ! @subject.nil? assert ! @subject.nil?
end end
it "generate a MD5 hash of the contents" do it "generates a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.path).to_s expected = Digest::MD5.file(@file.path).to_s
assert_equal expected, @subject.fingerprint assert_equal expected, @subject.fingerprint
end end
it "read the contents of the file" do it "reads the contents of the file" do
expected = @file.read expected = @file.read
assert expected.length > 0 assert expected.length > 0
assert_equal expected, @subject.read assert_equal expected, @subject.read
...@@ -60,11 +60,11 @@ describe Paperclip::FileAdapter do ...@@ -60,11 +60,11 @@ describe Paperclip::FileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "prefer officially registered mime type" do it "prefers officially registered mime type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "return content type as a string" do it "returns content type as a string" do
expect(@subject.content_type).to be_a String expect(@subject.content_type).to be_a String
end end
end end
...@@ -76,7 +76,7 @@ describe Paperclip::FileAdapter do ...@@ -76,7 +76,7 @@ describe Paperclip::FileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "return content type without newline character" do it "returns content type without newline character" do
assert_equal "application/vnd.ms-office", @subject.content_type assert_equal "application/vnd.ms-office", @subject.content_type
end end
end end
...@@ -96,11 +96,11 @@ describe Paperclip::FileAdapter do ...@@ -96,11 +96,11 @@ describe Paperclip::FileAdapter do
@subject.close @subject.close
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
assert_equal 'image_restricted.gif', @subject.original_filename assert_equal 'image_restricted.gif', @subject.original_filename
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
end end
...@@ -116,7 +116,7 @@ describe Paperclip::FileAdapter do ...@@ -116,7 +116,7 @@ describe Paperclip::FileAdapter do
@subject.close @subject.close
end end
it "provide correct mime-type" do it "provides correct mime-type" do
assert_match %r{.*/x-empty}, @subject.content_type assert_match %r{.*/x-empty}, @subject.content_type
end end
end end
......
...@@ -14,45 +14,45 @@ describe Paperclip::HttpUrlProxyAdapter do ...@@ -14,45 +14,45 @@ describe Paperclip::HttpUrlProxyAdapter do
@subject.close @subject.close
end end
it "return a file name" do it "returns a file name" do
assert_equal "thoughtbot-logo.png", @subject.original_filename assert_equal "thoughtbot-logo.png", @subject.original_filename
end end
it 'close open handle after reading' do it 'closes open handle after reading' do
assert_equal true, @open_return.closed? assert_equal true, @open_return.closed?
end end
it "return a content type" do it "returns a content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "return the size of the data" do it "returns the size of the data" do
assert_equal @open_return.size, @subject.size assert_equal @open_return.size, @subject.size
end end
it "generate an MD5 hash of the contents" do it "generates an MD5 hash of the contents" do
assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint
end end
it "generate correct fingerprint after read" do it "generates correct fingerprint after read" do
fingerprint = Digest::MD5.hexdigest(@subject.read) fingerprint = Digest::MD5.hexdigest(@subject.read)
assert_equal fingerprint, @subject.fingerprint assert_equal fingerprint, @subject.fingerprint
end end
it "generate same fingerprint" do it "generates same fingerprint" do
assert_equal @subject.fingerprint, @subject.fingerprint assert_equal @subject.fingerprint, @subject.fingerprint
end end
it "return the data contained in the StringIO" do it "returns the data contained in the StringIO" do
assert_equal "xxx", @subject.read assert_equal "xxx", @subject.read
end end
it 'accept a content_type' do it 'accepts a content_type' do
@subject.content_type = 'image/png' @subject.content_type = 'image/png'
assert_equal 'image/png', @subject.content_type assert_equal 'image/png', @subject.content_type
end end
it 'accept an original_filename' do it 'accepts an original_filename' do
@subject.original_filename = 'image.png' @subject.original_filename = 'image.png'
assert_equal 'image.png', @subject.original_filename assert_equal 'image.png', @subject.original_filename
end end
...@@ -69,7 +69,7 @@ describe Paperclip::HttpUrlProxyAdapter do ...@@ -69,7 +69,7 @@ describe Paperclip::HttpUrlProxyAdapter do
@subject.close @subject.close
end end
it "return a file name" do it "returns a file name" do
assert_equal "paperclip", @subject.original_filename assert_equal "paperclip", @subject.original_filename
end end
end end
...@@ -89,11 +89,11 @@ describe Paperclip::HttpUrlProxyAdapter do ...@@ -89,11 +89,11 @@ describe Paperclip::HttpUrlProxyAdapter do
end end
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
assert_equal "paper_clip.jpg", @subject.original_filename assert_equal "paper_clip.jpg", @subject.original_filename
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::IdentityAdapter do describe Paperclip::IdentityAdapter do
it "respond to #new by returning the argument" do it "responds to #new by returning the argument" do
adapter = Paperclip::IdentityAdapter.new adapter = Paperclip::IdentityAdapter.new
assert_equal :target, adapter.new(:target) assert_equal :target, adapter.new(:target)
end end
......
...@@ -6,19 +6,19 @@ describe Paperclip::NilAdapter do ...@@ -6,19 +6,19 @@ describe Paperclip::NilAdapter do
@subject = Paperclip.io_adapters.for(nil) @subject = Paperclip.io_adapters.for(nil)
end end
it "get the right filename" do it "gets the right filename" do
assert_equal "", @subject.original_filename assert_equal "", @subject.original_filename
end end
it "get the content type" do it "gets the content type" do
assert_equal "", @subject.content_type assert_equal "", @subject.content_type
end end
it "get the file's size" do it "gets the file's size" do
assert_equal 0, @subject.size assert_equal 0, @subject.size
end end
it "return true for a call to nil?" do it "returns true for a call to nil?" do
assert @subject.nil? assert @subject.nil?
end end
end end
......
...@@ -10,7 +10,7 @@ describe Paperclip::AttachmentRegistry do ...@@ -10,7 +10,7 @@ describe Paperclip::AttachmentRegistry do
@subject.register(AdapterTest){|t| Symbol === t } @subject.register(AdapterTest){|t| Symbol === t }
end end
it "return the class registered for the adapted type" do it "returns the class registered for the adapted type" do
assert_equal AdapterTest, @subject.for(:target).class assert_equal AdapterTest, @subject.for(:target).class
end end
end end
...@@ -24,11 +24,11 @@ describe Paperclip::AttachmentRegistry do ...@@ -24,11 +24,11 @@ describe Paperclip::AttachmentRegistry do
@subject.register(AdapterTest){|t| Symbol === t } @subject.register(AdapterTest){|t| Symbol === t }
end end
it "return true when the class of this adapter has been registered" do it "returns true when the class of this adapter has been registered" do
assert @subject.registered?(AdapterTest.new(:target)) assert @subject.registered?(AdapterTest.new(:target))
end end
it "return false when the adapter has not been registered" do it "returns false when the adapter has not been registered" do
assert ! @subject.registered?(Object) assert ! @subject.registered?(Object)
end end
end end
......
...@@ -8,51 +8,51 @@ describe Paperclip::StringioAdapter do ...@@ -8,51 +8,51 @@ describe Paperclip::StringioAdapter do
@subject = Paperclip.io_adapters.for(@stringio) @subject = Paperclip.io_adapters.for(@stringio)
end end
it "return a file name" do it "returns a file name" do
assert_equal "data.txt", @subject.original_filename assert_equal "data.txt", @subject.original_filename
end end
it "return a content type" do it "returns a content type" do
assert_equal "text/plain", @subject.content_type assert_equal "text/plain", @subject.content_type
end end
it "return the size of the data" do it "returns the size of the data" do
assert_equal 6, @subject.size assert_equal 6, @subject.size
end end
it "generate an MD5 hash of the contents" do it "generates an MD5 hash of the contents" do
assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint
end end
it "generate correct fingerprint after read" do it "generates correct fingerprint after read" do
fingerprint = Digest::MD5.hexdigest(@subject.read) fingerprint = Digest::MD5.hexdigest(@subject.read)
assert_equal fingerprint, @subject.fingerprint assert_equal fingerprint, @subject.fingerprint
end end
it "generate same fingerprint" do it "generates same fingerprint" do
assert_equal @subject.fingerprint, @subject.fingerprint assert_equal @subject.fingerprint, @subject.fingerprint
end end
it "return the data contained in the StringIO" do it "returns the data contained in the StringIO" do
assert_equal "abc123", @subject.read assert_equal "abc123", @subject.read
end end
it 'accept a content_type' do it 'accepts a content_type' do
@subject.content_type = 'image/png' @subject.content_type = 'image/png'
assert_equal 'image/png', @subject.content_type assert_equal 'image/png', @subject.content_type
end end
it 'accept an original_filename' do it 'accepts an original_filename' do
@subject.original_filename = 'image.png' @subject.original_filename = 'image.png'
assert_equal 'image.png', @subject.original_filename assert_equal 'image.png', @subject.original_filename
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
@subject.original_filename = 'image:restricted.png' @subject.original_filename = 'image:restricted.png'
assert_equal 'image_restricted.png', @subject.original_filename assert_equal 'image_restricted.png', @subject.original_filename
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
@subject.original_filename = 'image:restricted.png' @subject.original_filename = 'image:restricted.png'
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
......
...@@ -20,32 +20,32 @@ describe Paperclip::UploadedFileAdapter do ...@@ -20,32 +20,32 @@ describe Paperclip::UploadedFileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "get the right filename" do it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
it "force binmode on tempfile" do it "forces binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode? assert @subject.instance_variable_get("@tempfile").binmode?
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/x-png-by-browser", @subject.content_type assert_equal "image/x-png-by-browser", @subject.content_type
end end
it "get the file's size" do it "gets the file's size" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert ! @subject.nil? assert ! @subject.nil?
end end
it "generate a MD5 hash of the contents" do it "generates a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.tempfile.path).to_s expected = Digest::MD5.file(@file.tempfile.path).to_s
assert_equal expected, @subject.fingerprint assert_equal expected, @subject.fingerprint
end end
it "read the contents of the file" do it "reads the contents of the file" do
expected = @file.tempfile.read expected = @file.tempfile.read
assert expected.length > 0 assert expected.length > 0
assert_equal expected, @subject.read assert_equal expected, @subject.read
...@@ -66,11 +66,11 @@ describe Paperclip::UploadedFileAdapter do ...@@ -66,11 +66,11 @@ describe Paperclip::UploadedFileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
assert_equal 'image_restricted.gif', @subject.original_filename assert_equal 'image_restricted.gif', @subject.original_filename
end end
end end
...@@ -89,32 +89,32 @@ describe Paperclip::UploadedFileAdapter do ...@@ -89,32 +89,32 @@ describe Paperclip::UploadedFileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "get the right filename" do it "gets the right filename" do
assert_equal "5k.png", @subject.original_filename assert_equal "5k.png", @subject.original_filename
end end
it "force binmode on tempfile" do it "forces binmode on tempfile" do
assert @subject.instance_variable_get("@tempfile").binmode? assert @subject.instance_variable_get("@tempfile").binmode?
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/x-png-by-browser", @subject.content_type assert_equal "image/x-png-by-browser", @subject.content_type
end end
it "get the file's size" do it "gets the file's size" do
assert_equal 4456, @subject.size assert_equal 4456, @subject.size
end end
it "return false for a call to nil?" do it "returns false for a call to nil?" do
assert ! @subject.nil? assert ! @subject.nil?
end end
it "generate a MD5 hash of the contents" do it "generates a MD5 hash of the contents" do
expected = Digest::MD5.file(@file.path).to_s expected = Digest::MD5.file(@file.path).to_s
assert_equal expected, @subject.fingerprint assert_equal expected, @subject.fingerprint
end end
it "read the contents of the file" do it "reads the contents of the file" do
expected_file = File.new(@file.path) expected_file = File.new(@file.path)
expected_file.binmode expected_file.binmode
expected = expected_file.read expected = expected_file.read
...@@ -137,7 +137,7 @@ describe Paperclip::UploadedFileAdapter do ...@@ -137,7 +137,7 @@ describe Paperclip::UploadedFileAdapter do
@subject = Paperclip.io_adapters.for(@file) @subject = Paperclip.io_adapters.for(@file)
end end
it "get the content type" do it "gets the content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
end end
......
...@@ -10,45 +10,45 @@ describe Paperclip::UriAdapter do ...@@ -10,45 +10,45 @@ describe Paperclip::UriAdapter do
@subject = Paperclip.io_adapters.for(@uri) @subject = Paperclip.io_adapters.for(@uri)
end end
it "return a file name" do it "returns a file name" do
assert_equal "thoughtbot-logo.png", @subject.original_filename assert_equal "thoughtbot-logo.png", @subject.original_filename
end end
it 'close open handle after reading' do it 'closes open handle after reading' do
assert_equal true, @open_return.closed? assert_equal true, @open_return.closed?
end end
it "return a content type" do it "returns a content type" do
assert_equal "image/png", @subject.content_type assert_equal "image/png", @subject.content_type
end end
it "return the size of the data" do it "returns the size of the data" do
assert_equal @open_return.size, @subject.size assert_equal @open_return.size, @subject.size
end end
it "generate an MD5 hash of the contents" do it "generates an MD5 hash of the contents" do
assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint assert_equal Digest::MD5.hexdigest("xxx"), @subject.fingerprint
end end
it "generate correct fingerprint after read" do it "generates correct fingerprint after read" do
fingerprint = Digest::MD5.hexdigest(@subject.read) fingerprint = Digest::MD5.hexdigest(@subject.read)
assert_equal fingerprint, @subject.fingerprint assert_equal fingerprint, @subject.fingerprint
end end
it "generate same fingerprint" do it "generates same fingerprint" do
assert_equal @subject.fingerprint, @subject.fingerprint assert_equal @subject.fingerprint, @subject.fingerprint
end end
it "return the data contained in the StringIO" do it "returns the data contained in the StringIO" do
assert_equal "xxx", @subject.read assert_equal "xxx", @subject.read
end end
it 'accept a content_type' do it 'accepts a content_type' do
@subject.content_type = 'image/png' @subject.content_type = 'image/png'
assert_equal 'image/png', @subject.content_type assert_equal 'image/png', @subject.content_type
end end
it 'accept an orgiginal_filename' do it 'accepts an orgiginal_filename' do
@subject.original_filename = 'image.png' @subject.original_filename = 'image.png'
assert_equal 'image.png', @subject.original_filename assert_equal 'image.png', @subject.original_filename
end end
...@@ -62,11 +62,11 @@ describe Paperclip::UriAdapter do ...@@ -62,11 +62,11 @@ describe Paperclip::UriAdapter do
@subject = Paperclip.io_adapters.for(@uri) @subject = Paperclip.io_adapters.for(@uri)
end end
it "return a file name" do it "returns a file name" do
assert_equal "index.html", @subject.original_filename assert_equal "index.html", @subject.original_filename
end end
it "return a content type" do it "returns a content type" do
assert_equal "text/html", @subject.content_type assert_equal "text/html", @subject.content_type
end end
end end
...@@ -78,7 +78,7 @@ describe Paperclip::UriAdapter do ...@@ -78,7 +78,7 @@ describe Paperclip::UriAdapter do
@subject = Paperclip.io_adapters.for(@uri) @subject = Paperclip.io_adapters.for(@uri)
end end
it "return a file name" do it "returns a file name" do
assert_equal "paperclip", @subject.original_filename assert_equal "paperclip", @subject.original_filename
end end
end end
...@@ -90,11 +90,11 @@ describe Paperclip::UriAdapter do ...@@ -90,11 +90,11 @@ describe Paperclip::UriAdapter do
@subject = Paperclip.io_adapters.for(@uri) @subject = Paperclip.io_adapters.for(@uri)
end end
it "not generate filenames that include restricted characters" do it "does not generate filenames that include restricted characters" do
assert_equal "paper_clip.jpg", @subject.original_filename assert_equal "paper_clip.jpg", @subject.original_filename
end end
it "not generate paths that include restricted characters" do it "does not generate paths that include restricted characters" do
expect(@subject.path).to_not match(/:/) expect(@subject.path).to_not match(/:/)
end end
end end
......
...@@ -71,13 +71,13 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -71,13 +71,13 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
end end
end end
it "run the validation if the control is true" do it "runs the validation if the control is true" do
dummy = Dummy.new dummy = Dummy.new
dummy.go = true dummy.go = true
expect(matcher).to accept(dummy) expect(matcher).to accept(dummy)
end end
it "not run the validation if the control is false" do it "does not run the validation if the control is false" do
dummy = Dummy.new dummy = Dummy.new
dummy.go = false dummy.go = false
expect(matcher).to_not accept(dummy) expect(matcher).to_not accept(dummy)
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::MediaTypeSpoofDetector do describe Paperclip::MediaTypeSpoofDetector do
it 'reject a file that is named .html and identifies as PNG' do it 'rejects a file that is named .html and identifies as PNG' do
file = File.open(fixture_file("5k.png")) file = File.open(fixture_file("5k.png"))
assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html").spoofed? assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html").spoofed?
end end
it 'not reject a file that is named .jpg and identifies as PNG' do it 'does not reject a file that is named .jpg and identifies as PNG' do
file = File.open(fixture_file("5k.png")) file = File.open(fixture_file("5k.png"))
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg").spoofed? assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg").spoofed?
end end
it 'not reject a file that is named .html and identifies as HTML' do it 'does not reject a file that is named .html and identifies as HTML' do
file = File.open(fixture_file("empty.html")) file = File.open(fixture_file("empty.html"))
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html").spoofed? assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html").spoofed?
end end
it 'not reject a file that does not have a name' do it 'does not reject a file that does not have a name' do
file = File.open(fixture_file("empty.html")) file = File.open(fixture_file("empty.html"))
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "").spoofed? assert ! Paperclip::MediaTypeSpoofDetector.using(file, "").spoofed?
end end
it 'not reject when the supplied file is an IOAdapter' do it 'does not reject when the supplied file is an IOAdapter' do
adapter = Paperclip.io_adapters.for(File.new(fixture_file("5k.png"))) adapter = Paperclip.io_adapters.for(File.new(fixture_file("5k.png")))
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename).spoofed? assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename).spoofed?
end end
it 'not reject when the extension => content_type is in :content_type_mappings' do it 'does not reject when the extension => content_type is in :content_type_mappings' do
begin begin
Paperclip.options[:content_type_mappings] = { pem: "text/plain" } Paperclip.options[:content_type_mappings] = { pem: "text/plain" }
file = Tempfile.open(["test", ".PEM"]) file = Tempfile.open(["test", ".PEM"])
......
...@@ -7,7 +7,7 @@ describe 'Metaclasses' do ...@@ -7,7 +7,7 @@ describe 'Metaclasses' do
reset_class("Dummy") reset_class("Dummy")
end end
it "be able to use Paperclip like a normal class" do it "is able to use Paperclip like a normal class" do
@dummy = Dummy.new @dummy = Dummy.new
assert_nothing_raised do assert_nothing_raised do
...@@ -15,7 +15,7 @@ describe 'Metaclasses' do ...@@ -15,7 +15,7 @@ describe 'Metaclasses' do
end end
end end
it "work like any other instance" do it "works like any other instance" do
@dummy = Dummy.new @dummy = Dummy.new
rebuild_meta_class_of(@dummy) rebuild_meta_class_of(@dummy)
......
...@@ -9,7 +9,7 @@ describe 'Missing Attachment Styles' do ...@@ -9,7 +9,7 @@ describe 'Missing Attachment Styles' do
File.unlink(Paperclip.registered_attachments_styles_path) rescue nil File.unlink(Paperclip.registered_attachments_styles_path) rescue nil
end end
it "enable to get and set path to registered styles file" do it "enables to get and set path to registered styles file" do
assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml' Paperclip.registered_attachments_styles_path = '/tmp/config/paperclip_attachments.yml'
assert_equal '/tmp/config/paperclip_attachments.yml', Paperclip.registered_attachments_styles_path assert_equal '/tmp/config/paperclip_attachments.yml', Paperclip.registered_attachments_styles_path
...@@ -17,28 +17,28 @@ describe 'Missing Attachment Styles' do ...@@ -17,28 +17,28 @@ describe 'Missing Attachment Styles' do
assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path assert_equal ROOT.join('tmp/public/system/paperclip_attachments.yml').to_s, Paperclip.registered_attachments_styles_path
end end
it "be able to get current attachment styles" do it "is able to get current attachment styles" do
assert_equal Hash.new, Paperclip.send(:current_attachments_styles) assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
expected_hash = { Dummy: {avatar: [:big, :croppable]}} expected_hash = { Dummy: {avatar: [:big, :croppable]}}
assert_equal expected_hash, Paperclip.send(:current_attachments_styles) assert_equal expected_hash, Paperclip.send(:current_attachments_styles)
end end
it "be able to save current attachment styles for further comparison" do it "is able to save current attachment styles for further comparison" do
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles! Paperclip.save_current_attachments_styles!
expected_hash = { Dummy: {avatar: [:big, :croppable]}} expected_hash = { Dummy: {avatar: [:big, :croppable]}}
assert_equal expected_hash, YAML.load_file(Paperclip.registered_attachments_styles_path) assert_equal expected_hash, YAML.load_file(Paperclip.registered_attachments_styles_path)
end end
it "be able to read registered attachment styles from file" do it "is able to read registered attachment styles from file" do
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles! Paperclip.save_current_attachments_styles!
expected_hash = { Dummy: {avatar: [:big, :croppable]}} expected_hash = { Dummy: {avatar: [:big, :croppable]}}
assert_equal expected_hash, Paperclip.send(:get_registered_attachments_styles) assert_equal expected_hash, Paperclip.send(:get_registered_attachments_styles)
end end
it "be able to calculate differences between registered styles and current styles" do it "is able to calculate differences between registered styles and current styles" do
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles! Paperclip.save_current_attachments_styles!
rebuild_model styles: {thumb: 'x100', export: 'x400>', croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {thumb: 'x100', export: 'x400>', croppable: '600x600>', big: '1000x1000>'}
...@@ -60,7 +60,7 @@ describe 'Missing Attachment Styles' do ...@@ -60,7 +60,7 @@ describe 'Missing Attachment Styles' do
assert_equal Hash.new, Paperclip.missing_attachments_styles assert_equal Hash.new, Paperclip.missing_attachments_styles
end end
it "be able to calculate differences when a new attachment is added to a model" do it "is able to calculate differences when a new attachment is added to a model" do
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'} rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles! Paperclip.save_current_attachments_styles!
...@@ -77,7 +77,7 @@ describe 'Missing Attachment Styles' do ...@@ -77,7 +77,7 @@ describe 'Missing Attachment Styles' do
end end
# It's impossible to build styles hash without loading from database whole bunch of records # It's impossible to build styles hash without loading from database whole bunch of records
it "skip lambda-styles" do it "skips lambda-styles" do
rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} } rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} }
assert_equal Hash.new, Paperclip.send(:current_attachments_styles) assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
end end
......
...@@ -13,17 +13,17 @@ describe Paperclip do ...@@ -13,17 +13,17 @@ describe Paperclip do
Cocaine::CommandLine.path = @original_command_line_path Cocaine::CommandLine.path = @original_command_line_path
end end
it "run the command with Cocaine" do it "runs the command with Cocaine" do
Paperclip.run("convert", "stuff") Paperclip.run("convert", "stuff")
end end
it "save Cocaine::CommandLine.path that set before" do it "saves Cocaine::CommandLine.path that set before" do
Cocaine::CommandLine.path = "/opt/my_app/bin" Cocaine::CommandLine.path = "/opt/my_app/bin"
Paperclip.run("convert", "stuff") Paperclip.run("convert", "stuff")
assert_equal [Cocaine::CommandLine.path].flatten.include?("/opt/my_app/bin"), true assert_equal [Cocaine::CommandLine.path].flatten.include?("/opt/my_app/bin"), true
end end
it "not duplicate Cocaine::CommandLine.path on multiple runs" do it "does not duplicate Cocaine::CommandLine.path on multiple runs" do
Cocaine::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run)) Cocaine::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
Cocaine::CommandLine.path = nil Cocaine::CommandLine.path = nil
Paperclip.options[:command_path] = "/opt/my_app/bin" Paperclip.options[:command_path] = "/opt/my_app/bin"
...@@ -33,7 +33,7 @@ describe Paperclip do ...@@ -33,7 +33,7 @@ describe Paperclip do
end end
end end
it 'not raise errors when doing a lot of running' do it 'does not raise errors when doing a lot of running' do
Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024 Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024
Cocaine::CommandLine.path = "/something/else" Cocaine::CommandLine.path = "/something/else"
100.times do |x| 100.times do |x|
...@@ -52,14 +52,14 @@ describe Paperclip do ...@@ -52,14 +52,14 @@ describe Paperclip do
Paperclip.logger = ActiveRecord::Base.logger Paperclip.logger = ActiveRecord::Base.logger
end end
it "not raise an error when log is called" do it "does not raise an error when log is called" do
silence_stream(STDOUT) do silence_stream(STDOUT) do
Paperclip.log('something') Paperclip.log('something')
end end
end end
end end
context "Calling Paperclip.run with a logger" do context "Calling Paperclip.run with a logger" do
it "pass the defined logger if :log_command is set" do it "passes the defined logger if :log_command is set" do
Paperclip.options[:log_command] = true Paperclip.options[:log_command] = true
Cocaine::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run)) Cocaine::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
Paperclip.run("convert", "stuff") Paperclip.run("convert", "stuff")
...@@ -77,7 +77,7 @@ describe Paperclip do ...@@ -77,7 +77,7 @@ describe Paperclip do
after { @file.close } after { @file.close }
it "yield every instance of a model that has an attachment" do it "yields every instance of a model that has an attachment" do
actual = [] actual = []
Paperclip.each_instance_with_attachment("Dummy", "avatar") do |instance| Paperclip.each_instance_with_attachment("Dummy", "avatar") do |instance|
actual << instance actual << instance
...@@ -86,20 +86,20 @@ describe Paperclip do ...@@ -86,20 +86,20 @@ describe Paperclip do
end end
end end
it "raise when sent #processor and the name of a class that doesn't exist" do it "raises when sent #processor and the name of a class that doesn't exist" do
assert_raises(LoadError){ Paperclip.processor(:boogey_man) } assert_raises(LoadError){ Paperclip.processor(:boogey_man) }
end end
it "return a class when sent #processor and the name of a class under Paperclip" do it "returns a class when sent #processor and the name of a class under Paperclip" do
assert_equal ::Paperclip::Thumbnail, Paperclip.processor(:thumbnail) assert_equal ::Paperclip::Thumbnail, Paperclip.processor(:thumbnail)
end end
it "get a class from a namespaced class name" do it "gets a class from a namespaced class name" do
class ::One; class Two; end; end class ::One; class Two; end; end
assert_equal ::One::Two, Paperclip.class_for("One::Two") assert_equal ::One::Two, Paperclip.class_for("One::Two")
end end
it "raise when class doesn't exist in specified namespace" do it "raises when class doesn't exist in specified namespace" do
class ::Three; end class ::Three; end
class ::Four; end class ::Four; end
assert_raises NameError do assert_raises NameError do
...@@ -115,7 +115,7 @@ describe Paperclip do ...@@ -115,7 +115,7 @@ describe Paperclip do
after { @file.close } after { @file.close }
it "not error when trying to also create a 'blah' attachment" do it "does not error when trying to also create a 'blah' attachment" do
assert_nothing_raised do assert_nothing_raised do
Dummy.class_eval do Dummy.class_eval do
has_attached_file :blah has_attached_file :blah
...@@ -132,7 +132,7 @@ describe Paperclip do ...@@ -132,7 +132,7 @@ describe Paperclip do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not assign the avatar on mass-set" do it "does not assign the avatar on mass-set" do
@dummy.attributes = { other: "I'm set!", @dummy.attributes = { other: "I'm set!",
avatar: @file } avatar: @file }
...@@ -140,7 +140,7 @@ describe Paperclip do ...@@ -140,7 +140,7 @@ describe Paperclip do
assert ! @dummy.avatar? assert ! @dummy.avatar?
end end
it "still allow assigment on normal set" do it "allows assigment on normal set" do
@dummy.other = "I'm set!" @dummy.other = "I'm set!"
@dummy.avatar = @file @dummy.avatar = @file
...@@ -155,7 +155,7 @@ describe Paperclip do ...@@ -155,7 +155,7 @@ describe Paperclip do
class ::SubDummy < Dummy; end class ::SubDummy < Dummy; end
end end
it "be able to use the attachment from the subclass" do it "is able to use the attachment from the subclass" do
assert_nothing_raised do assert_nothing_raised do
@subdummy = SubDummy.create(avatar: @file) @subdummy = SubDummy.create(avatar: @file)
end end
...@@ -167,11 +167,11 @@ describe Paperclip do ...@@ -167,11 +167,11 @@ describe Paperclip do
end end
end end
it "have an avatar getter method" do it "has an avatar getter method" do
assert Dummy.new.respond_to?(:avatar) assert Dummy.new.respond_to?(:avatar)
end end
it "have an avatar setter method" do it "has an avatar setter method" do
assert Dummy.new.respond_to?(:avatar=) assert Dummy.new.respond_to?(:avatar=)
end end
...@@ -181,12 +181,12 @@ describe Paperclip do ...@@ -181,12 +181,12 @@ describe Paperclip do
@dummy.avatar = @file @dummy.avatar = @file
end end
it "be valid" do it "is valid" do
assert @dummy.valid? assert @dummy.valid?
end end
end end
it "not have Attachment in the ActiveRecord::Base namespace" do it "does not have Attachment in the ActiveRecord::Base namespace" do
assert_raises(NameError) do assert_raises(NameError) do
ActiveRecord::Base::Attachment ActiveRecord::Base::Attachment
end end
...@@ -206,7 +206,7 @@ describe Paperclip do ...@@ -206,7 +206,7 @@ describe Paperclip do
end end
end end
it "be able to find the custom processor" do it "is able to find the custom processor" do
assert_equal @freedom_processor, Paperclip.processor(:freedom) assert_equal @freedom_processor, Paperclip.processor(:freedom)
end end
......
require 'spec_helper' require 'spec_helper'
describe 'Plural cache' do describe 'Plural cache' do
it 'cache pluralizations' do it 'caches pluralizations' do
cache = Paperclip::Interpolations::PluralCache.new cache = Paperclip::Interpolations::PluralCache.new
word = "box" word = "box"
...@@ -11,7 +11,7 @@ describe 'Plural cache' do ...@@ -11,7 +11,7 @@ describe 'Plural cache' do
cache.pluralize(word) cache.pluralize(word)
end end
it 'cache pluralizations and underscores' do it 'caches pluralizations and underscores' do
cache = Paperclip::Interpolations::PluralCache.new cache = Paperclip::Interpolations::PluralCache.new
word = "BigBox" word = "BigBox"
...@@ -22,13 +22,13 @@ describe 'Plural cache' do ...@@ -22,13 +22,13 @@ describe 'Plural cache' do
cache.underscore_and_pluralize(word) cache.underscore_and_pluralize(word)
end end
it 'pluralize words' do it 'pluralizes words' do
cache = Paperclip::Interpolations::PluralCache.new cache = Paperclip::Interpolations::PluralCache.new
word = "box" word = "box"
assert_equal "boxes", cache.pluralize(word) assert_equal "boxes", cache.pluralize(word)
end end
it 'pluralize and underscore words' do it 'pluralizes and underscore words' do
cache = Paperclip::Interpolations::PluralCache.new cache = Paperclip::Interpolations::PluralCache.new
word = "BigBox" word = "BigBox"
assert_equal "big_boxes", cache.underscore_and_pluralize(word) assert_equal "big_boxes", cache.underscore_and_pluralize(word)
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::Processor do describe Paperclip::Processor do
it "instantiate and call #make when sent #make to the class" do it "instantiates and call #make when sent #make to the class" do
processor = mock processor = mock
processor.expects(:make).with() processor.expects(:make).with()
Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor) Paperclip::Processor.expects(:new).with(:one, :two, :three).returns(processor)
...@@ -9,7 +9,7 @@ describe Paperclip::Processor do ...@@ -9,7 +9,7 @@ describe Paperclip::Processor do
end end
context "Calling #convert" do context "Calling #convert" do
it "run the convert command with Cocaine" do it "runs the convert command with Cocaine" do
Paperclip.options[:log_command] = false Paperclip.options[:log_command] = false
Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run)) Cocaine::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
Paperclip::Processor.new('filename').convert("stuff") Paperclip::Processor.new('filename').convert("stuff")
...@@ -17,7 +17,7 @@ describe Paperclip::Processor do ...@@ -17,7 +17,7 @@ describe Paperclip::Processor do
end end
context "Calling #identify" do context "Calling #identify" do
it "run the identify command with Cocaine" do it "runs the identify command with Cocaine" do
Paperclip.options[:log_command] = false Paperclip.options[:log_command] = false
Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run)) Cocaine::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
Paperclip::Processor.new('filename').identify("stuff") Paperclip::Processor.new('filename').identify("stuff")
......
...@@ -20,18 +20,18 @@ describe Rake do ...@@ -20,18 +20,18 @@ describe Rake do
@bogus_instance.avatar.stubs(:reprocess!).raises @bogus_instance.avatar.stubs(:reprocess!).raises
end end
it "catch the exception" do it "catches the exception" do
assert_nothing_raised do assert_nothing_raised do
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
end end
it "continue to the next instance" do it "continues to the next instance" do
@valid_instance.avatar.expects(:reprocess!) @valid_instance.avatar.expects(:reprocess!)
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the exception" do it "prints the exception" do
exception_msg = 'Some Exception' exception_msg = 'Some Exception'
@bogus_instance.avatar.stubs(:reprocess!).raises(exception_msg) @bogus_instance.avatar.stubs(:reprocess!).raises(exception_msg)
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
...@@ -40,14 +40,14 @@ describe Rake do ...@@ -40,14 +40,14 @@ describe Rake do
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the class name" do it "prints the class name" do
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
str.match 'Dummy' str.match 'Dummy'
end end
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the instance ID" do it "prints the instance ID" do
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
str.match "ID #{@bogus_instance.id}" str.match "ID #{@bogus_instance.id}"
end end
...@@ -63,12 +63,12 @@ describe Rake do ...@@ -63,12 +63,12 @@ describe Rake do
@bogus_instance.stubs(:errors).returns(@errors) @bogus_instance.stubs(:errors).returns(@errors)
end end
it "continue to the next instance" do it "continues to the next instance" do
@valid_instance.avatar.expects(:reprocess!) @valid_instance.avatar.expects(:reprocess!)
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the error" do it "prints the error" do
error_msg = 'Some Error' error_msg = 'Some Error'
@errors.stubs(:full_messages).returns([error_msg]) @errors.stubs(:full_messages).returns([error_msg])
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
...@@ -77,14 +77,14 @@ describe Rake do ...@@ -77,14 +77,14 @@ describe Rake do
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the class name" do it "prints the class name" do
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
str.match 'Dummy' str.match 'Dummy'
end end
::Rake::Task['paperclip:refresh:thumbnails'].execute ::Rake::Task['paperclip:refresh:thumbnails'].execute
end end
it "print the instance ID" do it "prints the instance ID" do
Paperclip::Task.expects(:log_error).with do |str| Paperclip::Task.expects(:log_error).with do |str|
str.match "ID #{@bogus_instance.id}" str.match "ID #{@bogus_instance.id}"
end end
...@@ -94,7 +94,7 @@ describe Rake do ...@@ -94,7 +94,7 @@ describe Rake do
end end
context "Paperclip::Task.log_error method" do context "Paperclip::Task.log_error method" do
it "print its argument to STDERR" do it "prints its argument to STDERR" do
msg = 'Some Message' msg = 'Some Message'
$stderr.expects(:puts).with(msg) $stderr.expects(:puts).with(msg)
Paperclip::Task.log_error(msg) Paperclip::Task.log_error(msg)
......
...@@ -18,7 +18,7 @@ describe Paperclip::Schema do ...@@ -18,7 +18,7 @@ describe Paperclip::Schema do
before do before do
ActiveSupport::Deprecation.silenced = false ActiveSupport::Deprecation.silenced = false
end end
it "create attachment columns" do it "creates attachment columns" do
Dummy.connection.create_table :dummies, force: true do |t| Dummy.connection.create_table :dummies, force: true do |t|
ActiveSupport::Deprecation.silence do ActiveSupport::Deprecation.silence do
t.has_attached_file :avatar t.has_attached_file :avatar
...@@ -34,7 +34,7 @@ describe Paperclip::Schema do ...@@ -34,7 +34,7 @@ describe Paperclip::Schema do
expect(columns).to include(['avatar_updated_at', :datetime]) expect(columns).to include(['avatar_updated_at', :datetime])
end end
it "display deprecation warning" do it "displays deprecation warning" do
Dummy.connection.create_table :dummies, force: true do |t| Dummy.connection.create_table :dummies, force: true do |t|
assert_deprecated do assert_deprecated do
t.has_attached_file :avatar t.has_attached_file :avatar
...@@ -51,7 +51,7 @@ describe Paperclip::Schema do ...@@ -51,7 +51,7 @@ describe Paperclip::Schema do
rebuild_class rebuild_class
end end
it "create attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', :string])
...@@ -74,7 +74,7 @@ describe Paperclip::Schema do ...@@ -74,7 +74,7 @@ describe Paperclip::Schema do
rebuild_class rebuild_class
end end
it "create attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', :string])
...@@ -90,7 +90,7 @@ describe Paperclip::Schema do ...@@ -90,7 +90,7 @@ describe Paperclip::Schema do
rebuild_class rebuild_class
end end
it "create attachment columns" do it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.type] }
expect(columns).to include(['avatar_file_name', :string]) expect(columns).to include(['avatar_file_name', :string])
...@@ -105,7 +105,7 @@ describe Paperclip::Schema do ...@@ -105,7 +105,7 @@ describe Paperclip::Schema do
end end
context "with no attachment" do context "with no attachment" do
it "raise an error" do it "raises an error" do
assert_raises ArgumentError do assert_raises ArgumentError do
Dummy.connection.add_attachment :dummies Dummy.connection.add_attachment :dummies
rebuild_class rebuild_class
...@@ -128,7 +128,7 @@ describe Paperclip::Schema do ...@@ -128,7 +128,7 @@ describe Paperclip::Schema do
before do before do
ActiveSupport::Deprecation.silenced = false ActiveSupport::Deprecation.silenced = false
end end
it "remove the attachment columns" do it "removes the attachment columns" do
ActiveSupport::Deprecation.silence do ActiveSupport::Deprecation.silence do
Dummy.connection.drop_attached_file :dummies, :avatar Dummy.connection.drop_attached_file :dummies, :avatar
end end
...@@ -142,7 +142,7 @@ describe Paperclip::Schema do ...@@ -142,7 +142,7 @@ describe Paperclip::Schema do
expect(columns).to_not include(['avatar_updated_at', :datetime]) expect(columns).to_not include(['avatar_updated_at', :datetime])
end end
it "display a deprecation warning" do it "displays a deprecation warning" do
assert_deprecated do assert_deprecated do
Dummy.connection.drop_attached_file :dummies, :avatar Dummy.connection.drop_attached_file :dummies, :avatar
end end
...@@ -156,7 +156,7 @@ describe Paperclip::Schema do ...@@ -156,7 +156,7 @@ describe Paperclip::Schema do
rebuild_class rebuild_class
end end
it "remove the attachment columns" do it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.type] }
expect(columns).to_not include(['avatar_file_name', :string]) expect(columns).to_not include(['avatar_file_name', :string])
...@@ -179,7 +179,7 @@ describe Paperclip::Schema do ...@@ -179,7 +179,7 @@ describe Paperclip::Schema do
rebuild_class rebuild_class
end end
it "remove the attachment columns" do it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] } columns = Dummy.columns.map{ |column| [column.name, column.type] }
expect(columns).to_not include(['avatar_file_name', :string]) expect(columns).to_not include(['avatar_file_name', :string])
...@@ -194,7 +194,7 @@ describe Paperclip::Schema do ...@@ -194,7 +194,7 @@ describe Paperclip::Schema do
end end
context "with no attachment" do context "with no attachment" do
it "raise an error" do it "raises an error" do
assert_raises ArgumentError do assert_raises ArgumentError do
Dummy.connection.remove_attachment :dummies Dummy.connection.remove_attachment :dummies
end end
......
...@@ -13,21 +13,21 @@ describe Paperclip::Storage::Filesystem do ...@@ -13,21 +13,21 @@ describe Paperclip::Storage::Filesystem do
after { @file.close } after { @file.close }
it "allow file assignment" do it "allows file assignment" do
assert @dummy.save assert @dummy.save
end end
it "store the original" do it "stores the original" do
@dummy.save @dummy.save
assert_file_exists(@dummy.avatar.path) assert_file_exists(@dummy.avatar.path)
end end
it "store the thumbnail" do it "stores the thumbnail" do
@dummy.save @dummy.save
assert_file_exists(@dummy.avatar.path(:thumbnail)) assert_file_exists(@dummy.avatar.path(:thumbnail))
end end
it "be rewinded after flush_writes" do it "is rewinded after flush_writes" do
@dummy.avatar.instance_eval "def after_flush_writes; end" @dummy.avatar.instance_eval "def after_flush_writes; end"
files = @dummy.avatar.queued_for_write.values files = @dummy.avatar.queued_for_write.values
...@@ -35,14 +35,14 @@ describe Paperclip::Storage::Filesystem do ...@@ -35,14 +35,14 @@ describe Paperclip::Storage::Filesystem do
assert files.none?(&:eof?), "Expect all the files to be rewinded." assert files.none?(&:eof?), "Expect all the files to be rewinded."
end end
it "be removed after after_flush_writes" do it "is removed after after_flush_writes" do
paths = @dummy.avatar.queued_for_write.values.map(&:path) paths = @dummy.avatar.queued_for_write.values.map(&:path)
@dummy.save @dummy.save
assert paths.none?{ |path| File.exists?(path) }, assert paths.none?{ |path| File.exists?(path) },
"Expect all the files to be deleted." "Expect all the files to be deleted."
end end
it 'copy the file to a known location with copy_to_local_file' do it 'copies the file to a known location with copy_to_local_file' do
tempfile = Tempfile.new("known_location") tempfile = Tempfile.new("known_location")
@dummy.avatar.copy_to_local_file(:original, tempfile.path) @dummy.avatar.copy_to_local_file(:original, tempfile.path)
tempfile.rewind tempfile.rewind
...@@ -63,15 +63,15 @@ describe Paperclip::Storage::Filesystem do ...@@ -63,15 +63,15 @@ describe Paperclip::Storage::Filesystem do
after { @file.close } after { @file.close }
it "store the file" do it "stores the file" do
assert_file_exists(@dummy.avatar.path) assert_file_exists(@dummy.avatar.path)
end end
it "return a replaced version for path" do it "returns a replaced version for path" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
end end
it "return a replaced version for url" do it "returns a replaced version for url" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
end end
end end
......
...@@ -19,7 +19,7 @@ describe Paperclip::Storage::Fog do ...@@ -19,7 +19,7 @@ describe Paperclip::Storage::Fog do
after { @file.close } after { @file.close }
it "have the proper information loading credentials from a file" do it "has the proper information loading credentials from a file" do
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS' assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
end end
end end
...@@ -38,7 +38,7 @@ describe Paperclip::Storage::Fog do ...@@ -38,7 +38,7 @@ describe Paperclip::Storage::Fog do
after { @file.close } after { @file.close }
it "have the proper information loading credentials from a file" do it "has the proper information loading credentials from a file" do
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS' assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
end end
end end
...@@ -61,7 +61,7 @@ describe Paperclip::Storage::Fog do ...@@ -61,7 +61,7 @@ describe Paperclip::Storage::Fog do
after { @file.close } after { @file.close }
it "be able to interpolate the path without blowing up" do it "is able to interpolate the path without blowing up" do
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")), assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")),
@dummy.avatar.path @dummy.avatar.path
end end
...@@ -85,7 +85,7 @@ describe Paperclip::Storage::Fog do ...@@ -85,7 +85,7 @@ describe Paperclip::Storage::Fog do
after { @file.close } after { @file.close }
it "have correct path and url from interpolated defaults" do it "has correct path and url from interpolated defaults" do
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
end end
end end
...@@ -106,7 +106,7 @@ describe Paperclip::Storage::Fog do ...@@ -106,7 +106,7 @@ describe Paperclip::Storage::Fog do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "be able to evaluate correct values for file headers" do it "is able to evaluate correct values for file headers" do
assert_equal @dummy.avatar.send(:fog_file), { custom_header: 'foobar' } assert_equal @dummy.avatar.send(:fog_file), { custom_header: 'foobar' }
end end
end end
...@@ -137,7 +137,7 @@ describe Paperclip::Storage::Fog do ...@@ -137,7 +137,7 @@ describe Paperclip::Storage::Fog do
rebuild_model(@options) rebuild_model(@options)
end end
it "be extended by the Fog module" do it "is extended by the Fog module" do
assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog) assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
end end
...@@ -155,7 +155,7 @@ describe Paperclip::Storage::Fog do ...@@ -155,7 +155,7 @@ describe Paperclip::Storage::Fog do
directory.destroy directory.destroy
end end
it "be rewinded after flush_writes" do it "is rewound after flush_writes" do
@dummy.avatar.instance_eval "def after_flush_writes; end" @dummy.avatar.instance_eval "def after_flush_writes; end"
files = @dummy.avatar.queued_for_write.values files = @dummy.avatar.queued_for_write.values
...@@ -163,14 +163,14 @@ describe Paperclip::Storage::Fog do ...@@ -163,14 +163,14 @@ describe Paperclip::Storage::Fog do
assert files.none?(&:eof?), "Expect all the files to be rewinded." assert files.none?(&:eof?), "Expect all the files to be rewinded."
end end
it "be removed after after_flush_writes" do it "is removed after after_flush_writes" do
paths = @dummy.avatar.queued_for_write.values.map(&:path) paths = @dummy.avatar.queued_for_write.values.map(&:path)
@dummy.save @dummy.save
assert paths.none?{ |path| File.exists?(path) }, assert paths.none?{ |path| File.exists?(path) },
"Expect all the files to be deleted." "Expect all the files to be deleted."
end end
it 'be able to be copied to a local file' do it 'is able to be copied to a local file' do
@dummy.save @dummy.save
tempfile = Tempfile.new("known_location") tempfile = Tempfile.new("known_location")
tempfile.binmode tempfile.binmode
...@@ -181,7 +181,7 @@ describe Paperclip::Storage::Fog do ...@@ -181,7 +181,7 @@ describe Paperclip::Storage::Fog do
tempfile.close tempfile.close
end end
it "pass the content type to the Fog::Storage::AWS::Files instance" do it "passes the content type to the Fog::Storage::AWS::Files instance" do
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash| Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
hash[:content_type] hash[:content_type]
end end
...@@ -193,14 +193,14 @@ describe Paperclip::Storage::Fog do ...@@ -193,14 +193,14 @@ describe Paperclip::Storage::Fog do
@connection.directories.get(@fog_directory).destroy @connection.directories.get(@fog_directory).destroy
end end
it "create the bucket" do it "creates the bucket" do
assert @dummy.save assert @dummy.save
assert @connection.directories.get(@fog_directory) assert @connection.directories.get(@fog_directory)
end end
end end
context "with a bucket" do context "with a bucket" do
it "succeed" do it "succeeds" do
assert @dummy.save assert @dummy.save
end end
end end
...@@ -213,7 +213,7 @@ describe Paperclip::Storage::Fog do ...@@ -213,7 +213,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert !@dummy.avatar.url.nil? assert !@dummy.avatar.url.nil?
end end
end end
...@@ -226,7 +226,7 @@ describe Paperclip::Storage::Fog do ...@@ -226,7 +226,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/data\.txt\?\d*$/ assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/data\.txt\?\d*$/
end end
end end
...@@ -245,7 +245,7 @@ describe Paperclip::Storage::Fog do ...@@ -245,7 +245,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/data\.txt\?\d*$/ assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/data\.txt\?\d*$/
end end
end end
...@@ -258,7 +258,7 @@ describe Paperclip::Storage::Fog do ...@@ -258,7 +258,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it 'set the @fog_public instance variable to false' do it 'sets the @fog_public instance variable to false' do
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public] assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
assert_equal false, @dummy.avatar.fog_public assert_equal false, @dummy.avatar.fog_public
end end
...@@ -273,7 +273,7 @@ describe Paperclip::Storage::Fog do ...@@ -273,7 +273,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it 'set the @fog_public for a particular style to false' do it 'sets the @fog_public for a particular style to false' do
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public] assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
assert_equal false, @dummy.avatar.fog_public(:thumb) assert_equal false, @dummy.avatar.fog_public(:thumb)
end end
...@@ -288,7 +288,7 @@ describe Paperclip::Storage::Fog do ...@@ -288,7 +288,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it 'set the fog_public for a particular style to correct value' do it 'sets the fog_public for a particular style to correct value' do
assert_equal false, @dummy.avatar.fog_public(:medium) assert_equal false, @dummy.avatar.fog_public(:medium)
assert_equal true, @dummy.avatar.fog_public(:thumb) assert_equal true, @dummy.avatar.fog_public(:thumb)
end end
...@@ -302,23 +302,23 @@ describe Paperclip::Storage::Fog do ...@@ -302,23 +302,23 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "default fog_public to true" do it "defaults fog_public to true" do
assert_equal true, @dummy.avatar.fog_public assert_equal true, @dummy.avatar.fog_public
end end
end end
context "with a valid bucket name for a subdomain" do context "with a valid bucket name for a subdomain" do
it "provide an url in subdomain style" do it "provides an url in subdomain style" do
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url) assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
end end
it "provide an url that expires in subdomain style" do it "provides an url that expires in subdomain style" do
assert_match(/^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url) assert_match(/^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
end end
end end
context "generating an expiring url" do context "generating an expiring url" do
it "generate the same url when using Times and Integer offsets" do it "generates the same url when using Times and Integer offsets" do
rebuild_model(@options) rebuild_model(@options)
dummy = Dummy.new dummy = Dummy.new
dummy.avatar = StringIO.new('.') dummy.avatar = StringIO.new('.')
...@@ -326,12 +326,12 @@ describe Paperclip::Storage::Fog do ...@@ -326,12 +326,12 @@ describe Paperclip::Storage::Fog do
assert_equal dummy.avatar.expiring_url(1234), dummy.avatar.expiring_url(Time.now + 1234) assert_equal dummy.avatar.expiring_url(1234), dummy.avatar.expiring_url(Time.now + 1234)
end end
it 'match the default url if there is no assignment' do it 'matches the default url if there is no assignment' do
dummy = Dummy.new dummy = Dummy.new
assert_equal dummy.avatar.url, dummy.avatar.expiring_url assert_equal dummy.avatar.url, dummy.avatar.expiring_url
end end
it 'match the default url when given a style if there is no assignment' do it 'matches the default url when given a style if there is no assignment' do
dummy = Dummy.new dummy = Dummy.new
assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb) assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb)
end end
...@@ -345,18 +345,18 @@ describe Paperclip::Storage::Fog do ...@@ -345,18 +345,18 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "not match the bucket-subdomain restrictions" do it "does not match the bucket-subdomain restrictions" do
invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2) invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
invalid_subdomains.each do |name| invalid_subdomains.each do |name|
assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
end end
end end
it "provide an url in folder style" do it "provides an url in folder style" do
assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url) assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
end end
it "provide a url that expires in folder style" do it "provides a url that expires in folder style" do
assert_match(/^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url) assert_match(/^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
end end
...@@ -372,7 +372,7 @@ describe Paperclip::Storage::Fog do ...@@ -372,7 +372,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "have created the bucket" do it "has created the bucket" do
assert @connection.directories.get(@dynamic_fog_directory).inspect assert @connection.directories.get(@dynamic_fog_directory).inspect
end end
...@@ -387,7 +387,7 @@ describe Paperclip::Storage::Fog do ...@@ -387,7 +387,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url) assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
end end
...@@ -401,11 +401,11 @@ describe Paperclip::Storage::Fog do ...@@ -401,11 +401,11 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url) assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
end end
it "provide an expiring url" do it "provides an expiring url" do
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url) assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
end end
...@@ -417,7 +417,7 @@ describe Paperclip::Storage::Fog do ...@@ -417,7 +417,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide an expiring url" do it "provides an expiring url" do
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url) assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
end end
end end
...@@ -438,7 +438,7 @@ describe Paperclip::Storage::Fog do ...@@ -438,7 +438,7 @@ describe Paperclip::Storage::Fog do
@dummy.save @dummy.save
end end
it "provide a public url" do it "provides a public url" do
assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
end end
end end
...@@ -466,7 +466,7 @@ describe Paperclip::Storage::Fog do ...@@ -466,7 +466,7 @@ describe Paperclip::Storage::Fog do
Fog.mock! Fog.mock!
end end
it "return the public url in place of the expiring url" do it "returns the public url in place of the expiring url" do
assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
end end
end end
......
...@@ -16,7 +16,7 @@ unless ENV["S3_BUCKET"].blank? ...@@ -16,7 +16,7 @@ unless ENV["S3_BUCKET"].blank?
@file = File.new(fixture_file("5k.png")) @file = File.new(fixture_file("5k.png"))
end end
it "not raise any error" do it "does not raise any error" do
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
@attachment.assign(@file) @attachment.assign(@file)
@attachment.save @attachment.save
...@@ -26,7 +26,7 @@ unless ENV["S3_BUCKET"].blank? ...@@ -26,7 +26,7 @@ unless ENV["S3_BUCKET"].blank?
@attachment2.save @attachment2.save
end end
it "allow assignment from another S3 object" do it "allows assignment from another S3 object" do
@attachment = Dummy.new.avatar @attachment = Dummy.new.avatar
@attachment.assign(@file) @attachment.assign(@file)
@attachment.save @attachment.save
...@@ -73,7 +73,7 @@ unless ENV["S3_BUCKET"].blank? ...@@ -73,7 +73,7 @@ unless ENV["S3_BUCKET"].blank?
@dummy = Dummy.new @dummy = Dummy.new
end end
it "be extended by the S3 module" do it "is extended by the S3 module" do
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3) assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
end end
...@@ -93,7 +93,7 @@ unless ENV["S3_BUCKET"].blank? ...@@ -93,7 +93,7 @@ unless ENV["S3_BUCKET"].blank?
@dummy.save @dummy.save
end end
it "be on S3" do it "is on S3" do
assert true assert true
end end
end end
...@@ -117,23 +117,23 @@ unless ENV["S3_BUCKET"].blank? ...@@ -117,23 +117,23 @@ unless ENV["S3_BUCKET"].blank?
@dummy.save @dummy.save
end end
it "return a replaced version for path" do it "returns a replaced version for path" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
end end
it "return a replaced version for url" do it "returns a replaced version for url" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
end end
it "be accessible" do it "is accessible" do
assert_success_response @dummy.avatar.url assert_success_response @dummy.avatar.url
end end
it "be reprocessable" do it "is reprocessable" do
assert @dummy.avatar.reprocess! assert @dummy.avatar.reprocess!
end end
it "be destroyable" do it "is destroyable" do
url = @dummy.avatar.url url = @dummy.avatar.url
@dummy.destroy @dummy.destroy
assert_not_found_response url assert_not_found_response url
...@@ -172,7 +172,7 @@ unless ENV["S3_BUCKET"].blank? ...@@ -172,7 +172,7 @@ unless ENV["S3_BUCKET"].blank?
@dummy.save @dummy.save
end end
it "be encrypted on S3" do it "is encrypted on S3" do
assert @dummy.avatar.s3_object.server_side_encryption == :aes256 assert @dummy.avatar.s3_object.server_side_encryption == :aes256
end end
end end
......
...@@ -18,7 +18,7 @@ describe Paperclip::Storage::S3 do ...@@ -18,7 +18,7 @@ describe Paperclip::Storage::S3 do
@avatar = @dummy.avatar @avatar = @dummy.avatar
end end
it "get the correct credentials when RAILS_ENV is production" do it "gets the correct credentials when RAILS_ENV is production" do
rails_env("production") do rails_env("production") do
assert_equal({key: "12345"}, assert_equal({key: "12345"},
@avatar.parse_credentials('production' => {key: '12345'}, @avatar.parse_credentials('production' => {key: '12345'},
...@@ -26,7 +26,7 @@ describe Paperclip::Storage::S3 do ...@@ -26,7 +26,7 @@ describe Paperclip::Storage::S3 do
end end
end end
it "get the correct credentials when RAILS_ENV is development" do it "gets the correct credentials when RAILS_ENV is development" do
rails_env("development") do rails_env("development") do
assert_equal({key: "54321"}, assert_equal({key: "54321"},
@avatar.parse_credentials('production' => {key: '12345'}, @avatar.parse_credentials('production' => {key: '12345'},
...@@ -34,13 +34,13 @@ describe Paperclip::Storage::S3 do ...@@ -34,13 +34,13 @@ describe Paperclip::Storage::S3 do
end end
end end
it "return the argument if the key does not exist" do it "returns the argument if the key does not exist" do
rails_env("not really an env") do rails_env("not really an env") do
assert_equal({test: "12345"}, @avatar.parse_credentials(test: "12345")) assert_equal({test: "12345"}, @avatar.parse_credentials(test: "12345"))
end end
end end
it "support HTTP proxy settings" do it "supports HTTP proxy settings" do
rails_env("development") do rails_env("development") do
assert_equal(true, @avatar.using_http_proxy?) assert_equal(true, @avatar.using_http_proxy?)
assert_equal(@proxy_settings[:host], @avatar.http_proxy_host) assert_equal(@proxy_settings[:host], @avatar.http_proxy_host)
...@@ -59,7 +59,7 @@ describe Paperclip::Storage::S3 do ...@@ -59,7 +59,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "populate #bucket_name" do it "populates #bucket_name" do
assert_equal @dummy.avatar.bucket_name, 'testing' assert_equal @dummy.avatar.bucket_name, 'testing'
end end
...@@ -72,7 +72,7 @@ describe Paperclip::Storage::S3 do ...@@ -72,7 +72,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "populate #bucket_name" do it "populates #bucket_name" do
assert_equal @dummy.avatar.bucket_name, 'testing' assert_equal @dummy.avatar.bucket_name, 'testing'
end end
...@@ -90,7 +90,7 @@ describe Paperclip::Storage::S3 do ...@@ -90,7 +90,7 @@ describe Paperclip::Storage::S3 do
end end
it "raise an argument error" do it "raises an argument error" do
expect { @dummy.save }.to raise_error(ArgumentError, /missing required :bucket option/) expect { @dummy.save }.to raise_error(ArgumentError, /missing required :bucket option/)
end end
...@@ -107,15 +107,15 @@ describe Paperclip::Storage::S3 do ...@@ -107,15 +107,15 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an S3 path" do it "returns a url based on an S3 path" do
assert_match %r{^http://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
end end
it "use the correct bucket" do it "uses the correct bucket" do
assert_equal "bucket", @dummy.avatar.s3_bucket.name assert_equal "bucket", @dummy.avatar.s3_bucket.name
end end
it "use the correct key" do it "uses the correct key" do
assert_equal "avatars/data.txt", @dummy.avatar.s3_object.key assert_equal "avatars/data.txt", @dummy.avatar.s3_object.key
end end
end end
...@@ -129,7 +129,7 @@ describe Paperclip::Storage::S3 do ...@@ -129,7 +129,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "return the s3_protocol in string" do it "returns the s3_protocol in string" do
assert_equal protocol.to_s, @dummy.avatar.s3_protocol assert_equal protocol.to_s, @dummy.avatar.s3_protocol
end end
end end
...@@ -147,7 +147,7 @@ describe Paperclip::Storage::S3 do ...@@ -147,7 +147,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an S3 path" do it "returns a url based on an S3 path" do
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
end end
end end
...@@ -163,7 +163,7 @@ describe Paperclip::Storage::S3 do ...@@ -163,7 +163,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an S3 path" do it "returns a url based on an S3 path" do
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
end end
end end
...@@ -179,7 +179,7 @@ describe Paperclip::Storage::S3 do ...@@ -179,7 +179,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an S3 path" do it "returns a url based on an S3 path" do
assert_match %r{^//s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url assert_match %r{^//s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
end end
end end
...@@ -202,11 +202,11 @@ describe Paperclip::Storage::S3 do ...@@ -202,11 +202,11 @@ describe Paperclip::Storage::S3 do
@avatar = @dummy.avatar @avatar = @dummy.avatar
end end
it "use an S3 object based on the correct path for the default style" do it "uses an S3 object based on the correct path for the default style" do
assert_equal("avatars/original/data.txt", @dummy.avatar.s3_object.key) assert_equal("avatars/original/data.txt", @dummy.avatar.s3_object.key)
end end
it "use an S3 object based on the correct path for the custom style" do it "uses an S3 object based on the correct path for the custom style" do
assert_equal("avatars/thumb/data.txt", @dummy.avatar.s3_object(:thumb).key) assert_equal("avatars/thumb/data.txt", @dummy.avatar.s3_object(:thumb).key)
end end
end end
...@@ -222,11 +222,11 @@ describe Paperclip::Storage::S3 do ...@@ -222,11 +222,11 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an :s3_host_name path" do it "returns a url based on an :s3_host_name path" do
assert_match %r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
end end
it "use the S3 bucket with the correct host name" do it "uses the S3 bucket with the correct host name" do
assert_equal "s3-ap-northeast-1.amazonaws.com", @dummy.avatar.s3_bucket.config.s3_endpoint assert_equal "s3-ap-northeast-1.amazonaws.com", @dummy.avatar.s3_bucket.config.s3_endpoint
end end
end end
...@@ -245,7 +245,7 @@ describe Paperclip::Storage::S3 do ...@@ -245,7 +245,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "use s3_host_name as a proc if available" do it "uses s3_host_name as a proc if available" do
@dummy.value = "s3.something.com" @dummy.value = "s3.something.com"
assert_equal "http://s3.something.com/bucket/avatars/data.txt", @dummy.avatar.url(:original, timestamp: false) assert_equal "http://s3.something.com/bucket/avatars/data.txt", @dummy.avatar.url(:original, timestamp: false)
end end
...@@ -268,19 +268,19 @@ describe Paperclip::Storage::S3 do ...@@ -268,19 +268,19 @@ describe Paperclip::Storage::S3 do
end end
end end
it "return a url containing the correct original file mime type" do it "returns a url containing the correct original file mime type" do
assert_match /.+\/5k.png/, @dummy.avatar.url assert_match /.+\/5k.png/, @dummy.avatar.url
end end
it 'use the correct key for the original file mime type' do it 'uses the correct key for the original file mime type' do
assert_match /.+\/5k.png/, @dummy.avatar.s3_object.key assert_match /.+\/5k.png/, @dummy.avatar.s3_object.key
end end
it "return a url containing the correct processed file mime type" do it "returns a url containing the correct processed file mime type" do
assert_match /.+\/5k.jpg/, @dummy.avatar.url(:large) assert_match /.+\/5k.jpg/, @dummy.avatar.url(:large)
end end
it "use the correct key for the processed file mime type" do it "uses the correct key for the processed file mime type" do
assert_match /.+\/5k.jpg/, @dummy.avatar.s3_object(:large).key assert_match /.+\/5k.jpg/, @dummy.avatar.s3_object(:large).key
end end
end end
...@@ -319,7 +319,7 @@ describe Paperclip::Storage::S3 do ...@@ -319,7 +319,7 @@ describe Paperclip::Storage::S3 do
after { @file.close } after { @file.close }
it "succeed" do it "succeeds" do
assert_equal @dummy.counter, 7 assert_equal @dummy.counter, 7
end end
end end
...@@ -340,11 +340,11 @@ describe Paperclip::Storage::S3 do ...@@ -340,11 +340,11 @@ describe Paperclip::Storage::S3 do
end end
end end
it "return a replaced version for path" do it "returns a replaced version for path" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.path assert_match /.+\/spaced_file\.png/, @dummy.avatar.path
end end
it "return a replaced version for url" do it "returns a replaced version for url" do
assert_match /.+\/spaced_file\.png/, @dummy.avatar.url assert_match /.+\/spaced_file\.png/, @dummy.avatar.url
end end
end end
...@@ -371,11 +371,11 @@ describe Paperclip::Storage::S3 do ...@@ -371,11 +371,11 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "return a replaced version for path" do it "returns a replaced version for path" do
assert_match /.+\/question_mark\.png/, @dummy.avatar.path assert_match /.+\/question_mark\.png/, @dummy.avatar.path
end end
it "return a replaced version for url" do it "returns a replaced version for url" do
assert_match /.+\/question_mark\.png/, @dummy.avatar.url assert_match /.+\/question_mark\.png/, @dummy.avatar.url
end end
end end
...@@ -391,7 +391,7 @@ describe Paperclip::Storage::S3 do ...@@ -391,7 +391,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on an S3 subdomain" do it "returns a url based on an S3 subdomain" do
assert_match %r{^http://bucket.s3.amazonaws.com/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://bucket.s3.amazonaws.com/avatars/data.txt}, @dummy.avatar.url
end end
end end
...@@ -410,7 +410,7 @@ describe Paperclip::Storage::S3 do ...@@ -410,7 +410,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on the host_alias" do it "returns a url based on the host_alias" do
assert_match %r{^http://something.something.com/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://something.something.com/avatars/data.txt}, @dummy.avatar.url
end end
end end
...@@ -433,12 +433,12 @@ describe Paperclip::Storage::S3 do ...@@ -433,12 +433,12 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a url based on the host_alias" do it "returns a url based on the host_alias" do
assert_match %r{^http://cdn1.example.com/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://cdn1.example.com/avatars/data.txt}, @dummy.avatar.url
assert_match %r{^http://cdn2.example.com/avatars/data.txt}, @dummy.avatar.url assert_match %r{^http://cdn2.example.com/avatars/data.txt}, @dummy.avatar.url
end end
it "still return the bucket name" do it "still returns the bucket name" do
assert_equal "prod_bucket", @dummy.avatar.bucket_name assert_equal "prod_bucket", @dummy.avatar.bucket_name
end end
...@@ -455,7 +455,7 @@ describe Paperclip::Storage::S3 do ...@@ -455,7 +455,7 @@ describe Paperclip::Storage::S3 do
@dummy.avatar = stringy_file @dummy.avatar = stringy_file
end end
it "return a relative URL for Rails to calculate assets host" do it "returns a relative URL for Rails to calculate assets host" do
assert_match %r{^avatars/data\.txt}, @dummy.avatar.url assert_match %r{^avatars/data\.txt}, @dummy.avatar.url
end end
...@@ -480,7 +480,7 @@ describe Paperclip::Storage::S3 do ...@@ -480,7 +480,7 @@ describe Paperclip::Storage::S3 do
} }
end end
it "use default options" do it "uses default options" do
@build_model_with_options[{}] @build_model_with_options[{}]
rails_env("production") do rails_env("production") do
...@@ -495,7 +495,7 @@ describe Paperclip::Storage::S3 do ...@@ -495,7 +495,7 @@ describe Paperclip::Storage::S3 do
end end
end end
it "allow overriding s3_url_options" do it "allows overriding s3_url_options" do
@build_model_with_options[s3_url_options: { response_content_disposition: "inline" }] @build_model_with_options[s3_url_options: { response_content_disposition: "inline" }]
rails_env("production") do rails_env("production") do
...@@ -510,7 +510,7 @@ describe Paperclip::Storage::S3 do ...@@ -510,7 +510,7 @@ describe Paperclip::Storage::S3 do
end end
end end
it "allow overriding s3_object options with a proc" do it "allows overriding s3_object options with a proc" do
@build_model_with_options[s3_url_options: lambda {|attachment| { response_content_type: attachment.avatar_content_type } }] @build_model_with_options[s3_url_options: lambda {|attachment| { response_content_type: attachment.avatar_content_type } }]
rails_env("production") do rails_env("production") do
...@@ -539,16 +539,16 @@ describe Paperclip::Storage::S3 do ...@@ -539,16 +539,16 @@ describe Paperclip::Storage::S3 do
context "with no attachment" do context "with no attachment" do
before { assert(!@dummy.avatar.exists?) } before { assert(!@dummy.avatar.exists?) }
it "return the default URL" do it "returns the default URL" do
assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url) assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url)
end end
it 'generate a url for a style when a file does not exist' do it 'generates a url for a style when a file does not exist' do
assert_equal(@dummy.avatar.url(:thumb), @dummy.avatar.expiring_url(3600, :thumb)) assert_equal(@dummy.avatar.url(:thumb), @dummy.avatar.expiring_url(3600, :thumb))
end end
end end
it "generate the same url when using Times and Integer offsets" do it "generates the same url when using Times and Integer offsets" do
assert_equal @dummy.avatar.expiring_url(1234), @dummy.avatar.expiring_url(Time.now + 1234) assert_equal @dummy.avatar.expiring_url(1234), @dummy.avatar.expiring_url(Time.now + 1234)
end end
end end
...@@ -571,14 +571,14 @@ describe Paperclip::Storage::S3 do ...@@ -571,14 +571,14 @@ describe Paperclip::Storage::S3 do
end end
end end
it "should generate a url for the thumb" do it "generates a url for the thumb" do
object = stub object = stub
@dummy.avatar.stubs(:s3_object).with(:thumb).returns(object) @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
object.expects(:url_for).with(:read, expires: 1800, secure: true) object.expects(:url_for).with(:read, expires: 1800, secure: true)
@dummy.avatar.expiring_url(1800, :thumb) @dummy.avatar.expiring_url(1800, :thumb)
end end
it "should generate a url for the default style" do it "generates a url for the default style" do
object = stub object = stub
@dummy.avatar.stubs(:s3_object).with(:original).returns(object) @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
object.expects(:url_for).with(:read, expires: 1800, secure: true) object.expects(:url_for).with(:read, expires: 1800, secure: true)
...@@ -596,14 +596,14 @@ describe Paperclip::Storage::S3 do ...@@ -596,14 +596,14 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "get the right bucket in production" do it "gets the right bucket in production" do
rails_env("production") do rails_env("production") do
assert_equal "prod_bucket", @dummy.avatar.bucket_name assert_equal "prod_bucket", @dummy.avatar.bucket_name
assert_equal "prod_bucket", @dummy.avatar.s3_bucket.name assert_equal "prod_bucket", @dummy.avatar.s3_bucket.name
end end
end end
it "get the right bucket in development" do it "gets the right bucket in development" do
rails_env("development") do rails_env("development") do
assert_equal "dev_bucket", @dummy.avatar.bucket_name assert_equal "dev_bucket", @dummy.avatar.bucket_name
assert_equal "dev_bucket", @dummy.avatar.s3_bucket.name assert_equal "dev_bucket", @dummy.avatar.s3_bucket.name
...@@ -622,21 +622,21 @@ describe Paperclip::Storage::S3 do ...@@ -622,21 +622,21 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "get the right s3_host_name in production" do it "gets the right s3_host_name in production" do
rails_env("production") do rails_env("production") do
assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
end end
end end
it "get the right s3_host_name in development" do it "gets the right s3_host_name in development" do
rails_env("development") do rails_env("development") do
assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
end end
end end
it "get the right s3_host_name if the key does not exist" do it "gets the right s3_host_name if the key does not exist" do
rails_env("test") do rails_env("test") do
assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
...@@ -655,11 +655,11 @@ describe Paperclip::Storage::S3 do ...@@ -655,11 +655,11 @@ describe Paperclip::Storage::S3 do
} }
end end
it "be extended by the S3 module" do it "is extended by the S3 module" do
assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3) assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
end end
it "not be extended by the Filesystem module" do it "won't be extended by the Filesystem module" do
assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem) assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
end end
...@@ -672,13 +672,13 @@ describe Paperclip::Storage::S3 do ...@@ -672,13 +672,13 @@ describe Paperclip::Storage::S3 do
after { @file.close } after { @file.close }
it "not get a bucket to get a URL" do it "does not get a bucket to get a URL" do
@dummy.avatar.expects(:s3).never @dummy.avatar.expects(:s3).never
@dummy.avatar.expects(:s3_bucket).never @dummy.avatar.expects(:s3_bucket).never
assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
end end
it "be rewound after flush_writes" do it "is rewound after flush_writes" do
@dummy.avatar.instance_eval "def after_flush_writes; end" @dummy.avatar.instance_eval "def after_flush_writes; end"
@dummy.avatar.stubs(:s3_object).returns(stub(write: true)) @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
...@@ -687,7 +687,7 @@ describe Paperclip::Storage::S3 do ...@@ -687,7 +687,7 @@ describe Paperclip::Storage::S3 do
assert files.none?(&:eof?), "Expect all the files to be rewound." assert files.none?(&:eof?), "Expect all the files to be rewound."
end end
it "be removed after after_flush_writes" do it "is removed after after_flush_writes" do
@dummy.avatar.stubs(:s3_object).returns(stub(write: true)) @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
paths = @dummy.avatar.queued_for_write.values.map(&:path) paths = @dummy.avatar.queued_for_write.values.map(&:path)
@dummy.save @dummy.save
...@@ -705,7 +705,7 @@ describe Paperclip::Storage::S3 do ...@@ -705,7 +705,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -721,7 +721,7 @@ describe Paperclip::Storage::S3 do ...@@ -721,7 +721,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -733,7 +733,7 @@ describe Paperclip::Storage::S3 do ...@@ -733,7 +733,7 @@ describe Paperclip::Storage::S3 do
@dummy.destroy @dummy.destroy
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -743,7 +743,7 @@ describe Paperclip::Storage::S3 do ...@@ -743,7 +743,7 @@ describe Paperclip::Storage::S3 do
AWS::S3::S3Object.any_instance.stubs(:exists?).raises(AWS::Errors::Base) AWS::S3::S3Object.any_instance.stubs(:exists?).raises(AWS::Errors::Base)
end end
it 'return false on exists?' do it 'returns false on exists?' do
assert !@dummy.avatar.exists? assert !@dummy.avatar.exists?
end end
end end
...@@ -757,7 +757,7 @@ describe Paperclip::Storage::S3 do ...@@ -757,7 +757,7 @@ describe Paperclip::Storage::S3 do
s3_credentials: {not: :important} s3_credentials: {not: :important}
end end
it "get the right bucket name" do it "gets the right bucket name" do
assert "bucket_a", Dummy.new(other: 'a').avatar.bucket_name assert "bucket_a", Dummy.new(other: 'a').avatar.bucket_name
assert "bucket_a", Dummy.new(other: 'a').avatar.s3_bucket.name assert "bucket_a", Dummy.new(other: 'a').avatar.s3_bucket.name
assert "bucket_b", Dummy.new(other: 'b').avatar.bucket_name assert "bucket_b", Dummy.new(other: 'b').avatar.bucket_name
...@@ -774,7 +774,7 @@ describe Paperclip::Storage::S3 do ...@@ -774,7 +774,7 @@ describe Paperclip::Storage::S3 do
} }
end end
it "get the right credentials" do it "gets the right credentials" do
assert "access1234", Dummy.new(other: '1234').avatar.s3_credentials[:access_key_id] assert "access1234", Dummy.new(other: '1234').avatar.s3_credentials[:access_key_id]
assert "secret1234", Dummy.new(other: '1234').avatar.s3_credentials[:secret_access_key] assert "secret1234", Dummy.new(other: '1234').avatar.s3_credentials[:secret_access_key]
end end
...@@ -792,7 +792,7 @@ describe Paperclip::Storage::S3 do ...@@ -792,7 +792,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "set the credential-provider" do it "sets the credential-provider" do
expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
end end
end end
...@@ -803,7 +803,7 @@ describe Paperclip::Storage::S3 do ...@@ -803,7 +803,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not accept the credentials" do it "does not accept the credentials" do
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
@dummy.avatar.s3_credentials @dummy.avatar.s3_credentials
end end
...@@ -816,7 +816,7 @@ describe Paperclip::Storage::S3 do ...@@ -816,7 +816,7 @@ describe Paperclip::Storage::S3 do
@dummy = Dummy.new @dummy = Dummy.new
end end
it "not parse any credentials" do it "does not parse any credentials" do
assert_equal({}, @dummy.avatar.s3_credentials) assert_equal({}, @dummy.avatar.s3_credentials)
end end
end end
...@@ -853,7 +853,7 @@ describe Paperclip::Storage::S3 do ...@@ -853,7 +853,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -892,7 +892,7 @@ describe Paperclip::Storage::S3 do ...@@ -892,7 +892,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -931,7 +931,7 @@ describe Paperclip::Storage::S3 do ...@@ -931,7 +931,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -970,7 +970,7 @@ describe Paperclip::Storage::S3 do ...@@ -970,7 +970,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1009,7 +1009,7 @@ describe Paperclip::Storage::S3 do ...@@ -1009,7 +1009,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1049,7 +1049,7 @@ describe Paperclip::Storage::S3 do ...@@ -1049,7 +1049,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1088,7 +1088,7 @@ describe Paperclip::Storage::S3 do ...@@ -1088,7 +1088,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1110,7 +1110,7 @@ describe Paperclip::Storage::S3 do ...@@ -1110,7 +1110,7 @@ describe Paperclip::Storage::S3 do
end end
end end
it "parse the credentials" do it "parses the credentials" do
assert_equal 'pathname_bucket', @dummy.avatar.bucket_name assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
assert_equal 'pathname_key', @dummy.avatar.s3_bucket.config.access_key_id assert_equal 'pathname_key', @dummy.avatar.s3_bucket.config.access_key_id
assert_equal 'pathname_secret', @dummy.avatar.s3_bucket.config.secret_access_key assert_equal 'pathname_secret', @dummy.avatar.s3_bucket.config.secret_access_key
...@@ -1133,7 +1133,7 @@ describe Paperclip::Storage::S3 do ...@@ -1133,7 +1133,7 @@ describe Paperclip::Storage::S3 do
end end
end end
it "run the file through ERB" do it "runs the file through ERB" do
assert_equal 'env_bucket', @dummy.avatar.bucket_name assert_equal 'env_bucket', @dummy.avatar.bucket_name
assert_equal 'env_key', @dummy.avatar.s3_bucket.config.access_key_id assert_equal 'env_key', @dummy.avatar.s3_bucket.config.access_key_id
assert_equal 'env_secret', @dummy.avatar.s3_bucket.config.secret_access_key assert_equal 'env_secret', @dummy.avatar.s3_bucket.config.secret_access_key
...@@ -1171,7 +1171,7 @@ describe Paperclip::Storage::S3 do ...@@ -1171,7 +1171,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1209,7 +1209,7 @@ describe Paperclip::Storage::S3 do ...@@ -1209,7 +1209,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1255,7 +1255,7 @@ describe Paperclip::Storage::S3 do ...@@ -1255,7 +1255,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert true assert true
end end
end end
...@@ -1296,7 +1296,7 @@ describe Paperclip::Storage::S3 do ...@@ -1296,7 +1296,7 @@ describe Paperclip::Storage::S3 do
@dummy.save @dummy.save
end end
it "succeed" do it "succeeds" do
assert @dummy.avatar.url().include? "https://" assert @dummy.avatar.url().include? "https://"
assert @dummy.avatar.url(:thumb).include? "http://" assert @dummy.avatar.url(:thumb).include? "http://"
end end
......
...@@ -10,28 +10,28 @@ describe Paperclip::Style do ...@@ -10,28 +10,28 @@ describe Paperclip::Style do
@style = @attachment.styles[:foo] @style = @attachment.styles[:foo]
end end
it "be held as a Style object" do it "is held as a Style object" do
expect(@style).to be_a Paperclip::Style expect(@style).to be_a Paperclip::Style
end end
it "get processors from the attachment definition" do it "gets processors from the attachment definition" do
assert_equal [:thumbnail], @style.processors assert_equal [:thumbnail], @style.processors
end end
it "have the right geometry" do it "has the right geometry" do
assert_equal "100x100#", @style.geometry assert_equal "100x100#", @style.geometry
end end
it "be whiny if the attachment is" do it "is whiny if the attachment is" do
assert @style.whiny? assert @style.whiny?
end end
it "respond to hash notation" do it "responds to hash notation" do
assert_equal [:thumbnail], @style[:processors] assert_equal [:thumbnail], @style[:processors]
assert_equal "100x100#", @style[:geometry] assert_equal "100x100#", @style[:geometry]
end end
should "return the name of the style in processor options" do it "returns the name of the style in processor options" do
assert_equal :foo, @style.processor_options[:style] assert_equal :foo, @style.processor_options[:style]
end end
end end
...@@ -51,7 +51,7 @@ describe Paperclip::Style do ...@@ -51,7 +51,7 @@ describe Paperclip::Style do
} }
end end
it "call procs when they are needed" do it "calls procs when they are needed" do
assert_equal "300x300#", @attachment.styles[:foo].geometry assert_equal "300x300#", @attachment.styles[:foo].geometry
assert_equal "300x300#", @attachment.styles[:bar].geometry assert_equal "300x300#", @attachment.styles[:bar].geometry
assert_equal [:test], @attachment.styles[:foo].processors assert_equal [:test], @attachment.styles[:foo].processors
...@@ -71,36 +71,36 @@ describe Paperclip::Style do ...@@ -71,36 +71,36 @@ describe Paperclip::Style do
styles: styles styles: styles
end end
it "have the right number of styles" do it "has the right number of styles" do
expect(@attachment.styles).to be_a Hash expect(@attachment.styles).to be_a Hash
assert_equal 3, @attachment.styles.size assert_equal 3, @attachment.styles.size
end end
it "have styles as Style objects" do it "has styles as Style objects" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
expect(@attachment.styles[s]).to be_a Paperclip::Style expect(@attachment.styles[s]).to be_a Paperclip::Style
end end
end end
it "have the right geometries" do it "has the right geometries" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_equal @attachment.styles[s].geometry, "100x100" assert_equal @attachment.styles[s].geometry, "100x100"
end end
end end
it "have the right formats" do it "has the right formats" do
assert_equal @attachment.styles[:aslist].format, :png assert_equal @attachment.styles[:aslist].format, :png
assert_equal @attachment.styles[:ashash].format, :png assert_equal @attachment.styles[:ashash].format, :png
assert_nil @attachment.styles[:asstring].format assert_nil @attachment.styles[:asstring].format
end end
it "retain order" do it "retains order" do
assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys assert_equal [:aslist, :ashash, :asstring], @attachment.styles.keys
end end
end end
context "An attachment with :convert_options" do context "An attachment with :convert_options" do
it "not have called extra_options_for(:thumb/:large) on initialization" do it "does not have called extra_options_for(:thumb/:large) on initialization" do
@attachment = attachment path: ":basename.:extension", @attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"}, styles: {thumb: "100x100", large: "400x400"},
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"} convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
...@@ -108,7 +108,7 @@ describe Paperclip::Style do ...@@ -108,7 +108,7 @@ describe Paperclip::Style do
@style = @attachment.styles[:thumb] @style = @attachment.styles[:thumb]
end end
it "call extra_options_for(:thumb/:large) when convert options are requested" do it "calls extra_options_for(:thumb/:large) when convert options are requested" do
@attachment = attachment path: ":basename.:extension", @attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"}, styles: {thumb: "100x100", large: "400x400"},
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"} convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
...@@ -122,7 +122,7 @@ describe Paperclip::Style do ...@@ -122,7 +122,7 @@ describe Paperclip::Style do
end end
context "An attachment with :source_file_options" do context "An attachment with :source_file_options" do
it "not have called extra_source_file_options_for(:thumb/:large) on initialization" do it "does not have called extra_source_file_options_for(:thumb/:large) on initialization" do
@attachment = attachment path: ":basename.:extension", @attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"}, styles: {thumb: "100x100", large: "400x400"},
source_file_options: {all: "-density 400", thumb: "-depth 8"} source_file_options: {all: "-density 400", thumb: "-depth 8"}
...@@ -130,7 +130,7 @@ describe Paperclip::Style do ...@@ -130,7 +130,7 @@ describe Paperclip::Style do
@style = @attachment.styles[:thumb] @style = @attachment.styles[:thumb]
end end
it "call extra_options_for(:thumb/:large) when convert options are requested" do it "calls extra_options_for(:thumb/:large) when convert options are requested" do
@attachment = attachment path: ":basename.:extension", @attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"}, styles: {thumb: "100x100", large: "400x400"},
source_file_options: {all: "-density 400", thumb: "-depth 8"} source_file_options: {all: "-density 400", thumb: "-depth 8"}
...@@ -157,12 +157,12 @@ describe Paperclip::Style do ...@@ -157,12 +157,12 @@ describe Paperclip::Style do
@style = @attachment.styles[:foo] @style = @attachment.styles[:foo]
end end
it "not get processors from the attachment" do it "does not get processors from the attachment" do
@attachment.expects(:processors).never @attachment.expects(:processors).never
assert_not_equal [:thumbnail], @style.processors assert_not_equal [:thumbnail], @style.processors
end end
it "report its own processors" do it "reports its own processors" do
assert_equal [:test], @style.processors assert_equal [:test], @style.processors
end end
...@@ -181,11 +181,11 @@ describe Paperclip::Style do ...@@ -181,11 +181,11 @@ describe Paperclip::Style do
processors: [:thumbnail] processors: [:thumbnail]
end end
it "defer processing of procs until they are needed" do it "defers processing of procs until they are needed" do
expect(@attachment.styles[:foo].instance_variable_get("@processors")).to be_a Proc expect(@attachment.styles[:foo].instance_variable_get("@processors")).to be_a Proc
end end
it "call procs when they are needed" do it "calls procs when they are needed" do
assert_equal [:test], @attachment.styles[:foo].processors assert_equal [:test], @attachment.styles[:foo].processors
end end
end end
...@@ -204,12 +204,12 @@ describe Paperclip::Style do ...@@ -204,12 +204,12 @@ describe Paperclip::Style do
@file.stubs(:original_filename).returns("file.jpg") @file.stubs(:original_filename).returns("file.jpg")
end end
it "have empty options for :thumb style" do it "has empty options for :thumb style" do
assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options] assert_equal "", @attachment.styles[:thumb].processor_options[:convert_options]
assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options] assert_equal "", @attachment.styles[:thumb].processor_options[:source_file_options]
end end
it "have the right options for :large style" do it "has the right options for :large style" do
assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options] assert_equal "-do_stuff", @attachment.styles[:large].processor_options[:convert_options]
assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options] assert_equal "-do_extra_stuff", @attachment.styles[:large].processor_options[:source_file_options]
end end
...@@ -228,24 +228,24 @@ describe Paperclip::Style do ...@@ -228,24 +228,24 @@ describe Paperclip::Style do
} }
end end
it "have the right number of styles" do it "has the right number of styles" do
expect(@attachment.styles).to be_a Hash expect(@attachment.styles).to be_a Hash
assert_equal 3, @attachment.styles.size assert_equal 3, @attachment.styles.size
end end
it "have styles as Style objects" do it "has styles as Style objects" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
expect(@attachment.styles[s]).to be_a Paperclip::Style expect(@attachment.styles[s]).to be_a Paperclip::Style
end end
end end
it "have the right geometries" do it "has the right geometries" do
[:aslist, :ashash, :aslist].each do |s| [:aslist, :ashash, :aslist].each do |s|
assert_equal @attachment.styles[s].geometry, "300x300#" assert_equal @attachment.styles[s].geometry, "300x300#"
end end
end end
it "have the right formats" do it "has the right formats" do
assert_equal @attachment.styles[:aslist].format, :jpg assert_equal @attachment.styles[:aslist].format, :jpg
assert_equal @attachment.styles[:ashash].format, :png assert_equal @attachment.styles[:ashash].format, :png
assert_equal @attachment.styles[:asstring].format, :png assert_equal @attachment.styles[:asstring].format, :png
......
require 'spec_helper' require 'spec_helper'
describe Paperclip::TempfileFactory do describe Paperclip::TempfileFactory do
it "be able to generate a tempfile with the right name" do it "is able to generate a tempfile with the right name" do
file = subject.generate("omg.png") file = subject.generate("omg.png")
assert File.extname(file.path), "png" assert File.extname(file.path), "png"
end end
it "be able to generate a tempfile with the right name with a tilde at the beginning" do it "is able to generate a tempfile with the right name with a tilde at the beginning" do
file = subject.generate("~omg.png") file = subject.generate("~omg.png")
assert File.extname(file.path), "png" assert File.extname(file.path), "png"
end end
it "be able to generate a tempfile with the right name with a tilde at the end" do it "is able to generate a tempfile with the right name with a tilde at the end" do
file = subject.generate("omg.png~") file = subject.generate("omg.png~")
assert File.extname(file.path), "png" assert File.extname(file.path), "png"
end end
it "be able to generate a tempfile from a file with a really long name" do it "is able to generate a tempfile from a file with a really long name" do
filename = "#{"longfilename" * 100}.png" filename = "#{"longfilename" * 100}.png"
file = subject.generate(filename) file = subject.generate(filename)
assert File.extname(file.path), "png" assert File.extname(file.path), "png"
end end
it 'be able to take nothing as a parameter and not error' do it 'is able to take nothing as a parameter and not error' do
file = subject.generate file = subject.generate
assert File.exists?(file.path) assert File.exists?(file.path)
end end
......
...@@ -8,11 +8,11 @@ describe Paperclip::Thumbnail do ...@@ -8,11 +8,11 @@ describe Paperclip::Thumbnail do
after { @tempfile.close } after { @tempfile.close }
it "have its path contain a real extension" do it "has its path contain a real extension" do
assert_equal ".jpg", File.extname(@tempfile.path) assert_equal ".jpg", File.extname(@tempfile.path)
end end
it "be a real Tempfile" do it "is a real Tempfile" do
assert @tempfile.is_a?(::Tempfile) assert @tempfile.is_a?(::Tempfile)
end end
end end
...@@ -24,11 +24,11 @@ describe Paperclip::Thumbnail do ...@@ -24,11 +24,11 @@ describe Paperclip::Thumbnail do
after { @tempfile.close } after { @tempfile.close }
it "not have an extension if not given one" do it "does not have an extension if not given one" do
assert_equal "", File.extname(@tempfile.path) assert_equal "", File.extname(@tempfile.path)
end end
it "still be a real Tempfile" do it "is a real Tempfile" do
assert @tempfile.is_a?(::Tempfile) assert @tempfile.is_a?(::Tempfile)
end end
end end
...@@ -49,12 +49,12 @@ describe Paperclip::Thumbnail do ...@@ -49,12 +49,12 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: args[0]) @thumb = Paperclip::Thumbnail.new(@file, geometry: args[0])
end end
it "start with dimensions of 434x66" do it "starts with dimensions of 434x66" do
cmd = %Q[identify -format "%wx%h" "#{@file.path}"] cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
assert_equal "434x66", `#{cmd}`.chomp assert_equal "434x66", `#{cmd}`.chomp
end end
it "report the correct target geometry" do it "reports the correct target geometry" do
assert_equal args[0], @thumb.target_geometry.to_s assert_equal args[0], @thumb.target_geometry.to_s
end end
...@@ -63,7 +63,7 @@ describe Paperclip::Thumbnail do ...@@ -63,7 +63,7 @@ describe Paperclip::Thumbnail do
@thumb_result = @thumb.make @thumb_result = @thumb.make
end end
it "be the size we expect it to be" do it "is the size we expect it to be" do
cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"] cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
assert_equal args[1], `#{cmd}`.chomp assert_equal args[1], `#{cmd}`.chomp
end end
...@@ -76,7 +76,7 @@ describe Paperclip::Thumbnail do ...@@ -76,7 +76,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#") @thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
end end
it "let us know when a command isn't found versus a processing error" do it "lets us know when a command isn't found versus a processing error" do
old_path = ENV['PATH'] old_path = ENV['PATH']
begin begin
Cocaine::CommandLine.path = '' Cocaine::CommandLine.path = ''
...@@ -92,28 +92,28 @@ describe Paperclip::Thumbnail do ...@@ -92,28 +92,28 @@ describe Paperclip::Thumbnail do
end end
end end
it "report its correct current and target geometries" do it "reports its correct current and target geometries" do
assert_equal "100x50#", @thumb.target_geometry.to_s assert_equal "100x50#", @thumb.target_geometry.to_s
assert_equal "434x66", @thumb.current_geometry.to_s assert_equal "434x66", @thumb.current_geometry.to_s
end end
it "report its correct format" do it "reports its correct format" do
assert_nil @thumb.format assert_nil @thumb.format
end end
it "have whiny turned on by default" do it "has whiny turned on by default" do
assert @thumb.whiny assert @thumb.whiny
end end
it "have convert_options set to nil by default" do it "has convert_options set to nil by default" do
assert_equal nil, @thumb.convert_options assert_equal nil, @thumb.convert_options
end end
it "have source_file_options set to nil by default" do it "has source_file_options set to nil by default" do
assert_equal nil, @thumb.source_file_options assert_equal nil, @thumb.source_file_options
end end
it "send the right command to convert when sent #make" do it "sends the right command to convert when sent #make" do
@thumb.expects(:convert).with do |*arg| @thumb.expects(:convert).with do |*arg|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' && arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]" arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
...@@ -121,13 +121,13 @@ describe Paperclip::Thumbnail do ...@@ -121,13 +121,13 @@ describe Paperclip::Thumbnail do
@thumb.make @thumb.make
end end
it "create the thumbnail when sent #make" do it "creates the thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
end end
it 'properly crop a EXIF-rotated image' do it 'crops a EXIF-rotated image properly' do
file = File.new(fixture_file('rotated.jpg')) file = File.new(fixture_file('rotated.jpg'))
thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#") thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#")
...@@ -144,11 +144,11 @@ describe Paperclip::Thumbnail do ...@@ -144,11 +144,11 @@ describe Paperclip::Thumbnail do
source_file_options: "-strip") source_file_options: "-strip")
end end
it "have source_file_options value set" do it "has source_file_options value set" do
assert_equal ["-strip"], @thumb.source_file_options assert_equal ["-strip"], @thumb.source_file_options
end end
it "send the right command to convert when sent #make" do it "sends the right command to convert when sent #make" do
@thumb.expects(:convert).with do |*arg| @thumb.expects(:convert).with do |*arg|
arg[0] == '-strip :source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' && arg[0] == '-strip :source -auto-orient -resize "x50" -crop "100x50+114+0" +repage :dest' &&
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]" arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
...@@ -156,7 +156,7 @@ describe Paperclip::Thumbnail do ...@@ -156,7 +156,7 @@ describe Paperclip::Thumbnail do
@thumb.make @thumb.make
end end
it "create the thumbnail when sent #make" do it "creates the thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
...@@ -168,7 +168,7 @@ describe Paperclip::Thumbnail do ...@@ -168,7 +168,7 @@ describe Paperclip::Thumbnail do
source_file_options: "-this-aint-no-option") source_file_options: "-this-aint-no-option")
end end
it "error when trying to create the thumbnail" do it "errors when trying to create the thumbnail" do
assert_raises(Paperclip::Error) do assert_raises(Paperclip::Error) do
silence_stream(STDERR) do silence_stream(STDERR) do
@thumb.make @thumb.make
...@@ -185,11 +185,11 @@ describe Paperclip::Thumbnail do ...@@ -185,11 +185,11 @@ describe Paperclip::Thumbnail do
convert_options: "-strip -depth 8") convert_options: "-strip -depth 8")
end end
it "have convert_options value set" do it "has convert_options value set" do
assert_equal %w"-strip -depth 8", @thumb.convert_options assert_equal %w"-strip -depth 8", @thumb.convert_options
end end
it "send the right command to convert when sent #make" do it "sends the right command to convert when sent #make" do
@thumb.expects(:convert).with do |*arg| @thumb.expects(:convert).with do |*arg|
arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' && arg[0] == ':source -auto-orient -resize "x50" -crop "100x50+114+0" +repage -strip -depth 8 :dest' &&
arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]" arg[1][:source] == "#{File.expand_path(@thumb.file.path)}[0]"
...@@ -197,7 +197,7 @@ describe Paperclip::Thumbnail do ...@@ -197,7 +197,7 @@ describe Paperclip::Thumbnail do
@thumb.make @thumb.make
end end
it "create the thumbnail when sent #make" do it "creates the thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
assert_match /100x50/, `identify "#{dst.path}"` assert_match /100x50/, `identify "#{dst.path}"`
end end
...@@ -209,7 +209,7 @@ describe Paperclip::Thumbnail do ...@@ -209,7 +209,7 @@ describe Paperclip::Thumbnail do
convert_options: "-this-aint-no-option") convert_options: "-this-aint-no-option")
end end
it "error when trying to create the thumbnail" do it "errors when trying to create the thumbnail" do
assert_raises(Paperclip::Error) do assert_raises(Paperclip::Error) do
silence_stream(STDERR) do silence_stream(STDERR) do
@thumb.make @thumb.make
...@@ -217,7 +217,7 @@ describe Paperclip::Thumbnail do ...@@ -217,7 +217,7 @@ describe Paperclip::Thumbnail do
end end
end end
it "let us know when a command isn't found versus a processing error" do it "lets us know when a command isn't found versus a processing error" do
old_path = ENV['PATH'] old_path = ENV['PATH']
begin begin
Cocaine::CommandLine.path = '' Cocaine::CommandLine.path = ''
...@@ -242,13 +242,13 @@ describe Paperclip::Thumbnail do ...@@ -242,13 +242,13 @@ describe Paperclip::Thumbnail do
convert_options: "-gravity center -crop \"300x300+0-0\"") convert_options: "-gravity center -crop \"300x300+0-0\"")
end end
it "not get resized by default" do it "does not get resized by default" do
assert !@thumb.transformation_command.include?("-resize") assert !@thumb.transformation_command.include?("-resize")
end end
end end
context "being thumbnailed with default animated option (true)" do context "being thumbnailed with default animated option (true)" do
it "call identify to check for animated images when sent #make" do it "calls identify to check for animated images when sent #make" do
thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#") thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
thumb.expects(:identify).at_least_once.with do |*arg| thumb.expects(:identify).at_least_once.with do |*arg|
arg[0] == '-format %m :file' && arg[0] == '-format %m :file' &&
...@@ -263,7 +263,7 @@ describe Paperclip::Thumbnail do ...@@ -263,7 +263,7 @@ describe Paperclip::Thumbnail do
Object.send(:remove_const, :GeoParser) Object.send(:remove_const, :GeoParser)
end end
it "produce the appropriate transformation_command" do it "produces the appropriate transformation_command" do
GeoParser = Class.new do GeoParser = Class.new do
def self.from_file(file) def self.from_file(file)
new new
...@@ -294,7 +294,7 @@ describe Paperclip::Thumbnail do ...@@ -294,7 +294,7 @@ describe Paperclip::Thumbnail do
Object.send(:remove_const, :GeoParser) Object.send(:remove_const, :GeoParser)
end end
it "produce the appropriate transformation_command" do it "produces the appropriate transformation_command" do
GeoParser = Class.new do GeoParser = Class.new do
def self.parse(s) def self.parse(s)
new new
...@@ -322,7 +322,7 @@ describe Paperclip::Thumbnail do ...@@ -322,7 +322,7 @@ describe Paperclip::Thumbnail do
after { @file.close } after { @file.close }
it "start with two pages with dimensions 612x792" do it "starts with two pages with dimensions 612x792" do
cmd = %Q[identify -format "%wx%h" "#{@file.path}"] cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
assert_equal "612x792"*2, `#{cmd}`.chomp assert_equal "612x792"*2, `#{cmd}`.chomp
end end
...@@ -332,16 +332,16 @@ describe Paperclip::Thumbnail do ...@@ -332,16 +332,16 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png) @thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png)
end end
it "report its correct current and target geometries" do it "reports its correct current and target geometries" do
assert_equal "100x100#", @thumb.target_geometry.to_s assert_equal "100x100#", @thumb.target_geometry.to_s
assert_equal "612x792", @thumb.current_geometry.to_s assert_equal "612x792", @thumb.current_geometry.to_s
end end
it "report its correct format" do it "reports its correct format" do
assert_equal :png, @thumb.format assert_equal :png, @thumb.format
end end
it "create the thumbnail when sent #make" do it "creates the thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
assert_match /100x100/, `identify "#{dst.path}"` assert_match /100x100/, `identify "#{dst.path}"`
end end
...@@ -355,7 +355,7 @@ describe Paperclip::Thumbnail do ...@@ -355,7 +355,7 @@ describe Paperclip::Thumbnail do
after { @file.close } after { @file.close }
it "start with 12 frames with size 100x100" do it "starts with 12 frames with size 100x100" do
cmd = %Q[identify -format "%wx%h" "#{@file.path}"] cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
assert_equal "100x100"*12, `#{cmd}`.chomp assert_equal "100x100"*12, `#{cmd}`.chomp
end end
...@@ -365,7 +365,7 @@ describe Paperclip::Thumbnail do ...@@ -365,7 +365,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg) @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
end end
it "create the single frame thumbnail when sent #make" do it "creates the single frame thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h" "#{dst.path}"] cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
assert_equal "50x50", `#{cmd}`.chomp assert_equal "50x50", `#{cmd}`.chomp
...@@ -377,7 +377,7 @@ describe Paperclip::Thumbnail do ...@@ -377,7 +377,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif) @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
end end
it "create the 12 frames thumbnail when sent #make" do it "creates the 12 frames thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h," "#{dst.path}"] cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
frames = `#{cmd}`.chomp.split(',') frames = `#{cmd}`.chomp.split(',')
...@@ -385,11 +385,11 @@ describe Paperclip::Thumbnail do ...@@ -385,11 +385,11 @@ describe Paperclip::Thumbnail do
assert_frame_dimensions (45..50), frames assert_frame_dimensions (45..50), frames
end end
it "use the -coalesce option" do it "uses the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce" assert_equal @thumb.transformation_command.first, "-coalesce"
end end
it "use the -layers 'optimize' option" do it "uses the -layers 'optimize' option" do
assert_equal @thumb.transformation_command.last, '-layers "optimize"' assert_equal @thumb.transformation_command.last, '-layers "optimize"'
end end
end end
...@@ -399,7 +399,7 @@ describe Paperclip::Thumbnail do ...@@ -399,7 +399,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50") @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
end end
it "create the 12 frames thumbnail when sent #make" do it "creates the 12 frames thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h," "#{dst.path}"] cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
frames = `#{cmd}`.chomp.split(',') frames = `#{cmd}`.chomp.split(',')
...@@ -407,11 +407,11 @@ describe Paperclip::Thumbnail do ...@@ -407,11 +407,11 @@ describe Paperclip::Thumbnail do
assert_frame_dimensions (45..50), frames assert_frame_dimensions (45..50), frames
end end
it "use the -coalesce option" do it "uses the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce" assert_equal @thumb.transformation_command.first, "-coalesce"
end end
it "use the -layers 'optimize' option" do it "uses the -layers 'optimize' option" do
assert_equal @thumb.transformation_command.last, '-layers "optimize"' assert_equal @thumb.transformation_command.last, '-layers "optimize"'
end end
end end
...@@ -422,7 +422,7 @@ describe Paperclip::Thumbnail do ...@@ -422,7 +422,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60") @thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
end end
it "create the 12 frames thumbnail when sent #make" do it "creates the 12 frames thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h," "#{dst.path}"] cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
frames = `#{cmd}`.chomp.split(',') frames = `#{cmd}`.chomp.split(',')
...@@ -430,11 +430,11 @@ describe Paperclip::Thumbnail do ...@@ -430,11 +430,11 @@ describe Paperclip::Thumbnail do
assert_frame_dimensions (55..60), frames assert_frame_dimensions (55..60), frames
end end
it "use the -coalesce option" do it "uses the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce" assert_equal @thumb.transformation_command.first, "-coalesce"
end end
it "use the -layers 'optimize' option" do it "uses the -layers 'optimize' option" do
assert_equal @thumb.transformation_command.last, '-layers "optimize"' assert_equal @thumb.transformation_command.last, '-layers "optimize"'
end end
end end
...@@ -445,7 +445,7 @@ describe Paperclip::Thumbnail do ...@@ -445,7 +445,7 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70") @thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
end end
it "create the 12 frames thumbnail when sent #make" do it "creates the 12 frames thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h," "#{dst.path}"] cmd = %Q[identify -format "%wx%h," "#{dst.path}"]
frames = `#{cmd}`.chomp.split(',') frames = `#{cmd}`.chomp.split(',')
...@@ -453,11 +453,11 @@ describe Paperclip::Thumbnail do ...@@ -453,11 +453,11 @@ describe Paperclip::Thumbnail do
assert_frame_dimensions (60..70), frames assert_frame_dimensions (60..70), frames
end end
it "use the -coalesce option" do it "uses the -coalesce option" do
assert_equal @thumb.transformation_command.first, "-coalesce" assert_equal @thumb.transformation_command.first, "-coalesce"
end end
it "use the -layers 'optimize' option" do it "uses the -layers 'optimize' option" do
assert_equal @thumb.transformation_command.last, '-layers "optimize"' assert_equal @thumb.transformation_command.last, '-layers "optimize"'
end end
end end
...@@ -467,13 +467,13 @@ describe Paperclip::Thumbnail do ...@@ -467,13 +467,13 @@ describe Paperclip::Thumbnail do
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false) @thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
end end
it "output the gif format" do it "outputs the gif format" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify "#{dst.path}"] cmd = %Q[identify "#{dst.path}"]
assert_match /GIF/, `#{cmd}`.chomp assert_match /GIF/, `#{cmd}`.chomp
end end
it "create the single frame thumbnail when sent #make" do it "creates the single frame thumbnail when sent #make" do
dst = @thumb.make dst = @thumb.make
cmd = %Q[identify -format "%wx%h" "#{dst.path}"] cmd = %Q[identify -format "%wx%h" "#{dst.path}"]
assert_equal "50x50", `#{cmd}`.chomp assert_equal "50x50", `#{cmd}`.chomp
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Paperclip::UrlGenerator do describe Paperclip::UrlGenerator do
it "use the given interpolator" do it "uses the given interpolator" do
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -16,7 +16,7 @@ describe Paperclip::UrlGenerator do ...@@ -16,7 +16,7 @@ describe Paperclip::UrlGenerator do
assert mock_interpolator.has_interpolated_style_name?(:style_name) assert mock_interpolator.has_interpolated_style_name?(:style_name)
end end
it "use the default URL when no file is assigned" do it "uses the default URL when no file is assigned" do
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
default_url = "the default url" default_url = "the default url"
...@@ -29,7 +29,7 @@ describe Paperclip::UrlGenerator do ...@@ -29,7 +29,7 @@ describe Paperclip::UrlGenerator do
"expected the interpolator to be passed #{default_url.inspect} but it wasn't" "expected the interpolator to be passed #{default_url.inspect} but it wasn't"
end end
it "execute the default URL lambda when no file is assigned" do it "executes the default URL lambda when no file is assigned" do
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
default_url = lambda {|attachment| "the #{attachment.class.name} default url" } default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
...@@ -42,7 +42,7 @@ describe Paperclip::UrlGenerator do ...@@ -42,7 +42,7 @@ describe Paperclip::UrlGenerator do
%{expected the interpolator to be passed "the MockAttachment default url", but it wasn't} %{expected the interpolator to be passed "the MockAttachment default url", but it wasn't}
end end
it "execute the method named by the symbol as the default URL when no file is assigned" do it "executes the method named by the symbol as the default URL when no file is assigned" do
mock_model = MockModel.new mock_model = MockModel.new
mock_attachment = MockAttachment.new(model: mock_model) mock_attachment = MockAttachment.new(model: mock_model)
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
...@@ -56,7 +56,7 @@ describe Paperclip::UrlGenerator do ...@@ -56,7 +56,7 @@ describe Paperclip::UrlGenerator do
%{expected the interpolator to be passed #{mock_model.to_s}, but it wasn't} %{expected the interpolator to be passed #{mock_model.to_s}, but it wasn't}
end end
it "URL-escape spaces if asked to" do it "URL-escapes spaces if asked to" do
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -68,7 +68,7 @@ describe Paperclip::UrlGenerator do ...@@ -68,7 +68,7 @@ describe Paperclip::UrlGenerator do
assert_equal "the%20expected%20result", result assert_equal "the%20expected%20result", result
end end
it "escape the result of the interpolator using a method on the object, if asked to escape" do it "escapes the result of the interpolator using a method on the object, if asked to escape" do
expected = Class.new do expected = Class.new do
def escape def escape
"the escaped result" "the escaped result"
...@@ -84,7 +84,7 @@ describe Paperclip::UrlGenerator do ...@@ -84,7 +84,7 @@ describe Paperclip::UrlGenerator do
assert_equal "the escaped result", result assert_equal "the escaped result", result
end end
it "leave spaces unescaped as asked to" do it "leaves spaces unescaped as asked to" do
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -96,7 +96,7 @@ describe Paperclip::UrlGenerator do ...@@ -96,7 +96,7 @@ describe Paperclip::UrlGenerator do
assert_equal "the expected result", result assert_equal "the expected result", result
end end
it "default to leaving spaces unescaped" do it "defaults to leaving spaces unescaped" do
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -108,7 +108,7 @@ describe Paperclip::UrlGenerator do ...@@ -108,7 +108,7 @@ describe Paperclip::UrlGenerator do
assert_equal "the expected result", result assert_equal "the expected result", result
end end
it "produce URLs without the updated_at value when the object does not respond to updated_at" do it "produces URLs without the updated_at value when the object does not respond to updated_at" do
expected = "the expected result" expected = "the expected result"
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(responds_to_updated_at: false) mock_attachment = MockAttachment.new(responds_to_updated_at: false)
...@@ -120,7 +120,7 @@ describe Paperclip::UrlGenerator do ...@@ -120,7 +120,7 @@ describe Paperclip::UrlGenerator do
assert_equal expected, result assert_equal expected, result
end end
it "produce URLs without the updated_at value when the updated_at value is nil" do it "produces URLs without the updated_at value when the updated_at value is nil" do
expected = "the expected result" expected = "the expected result"
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(responds_to_updated_at: true, updated_at: nil) mock_attachment = MockAttachment.new(responds_to_updated_at: true, updated_at: nil)
...@@ -132,7 +132,7 @@ describe Paperclip::UrlGenerator do ...@@ -132,7 +132,7 @@ describe Paperclip::UrlGenerator do
assert_equal expected, result assert_equal expected, result
end end
it "produce URLs with the updated_at when it exists" do it "produces URLs with the updated_at when it exists" do
expected = "the expected result" expected = "the expected result"
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -145,7 +145,7 @@ describe Paperclip::UrlGenerator do ...@@ -145,7 +145,7 @@ describe Paperclip::UrlGenerator do
assert_equal "#{expected}?#{updated_at}", result assert_equal "#{expected}?#{updated_at}", result
end end
it "produce URLs with the updated_at when it exists, separated with a & if a ? follow by = already exists" do it "produces URLs with the updated_at when it exists, separated with a & if a ? follow by = already exists" do
expected = "the?expected=result" expected = "the?expected=result"
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -158,7 +158,7 @@ describe Paperclip::UrlGenerator do ...@@ -158,7 +158,7 @@ describe Paperclip::UrlGenerator do
assert_equal "#{expected}&#{updated_at}", result assert_equal "#{expected}&#{updated_at}", result
end end
it "produce URLs without the updated_at when told to do as much" do it "produces URLs without the updated_at when told to do as much" do
expected = "the expected result" expected = "the expected result"
updated_at = 1231231234 updated_at = 1231231234
mock_interpolator = MockInterpolator.new(result: expected) mock_interpolator = MockInterpolator.new(result: expected)
...@@ -171,7 +171,7 @@ describe Paperclip::UrlGenerator do ...@@ -171,7 +171,7 @@ describe Paperclip::UrlGenerator do
assert_equal expected, result assert_equal expected, result
end end
it "produce the correct URL when the instance has a file name" do it "produces the correct URL when the instance has a file name" do
expected = "the expected result" expected = "the expected result"
mock_attachment = MockAttachment.new(original_filename: 'exists') mock_attachment = MockAttachment.new(original_filename: 'exists')
mock_interpolator = MockInterpolator.new mock_interpolator = MockInterpolator.new
......
...@@ -19,7 +19,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -19,7 +19,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -32,7 +32,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -32,7 +32,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "allow avatar_content_type as nil" do it "allows avatar_content_type as nil" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -44,7 +44,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -44,7 +44,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not allow avatar_content_type as nil" do it "does not allow avatar_content_type as nil" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
end end
end end
...@@ -57,12 +57,12 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -57,12 +57,12 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "add error to the base object" do it "adds error to the base object" do
assert @dummy.errors[:avatar].present?, assert @dummy.errors[:avatar].present?,
"Error not added to base attribute" "Error not added to base attribute"
end end
it "add error to base object as a string" do it "adds error to base object as a string" do
expect(@dummy.errors[:avatar].first).to be_a String expect(@dummy.errors[:avatar].first).to be_a String
end end
end end
...@@ -74,7 +74,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -74,7 +74,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not add error to the base object" do it "does not add error to the base object" do
assert @dummy.errors[:avatar].blank?, assert @dummy.errors[:avatar].blank?,
"Error was added to base attribute" "Error was added to base attribute"
end end
...@@ -88,7 +88,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -88,7 +88,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "allow avatar_content_type as blank" do it "allows avatar_content_type as blank" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -100,7 +100,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -100,7 +100,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not allow avatar_content_type as blank" do it "does not allow avatar_content_type as blank" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
end end
end end
...@@ -115,7 +115,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -115,7 +115,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -127,7 +127,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -127,7 +127,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -139,7 +139,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -139,7 +139,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -153,7 +153,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -153,7 +153,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct default error message" do it "sets a correct default error message" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
expect(@dummy.errors[:avatar_content_type]).to include "is invalid" expect(@dummy.errors[:avatar_content_type]).to include "is invalid"
end end
...@@ -166,7 +166,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -166,7 +166,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct default error message" do it "sets a correct default error message" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
expect(@dummy.errors[:avatar_content_type]).to include "is invalid" expect(@dummy.errors[:avatar_content_type]).to include "is invalid"
end end
...@@ -180,7 +180,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -180,7 +180,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct error message" do it "sets a correct error message" do
expect(@dummy.errors[:avatar_content_type]).to include "should be a PNG image" expect(@dummy.errors[:avatar_content_type]).to include "should be a PNG image"
end end
end end
...@@ -192,7 +192,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -192,7 +192,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct error message" do it "sets a correct error message" do
expect(@dummy.errors[:avatar_content_type]).to include "should have content type image/png" expect(@dummy.errors[:avatar_content_type]).to include "should have content type image/png"
end end
end end
...@@ -209,7 +209,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -209,7 +209,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -221,7 +221,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -221,7 +221,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -233,7 +233,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -233,7 +233,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_content_type].blank? assert @dummy.errors[:avatar_content_type].blank?
end end
end end
...@@ -247,7 +247,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -247,7 +247,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct default error message" do it "sets a correct default error message" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
expect(@dummy.errors[:avatar_content_type]).to include "is invalid" expect(@dummy.errors[:avatar_content_type]).to include "is invalid"
end end
...@@ -260,7 +260,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -260,7 +260,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct default error message" do it "sets a correct default error message" do
assert @dummy.errors[:avatar_content_type].present? assert @dummy.errors[:avatar_content_type].present?
expect(@dummy.errors[:avatar_content_type]).to include "is invalid" expect(@dummy.errors[:avatar_content_type]).to include "is invalid"
end end
...@@ -274,7 +274,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -274,7 +274,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct error message" do it "sets a correct error message" do
expect(@dummy.errors[:avatar_content_type]).to include "should not be a PNG image" expect(@dummy.errors[:avatar_content_type]).to include "should not be a PNG image"
end end
end end
...@@ -286,7 +286,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -286,7 +286,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "set a correct error message" do it "sets a correct error message" do
expect(@dummy.errors[:avatar_content_type]).to include "should not have content type image/png" expect(@dummy.errors[:avatar_content_type]).to include "should not have content type image/png"
end end
end end
...@@ -299,23 +299,23 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do ...@@ -299,23 +299,23 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
Dummy.validates_attachment_content_type :avatar, content_type: "image/jpg" Dummy.validates_attachment_content_type :avatar, content_type: "image/jpg"
end end
it "add the validator to the class" do it "adds the validator to the class" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type }
end end
end end
context "given options" do context "given options" do
it "raise argument error if no required argument was given" do it "raises argument error if no required argument was given" do
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
build_validator message: "Some message" build_validator message: "Some message"
end end
end end
it "not raise argument error if :content_type was given" do it "does not raise argument error if :content_type was given" do
build_validator content_type: "image/jpg" build_validator content_type: "image/jpg"
end end
it "not raise argument error if :not was given" do it "does not raise argument error if :not was given" do
build_validator not: "image/jpg" build_validator not: "image/jpg"
end end
end end
......
...@@ -19,17 +19,17 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -19,17 +19,17 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "add error to the base object" do it "adds error to the base object" do
assert @dummy.errors[:avatar].present?, assert @dummy.errors[:avatar].present?,
"Error not added to base attribute" "Error not added to base attribute"
end end
it "add error to base object as a string" do it "adds error to base object as a string" do
expect(@dummy.errors[:avatar].first).to be_a String expect(@dummy.errors[:avatar].first).to be_a String
end end
end end
it "not add error to the base object with a successful validation" do it "does not add error to the base object with a successful validation" do
build_validator matches: /.*\.png$/, allow_nil: false build_validator matches: /.*\.png$/, allow_nil: false
@dummy.stubs(avatar_file_name: "image.png") @dummy.stubs(avatar_file_name: "image.png")
@validator.validate(@dummy) @validator.validate(@dummy)
...@@ -46,7 +46,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -46,7 +46,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
...@@ -58,14 +58,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -58,14 +58,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
end end
context "with a disallowed type" do context "with a disallowed type" do
it "set a correct default error message" do it "sets a correct default error message" do
build_validator matches: /^text\/.*/ build_validator matches: /^text\/.*/
@dummy.stubs(avatar_file_name: "image.jpg") @dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy) @validator.validate(@dummy)
...@@ -74,7 +74,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -74,7 +74,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
expect(@dummy.errors[:avatar_file_name]).to include "is invalid" expect(@dummy.errors[:avatar_file_name]).to include "is invalid"
end end
it "set a correct custom error message" do it "sets a correct custom error message" do
build_validator matches: /.*\.png$/, message: "should be a PNG image" build_validator matches: /.*\.png$/, message: "should be a PNG image"
@dummy.stubs(avatar_file_name: "image.jpg") @dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy) @validator.validate(@dummy)
...@@ -93,7 +93,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -93,7 +93,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
...@@ -105,14 +105,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -105,14 +105,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not set an error message" do it "does not set an error message" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
end end
context "with a disallowed type" do context "with a disallowed type" do
it "set a correct default error message" do it "sets a correct default error message" do
build_validator not: /data.*/ build_validator not: /data.*/
@dummy.stubs(avatar_file_name: "data.txt") @dummy.stubs(avatar_file_name: "data.txt")
@validator.validate(@dummy) @validator.validate(@dummy)
...@@ -121,7 +121,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -121,7 +121,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
expect(@dummy.errors[:avatar_file_name]).to include "is invalid" expect(@dummy.errors[:avatar_file_name]).to include "is invalid"
end end
it "set a correct custom error message" do it "sets a correct custom error message" do
build_validator not: /.*\.png$/, message: "should not be a PNG image" build_validator not: /.*\.png$/, message: "should not be a PNG image"
@dummy.stubs(avatar_file_name: "image.png") @dummy.stubs(avatar_file_name: "image.png")
@validator.validate(@dummy) @validator.validate(@dummy)
...@@ -136,23 +136,23 @@ describe Paperclip::Validators::AttachmentFileNameValidator do ...@@ -136,23 +136,23 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
Dummy.validates_attachment_file_name :avatar, matches: /.*\.jpg$/ Dummy.validates_attachment_file_name :avatar, matches: /.*\.jpg$/
end end
it "add the validator to the class" do it "adds the validator to the class" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
end end
end end
context "given options" do context "given options" do
it "raise argument error if no required argument was given" do it "raises argument error if no required argument was given" do
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
build_validator message: "Some message" build_validator message: "Some message"
end end
end end
it "not raise argument error if :matches was given" do it "does not raise argument error if :matches was given" do
build_validator matches: /.*\.jpg$/ build_validator matches: /.*\.jpg$/
end end
it "not raise argument error if :not was given" do it "does not raise argument error if :not was given" do
build_validator not: /.*\.jpg$/ build_validator not: /.*\.jpg$/
end end
end end
......
...@@ -23,11 +23,11 @@ describe Paperclip::Validators::AttachmentPresenceValidator do ...@@ -23,11 +23,11 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "add error on the attachment" do it "adds error on the attachment" do
assert @dummy.errors[:avatar].present? assert @dummy.errors[:avatar].present?
end end
it "not add an error on the file_name attribute" do it "does not add an error on the file_name attribute" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
...@@ -39,7 +39,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do ...@@ -39,7 +39,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "perform a validation" do it "performs a validation" do
assert @dummy.errors[:avatar].present? assert @dummy.errors[:avatar].present?
end end
end end
...@@ -50,7 +50,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do ...@@ -50,7 +50,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "perform a validation" do it "performs a validation" do
assert @dummy.errors[:avatar].present? assert @dummy.errors[:avatar].present?
end end
end end
...@@ -64,11 +64,11 @@ describe Paperclip::Validators::AttachmentPresenceValidator do ...@@ -64,11 +64,11 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "not add error on the attachment" do it "does not add error on the attachment" do
assert @dummy.errors[:avatar].blank? assert @dummy.errors[:avatar].blank?
end end
it "not add an error on the file_name attribute" do it "does not add an error on the file_name attribute" do
assert @dummy.errors[:avatar_file_name].blank? assert @dummy.errors[:avatar_file_name].blank?
end end
end end
...@@ -78,7 +78,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do ...@@ -78,7 +78,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
Dummy.validates_attachment_presence :avatar Dummy.validates_attachment_presence :avatar
end end
it "add the validator to the class" do it "adds the validator to the class" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
end end
end end
......
...@@ -14,14 +14,14 @@ describe Paperclip::Validators::AttachmentSizeValidator do ...@@ -14,14 +14,14 @@ describe Paperclip::Validators::AttachmentSizeValidator do
def self.should_allow_attachment_file_size(size) def self.should_allow_attachment_file_size(size)
context "when the attachment size is #{size}" do context "when the attachment size is #{size}" do
it "add error to dummy object" do it "adds error to dummy object" do
@dummy.stubs(:avatar_file_size).returns(size) @dummy.stubs(:avatar_file_size).returns(size)
@validator.validate(@dummy) @validator.validate(@dummy)
assert @dummy.errors[:avatar_file_size].blank?, assert @dummy.errors[:avatar_file_size].blank?,
"Expect an error message on :avatar_file_size, got none." "Expect an error message on :avatar_file_size, got none."
end end
it "not add error to the base dummy object" do it "does not add error to the base dummy object" do
assert @dummy.errors[:avatar].blank?, assert @dummy.errors[:avatar].blank?,
"Error added to base attribute" "Error added to base attribute"
end end
...@@ -35,22 +35,22 @@ describe Paperclip::Validators::AttachmentSizeValidator do ...@@ -35,22 +35,22 @@ describe Paperclip::Validators::AttachmentSizeValidator do
@validator.validate(@dummy) @validator.validate(@dummy)
end end
it "add error to dummy object" do it "adds error to dummy object" do
assert @dummy.errors[:avatar_file_size].present?, assert @dummy.errors[:avatar_file_size].present?,
"Unexpected error message on :avatar_file_size" "Unexpected error message on :avatar_file_size"
end end
it "add error to the base dummy object" do it "adds error to the base dummy object" do
assert @dummy.errors[:avatar].present?, assert @dummy.errors[:avatar].present?,
"Error not added to base attribute" "Error not added to base attribute"
end end
it "add error to base object as a string" do it "adds error to base object as a string" do
expect(@dummy.errors[:avatar].first).to be_a String expect(@dummy.errors[:avatar].first).to be_a String
end end
if options[:message] if options[:message]
it "return a correct error message" do it "returns a correct error message" do
expect(@dummy.errors[:avatar_file_size]).to include options[:message] expect(@dummy.errors[:avatar_file_size]).to include options[:message]
end end
end end
...@@ -196,25 +196,25 @@ describe Paperclip::Validators::AttachmentSizeValidator do ...@@ -196,25 +196,25 @@ describe Paperclip::Validators::AttachmentSizeValidator do
Dummy.validates_attachment_size :avatar, in: (5.kilobytes..10.kilobytes) Dummy.validates_attachment_size :avatar, in: (5.kilobytes..10.kilobytes)
end end
it "add the validator to the class" do it "adds the validator to the class" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
end end
end end
context "given options" do context "given options" do
it "raise argument error if no required argument was given" do it "raises argument error if no required argument was given" do
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
build_validator message: "Some message" build_validator message: "Some message"
end end
end end
(Paperclip::Validators::AttachmentSizeValidator::AVAILABLE_CHECKS).each do |argument| (Paperclip::Validators::AttachmentSizeValidator::AVAILABLE_CHECKS).each do |argument|
it "not raise arguemnt error if #{argument} was given" do it "does not raise arguemnt error if #{argument} was given" do
build_validator argument => 5.kilobytes build_validator argument => 5.kilobytes
end end
end end
it "not raise argument error if :in was given" do it "does not raise argument error if :in was given" do
build_validator in: (5.kilobytes..10.kilobytes) build_validator in: (5.kilobytes..10.kilobytes)
end end
end end
......
...@@ -12,11 +12,11 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do ...@@ -12,11 +12,11 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
)) ))
end end
it "be on the attachment without being explicitly added" do it "is on the attachment without being explicitly added" do
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :media_type_spoof_detection } assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :media_type_spoof_detection }
end end
it "return default error message for spoofed media type" do it "returns default error message for spoofed media type" do
build_validator build_validator
file = File.new(fixture_file("5k.png"), "rb") file = File.new(fixture_file("5k.png"), "rb")
@dummy.avatar.assign(file) @dummy.avatar.assign(file)
...@@ -28,7 +28,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do ...@@ -28,7 +28,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
assert_equal "has an extension that does not match its contents", @dummy.errors[:avatar].first assert_equal "has an extension that does not match its contents", @dummy.errors[:avatar].first
end end
it "run when attachment is dirty" do it "runs when attachment is dirty" do
build_validator build_validator
file = File.new(fixture_file("5k.png"), "rb") file = File.new(fixture_file("5k.png"), "rb")
@dummy.avatar.assign(file) @dummy.avatar.assign(file)
...@@ -39,7 +39,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do ...@@ -39,7 +39,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.once } assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.once }
end end
it "not run when attachment is not dirty" do it "does not run when attachment is not dirty" do
Paperclip::MediaTypeSpoofDetector.stubs(:using).never Paperclip::MediaTypeSpoofDetector.stubs(:using).never
@dummy.valid? @dummy.valid?
assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.never } assert_received(Paperclip::MediaTypeSpoofDetector, :using){|e| e.never }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment