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' })
......
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
......
...@@ -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
......
...@@ -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
......
...@@ -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
......
...@@ -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