Commit 71727f49 by Jon Yurek

Give all spec names the correct tense

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