Commit 40010c4d by Jon Yurek

Convert applicable hashes to 1.9 syntax

parent 1f3a7467
......@@ -3,10 +3,10 @@ require 'spec_helper'
describe "Attachment Definitions" do
it 'returns all of the attachments on the class' do
reset_class "Dummy"
Dummy.has_attached_file :avatar, {:path => "abc"}
Dummy.has_attached_file :other_attachment, {:url => "123"}
Dummy.has_attached_file :avatar, {path: "abc"}
Dummy.has_attached_file :other_attachment, {url: "123"}
Dummy.do_not_validate_attachment_file_type :avatar
expected = {:avatar => {:path => "abc"}, :other_attachment => {:url => "123"}}
expected = {avatar: {path: "abc"}, other_attachment: {url: "123"}}
assert_equal expected, Dummy.attachment_definitions
end
......
......@@ -9,7 +9,7 @@ describe 'Attachment Processing' do
it 'process attachments given a valid assignment' do
file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, :content_type => "image/png"
Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles)
......@@ -19,7 +19,7 @@ describe 'Attachment Processing' do
it '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"
Dummy.validates_attachment_content_type :avatar, not: "image/png"
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles).never
......@@ -29,7 +29,7 @@ describe 'Attachment Processing' do
it '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"
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff"
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles).never
......@@ -39,7 +39,7 @@ describe 'Attachment Processing' do
it 'when validation :if clause returns false, allow what would be an invalid assignment' do
invalid_assignment = File.new(fixture_file("5k.png"))
Dummy.validates_attachment_content_type :avatar, :content_type => "image/tiff", :if => lambda{false}
Dummy.validates_attachment_content_type :avatar, content_type: "image/tiff", if: lambda{false}
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles)
......@@ -51,7 +51,7 @@ describe 'Attachment Processing' do
context 'using validates_attachment' do
it 'process attachments given a valid assignment' do
file = File.new(fixture_file("5k.png"))
Dummy.validates_attachment :avatar, :content_type => {:content_type => "image/png"}
Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"}
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles)
......@@ -61,7 +61,7 @@ describe 'Attachment Processing' do
it '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"}
Dummy.validates_attachment :avatar, content_type: {not: "image/png"}
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles).never
......@@ -71,7 +71,7 @@ describe 'Attachment Processing' do
it '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"}
Dummy.validates_attachment :avatar, content_type: {content_type: "image/tiff"}
instance = Dummy.new
attachment = instance.avatar
attachment.expects(:post_process_styles).never
......
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe Paperclip::GeometryDetector do
it 'identify an image and extract its dimensions' do
Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(:make => :correct))
Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(make: :correct))
file = fixture_file("5k.png")
factory = Paperclip::GeometryDetector.new(file)
......@@ -12,7 +12,7 @@ describe Paperclip::GeometryDetector do
end
it 'identify an image and extract its dimensions and orientation' do
Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(:make => :correct))
Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(make: :correct))
file = fixture_file("rotated.jpg")
factory = Paperclip::GeometryDetector.new(file)
......
......@@ -3,10 +3,10 @@ require 'spec_helper'
describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions with no orientation' do
Paperclip::Geometry.stubs(:new).with(
:height => '73',
:width => '434',
:modifier => nil,
:orientation => nil
height: '73',
width: '434',
modifier: nil,
orientation: nil
).returns(:correct)
factory = Paperclip::GeometryParser.new("434x73")
......@@ -17,10 +17,10 @@ describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions with an empty orientation' do
Paperclip::Geometry.stubs(:new).with(
:height => '73',
:width => '434',
:modifier => nil,
:orientation => ''
height: '73',
width: '434',
modifier: nil,
orientation: ''
).returns(:correct)
factory = Paperclip::GeometryParser.new("434x73,")
......@@ -31,10 +31,10 @@ describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions and orientation' do
Paperclip::Geometry.stubs(:new).with(
:height => '200',
:width => '300',
:modifier => nil,
:orientation => '6'
height: '200',
width: '300',
modifier: nil,
orientation: '6'
).returns(:correct)
factory = Paperclip::GeometryParser.new("300x200,6")
......@@ -45,10 +45,10 @@ describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions and modifier' do
Paperclip::Geometry.stubs(:new).with(
:height => '64',
:width => '64',
:modifier => '#',
:orientation => nil
height: '64',
width: '64',
modifier: '#',
orientation: nil
).returns(:correct)
factory = Paperclip::GeometryParser.new("64x64#")
......@@ -59,10 +59,10 @@ describe Paperclip::GeometryParser do
it 'identify an image and extract its dimensions, orientation, and modifier' do
Paperclip::Geometry.stubs(:new).with(
:height => '50',
:width => '100',
:modifier => '>',
:orientation => '7'
height: '50',
width: '100',
modifier: '>',
orientation: '7'
).returns(:correct)
factory = Paperclip::GeometryParser.new("100x50,7>")
......
......@@ -50,7 +50,7 @@ describe Paperclip::Geometry do
end
it "recognize an EXIF orientation and not rotate with auto_orient if not necessary" do
geo = Paperclip::Geometry.new(:width => 1024, :height => 768, :orientation => 1)
geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 1)
assert geo
assert_equal 1024, geo.width
assert_equal 768, geo.height
......@@ -62,7 +62,7 @@ describe Paperclip::Geometry do
end
it "recognize an EXIF orientation and rotate with auto_orient if necessary" do
geo = Paperclip::Geometry.new(:width => 1024, :height => 768, :orientation => 6)
geo = Paperclip::Geometry.new(width: 1024, height: 768, orientation: 6)
assert geo
assert_equal 1024, geo.width
assert_equal 768, geo.height
......@@ -161,7 +161,7 @@ describe Paperclip::Geometry do
end
it "not generate from a file with no path" do
file = mock("file", :path => "")
file = mock("file", path: "")
file.stubs(:respond_to?).with(:path).returns(true)
expect { @geo = Paperclip::Geometry.from_file(file) }.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError)
end
......
......@@ -46,7 +46,7 @@ describe Paperclip::Interpolations do
it "return 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"}})
attachment.expects(:styles).twice.returns({style: {format: "png"}})
[:style, 'style'].each do |style|
assert_equal "png", Paperclip::Interpolations.extension(attachment, style)
......@@ -83,7 +83,7 @@ describe Paperclip::Interpolations do
it "return 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"}})
attachment.expects(:styles).returns({style: {format: "png"}})
interpolations = Paperclip::Interpolations
interpolations.expects(:extension).returns('random')
assert_equal "png", interpolations.content_type_extension(attachment, :style)
......@@ -91,7 +91,7 @@ describe Paperclip::Interpolations do
it "be able to handle numeric style names" do
attachment = mock(
:styles => {:"4" => {:format => :expected_extension}}
styles: {:"4" => {format: :expected_extension}}
)
assert_equal :expected_extension, Paperclip::Interpolations.extension(attachment, 4)
end
......@@ -156,7 +156,7 @@ describe Paperclip::Interpolations do
it "reinterpolate :url" do
attachment = mock
attachment.expects(:url).with(:style, :timestamp => false, :escape => false).returns("1234")
attachment.expects(:url).with(:style, timestamp: false, escape: false).returns("1234")
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
end
......@@ -179,7 +179,7 @@ describe Paperclip::Interpolations do
it "return the filename as basename.extension when format supplied" do
attachment = mock
attachment.expects(:styles).returns({:style => {:format => :png}})
attachment.expects(:styles).returns({style: {format: :png}})
attachment.expects(:original_filename).returns("one.jpg").times(2)
assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
end
......
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe Paperclip::AttachmentAdapter do
before do
rebuild_model :path => "tmp/:class/:attachment/:style/:filename", :styles => {:thumb => '50x50'}
rebuild_model path: "tmp/:class/:attachment/:style/:filename", styles: {thumb: '50x50'}
@attachment = Dummy.new.avatar
end
......
......@@ -11,11 +11,11 @@ describe Paperclip::UploadedFileAdapter do
tempfile.binmode
@file = UploadedFile.new(
:original_filename => "5k.png",
:content_type => "image/x-png-by-browser\r",
:head => "",
:tempfile => tempfile,
:path => tempfile.path
original_filename: "5k.png",
content_type: "image/x-png-by-browser\r",
head: "",
tempfile: tempfile,
path: tempfile.path
)
@subject = Paperclip.io_adapters.for(@file)
end
......@@ -58,10 +58,10 @@ describe Paperclip::UploadedFileAdapter do
class UploadedFile < OpenStruct; end
@file = UploadedFile.new(
:original_filename => "image:restricted.gif",
:content_type => "image/x-png-by-browser",
:head => "",
:path => fixture_file("5k.png")
original_filename: "image:restricted.gif",
content_type: "image/x-png-by-browser",
head: "",
path: fixture_file("5k.png")
)
@subject = Paperclip.io_adapters.for(@file)
end
......@@ -81,10 +81,10 @@ describe Paperclip::UploadedFileAdapter do
class UploadedFile < OpenStruct; end
@file = UploadedFile.new(
:original_filename => "5k.png",
:content_type => "image/x-png-by-browser",
:head => "",
:path => fixture_file("5k.png")
original_filename: "5k.png",
content_type: "image/x-png-by-browser",
head: "",
path: fixture_file("5k.png")
)
@subject = Paperclip.io_adapters.for(@file)
end
......@@ -129,10 +129,10 @@ describe Paperclip::UploadedFileAdapter do
class UploadedFile < OpenStruct; end
@file = UploadedFile.new(
:original_filename => "5k.png",
:content_type => "image/x-png-by-browser",
:head => "",
:path => fixture_file("5k.png")
original_filename: "5k.png",
content_type: "image/x-png-by-browser",
head: "",
path: fixture_file("5k.png")
)
@subject = Paperclip.io_adapters.for(@file)
end
......
......@@ -25,7 +25,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class with a validation that doesn't match" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
end
should_reject_dummy_class
......@@ -33,7 +33,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class with a matching validation" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
end
should_accept_dummy_class
......@@ -42,7 +42,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class with other validations but matching types" do
before do
Dummy.validates_presence_of :title
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
end
should_accept_dummy_class
......@@ -50,7 +50,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class that matches and a matcher that only specifies 'allowing'" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
@matcher = self.class.validate_attachment_content_type(:avatar).
allowing(%w(image/png image/jpeg))
end
......@@ -60,7 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class that does not match and a matcher that only specifies 'allowing'" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
@matcher = self.class.validate_attachment_content_type(:avatar).
allowing(%w(image/png image/jpeg))
end
......@@ -70,7 +70,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class that matches and a matcher that only specifies 'rejecting'" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
@matcher = self.class.validate_attachment_content_type(:avatar).
rejecting(%w(audio/mp3 application/octet-stream))
end
......@@ -80,7 +80,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "given a class that does not match and a matcher that only specifies 'rejecting'" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
@matcher = self.class.validate_attachment_content_type(:avatar).
rejecting(%w(audio/mp3 application/octet-stream))
end
......@@ -91,7 +91,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
context "using an :if to control the validation" do
before do
Dummy.class_eval do
validates_attachment_content_type :avatar, :content_type => %r{image/*} , :if => :go
validates_attachment_content_type :avatar, content_type: %r{image/*} , if: :go
attr_accessor :go
end
@matcher = self.class.validate_attachment_content_type(:avatar).
......
......@@ -36,7 +36,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
Dummy.class_eval do
validates_attachment_presence :avatar
validates_attachment_content_type :avatar, :content_type => 'image/gif'
validates_attachment_content_type :avatar, content_type: 'image/gif'
end
@dummy = Dummy.new
......@@ -52,7 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentPresenceMatcher do
context "using an :if to control the validation" do
before do
Dummy.class_eval do
validates_attachment_presence :avatar, :if => :go
validates_attachment_presence :avatar, if: :go
attr_accessor :go
end
@dummy = Dummy.new
......
......@@ -25,17 +25,17 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
end
context "given a class with a validation that's too high" do
before { Dummy.validates_attachment_size :avatar, :in => 256..2048 }
before { Dummy.validates_attachment_size :avatar, in: 256..2048 }
should_reject_dummy_class
end
context "given a class with a validation that's too low" do
before { Dummy.validates_attachment_size :avatar, :in => 0..1024 }
before { Dummy.validates_attachment_size :avatar, in: 0..1024 }
should_reject_dummy_class
end
context "given a class with a validation that matches" do
before { Dummy.validates_attachment_size :avatar, :in => 256..1024 }
before { Dummy.validates_attachment_size :avatar, in: 256..1024 }
should_accept_dummy_class
end
end
......@@ -46,12 +46,12 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
end
context "given a class with an upper limit" do
before { Dummy.validates_attachment_size :avatar, :less_than => 1 }
before { Dummy.validates_attachment_size :avatar, less_than: 1 }
should_accept_dummy_class
end
context "given a class with a lower limit" do
before { Dummy.validates_attachment_size :avatar, :greater_than => 1 }
before { Dummy.validates_attachment_size :avatar, greater_than: 1 }
should_accept_dummy_class
end
end
......@@ -59,7 +59,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
context "using an :if to control the validation" do
before do
Dummy.class_eval do
validates_attachment_size :avatar, :greater_than => 1024, :if => :go
validates_attachment_size :avatar, greater_than: 1024, if: :go
attr_accessor :go
end
@dummy = Dummy.new
......@@ -79,7 +79,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentSizeMatcher do
context "post processing" do
before do
Dummy.validates_attachment_size :avatar, :greater_than => 1024
Dummy.validates_attachment_size :avatar, greater_than: 1024
@dummy = Dummy.new
@matcher = self.class.validate_attachment_size(:avatar).greater_than(1024)
......
......@@ -19,41 +19,41 @@ describe 'Missing Attachment Styles' do
it "be 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]}}
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
rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles!
expected_hash = { :Dummy => {:avatar => [:big, :croppable]}}
expected_hash = { Dummy: {avatar: [:big, :croppable]}}
assert_equal expected_hash, YAML.load_file(Paperclip.registered_attachments_styles_path)
end
it "be able to read registered attachment styles from file" do
rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles!
expected_hash = { :Dummy => {:avatar => [:big, :croppable]}}
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
rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles!
rebuild_model :styles => {:thumb => 'x100', :export => 'x400>', :croppable => '600x600>', :big => '1000x1000>'}
expected_hash = { :Dummy => {:avatar => [:export, :thumb]} }
rebuild_model styles: {thumb: 'x100', export: 'x400>', croppable: '600x600>', big: '1000x1000>'}
expected_hash = { Dummy: {avatar: [:export, :thumb]} }
assert_equal expected_hash, Paperclip.missing_attachments_styles
ActiveRecord::Base.connection.create_table :books, :force => true
ActiveRecord::Base.connection.create_table :books, force: true
class ::Book < ActiveRecord::Base
has_attached_file :cover, :styles => {:small => 'x100', :large => '1000x1000>'}
has_attached_file :sample, :styles => {:thumb => 'x100'}
has_attached_file :cover, styles: {small: 'x100', large: '1000x1000>'}
has_attached_file :sample, styles: {thumb: 'x100'}
end
expected_hash = {
:Dummy => {:avatar => [:export, :thumb]},
:Book => {:sample => [:thumb], :cover => [:large, :small]}
Dummy: {avatar: [:export, :thumb]},
Book: {sample: [:thumb], cover: [:large, :small]}
}
assert_equal expected_hash, Paperclip.missing_attachments_styles
Paperclip.save_current_attachments_styles!
......@@ -61,15 +61,15 @@ describe 'Missing Attachment Styles' do
end
it "be able to calculate differences when a new attachment is added to a model" do
rebuild_model :styles => {:croppable => '600x600>', :big => '1000x1000>'}
rebuild_model styles: {croppable: '600x600>', big: '1000x1000>'}
Paperclip.save_current_attachments_styles!
class ::Dummy
has_attached_file :photo, :styles => {:small => 'x100', :large => '1000x1000>'}
has_attached_file :photo, styles: {small: 'x100', large: '1000x1000>'}
end
expected_hash = {
:Dummy => {:photo => [:large, :small]}
Dummy: {photo: [:large, :small]}
}
assert_equal expected_hash, Paperclip.missing_attachments_styles
Paperclip.save_current_attachments_styles!
......@@ -78,7 +78,7 @@ describe 'Missing Attachment Styles' do
# It's impossible to build styles hash without loading from database whole bunch of records
it "skip lambda-styles" do
rebuild_model :styles => lambda{ |attachment| attachment.instance.other == 'a' ? {:thumb => "50x50#"} : {:large => "400x400"} }
rebuild_model styles: lambda{ |attachment| attachment.instance.other == 'a' ? {thumb: "50x50#"} : {large: "400x400"} }
assert_equal Hash.new, Paperclip.send(:current_attachments_styles)
end
end
......@@ -61,7 +61,7 @@ describe Paperclip do
context "Calling Paperclip.run with a logger" do
it "pass 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))
Cocaine::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
Paperclip.run("convert", "stuff")
end
end
......@@ -69,9 +69,9 @@ describe Paperclip do
context "Paperclip.each_instance_with_attachment" do
before do
@file = File.new(fixture_file("5k.png"), 'rb')
d1 = Dummy.create(:avatar => @file)
d1 = Dummy.create(avatar: @file)
d2 = Dummy.create
d3 = Dummy.create(:avatar => @file)
d3 = Dummy.create(avatar: @file)
@expected = [d1, d3]
end
......@@ -109,7 +109,7 @@ describe Paperclip do
context "An ActiveRecord model with an 'avatar' attachment" do
before do
rebuild_model :path => "tmp/:class/omg/:style.:extension"
rebuild_model path: "tmp/:class/omg/:style.:extension"
@file = File.new(fixture_file("5k.png"), 'rb')
end
......@@ -133,8 +133,8 @@ describe Paperclip do
end
it "not assign the avatar on mass-set" do
@dummy.attributes = { :other => "I'm set!",
:avatar => @file }
@dummy.attributes = { other: "I'm set!",
avatar: @file }
assert_equal "I'm set!", @dummy.other
assert ! @dummy.avatar?
......@@ -157,7 +157,7 @@ describe Paperclip do
it "be able to use the attachment from the subclass" do
assert_nothing_raised do
@subdummy = SubDummy.create(:avatar => @file)
@subdummy = SubDummy.create(avatar: @file)
end
end
......
......@@ -19,7 +19,7 @@ describe Paperclip::Schema do
ActiveSupport::Deprecation.silenced = false
end
it "create attachment columns" do
Dummy.connection.create_table :dummies, :force => true do |t|
Dummy.connection.create_table :dummies, force: true do |t|
ActiveSupport::Deprecation.silence do
t.has_attached_file :avatar
end
......@@ -35,7 +35,7 @@ describe Paperclip::Schema do
end
it "display deprecation warning" do
Dummy.connection.create_table :dummies, :force => true do |t|
Dummy.connection.create_table :dummies, force: true do |t|
assert_deprecated do
t.has_attached_file :avatar
end
......@@ -45,7 +45,7 @@ describe Paperclip::Schema do
context "using #attachment" do
before do
Dummy.connection.create_table :dummies, :force => true do |t|
Dummy.connection.create_table :dummies, force: true do |t|
t.attachment :avatar
end
rebuild_class
......@@ -64,7 +64,7 @@ describe Paperclip::Schema do
context "within schema statement" do
before do
Dummy.connection.create_table :dummies, :force => true
Dummy.connection.create_table :dummies, force: true
end
context "migrating up" do
......
......@@ -4,7 +4,7 @@ describe Paperclip::Storage::Filesystem do
context "Filesystem" do
context "normal file" do
before do
rebuild_model :styles => { :thumbnail => "25x25#" }
rebuild_model styles: { thumbnail: "25x25#" }
@dummy = Dummy.create!
@file = File.open(fixture_file('5k.png'))
......@@ -53,7 +53,7 @@ describe Paperclip::Storage::Filesystem do
context "with file that has space in file name" do
before do
rebuild_model :styles => { :thumbnail => "25x25#" }
rebuild_model styles: { thumbnail: "25x25#" }
@dummy = Dummy.create!
@file = File.open(fixture_file('spaced file.png'))
......
......@@ -4,13 +4,13 @@ unless ENV["S3_BUCKET"].blank?
describe Paperclip::Storage::S3, 'Live S3' do
context "when assigning an S3 attachment directly to another model" do
before do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => {
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secre_access_key => ENV['AWS_SECRET_ACCESS_KEY']
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
storage: :s3,
bucket: ENV["S3_BUCKET"],
path: ":class/:attachment/:id/:style.:extension",
s3_credentials: {
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
@file = File.new(fixture_file("5k.png"))
......@@ -41,13 +41,13 @@ unless ENV["S3_BUCKET"].blank?
context "Generating an expiring url on a nonexistant attachment" do
before do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => {
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secre_access_key => ENV['AWS_SECRET_ACCESS_KEY']
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
storage: :s3,
bucket: ENV["S3_BUCKET"],
path: ":class/:attachment/:id/:style.:extension",
s3_credentials: {
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
@dummy = Dummy.new
......@@ -60,13 +60,13 @@ unless ENV["S3_BUCKET"].blank?
context "Using S3 for real, an attachment with S3 storage" do
before do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => {
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secre_access_key => ENV['AWS_SECRET_ACCESS_KEY']
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
storage: :s3,
bucket: ENV["S3_BUCKET"],
path: ":class/:attachment/:id/:style.:extension",
s3_credentials: {
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
Dummy.delete_all
......@@ -102,12 +102,12 @@ unless ENV["S3_BUCKET"].blank?
context "An attachment that uses S3 for storage and has spaces in file name" do
before do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:s3_credentials => {
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secre_access_key => ENV['AWS_SECRET_ACCESS_KEY']
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
storage: :s3,
bucket: ENV["S3_BUCKET"],
s3_credentials: {
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
Dummy.delete_all
......@@ -142,15 +142,15 @@ unless ENV["S3_BUCKET"].blank?
context "An attachment that uses S3 for storage and uses AES256 encryption" do
before do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => {
:aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:aws_secre_access_key => ENV['AWS_SECRET_ACCESS_KEY']
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
storage: :s3,
bucket: ENV["S3_BUCKET"],
path: ":class/:attachment/:id/:style.:extension",
s3_credentials: {
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
},
:s3_server_side_encryption => :aes256
s3_server_side_encryption: :aes256
Dummy.delete_all
@dummy = Dummy.new
......
......@@ -4,9 +4,9 @@ require 'spec_helper'
describe Paperclip::Style do
context "A style rule" do
before do
@attachment = attachment :path => ":basename.:extension",
:styles => { :foo => {:geometry => "100x100#", :format => :png} },
:whiny => true
@attachment = attachment path: ":basename.:extension",
styles: { foo: {geometry: "100x100#", format: :png} },
whiny: true
@style = @attachment.styles[:foo]
end
......@@ -38,15 +38,15 @@ describe Paperclip::Style do
context "A style rule with properties supplied as procs" do
before do
@attachment = attachment :path => ":basename.:extension",
:whiny_thumbnails => true,
:processors => lambda {|a| [:test]},
:styles => {
:foo => lambda{|a| "300x300#"},
:bar => {
:geometry => lambda{|a| "300x300#"},
:convert_options => lambda{|a| "-do_stuff"},
:source_file_options => lambda{|a| "-do_extra_stuff"}
@attachment = attachment path: ":basename.:extension",
whiny_thumbnails: true,
processors: lambda {|a| [:test]},
styles: {
foo: lambda{|a| "300x300#"},
bar: {
geometry: lambda{|a| "300x300#"},
convert_options: lambda{|a| "-do_stuff"},
source_file_options: lambda{|a| "-do_extra_stuff"}
}
}
end
......@@ -65,10 +65,10 @@ describe Paperclip::Style do
before do
styles = {}
styles[:aslist] = ["100x100", :png]
styles[:ashash] = {:geometry => "100x100", :format => :png}
styles[:ashash] = {geometry: "100x100", format: :png}
styles[:asstring] = "100x100"
@attachment = attachment :path => ":basename.:extension",
:styles => styles
@attachment = attachment path: ":basename.:extension",
styles: styles
end
it "have the right number of styles" do
......@@ -101,17 +101,17 @@ describe Paperclip::Style do
context "An attachment with :convert_options" do
it "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"}
@attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"},
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
@attachment.expects(:extra_options_for).never
@style = @attachment.styles[:thumb]
end
it "call 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"}
@attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"},
convert_options: {all: "-do_stuff", thumb: "-thumbnailize"}
@style = @attachment.styles[:thumb]
@file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg")
......@@ -123,17 +123,17 @@ describe Paperclip::Style do
context "An attachment with :source_file_options" do
it "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"}
@attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"},
source_file_options: {all: "-density 400", thumb: "-depth 8"}
@attachment.expects(:extra_source_file_options_for).never
@style = @attachment.styles[:thumb]
end
it "call 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"}
@attachment = attachment path: ":basename.:extension",
styles: {thumb: "100x100", large: "400x400"},
source_file_options: {all: "-density 400", thumb: "-depth 8"}
@style = @attachment.styles[:thumb]
@file = StringIO.new("...")
@file.stubs(:original_filename).returns("file.jpg")
......@@ -145,15 +145,15 @@ describe Paperclip::Style do
context "A style rule with its own :processors" do
before do
@attachment = attachment :path => ":basename.:extension",
:styles => {
:foo => {
:geometry => "100x100#",
:format => :png,
:processors => [:test]
@attachment = attachment path: ":basename.:extension",
styles: {
foo: {
geometry: "100x100#",
format: :png,
processors: [:test]
}
},
:processors => [:thumbnail]
processors: [:thumbnail]
@style = @attachment.styles[:foo]
end
......@@ -170,15 +170,15 @@ describe Paperclip::Style do
context "A style rule with :processors supplied as procs" do
before do
@attachment = attachment :path => ":basename.:extension",
:styles => {
:foo => {
:geometry => "100x100#",
:format => :png,
:processors => lambda{|a| [:test]}
@attachment = attachment path: ":basename.:extension",
styles: {
foo: {
geometry: "100x100#",
format: :png,
processors: lambda{|a| [:test]}
}
},
:processors => [:thumbnail]
processors: [:thumbnail]
end
it "defer processing of procs until they are needed" do
......@@ -192,12 +192,12 @@ describe Paperclip::Style do
context "An attachment with :convert_options and :source_file_options in :styles" do
before do
@attachment = attachment :path => ":basename.:extension",
:styles => {
:thumb => "100x100",
:large => {:geometry => "400x400",
:convert_options => "-do_stuff",
:source_file_options => "-do_extra_stuff"
@attachment = attachment path: ":basename.:extension",
styles: {
thumb: "100x100",
large: {geometry: "400x400",
convert_options: "-do_stuff",
source_file_options: "-do_extra_stuff"
}
}
@file = StringIO.new("...")
......@@ -217,13 +217,13 @@ describe Paperclip::Style do
context "A style rule supplied with default format" do
before do
@attachment = attachment :default_format => :png,
:styles => {
:asstring => "300x300#",
:aslist => ["300x300#", :jpg],
:ashash => {
:geometry => "300x300#",
:convert_options => "-do_stuff"
@attachment = attachment default_format: :png,
styles: {
asstring: "300x300#",
aslist: ["300x300#", :jpg],
ashash: {
geometry: "300x300#",
convert_options: "-do_stuff"
}
}
end
......
......@@ -46,7 +46,7 @@ describe Paperclip::Thumbnail do
].each do |args|
context "being thumbnailed with a geometry of #{args[0]}" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
@thumb = Paperclip::Thumbnail.new(@file, geometry: args[0])
end
it "start with dimensions of 434x66" do
......@@ -73,7 +73,7 @@ describe Paperclip::Thumbnail do
context "being thumbnailed at 100x50 with cropping" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
end
it "let us know when a command isn't found versus a processing error" do
......@@ -129,19 +129,19 @@ describe Paperclip::Thumbnail do
it 'properly crop a EXIF-rotated image' do
file = File.new(fixture_file('rotated.jpg'))
thumb = Paperclip::Thumbnail.new(file, :geometry => "50x50#")
thumb = Paperclip::Thumbnail.new(file, geometry: "50x50#")
output_file = thumb.make
command = Cocaine::CommandLine.new("identify", "-format %wx%h :file")
assert_equal "50x50", command.run(:file => output_file.path).strip
assert_equal "50x50", command.run(file: output_file.path).strip
end
context "being thumbnailed with source file options set" do
before do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:source_file_options => "-strip")
geometry: "100x50#",
source_file_options: "-strip")
end
it "have source_file_options value set" do
......@@ -164,8 +164,8 @@ describe Paperclip::Thumbnail do
context "redefined to have bad source_file_options setting" do
before do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:source_file_options => "-this-aint-no-option")
geometry: "100x50#",
source_file_options: "-this-aint-no-option")
end
it "error when trying to create the thumbnail" do
......@@ -181,8 +181,8 @@ describe Paperclip::Thumbnail do
context "being thumbnailed with convert options set" do
before do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:convert_options => "-strip -depth 8")
geometry: "100x50#",
convert_options: "-strip -depth 8")
end
it "have convert_options value set" do
......@@ -205,8 +205,8 @@ describe Paperclip::Thumbnail do
context "redefined to have bad convert_options setting" do
before do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "100x50#",
:convert_options => "-this-aint-no-option")
geometry: "100x50#",
convert_options: "-this-aint-no-option")
end
it "error when trying to create the thumbnail" do
......@@ -238,8 +238,8 @@ describe Paperclip::Thumbnail do
context "being thumbnailed with a blank geometry string" do
before do
@thumb = Paperclip::Thumbnail.new(@file,
:geometry => "",
:convert_options => "-gravity center -crop \"300x300+0-0\"")
geometry: "",
convert_options: "-gravity center -crop \"300x300+0-0\"")
end
it "not get resized by default" do
......@@ -249,7 +249,7 @@ describe Paperclip::Thumbnail do
context "being thumbnailed with default animated option (true)" do
it "call identify to check for animated images when sent #make" do
thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
thumb = Paperclip::Thumbnail.new(@file, geometry: "100x50#")
thumb.expects(:identify).at_least_once.with do |*arg|
arg[0] == '-format %m :file' &&
arg[1][:file] == "#{File.expand_path(thumb.file.path)}[0]"
......@@ -274,7 +274,7 @@ describe Paperclip::Thumbnail do
end
end
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :file_geometry_parser => ::GeoParser)
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', file_geometry_parser: ::GeoParser)
transformation_command = thumb.transformation_command
......@@ -305,7 +305,7 @@ describe Paperclip::Thumbnail do
end
end
thumb = Paperclip::Thumbnail.new(@file, :geometry => '50x50', :string_geometry_parser => ::GeoParser)
thumb = Paperclip::Thumbnail.new(@file, geometry: '50x50', string_geometry_parser: ::GeoParser)
transformation_command = thumb.transformation_command
......@@ -329,7 +329,7 @@ describe Paperclip::Thumbnail do
context "being thumbnailed at 100x100 with cropping" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x100#", :format => :png)
@thumb = Paperclip::Thumbnail.new(@file, geometry: "100x100#", format: :png)
end
it "report its correct current and target geometries" do
......@@ -362,7 +362,7 @@ describe Paperclip::Thumbnail do
context "with static output" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :jpg)
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :jpg)
end
it "create the single frame thumbnail when sent #make" do
......@@ -374,7 +374,7 @@ describe Paperclip::Thumbnail do
context "with animated output format" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :format => :gif)
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
end
it "create the 12 frames thumbnail when sent #make" do
......@@ -396,7 +396,7 @@ describe Paperclip::Thumbnail do
context "with omitted output format" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50")
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50")
end
it "create the 12 frames thumbnail when sent #make" do
......@@ -419,7 +419,7 @@ describe Paperclip::Thumbnail do
context "with unidentified source format" do
before do
@unidentified_file = File.new(fixture_file("animated.unknown"), 'rb')
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "60x60")
@thumb = Paperclip::Thumbnail.new(@file, geometry: "60x60")
end
it "create the 12 frames thumbnail when sent #make" do
......@@ -442,7 +442,7 @@ describe Paperclip::Thumbnail do
context "with no source format" do
before do
@unidentified_file = File.new(fixture_file("animated"), 'rb')
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "70x70")
@thumb = Paperclip::Thumbnail.new(@file, geometry: "70x70")
end
it "create the 12 frames thumbnail when sent #make" do
......@@ -464,7 +464,7 @@ describe Paperclip::Thumbnail do
context "with animated option set to false" do
before do
@thumb = Paperclip::Thumbnail.new(@file, :geometry => "50x50", :animated => false)
@thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", animated: false)
end
it "output the gif format" do
......
......@@ -5,10 +5,10 @@ describe Paperclip::UrlGenerator do
it "use the given interpolator" do
expected = "the expected result"
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected)
mock_interpolator = MockInterpolator.new(result: expected)
url_generator = Paperclip::UrlGenerator.new(mock_attachment,
{ :interpolator => mock_interpolator })
{ interpolator: mock_interpolator })
result = url_generator.for(:style_name, {})
assert_equal expected, result
......@@ -20,7 +20,7 @@ describe Paperclip::UrlGenerator do
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new
default_url = "the default url"
options = { :interpolator => mock_interpolator, :default_url => default_url}
options = { interpolator: mock_interpolator, default_url: default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
......@@ -33,7 +33,7 @@ describe Paperclip::UrlGenerator do
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new
default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
options = { :interpolator => mock_interpolator, :default_url => default_url}
options = { interpolator: mock_interpolator, default_url: default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
......@@ -44,10 +44,10 @@ describe Paperclip::UrlGenerator do
it "execute 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_attachment = MockAttachment.new(model: mock_model)
mock_interpolator = MockInterpolator.new
default_url = :to_s
options = { :interpolator => mock_interpolator, :default_url => default_url}
options = { interpolator: mock_interpolator, default_url: default_url}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
......@@ -59,11 +59,11 @@ describe Paperclip::UrlGenerator do
it "URL-escape spaces if asked to" do
expected = "the expected result"
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => true})
result = url_generator.for(:style_name, {escape: true})
assert_equal "the%20expected%20result", result
end
......@@ -75,11 +75,11 @@ describe Paperclip::UrlGenerator do
end
end.new
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => true})
result = url_generator.for(:style_name, {escape: true})
assert_equal "the escaped result", result
end
......@@ -87,11 +87,11 @@ describe Paperclip::UrlGenerator do
it "leave spaces unescaped as asked to" do
expected = "the expected result"
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:escape => false})
result = url_generator.for(:style_name, {escape: false})
assert_equal "the expected result", result
end
......@@ -99,8 +99,8 @@ describe Paperclip::UrlGenerator do
it "default to leaving spaces unescaped" do
expected = "the expected result"
mock_attachment = MockAttachment.new
mock_interpolator = MockInterpolator.new(:result => expected)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {})
......@@ -110,24 +110,24 @@ describe Paperclip::UrlGenerator do
it "produce 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)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(responds_to_updated_at: false)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true})
result = url_generator.for(:style_name, {timestamp: true})
assert_equal expected, result
end
it "produce 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)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(responds_to_updated_at: true, updated_at: nil)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true})
result = url_generator.for(:style_name, {timestamp: true})
assert_equal expected, result
end
......@@ -135,12 +135,12 @@ describe Paperclip::UrlGenerator do
it "produce URLs with the updated_at when it exists" do
expected = "the expected result"
updated_at = 1231231234
mock_interpolator = MockInterpolator.new(:result => expected)
mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(updated_at: updated_at)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true})
result = url_generator.for(:style_name, {timestamp: true})
assert_equal "#{expected}?#{updated_at}", result
end
......@@ -148,12 +148,12 @@ describe Paperclip::UrlGenerator do
it "produce 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)
mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(updated_at: updated_at)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => true})
result = url_generator.for(:style_name, {timestamp: true})
assert_equal "#{expected}&#{updated_at}", result
end
......@@ -161,21 +161,21 @@ describe Paperclip::UrlGenerator do
it "produce 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)
mock_attachment = MockAttachment.new(:updated_at => updated_at)
options = { :interpolator => mock_interpolator }
mock_interpolator = MockInterpolator.new(result: expected)
mock_attachment = MockAttachment.new(updated_at: updated_at)
options = { interpolator: mock_interpolator }
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
result = url_generator.for(:style_name, {:timestamp => false})
result = url_generator.for(:style_name, {timestamp: false})
assert_equal expected, result
end
it "produce the correct URL when the instance has a file name" do
expected = "the expected result"
mock_attachment = MockAttachment.new(:original_filename => 'exists')
mock_attachment = MockAttachment.new(original_filename: 'exists')
mock_interpolator = MockInterpolator.new
options = { :interpolator => mock_interpolator, :url => expected}
options = { interpolator: mock_interpolator, url: expected}
url_generator = Paperclip::UrlGenerator.new(mock_attachment, options)
url_generator.for(:style_name, {})
......
......@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
def build_validator(options)
@validator = Paperclip::Validators::AttachmentFileNameValidator.new(options.merge(
:attributes => :avatar
attributes: :avatar
))
end
context "with a failing validation" do
before do
build_validator :matches => /.*\.png$/, :allow_nil => false
@dummy.stubs(:avatar_file_name => "data.txt")
build_validator matches: /.*\.png$/, allow_nil: false
@dummy.stubs(avatar_file_name: "data.txt")
@validator.validate(@dummy)
end
......@@ -30,8 +30,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
it "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")
build_validator matches: /.*\.png$/, allow_nil: false
@dummy.stubs(avatar_file_name: "image.png")
@validator.validate(@dummy)
assert @dummy.errors[:avatar].blank?, "Error was added to base attribute"
......@@ -41,8 +41,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "with an allowed type" do
context "as a single regexp" do
before do
build_validator :matches => /.*\.jpg$/
@dummy.stubs(:avatar_file_name => "image.jpg")
build_validator matches: /.*\.jpg$/
@dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy)
end
......@@ -53,8 +53,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "as a list" do
before do
build_validator :matches => [/.*\.png$/, /.*\.jpe?g$/]
@dummy.stubs(:avatar_file_name => "image.jpg")
build_validator matches: [/.*\.png$/, /.*\.jpe?g$/]
@dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy)
end
......@@ -66,8 +66,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "with a disallowed type" do
it "set a correct default error message" do
build_validator :matches => /^text\/.*/
@dummy.stubs(:avatar_file_name => "image.jpg")
build_validator matches: /^text\/.*/
@dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy)
assert @dummy.errors[:avatar_file_name].present?
......@@ -75,8 +75,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
it "set a correct custom error message" do
build_validator :matches => /.*\.png$/, :message => "should be a PNG image"
@dummy.stubs(:avatar_file_name => "image.jpg")
build_validator matches: /.*\.png$/, message: "should be a PNG image"
@dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy)
expect(@dummy.errors[:avatar_file_name]).to include "should be a PNG image"
......@@ -88,8 +88,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "with an allowed type" do
context "as a single regexp" do
before do
build_validator :not => /^text\/.*/
@dummy.stubs(:avatar_file_name => "image.jpg")
build_validator not: /^text\/.*/
@dummy.stubs(avatar_file_name: "image.jpg")
@validator.validate(@dummy)
end
......@@ -100,8 +100,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "as a list" do
before do
build_validator :not => [/.*\.png$/, /.*\.jpe?g$/]
@dummy.stubs(:avatar_file_name => "image.gif")
build_validator not: [/.*\.png$/, /.*\.jpe?g$/]
@dummy.stubs(avatar_file_name: "image.gif")
@validator.validate(@dummy)
end
......@@ -113,8 +113,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "with a disallowed type" do
it "set a correct default error message" do
build_validator :not => /data.*/
@dummy.stubs(:avatar_file_name => "data.txt")
build_validator not: /data.*/
@dummy.stubs(avatar_file_name: "data.txt")
@validator.validate(@dummy)
assert @dummy.errors[:avatar_file_name].present?
......@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
end
it "set a correct custom error message" do
build_validator :not => /.*\.png$/, :message => "should not be a PNG image"
@dummy.stubs(:avatar_file_name => "image.png")
build_validator not: /.*\.png$/, message: "should not be a PNG image"
@dummy.stubs(avatar_file_name: "image.png")
@validator.validate(@dummy)
expect(@dummy.errors[:avatar_file_name]).to include "should not be a PNG image"
......@@ -133,7 +133,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "using the helper" do
before do
Dummy.validates_attachment_file_name :avatar, :matches => /.*\.jpg$/
Dummy.validates_attachment_file_name :avatar, matches: /.*\.jpg$/
end
it "add the validator to the class" do
......@@ -144,16 +144,16 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
context "given options" do
it "raise argument error if no required argument was given" do
assert_raises(ArgumentError) do
build_validator :message => "Some message"
build_validator message: "Some message"
end
end
it "not raise argument error if :matches was given" do
build_validator :matches => /.*\.jpg$/
build_validator matches: /.*\.jpg$/
end
it "not raise argument error if :not was given" do
build_validator :not => /.*\.jpg$/
build_validator not: /.*\.jpg$/
end
end
end
......
......@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
def build_validator(options={})
@validator = Paperclip::Validators::AttachmentPresenceValidator.new(options.merge(
:attributes => :avatar
attributes: :avatar
))
end
......@@ -35,7 +35,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
context "with :if option" do
context "returning true" do
before do
build_validator :if => true
build_validator if: true
@validator.validate(@dummy)
end
......@@ -46,7 +46,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
context "returning false" do
before do
build_validator :if => false
build_validator if: false
@validator.validate(@dummy)
end
......
......@@ -8,7 +8,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
def build_validator(options)
@validator = Paperclip::Validators::AttachmentSizeValidator.new(options.merge(
:attributes => :avatar
attributes: :avatar
))
end
......@@ -60,7 +60,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "with :in option" do
context "as a range" do
before do
build_validator :in => (5.kilobytes..10.kilobytes)
build_validator in: (5.kilobytes..10.kilobytes)
end
should_allow_attachment_file_size(7.kilobytes)
......@@ -70,7 +70,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "as a proc" do
before do
build_validator :in => lambda { |avatar| (5.kilobytes..10.kilobytes) }
build_validator in: lambda { |avatar| (5.kilobytes..10.kilobytes) }
end
should_allow_attachment_file_size(7.kilobytes)
......@@ -82,7 +82,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "with :greater_than option" do
context "as number" do
before do
build_validator :greater_than => 10.kilobytes
build_validator greater_than: 10.kilobytes
end
should_allow_attachment_file_size 11.kilobytes
......@@ -91,7 +91,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "as a proc" do
before do
build_validator :greater_than => lambda { |avatar| 10.kilobytes }
build_validator greater_than: lambda { |avatar| 10.kilobytes }
end
should_allow_attachment_file_size 11.kilobytes
......@@ -102,7 +102,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "with :less_than option" do
context "as number" do
before do
build_validator :less_than => 10.kilobytes
build_validator less_than: 10.kilobytes
end
should_allow_attachment_file_size 9.kilobytes
......@@ -111,7 +111,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "as a proc" do
before do
build_validator :less_than => lambda { |avatar| 10.kilobytes }
build_validator less_than: lambda { |avatar| 10.kilobytes }
end
should_allow_attachment_file_size 9.kilobytes
......@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "with :greater_than and :less_than option" do
context "as numbers" do
before do
build_validator :greater_than => 5.kilobytes,
:less_than => 10.kilobytes
build_validator greater_than: 5.kilobytes,
less_than: 10.kilobytes
end
should_allow_attachment_file_size 7.kilobytes
......@@ -133,8 +133,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "as a proc" do
before do
build_validator :greater_than => lambda { |avatar| 5.kilobytes },
:less_than => lambda { |avatar| 10.kilobytes }
build_validator greater_than: lambda { |avatar| 5.kilobytes },
less_than: lambda { |avatar| 10.kilobytes }
end
should_allow_attachment_file_size 7.kilobytes
......@@ -146,54 +146,54 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "with :message option" do
context "given a range" do
before do
build_validator :in => (5.kilobytes..10.kilobytes),
:message => "is invalid. (Between %{min} and %{max} please.)"
build_validator in: (5.kilobytes..10.kilobytes),
message: "is invalid. (Between %{min} and %{max} please.)"
end
should_not_allow_attachment_file_size 11.kilobytes,
:message => "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
message: "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
end
context "given :less_than and :greater_than" do
before do
build_validator :less_than => 10.kilobytes,
:greater_than => 5.kilobytes,
:message => "is invalid. (Between %{min} and %{max} please.)"
build_validator less_than: 10.kilobytes,
greater_than: 5.kilobytes,
message: "is invalid. (Between %{min} and %{max} please.)"
end
should_not_allow_attachment_file_size 11.kilobytes,
:message => "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
message: "is invalid. (Between 5120 Bytes and 10240 Bytes please.)"
end
end
context "default error messages" do
context "given :less_than and :greater_than" do
before do
build_validator :greater_than => 5.kilobytes,
:less_than => 10.kilobytes
build_validator greater_than: 5.kilobytes,
less_than: 10.kilobytes
end
should_not_allow_attachment_file_size 11.kilobytes,
:message => "must be less than 10240 Bytes"
message: "must be less than 10240 Bytes"
should_not_allow_attachment_file_size 4.kilobytes,
:message => "must be greater than 5120 Bytes"
message: "must be greater than 5120 Bytes"
end
context "given a size range" do
before do
build_validator :in => (5.kilobytes..10.kilobytes)
build_validator in: (5.kilobytes..10.kilobytes)
end
should_not_allow_attachment_file_size 11.kilobytes,
:message => "must be in between 5120 Bytes and 10240 Bytes"
message: "must be in between 5120 Bytes and 10240 Bytes"
should_not_allow_attachment_file_size 4.kilobytes,
:message => "must be in between 5120 Bytes and 10240 Bytes"
message: "must be in between 5120 Bytes and 10240 Bytes"
end
end
context "using the helper" do
before do
Dummy.validates_attachment_size :avatar, :in => (5.kilobytes..10.kilobytes)
Dummy.validates_attachment_size :avatar, in: (5.kilobytes..10.kilobytes)
end
it "add the validator to the class" do
......@@ -204,7 +204,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
context "given options" do
it "raise argument error if no required argument was given" do
assert_raises(ArgumentError) do
build_validator :message => "Some message"
build_validator message: "Some message"
end
end
......@@ -215,7 +215,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
end
it "not raise argument error if :in was given" do
build_validator :in => (5.kilobytes..10.kilobytes)
build_validator in: (5.kilobytes..10.kilobytes)
end
end
end
......@@ -8,7 +8,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
def build_validator(options = {})
@validator = Paperclip::Validators::MediaTypeSpoofDetectionValidator.new(options.merge(
:attributes => :avatar
attributes: :avatar
))
end
......
......@@ -3,7 +3,7 @@ require 'spec_helper'
describe Paperclip::Validators do
context "using the helper" do
before do
Dummy.validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/jpeg" }, :size => { :in => 0..10240 }
Dummy.validates_attachment :avatar, presence: true, content_type: { content_type: "image/jpeg" }, size: { in: 0..10240 }
end
it "adds the attachment_presence validator to the class" do
......@@ -20,7 +20,7 @@ describe Paperclip::Validators do
it 'prevents you from attaching a file that violates that validation' do
Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
assert_raises(RuntimeError){ dummy.valid? }
end
......@@ -29,10 +29,10 @@ describe Paperclip::Validators do
context "using the helper with a conditional" do
before do
rebuild_class
Dummy.validates_attachment :avatar, :presence => true,
:content_type => { :content_type => "image/jpeg" },
:size => { :in => 0..10240 },
:if => :title_present?
Dummy.validates_attachment :avatar, presence: true,
content_type: { content_type: "image/jpeg" },
size: { in: 0..10240 },
if: :title_present?
end
it "validates the attachment if title is present" do
......@@ -41,7 +41,7 @@ describe Paperclip::Validators do
true
end
end
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
end
......@@ -65,31 +65,31 @@ describe Paperclip::Validators do
it 'raises an error when no content_type validation exists' do
assert_raises(Paperclip::Errors::MissingRequiredValidatorError) do
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
Dummy.new(avatar: File.new(fixture_file("12k.png")))
end
end
it 'does not raise an error when a content_type validation exists' do
Dummy.validates_attachment :avatar, :content_type => { :content_type => "image/jpeg" }
Dummy.validates_attachment :avatar, content_type: { content_type: "image/jpeg" }
assert_nothing_raised do
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
Dummy.new(avatar: File.new(fixture_file("12k.png")))
end
end
it 'does not raise an error when a file_name validation exists' do
Dummy.validates_attachment :avatar, :file_name => { :matches => /png$/ }
Dummy.validates_attachment :avatar, file_name: { matches: /png$/ }
assert_nothing_raised do
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
Dummy.new(avatar: File.new(fixture_file("12k.png")))
end
end
it 'does not raise an error when a the validation has been explicitly rejected' do
Dummy.validates_attachment :avatar, :file_type_ignorance => true
Dummy.validates_attachment :avatar, file_type_ignorance: true
assert_nothing_raised do
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
Dummy.new(avatar: File.new(fixture_file("12k.png")))
end
end
end
......
......@@ -54,7 +54,7 @@ end
def reset_table table_name, &block
block ||= lambda { |table| true }
ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block
ActiveRecord::Base.connection.create_table :dummies, {force: true}, &block
end
def modify_table table_name, &block
......@@ -62,7 +62,7 @@ def modify_table table_name, &block
end
def rebuild_model options = {}
ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
ActiveRecord::Base.connection.create_table :dummies, force: true do |table|
table.column :title, :string
table.column :other, :string
table.column :avatar_file_name, :string
......
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