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
......
......@@ -20,7 +20,7 @@ describe Paperclip::Attachment do
it "processes :original style first" do
file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
rebuild_class styles: { small: '100x>', original: '42x42#' }
dummy = Dummy.new
dummy.avatar = file
dummy.save
......@@ -33,9 +33,12 @@ describe Paperclip::Attachment do
it "not delete styles that don't get reprocessed" do
file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>',
:large => '500x>',
:original => '42x42#' }
rebuild_class styles: {
small: '100x>',
large: '500x>',
original: '42x42#'
}
dummy = Dummy.new
dummy.avatar = file
dummy.save
......@@ -54,7 +57,7 @@ describe Paperclip::Attachment do
context "having a not empty hash as a default option" do
before do
@old_default_options = Paperclip::Attachment.default_options.dup
@new_default_options = { :convert_options => { :all => "-background white" } }
@new_default_options = { convert_options: { all: "-background white" } }
Paperclip::Attachment.default_options.merge!(@new_default_options)
end
......@@ -63,7 +66,7 @@ describe Paperclip::Attachment do
end
it "deep merge when it is overridden" do
new_options = { :convert_options => { :thumb => "-thumbnailize" } }
new_options = { convert_options: { thumb: "-thumbnailize" } }
attachment = Paperclip::Attachment.new(:name, :instance, new_options)
expect(Paperclip::Attachment.default_options.deep_merge(new_options)).to eq attachment.instance_variable_get("@options")
......@@ -72,115 +75,115 @@ describe Paperclip::Attachment do
it "handles a boolean second argument to #url" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name, :instance, :url_generator => mock_url_generator_builder)
attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder)
attachment.url(:style_name, true)
expect(mock_url_generator_builder.has_generated_url_with_options?(:timestamp => true, :escape => true)).to be_true
expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: true, escape: true)).to be_true
attachment.url(:style_name, false)
expect(mock_url_generator_builder.has_generated_url_with_options?(:timestamp => false, :escape => true)).to be_true
expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: false, escape: true)).to be_true
end
it "pass 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)
attachment = Paperclip::Attachment.new(:name, :instance, url_generator: mock_url_generator_builder)
attachment.url(:style_name, :options => :values)
expect(mock_url_generator_builder.has_generated_url_with_options?(:options => :values)).to be_true
attachment.url(:style_name, options: :values)
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
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name,
:instance,
:url_generator => mock_url_generator_builder,
:use_timestamp => true)
url_generator: mock_url_generator_builder,
use_timestamp: true)
attachment.url(:style_name)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end
it "pass default style and options through when #url is given no arguments" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name,
:instance,
:default_style => 'default style',
:url_generator => mock_url_generator_builder,
:use_timestamp => true)
default_style: 'default style',
url_generator: mock_url_generator_builder,
use_timestamp: true)
attachment.url
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
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 "pass 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,
:url_generator => mock_url_generator_builder,
:use_timestamp => true)
url_generator: mock_url_generator_builder,
use_timestamp: true)
attachment.url(:style_name)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end
it "pass the option :timestamp => false if :use_timestamp is false and :timestamp is not passed" do
it "pass 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,
:url_generator => mock_url_generator_builder,
:use_timestamp => false)
url_generator: mock_url_generator_builder,
use_timestamp: false)
attachment.url(:style_name)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => false)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: false)
end
it "not change the :timestamp if :timestamp is passed" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name,
:instance,
:url_generator => mock_url_generator_builder,
:use_timestamp => false)
url_generator: mock_url_generator_builder,
use_timestamp: false)
attachment.url(:style_name, :timestamp => true)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true, :timestamp => true)
attachment.url(:style_name, timestamp: true)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true, timestamp: true)
end
it "render JSON as default style" do
mock_url_generator_builder = MockUrlGeneratorBuilder.new
attachment = Paperclip::Attachment.new(:name,
:instance,
:default_style => 'default style',
:url_generator => mock_url_generator_builder)
default_style: 'default style',
url_generator: mock_url_generator_builder)
attachment.as_json
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 "pass 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,
:url_generator => mock_url_generator_builder,
:escape_url => true)
url_generator: mock_url_generator_builder,
escape_url: true)
attachment.url(:style_name)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => true)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: true)
end
it "pass the option :escape => false if :escape_url is false and :escape is not passed" do
it "pass 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,
:url_generator => mock_url_generator_builder,
:escape_url => false)
url_generator: mock_url_generator_builder,
escape_url: false)
attachment.url(:style_name)
assert mock_url_generator_builder.has_generated_url_with_options?(:escape => false)
assert mock_url_generator_builder.has_generated_url_with_options?(escape: false)
end
it "return the path based on the url by default" do
@attachment = attachment :url => "/:class/:id/:basename"
@attachment = attachment url: "/:class/:id/:basename"
@model = @attachment.instance
@model.id = 1234
@model.avatar_file_name = "fake.jpg"
......@@ -214,7 +217,7 @@ describe Paperclip::Attachment do
expected_string = %({"dummy":#{expected_string}})
end
# active_model pre-3.2 checks only by calling any? on it, thus it doesn't work if it is empty
assert_equal expected_string, dummy.to_json(:only => [:dummy_key_for_old_active_model], :methods => [:avatar])
assert_equal expected_string, dummy.to_json(only: [:dummy_key_for_old_active_model], methods: [:avatar])
end
context "Attachment default_options" do
......@@ -222,9 +225,9 @@ describe Paperclip::Attachment do
rebuild_model
@old_default_options = Paperclip::Attachment.default_options.dup
@new_default_options = @old_default_options.merge({
:path => "argle/bargle",
:url => "fooferon",
:default_url => "not here.png"
path: "argle/bargle",
url: "fooferon",
default_url: "not here.png"
})
end
......@@ -284,7 +287,7 @@ describe Paperclip::Attachment do
context "An attachment with similarly named interpolations" do
before do
rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
rebuild_model path: ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
@dummy = Dummy.new
@dummy.stubs(:id).returns(1024)
@file = File.new(fixture_file("5k.png"), 'rb')
......@@ -309,7 +312,7 @@ describe Paperclip::Attachment do
context "using default time zone" do
before do
rebuild_model :path => ":timestamp", :use_default_time_zone => true
rebuild_model path: ":timestamp", use_default_time_zone: true
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -321,7 +324,7 @@ describe Paperclip::Attachment do
context "using per-thread time zone" do
before do
rebuild_model :path => ":timestamp", :use_default_time_zone => false
rebuild_model path: ":timestamp", use_default_time_zone: false
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -338,7 +341,7 @@ describe Paperclip::Attachment do
end
it "raise if no secret is provided" do
rebuild_model :path => ":hash"
rebuild_model path: ":hash"
@attachment = Dummy.new.avatar
@attachment.assign @file
......@@ -349,9 +352,9 @@ describe Paperclip::Attachment do
context "when secret is set" do
before do
rebuild_model :path => ":hash",
:hash_secret => "w00t",
:hash_data => ":class/:attachment/:style/:filename"
rebuild_model path: ":hash",
hash_secret: "w00t",
hash_data: ":class/:attachment/:style/:filename"
@attachment = Dummy.new.avatar
@attachment.assign @file
end
......@@ -374,7 +377,7 @@ describe Paperclip::Attachment do
before do
@rails_env = "blah"
@id = 1024
rebuild_model :path => ":rails_env/:id.png"
rebuild_model path: ":rails_env/:id.png"
@dummy = Dummy.new
@dummy.stubs(:id).returns(@id)
@file = StringIO.new(".")
......@@ -389,9 +392,9 @@ describe Paperclip::Attachment do
context "An attachment with a default style and an extension interpolation" do
before do
rebuild_model :path => ":basename.:extension",
:styles => { :default => ["100x100", :jpg] },
:default_style => :default
rebuild_model path: ":basename.:extension",
styles: { default: ["100x100", :jpg] },
default_style: :default
@attachment = Dummy.new.avatar
@file = File.open(fixture_file("5k.png"))
@file.stubs(:original_filename).returns("file.png")
......@@ -404,13 +407,13 @@ describe Paperclip::Attachment do
context "An attachment with :convert_options" do
before do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
rebuild_model styles: {
thumb: "100x100",
large: "400x400"
},
:convert_options => {
:all => "-do_stuff",
:thumb => "-thumbnailize"
convert_options: {
all: "-do_stuff",
thumb: "-thumbnailize"
}
@dummy = Dummy.new
@dummy.avatar
......@@ -427,13 +430,13 @@ describe Paperclip::Attachment do
context "An attachment with :source_file_options" do
before do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
rebuild_model styles: {
thumb: "100x100",
large: "400x400"
},
:source_file_options => {
:all => "-density 400",
:thumb => "-depth 8"
source_file_options: {
all: "-density 400",
thumb: "-depth 8"
}
@dummy = Dummy.new
@dummy.avatar
......@@ -450,11 +453,11 @@ describe Paperclip::Attachment do
context "An attachment with :only_process" do
before do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
rebuild_model styles: {
thumb: "100x100",
large: "400x400"
},
:only_process => [:thumb]
only_process: [:thumb]
@file = StringIO.new("...")
@attachment = Dummy.new.avatar
end
......@@ -468,11 +471,11 @@ describe Paperclip::Attachment do
context "An attachment with :only_process that is a proc" do
before do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
rebuild_model styles: {
thumb: "100x100",
large: "400x400"
},
:only_process => lambda { |attachment| [:thumb] }
only_process: lambda { |attachment| [:thumb] }
@file = StringIO.new("...")
@attachment = Dummy.new.avatar
......@@ -487,13 +490,13 @@ describe Paperclip::Attachment do
context "An attachment with :convert_options that is a proc" do
before do
rebuild_model :styles => {
:thumb => "100x100",
:large => "400x400"
rebuild_model styles: {
thumb: "100x100",
large: "400x400"
},
:convert_options => {
:all => lambda{|i| i.all },
:thumb => lambda{|i| i.thumb }
convert_options: {
all: lambda{|i| i.all },
thumb: lambda{|i| i.thumb }
}
Dummy.class_eval do
def all; "-all"; end
......@@ -514,12 +517,12 @@ describe Paperclip::Attachment do
context "An attachment with :path that is a proc" do
before do
rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
rebuild_model path: lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
@file = File.new(fixture_file("5k.png"), 'rb')
@dummyA = Dummy.new(:other => 'a')
@dummyA = Dummy.new(other: 'a')
@dummyA.avatar = @file
@dummyB = Dummy.new(:other => 'b')
@dummyB = Dummy.new(other: 'b')
@dummyB.avatar = @file
end
......@@ -533,7 +536,7 @@ describe Paperclip::Attachment do
context "An attachment with :styles that is a proc" do
before do
rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} }
rebuild_model styles: lambda{ |attachment| {thumb: "50x50#", large: "400x400"} }
@attachment = Dummy.new.avatar
end
......@@ -545,9 +548,9 @@ describe Paperclip::Attachment do
context "An attachment with conditional :styles that is a proc" do
before 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"} }
@dummy = Dummy.new(:other => 'a')
@dummy = Dummy.new(other: 'a')
end
it "have the correct styles for the assigned instance values" do
......@@ -564,12 +567,12 @@ describe Paperclip::Attachment do
geometry_specs = [
[ lambda{|z| "50x50#" }, :png ],
lambda{|z| "50x50#" },
{ :geometry => lambda{|z| "50x50#" } }
{ geometry: lambda{|z| "50x50#" } }
]
geometry_specs.each do |geometry_spec|
context "An attachment geometry like #{geometry_spec}" do
before do
rebuild_model :styles => { :normal => geometry_spec }
rebuild_model styles: { normal: geometry_spec }
@attachment = Dummy.new.avatar
end
......@@ -588,9 +591,9 @@ describe Paperclip::Attachment do
context "An attachment with both 'normal' and hash-style styles" do
before do
rebuild_model :styles => {
:normal => ["50x50#", :png],
:hash => { :geometry => "50x50#", :format => :png }
rebuild_model styles: {
normal: ["50x50#", :png],
hash: { geometry: "50x50#", format: :png }
}
@dummy = Dummy.new
@attachment = @dummy.avatar
......@@ -609,7 +612,7 @@ describe Paperclip::Attachment do
@file = StringIO.new("...")
Paperclip::Test.stubs(:make).returns(@file)
rebuild_model :styles => { :normal => '' }, :processors => lambda { |a| [ :test ] }
rebuild_model styles: { normal: '' }, processors: lambda { |a| [ :test ] }
@attachment = Dummy.new.avatar
end
......@@ -626,7 +629,7 @@ describe Paperclip::Attachment do
context "An attachment with erroring processor" do
before do
rebuild_model :processor => [:thumbnail], :styles => { :small => '' }, :whiny_thumbnails => true
rebuild_model processor: [:thumbnail], styles: { small: '' }, whiny_thumbnails: true
@dummy = Dummy.new
Paperclip::Thumbnail.expects(:make).raises(Paperclip::Error, "cannot be processed.")
@file = StringIO.new("...")
......@@ -643,8 +646,8 @@ describe Paperclip::Attachment do
context "An attachment with multiple processors" do
before do
class Paperclip::Test < Paperclip::Processor; end
@style_params = { :once => {:one => 1, :two => 2} }
rebuild_model :processors => [:thumbnail, :test], :styles => @style_params
@style_params = { once: {one: 1, two: 2} }
rebuild_model processors: [:thumbnail, :test], styles: @style_params
@dummy = Dummy.new
@file = StringIO.new("...")
@file.stubs(:close)
......@@ -665,10 +668,10 @@ describe Paperclip::Attachment do
it "call #make with the right parameters passed as second argument" do
expected_params = @style_params[:once].merge({
:processors => [:thumbnail, :test],
:whiny => true,
:convert_options => "",
:source_file_options => ""
processors: [:thumbnail, :test],
whiny: true,
convert_options: "",
source_file_options: ""
})
Paperclip::Thumbnail.stubs(:make).returns(@file)
......@@ -688,23 +691,23 @@ describe Paperclip::Attachment do
end
it "include the filesystem module when loading the filesystem storage" do
rebuild_model :storage => :filesystem
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
rebuild_model :storage => :FileSystem
rebuild_model storage: :FileSystem
@dummy = Dummy.new
assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
rebuild_model :storage => :Filesystem
rebuild_model storage: :Filesystem
@dummy = Dummy.new
assert @dummy.avatar.is_a?(Paperclip::Storage::Filesystem)
end
it "convert underscored storage name to camelcase" do
rebuild_model :storage => :not_here
rebuild_model storage: :not_here
@dummy = Dummy.new
exception = assert_raises(Paperclip::Errors::StorageMethodNotFound, /NotHere/) do
@dummy.avatar
......@@ -712,7 +715,7 @@ describe Paperclip::Attachment do
end
it "raise an error if you try to include a storage module that doesn't exist" do
rebuild_model :storage => :not_here
rebuild_model storage: :not_here
@dummy = Dummy.new
assert_raises(Paperclip::Errors::StorageMethodNotFound) do
@dummy.avatar
......@@ -721,7 +724,7 @@ describe Paperclip::Attachment do
context "An attachment with styles but no processors defined" do
before do
rebuild_model :processors => [], :styles => {:something => '1'}
rebuild_model processors: [], styles: {something: '1'}
@dummy = Dummy.new
@file = StringIO.new("...")
end
......@@ -732,7 +735,7 @@ describe Paperclip::Attachment do
context "An attachment without styles and with no processors defined" do
before do
rebuild_model :processors => [], :styles => {}
rebuild_model processors: [], styles: {}
@dummy = Dummy.new
@file = StringIO.new("...")
end
......@@ -743,7 +746,7 @@ describe Paperclip::Attachment do
context "Assigning an attachment with post_process hooks" do
before do
rebuild_class :styles => { :something => "100x100#" }
rebuild_class styles: { something: "100x100#" }
Dummy.class_eval do
before_avatar_post_process :do_before_avatar
after_avatar_post_process :do_after_avatar
......@@ -800,7 +803,7 @@ describe Paperclip::Attachment do
context "Assigning an attachment" do
before do
rebuild_model :styles => { :something => "100x100#" }
rebuild_model styles: { something: "100x100#" }
@file = File.new(fixture_file("5k.png"), "rb")
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -817,7 +820,7 @@ describe Paperclip::Attachment do
context "Assigning an attachment" do
before do
rebuild_model :styles => { :something => "100x100#" }
rebuild_model styles: { something: "100x100#" }
@file = File.new(fixture_file("5k.png"), "rb")
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -907,7 +910,7 @@ describe Paperclip::Attachment do
context 'as another regexp' do
before do
Paperclip::Attachment.default_options.merge! :restricted_characters => /o/
Paperclip::Attachment.default_options.merge! restricted_characters: /o/
@file.stubs(:original_filename).returns("goood.png")
@dummy = Dummy.new
......@@ -921,7 +924,7 @@ describe Paperclip::Attachment do
context 'as nil' do
before do
Paperclip::Attachment.default_options.merge! :restricted_characters => nil
Paperclip::Attachment.default_options.merge! restricted_characters: nil
@file.stubs(:original_filename).returns("goood.png")
@dummy = Dummy.new
......@@ -974,13 +977,13 @@ describe Paperclip::Attachment do
before do
@old_defaults = Paperclip::Attachment.default_options.dup
Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
})
FileUtils.rm_rf("tmp")
rebuild_model :styles => { :large => ["400x400", :jpg],
:medium => ["100x100", :jpg],
:small => ["32x32#", :jpg]},
:default_style => :small
rebuild_model styles: { large: ["400x400", :jpg],
medium: ["100x100", :jpg],
small: ["32x32#", :jpg]},
default_style: :small
@instance = Dummy.new
@instance.stubs(:id).returns 123
@file = File.new(fixture_file("uppercase.PNG"), 'rb')
......@@ -1012,7 +1015,7 @@ describe Paperclip::Attachment do
before do
@old_defaults = Paperclip::Attachment.default_options.dup
Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
path: ":rails_root/:attachment/:class/:style/:id/:basename.:extension"
})
FileUtils.rm_rf("tmp")
rebuild_model
......@@ -1085,10 +1088,10 @@ describe Paperclip::Attachment do
context "when expecting three styles" do
before do
rebuild_class :styles => {
:large => ["400x400", :png],
:medium => ["100x100", :gif],
:small => ["32x32#", :jpg]
rebuild_class styles: {
large: ["400x400", :png],
medium: ["100x100", :gif],
small: ["32x32#", :jpg]
}
@instance = Dummy.new
@instance.stubs(:id).returns 123
......@@ -1215,7 +1218,7 @@ describe Paperclip::Attachment do
context "when trying a nonexistant storage type" do
before do
rebuild_model :storage => :not_here
rebuild_model storage: :not_here
end
it "not be able to find the module" do
......@@ -1226,7 +1229,7 @@ describe Paperclip::Attachment do
context "An attachment with only a avatar_file_name column" do
before do
ActiveRecord::Base.connection.create_table :dummies, :force => true do |table|
ActiveRecord::Base.connection.create_table :dummies, force: true do |table|
table.column :avatar_file_name, :string
end
rebuild_class
......@@ -1379,7 +1382,7 @@ describe Paperclip::Attachment do
context "an attachment with delete_file option set to false" do
before do
rebuild_model :preserve_files => true
rebuild_model preserve_files: true
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
......
......@@ -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
......
......@@ -8,11 +8,11 @@ describe 'Paperclip' do
rebuild_model
@file = File.new(fixture_file("5k.png"), 'rb')
300.times do |i|
Dummy.create! :avatar => @file
Dummy.create! avatar: @file
end
end
# after { @file.close }
after { @file.close }
it "not exceed the open file limit" do
assert_nothing_raised do
......@@ -23,14 +23,14 @@ describe 'Paperclip' do
context "An attachment" do
before do
rebuild_model :styles => { :thumb => "50x50#" }
rebuild_model styles: { thumb: "50x50#" }
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
assert @dummy.save
end
# after { @file.close }
after { @file.close }
it "create its thumbnails properly" do
assert_match(/\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`)
......@@ -53,13 +53,13 @@ describe 'Paperclip' do
end
end
# after { File.chmod(0644, @dummy.avatar.path) }
after { File.chmod(0644, @dummy.avatar.path) }
end
context "redefining its attachment styles" do
before do
Dummy.class_eval do
has_attached_file :avatar, :styles => { :thumb => "150x25#", :dynamic => lambda { |a| '50x50#' } }
has_attached_file :avatar, styles: { thumb: "150x25#", dynamic: lambda { |a| '50x50#' } }
end
@d2 = Dummy.find(@dummy.id)
@original_timestamp = @d2.avatar_updated_at
......@@ -82,13 +82,13 @@ describe 'Paperclip' do
before do
@thumb_path = "tmp/public/system/dummies/avatars/000/000/001/thumb/5k.png"
File.delete(@thumb_path) if File.exists?(@thumb_path)
rebuild_model :styles => { :thumb => "50x50#" }
rebuild_model styles: { thumb: "50x50#" }
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
end
# after { @file.close }
after { @file.close }
it "not create the thumbnails upon saving when post-processing is disabled" do
@dummy.avatar.post_processing = false
......@@ -111,7 +111,7 @@ describe 'Paperclip' do
@thumb_large_path = "tmp/public/system/dummies/avatars/000/000/001/thumb_large/5k.png"
File.delete(@thumb_small_path) if File.exists?(@thumb_small_path)
File.delete(@thumb_large_path) if File.exists?(@thumb_large_path)
rebuild_model :styles => { :thumb_small => "50x50#", :thumb_large => "60x60#" }
rebuild_model styles: { thumb_small: "50x50#", thumb_large: "60x60#" }
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
......@@ -121,7 +121,7 @@ describe 'Paperclip' do
@dummy.avatar.post_processing = true
end
# after { @file.close }
after { @file.close }
it "allow us to create all thumbnails in one go" do
assert_file_not_exists(@thumb_small_path)
......@@ -148,7 +148,7 @@ describe 'Paperclip' do
context "A model that modifies its original" do
before do
rebuild_model :styles => { :original => "2x2#" }
rebuild_model styles: { original: "2x2#" }
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
......@@ -158,20 +158,20 @@ describe 'Paperclip' do
assert_not_equal File.size(@file.path), @dummy.avatar.size
end
# after { @file.close }
after { @file.close }
end
context "A model with attachments scoped under an id" do
before do
rebuild_model :styles => { :large => "100x100",
:medium => "50x50" },
:path => ":rails_root/tmp/:id/:attachments/:style.:extension"
rebuild_model styles: { large: "100x100",
medium: "50x50" },
path: ":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
end
# after { @file.close }
after { @file.close }
context "when saved" do
before do
......@@ -220,10 +220,10 @@ describe 'Paperclip' do
@umask = File.umask(umask)
end
# after do
# File.umask @umask
# @file.close
# end
after do
File.umask @umask
@file.close
end
it "respect the current umask" do
@dummy.avatar = @file
......@@ -236,14 +236,14 @@ describe 'Paperclip' do
[0666,0664,0640].each do |perms|
context "when the perms are #{perms}" do
before do
rebuild_model :override_file_permissions => perms
rebuild_model override_file_permissions: perms
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
end
# after do
# @file.close
# end
after do
@file.close
end
it "respect the current perms" do
@dummy.avatar = @file
......@@ -256,7 +256,7 @@ describe 'Paperclip' do
it "skip 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
rebuild_model override_file_permissions: false
dummy = Dummy.create!
dummy.avatar = @file
dummy.save
......@@ -264,12 +264,12 @@ describe 'Paperclip' do
context "A model with a filesystem attachment" do
before do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif] },
:default_style => :medium,
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
rebuild_model styles: { large: "300x300>",
medium: "100x100",
thumb: ["32x32#", :gif] },
default_style: :medium,
url: "/:attachment/:class/:style/:id/:basename.:extension",
path: ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new
@file = File.new(fixture_file("5k.png"), 'rb')
@bad_file = File.new(fixture_file("bad.png"), 'rb')
......@@ -279,7 +279,7 @@ describe 'Paperclip' do
assert @dummy.save
end
# after { [@file, @bad_file].each(&:close) }
after { [@file, @bad_file].each(&:close) }
it "write and delete its files" do
[["434x66", :original],
......@@ -374,7 +374,7 @@ describe 'Paperclip' do
@dummy2.save
end
# after { @file2.close }
after { @file2.close }
it "work when assigned a file" do
assert_not_equal `identify -format "%wx%h" "#{@dummy.avatar.path(:original)}"`,
......@@ -393,7 +393,7 @@ describe 'Paperclip' do
context "A model with an attachments association and a Paperclip attachment" do
before do
Dummy.class_eval do
has_many :attachments, :class_name => 'Dummy'
has_many :attachments, class_name: 'Dummy'
end
@file = File.new(fixture_file("5k.png"), 'rb')
......@@ -401,7 +401,7 @@ describe 'Paperclip' do
@dummy.avatar = @file
end
# after { @file.close }
after { @file.close }
it "should not error when saving" do
@dummy.save!
......@@ -410,20 +410,20 @@ describe 'Paperclip' do
context "A model with an attachment with hash in file name" do
before do
@settings = { :styles => { :thumb => "50x50#" },
:path => ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
:url => "/system/:attachment/:id_partition/:style/:hash.:extension",
:hash_secret => "somesecret" }
@settings = { styles: { thumb: "50x50#" },
path: ":rails_root/public/system/:attachment/:id_partition/:style/:hash.:extension",
url: "/system/:attachment/:id_partition/:style/:hash.:extension",
hash_secret: "somesecret" }
rebuild_model @settings
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy = Dummy.create! :avatar => @file
@dummy = Dummy.create! avatar: @file
end
# after do
# @file.close
# end
after do
@file.close
end
it "be accessible" do
assert_file_exists(@dummy.avatar.path(:original))
......@@ -434,7 +434,7 @@ describe 'Paperclip' do
before do
@dummy.avatar.options[:styles][:mini] = "25x25#"
@dummy.avatar.instance_variable_set :@normalized_styles, nil
Time.stubs(:now => Time.now + 10)
Time.stubs(now: Time.now + 10)
@dummy.avatar.reprocess!
@dummy.reload
end
......@@ -470,21 +470,24 @@ describe 'Paperclip' do
context "A model with an S3 attachment" do
before do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif],
:custom => {
:geometry => "32x32#",
:s3_headers => { 'Cache-Control' => 'max-age=31557600' },
:s3_metadata => { 'foo' => 'bar'}
rebuild_model(
styles: {
large: "300x300>",
medium: "100x100",
thumb: ["32x32#", :gif],
custom: {
geometry: "32x32#",
s3_headers: { 'Cache-Control' => 'max-age=31557600' },
s3_metadata: { 'foo' => 'bar'}
}
},
:storage => :s3,
:s3_credentials => File.new(fixture_file('s3.yml')),
:s3_options => { :logger => Paperclip.logger },
:default_style => :medium,
:bucket => ENV['S3_BUCKET'],
:path => ":class/:attachment/:id/:style/:basename.:extension"
storage: :s3,
s3_credentials: File.new(fixture_file('s3.yml')),
s3_options: { logger: Paperclip.logger },
default_style: :medium,
bucket: ENV['S3_BUCKET'],
path: ":class/:attachment/:id/:style/:basename.:extension"
)
@dummy = Dummy.new
@file = File.new(fixture_file('5k.png'), 'rb')
......@@ -497,11 +500,11 @@ describe 'Paperclip' do
@files_on_s3 = s3_files_for(@dummy.avatar)
end
# after do
# @file.close
# @bad_file.close
# @files_on_s3.values.each(&:close) if @files_on_s3
# end
after do
@file.close
@bad_file.close
@files_on_s3.values.each(&:close) if @files_on_s3
end
context 'assigning itself to a new model' do
before do
......@@ -634,7 +637,7 @@ describe 'Paperclip' do
@file = File.new(fixture_file("5k.png"), 'rb')
end
# after { @file.close }
after { @file.close }
it "succeed when original attachment is a file" do
original = Dummy.new
......
......@@ -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'))
......
......@@ -7,11 +7,11 @@ describe Paperclip::Storage::Fog do
context "with credentials provided in a path string" do
before do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:url => '/:attachment/:filename',
:fog_directory => "paperclip",
:fog_credentials => fixture_file('fog.yml')
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
storage: :fog,
url: '/:attachment/:filename',
fog_directory: "paperclip",
fog_credentials: fixture_file('fog.yml')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -26,11 +26,11 @@ describe Paperclip::Storage::Fog do
context "with credentials provided in a File object" do
before do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:url => '/:attachment/:filename',
:fog_directory => "paperclip",
:fog_credentials => File.open(fixture_file('fog.yml'))
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
storage: :fog,
url: '/:attachment/:filename',
fog_directory: "paperclip",
fog_credentials: File.open(fixture_file('fog.yml'))
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -45,14 +45,14 @@ describe Paperclip::Storage::Fog do
context "with default values for path and url" do
before do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:url => '/:attachment/:filename',
:fog_directory => "paperclip",
:fog_credentials => {
:provider => 'AWS',
:aws_access_key_id => 'AWS_ID',
:aws_secret_access_key => 'AWS_SECRET'
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
storage: :fog,
url: '/:attachment/:filename',
fog_directory: "paperclip",
fog_credentials: {
provider: 'AWS',
aws_access_key_id: 'AWS_ID',
aws_secret_access_key: 'AWS_SECRET'
}
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
......@@ -69,13 +69,13 @@ describe Paperclip::Storage::Fog do
context "with no path or url given and using defaults" do
before do
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:fog_directory => "paperclip",
:fog_credentials => {
:provider => 'AWS',
:aws_access_key_id => 'AWS_ID',
:aws_secret_access_key => 'AWS_SECRET'
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
storage: :fog,
fog_directory: "paperclip",
fog_credentials: {
provider: 'AWS',
aws_access_key_id: 'AWS_ID',
aws_secret_access_key: 'AWS_SECRET'
}
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
......@@ -92,9 +92,9 @@ describe Paperclip::Storage::Fog do
context "with file params provided as lambda" do
before do
fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
klass = rebuild_model :storage => :fog,
:fog_file => fog_file
fog_file = lambda{ |a| { custom_header: a.instance.custom_method }}
klass = rebuild_model storage: :fog,
fog_file: fog_file
klass.class_eval do
def custom_method
......@@ -107,7 +107,7 @@ describe Paperclip::Storage::Fog do
end
it "be able to evaluate correct values for file headers" do
assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
assert_equal @dummy.avatar.send(:fog_file), { custom_header: 'foobar' }
end
end
......@@ -115,23 +115,23 @@ describe Paperclip::Storage::Fog do
@fog_directory = 'papercliptests'
@credentials = {
:provider => 'AWS',
:aws_access_key_id => 'ID',
:aws_secret_access_key => 'SECRET'
provider: 'AWS',
aws_access_key_id: 'ID',
aws_secret_access_key: 'SECRET'
}
@connection = Fog::Storage.new(@credentials)
@connection.directories.create(
:key => @fog_directory
key: @fog_directory
)
@options = {
:fog_directory => @fog_directory,
:fog_credentials => @credentials,
:fog_host => nil,
:fog_file => {:cache_control => 1234},
:path => ":attachment/:basename.:extension",
:storage => :fog
fog_directory: @fog_directory,
fog_credentials: @credentials,
fog_host: nil,
fog_file: {cache_control: 1234},
path: ":attachment/:basename.:extension",
storage: :fog
}
rebuild_model(@options)
......@@ -150,7 +150,7 @@ describe Paperclip::Storage::Fog do
after do
@file.close
directory = @connection.directories.new(:key => @fog_directory)
directory = @connection.directories.new(key: @fog_directory)
directory.files.each {|file| file.destroy}
directory.destroy
end
......@@ -207,7 +207,7 @@ describe Paperclip::Storage::Fog do
context "without a fog_host" do
before do
rebuild_model(@options.merge(:fog_host => nil))
rebuild_model(@options.merge(fog_host: nil))
@dummy = Dummy.new
@dummy.avatar = StringIO.new('.')
@dummy.save
......@@ -220,7 +220,7 @@ describe Paperclip::Storage::Fog do
context "with a fog_host" do
before do
rebuild_model(@options.merge(:fog_host => 'http://example.com'))
rebuild_model(@options.merge(fog_host: 'http://example.com'))
@dummy = Dummy.new
@dummy.avatar = StringIO.new(".\n")
@dummy.save
......@@ -234,11 +234,11 @@ describe Paperclip::Storage::Fog do
context "with a fog_host that includes a wildcard placeholder" do
before do
rebuild_model(
:fog_directory => @fog_directory,
:fog_credentials => @credentials,
:fog_host => 'http://img%d.example.com',
:path => ":attachment/:basename.:extension",
:storage => :fog
fog_directory: @fog_directory,
fog_credentials: @credentials,
fog_host: 'http://img%d.example.com',
path: ":attachment/:basename.:extension",
storage: :fog
)
@dummy = Dummy.new
@dummy.avatar = StringIO.new(".\n")
......@@ -252,7 +252,7 @@ describe Paperclip::Storage::Fog do
context "with fog_public set to false" do
before do
rebuild_model(@options.merge(:fog_public => false))
rebuild_model(@options.merge(fog_public: false))
@dummy = Dummy.new
@dummy.avatar = StringIO.new('.')
@dummy.save
......@@ -266,7 +266,7 @@ describe Paperclip::Storage::Fog do
context "with styles set and fog_public set to false" do
before do
rebuild_model(@options.merge(:fog_public => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -281,7 +281,7 @@ describe Paperclip::Storage::Fog do
context "with styles set and fog_public set per-style" do
before do
rebuild_model(@options.merge(:fog_public => { :medium => false, :thumb => true}, :styles => { :medium => "300x300>", :thumb => "100x100>" }))
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true}, styles: { medium: "300x300>", thumb: "100x100>" }))
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
......@@ -339,7 +339,7 @@ describe Paperclip::Storage::Fog do
context "with an invalid bucket name for a subdomain" do
before do
rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
rebuild_model(@options.merge(fog_directory: "this_is_invalid"))
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
......@@ -365,7 +365,7 @@ describe Paperclip::Storage::Fog do
context "with a proc for a bucket name evaluating a model method" do
before do
@dynamic_fog_directory = 'dynamicpaperclip'
rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
rebuild_model(@options.merge(fog_directory: lambda { |attachment| attachment.instance.bucket_name }))
@dummy = Dummy.new
@dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
@dummy.avatar = @file
......@@ -380,7 +380,7 @@ describe Paperclip::Storage::Fog do
context "with a proc for the fog_host evaluating a model method" do
before do
rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))
@dummy = Dummy.new
@dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
@dummy.avatar = @file
......@@ -395,7 +395,7 @@ describe Paperclip::Storage::Fog do
context "with a custom fog_host" do
before do
rebuild_model(@options.merge(:fog_host => "http://dynamicfoghost.com"))
rebuild_model(@options.merge(fog_host: "http://dynamicfoghost.com"))
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
......@@ -411,7 +411,7 @@ describe Paperclip::Storage::Fog do
context "with an invalid bucket name for a subdomain" do
before do
rebuild_model(@options.merge({:fog_directory => "this_is_invalid", :fog_host => "http://dynamicfoghost.com"}))
rebuild_model(@options.merge({fog_directory: "this_is_invalid", fog_host: "http://dynamicfoghost.com"}))
@dummy = Dummy.new
@dummy.avatar = @file
@dummy.save
......@@ -427,11 +427,11 @@ describe Paperclip::Storage::Fog do
context "with a proc for the fog_credentials evaluating a model method" do
before do
@dynamic_fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'DYNAMIC_ID',
:aws_secret_access_key => 'DYNAMIC_SECRET'
provider: 'AWS',
aws_access_key_id: 'DYNAMIC_ID',
aws_secret_access_key: 'DYNAMIC_SECRET'
}
rebuild_model(@options.merge(:fog_credentials => lambda { |attachment| attachment.instance.fog_credentials }))
rebuild_model(@options.merge(fog_credentials: lambda { |attachment| attachment.instance.fog_credentials }))
@dummy = Dummy.new
@dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
@dummy.avatar = @file
......@@ -449,12 +449,12 @@ describe Paperclip::Storage::Fog do
context "when using local storage" do
before do
Fog.unmock!
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :fog,
:url => '/:attachment/:filename',
:fog_directory => "paperclip",
:fog_credentials => { :provider => :local, :local_root => "." },
:fog_host => 'localhost'
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
storage: :fog,
url: '/:attachment/:filename',
fog_directory: "paperclip",
fog_credentials: { provider: :local, local_root: "." },
fog_host: 'localhost'
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
......
......@@ -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
......
......@@ -8,11 +8,11 @@ describe Paperclip::Storage::S3 do
context "Parsing S3 credentials" do
before do
@proxy_settings = {:host => "127.0.0.1", :port => 8888, :user => "foo", :password => "bar"}
rebuild_model :storage => :s3,
:bucket => "testing",
:http_proxy => @proxy_settings,
:s3_credentials => {:not => :important}
@proxy_settings = {host: "127.0.0.1", port: 8888, user: "foo", password: "bar"}
rebuild_model storage: :s3,
bucket: "testing",
http_proxy: @proxy_settings,
s3_credentials: {not: :important}
@dummy = Dummy.new
@avatar = @dummy.avatar
......@@ -20,23 +20,23 @@ describe Paperclip::Storage::S3 do
it "get the correct credentials when RAILS_ENV is production" do
rails_env("production") do
assert_equal({:key => "12345"},
@avatar.parse_credentials('production' => {:key => '12345'},
:development => {:key => "54321"}))
assert_equal({key: "12345"},
@avatar.parse_credentials('production' => {key: '12345'},
development: {key: "54321"}))
end
end
it "get the correct credentials when RAILS_ENV is development" do
rails_env("development") do
assert_equal({:key => "54321"},
@avatar.parse_credentials('production' => {:key => '12345'},
:development => {:key => "54321"}))
assert_equal({key: "54321"},
@avatar.parse_credentials('production' => {key: '12345'},
development: {key: "54321"}))
end
end
it "return 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"))
assert_equal({test: "12345"}, @avatar.parse_credentials(test: "12345"))
end
end
......@@ -55,7 +55,7 @@ describe Paperclip::Storage::S3 do
context ":bucket option via :s3_credentials" do
before do
rebuild_model :storage => :s3, :s3_credentials => {:bucket => 'testing'}
rebuild_model storage: :s3, s3_credentials: {bucket: 'testing'}
@dummy = Dummy.new
end
......@@ -68,7 +68,7 @@ describe Paperclip::Storage::S3 do
context ":bucket option" do
before do
rebuild_model :storage => :s3, :bucket => "testing", :s3_credentials => {}
rebuild_model storage: :s3, bucket: "testing", s3_credentials: {}
@dummy = Dummy.new
end
......@@ -81,9 +81,9 @@ describe Paperclip::Storage::S3 do
context "missing :bucket option" do
before do
rebuild_model :storage => :s3,
:http_proxy => @proxy_settings,
:s3_credentials => {:not => :important}
rebuild_model storage: :s3,
http_proxy: @proxy_settings,
s3_credentials: {not: :important}
@dummy = Dummy.new
@dummy.avatar = stringy_file
......@@ -98,11 +98,11 @@ describe Paperclip::Storage::S3 do
context "" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:url => ":s3_path_url"
rebuild_model storage: :s3,
s3_credentials: {},
bucket: "bucket",
path: ":attachment/:basename.:extension",
url: ":s3_path_url"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -124,7 +124,7 @@ describe Paperclip::Storage::S3 do
["http", :http, ""].each do |protocol|
context "as #{protocol.inspect}" do
before do
rebuild_model :storage => :s3, :s3_protocol => protocol
rebuild_model storage: :s3, s3_protocol: protocol
@dummy = Dummy.new
end
......@@ -136,13 +136,13 @@ describe Paperclip::Storage::S3 do
end
end
context ":s3_protocol => 'https'" do
context "s3_protocol: 'https'" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:s3_protocol => 'https',
:bucket => "bucket",
:path => ":attachment/:basename.:extension"
rebuild_model storage: :s3,
s3_credentials: {},
s3_protocol: 'https',
bucket: "bucket",
path: ":attachment/:basename.:extension"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -152,13 +152,13 @@ describe Paperclip::Storage::S3 do
end
end
context ":s3_protocol => :https" do
context "s3_protocol: :https" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:s3_protocol => :https,
:bucket => "bucket",
:path => ":attachment/:basename.:extension"
rebuild_model storage: :s3,
s3_credentials: {},
s3_protocol: :https,
bucket: "bucket",
path: ":attachment/:basename.:extension"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -168,13 +168,13 @@ describe Paperclip::Storage::S3 do
end
end
context ":s3_protocol => ''" do
context "s3_protocol: ''" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:s3_protocol => '',
:bucket => "bucket",
:path => ":attachment/:basename.:extension"
rebuild_model storage: :s3,
s3_credentials: {},
s3_protocol: '',
bucket: "bucket",
path: ":attachment/:basename.:extension"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -186,13 +186,13 @@ describe Paperclip::Storage::S3 do
context "An attachment that uses S3 for storage and has the style in the path" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
styles: {
thumb: "80x80>"
},
:s3_credentials => {
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -213,11 +213,11 @@ describe Paperclip::Storage::S3 do
context "s3_host_name" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:s3_host_name => "s3-ap-northeast-1.amazonaws.com"
rebuild_model storage: :s3,
s3_credentials: {},
bucket: "bucket",
path: ":attachment/:basename.:extension",
s3_host_name: "s3-ap-northeast-1.amazonaws.com"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -233,11 +233,11 @@ describe Paperclip::Storage::S3 do
context "dynamic s3_host_name" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:s3_host_name => lambda {|a| a.instance.value }
rebuild_model storage: :s3,
s3_credentials: {},
bucket: "bucket",
path: ":attachment/:basename.:extension",
s3_host_name: lambda {|a| a.instance.value }
@dummy = Dummy.new
class << @dummy
attr_accessor :value
......@@ -247,17 +247,17 @@ describe Paperclip::Storage::S3 do
it "use 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)
assert_equal "http://s3.something.com/bucket/avatars/data.txt", @dummy.avatar.url(:original, timestamp: false)
end
end
context "An attachment that uses S3 for storage and has styles that return different file types" do
before do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
:storage => :s3,
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:s3_credentials => {
rebuild_model styles: { large: ['500x500#', :jpg] },
storage: :s3,
bucket: "bucket",
path: ":attachment/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -287,11 +287,11 @@ describe Paperclip::Storage::S3 do
context "An attachment that uses S3 for storage and has a proc for styles" do
before do
rebuild_model :styles => lambda { |attachment| attachment.instance.counter; {:thumbnail => { :geometry => "50x50#", :s3_headers => {'Cache-Control' => 'max-age=31557600'}} }},
:storage => :s3,
:bucket => "bucket",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model styles: lambda { |attachment| attachment.instance.counter; {thumbnail: { geometry: "50x50#", s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
storage: :s3,
bucket: "bucket",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -312,8 +312,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).with(:original).returns(object)
@dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
object.expects(:write).with(anything, :content_type => 'image/png', :acl => :public_read)
object.expects(:write).with(anything, :content_type => 'image/png', :acl => :public_read, :cache_control => 'max-age=31557600')
object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read)
object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read, cache_control: 'max-age=31557600')
@dummy.save
end
......@@ -326,10 +326,10 @@ describe Paperclip::Storage::S3 do
context "An attachment that uses S3 for storage and has spaces in file name" do
before do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
:storage => :s3,
:bucket => "bucket",
:s3_credentials => {
rebuild_model styles: { large: ['500x500#', :jpg] },
storage: :s3,
bucket: "bucket",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -351,10 +351,10 @@ describe Paperclip::Storage::S3 do
context "An attachment that uses S3 for storage and has a question mark in file name" do
before do
rebuild_model :styles => { :large => ['500x500#', :jpg] },
:storage => :s3,
:bucket => "bucket",
:s3_credentials => {
rebuild_model styles: { large: ['500x500#', :jpg] },
storage: :s3,
bucket: "bucket",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -382,11 +382,11 @@ describe Paperclip::Storage::S3 do
context "" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:url => ":s3_domain_url"
rebuild_model storage: :s3,
s3_credentials: {},
bucket: "bucket",
path: ":attachment/:basename.:extension",
url: ":s3_domain_url"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -398,14 +398,14 @@ describe Paperclip::Storage::S3 do
context "" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
rebuild_model storage: :s3,
s3_credentials: {
production: { bucket: "prod_bucket" },
development: { bucket: "dev_bucket" }
},
:s3_host_alias => "something.something.com",
:path => ":attachment/:basename.:extension",
:url => ":s3_alias_url"
s3_host_alias: "something.something.com",
path: ":attachment/:basename.:extension",
url: ":s3_alias_url"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -417,11 +417,11 @@ describe Paperclip::Storage::S3 do
context "generating a url with a proc as the host alias" do
before do
rebuild_model :storage => :s3,
:s3_credentials => { :bucket => "prod_bucket" },
:s3_host_alias => Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
:path => ":attachment/:basename.:extension",
:url => ":s3_alias_url"
rebuild_model storage: :s3,
s3_credentials: { bucket: "prod_bucket" },
s3_host_alias: Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
path: ":attachment/:basename.:extension",
url: ":s3_alias_url"
Dummy.class_eval do
def counter
@counter ||= 0
......@@ -446,11 +446,11 @@ describe Paperclip::Storage::S3 do
context "" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:url => ":asset_host"
rebuild_model storage: :s3,
s3_credentials: {},
bucket: "bucket",
path: ":attachment/:basename.:extension",
url: ":asset_host"
@dummy = Dummy.new
@dummy.avatar = stringy_file
end
......@@ -465,15 +465,15 @@ describe Paperclip::Storage::S3 do
before do
@build_model_with_options = lambda {|options|
base_options = {
:storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
storage: :s3,
s3_credentials: {
production: { bucket: "prod_bucket" },
development: { bucket: "dev_bucket" }
},
:s3_host_alias => "something.something.com",
:s3_permissions => "private",
:path => ":attachment/:basename.:extension",
:url => ":s3_alias_url"
s3_host_alias: "something.something.com",
s3_permissions: "private",
path: ":attachment/:basename.:extension",
url: ":s3_alias_url"
}
rebuild_model base_options.merge(options)
......@@ -489,14 +489,14 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:url_for).with(:read, :expires => 3600, :secure => true)
object.expects(:url_for).with(:read, expires: 3600, secure: true)
@dummy.avatar.expiring_url
end
end
it "allow overriding s3_url_options" do
@build_model_with_options[:s3_url_options => { :response_content_disposition => "inline" }]
@build_model_with_options[s3_url_options: { response_content_disposition: "inline" }]
rails_env("production") do
@dummy = Dummy.new
......@@ -504,14 +504,14 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:url_for).with(:read, :expires => 3600, :secure => true, :response_content_disposition => "inline")
object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_disposition: "inline")
@dummy.avatar.expiring_url
end
end
it "allow overriding s3_object options with a proc" do
@build_model_with_options[:s3_url_options => lambda {|attachment| { :response_content_type => attachment.avatar_content_type } }]
@build_model_with_options[s3_url_options: lambda {|attachment| { response_content_type: attachment.avatar_content_type } }]
rails_env("production") do
@dummy = Dummy.new
......@@ -526,7 +526,7 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:url_for).with(:read, :expires => 3600, :secure => true, :response_content_type => "image/png")
object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_type: "image/png")
@dummy.avatar.expiring_url
end
......@@ -555,15 +555,15 @@ describe Paperclip::Storage::S3 do
context "Generating a url with an expiration for each style" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
rebuild_model storage: :s3,
s3_credentials: {
production: { bucket: "prod_bucket" },
development: { bucket: "dev_bucket" }
},
:s3_permissions => :private,
:s3_host_alias => "something.something.com",
:path => ":attachment/:style/:basename.:extension",
:url => ":s3_alias_url"
s3_permissions: :private,
s3_host_alias: "something.something.com",
path: ":attachment/:style/:basename.:extension",
url: ":s3_alias_url"
rails_env("production") do
@dummy = Dummy.new
......@@ -574,24 +574,24 @@ describe Paperclip::Storage::S3 do
it "should generate 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)
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
object = stub
@dummy.avatar.stubs(:s3_object).with(:original).returns(object)
object.expects(:url_for).with(:read, :expires => 1800, :secure => true)
object.expects(:url_for).with(:read, expires: 1800, secure: true)
@dummy.avatar.expiring_url(1800)
end
end
context "Parsing S3 credentials with a bucket in them" do
before do
rebuild_model :storage => :s3,
:s3_credentials => {
:production => { :bucket => "prod_bucket" },
:development => { :bucket => "dev_bucket" }
rebuild_model storage: :s3,
s3_credentials: {
production: { bucket: "prod_bucket" },
development: { bucket: "dev_bucket" }
}
@dummy = Dummy.new
end
......@@ -613,11 +613,11 @@ describe Paperclip::Storage::S3 do
context "Parsing S3 credentials with a s3_host_name in them" do
before do
rebuild_model :storage => :s3,
:bucket => 'testing',
:s3_credentials => {
:production => { :s3_host_name => "s3-world-end.amazonaws.com" },
:development => { :s3_host_name => "s3-ap-northeast-1.amazonaws.com" }
rebuild_model storage: :s3,
bucket: 'testing',
s3_credentials: {
production: { s3_host_name: "s3-world-end.amazonaws.com" },
development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
}
@dummy = Dummy.new
end
......@@ -646,12 +646,12 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
:aws_access_key_id => "12345",
:aws_secret_access_key => "54321"
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
aws_access_key_id: "12345",
aws_secret_access_key: "54321"
}
end
......@@ -700,8 +700,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read)
content_type: "image/png",
acl: :public_read)
@dummy.save
end
......@@ -715,8 +715,8 @@ describe Paperclip::Storage::S3 do
AWS::S3::BucketCollection.any_instance.expects(:create).with("testing")
AWS::S3::S3Object.any_instance.stubs(:write).
raises(AWS::S3::Errors::NoSuchBucket.new(stub,
stub(:status => 404,
:body => "<foo/>"))).
stub(status: 404,
body: "<foo/>"))).
then.returns(nil)
@dummy.save
end
......@@ -752,31 +752,31 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and bucket defined as a Proc" do
before do
rebuild_model :storage => :s3,
:bucket => lambda { |attachment| "bucket_#{attachment.instance.other}" },
:s3_credentials => {:not => :important}
rebuild_model storage: :s3,
bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
s3_credentials: {not: :important}
end
it "get 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
assert "bucket_b", Dummy.new(:other => 'b').avatar.s3_bucket.name
assert "bucket_a", Dummy.new(other: 'a').avatar.bucket_name
assert "bucket_a", Dummy.new(other: 'a').avatar.s3_bucket.name
assert "bucket_b", Dummy.new(other: 'b').avatar.bucket_name
assert "bucket_b", Dummy.new(other: 'b').avatar.s3_bucket.name
end
end
context "An attachment with S3 storage and S3 credentials defined as a Proc" do
before do
rebuild_model :storage => :s3,
:bucket => {:not => :important},
:s3_credentials => lambda { |attachment|
rebuild_model storage: :s3,
bucket: {not: :important},
s3_credentials: lambda { |attachment|
Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
}
end
it "get 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]
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
end
......@@ -784,10 +784,10 @@ describe Paperclip::Storage::S3 do
before do
class DummyCredentialProvider; end
rebuild_model :storage => :s3,
:bucket => "testing",
:s3_credentials => {
:credential_provider => DummyCredentialProvider.new
rebuild_model storage: :s3,
bucket: "testing",
s3_credentials: {
credential_provider: DummyCredentialProvider.new
}
@dummy = Dummy.new
end
......@@ -799,7 +799,7 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and S3 credentials in an unsupported manor" do
before do
rebuild_model :storage => :s3, :bucket => "testing", :s3_credentials => ["unsupported"]
rebuild_model storage: :s3, bucket: "testing", s3_credentials: ["unsupported"]
@dummy = Dummy.new
end
......@@ -812,7 +812,7 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and S3 credentials not supplied" do
before do
rebuild_model :storage => :s3, :bucket => "testing"
rebuild_model storage: :s3, bucket: "testing"
@dummy = Dummy.new
end
......@@ -823,14 +823,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and specific s3 headers set" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_headers => {'Cache-Control' => 'max-age=31557600'}
s3_headers: {'Cache-Control' => 'max-age=31557600'}
end
context "when assigned" do
......@@ -847,9 +847,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:cache_control => 'max-age=31557600')
content_type: "image/png",
acl: :public_read,
cache_control: 'max-age=31557600')
@dummy.save
end
......@@ -862,14 +862,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and metadata set using header names" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_headers => {'x-amz-meta-color' => 'red'}
s3_headers: {'x-amz-meta-color' => 'red'}
end
context "when assigned" do
......@@ -886,9 +886,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:metadata => { "color" => "red" })
content_type: "image/png",
acl: :public_read,
metadata: { "color" => "red" })
@dummy.save
end
......@@ -901,14 +901,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and metadata set using the :s3_metadata option" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_metadata => { "color" => "red" }
s3_metadata: { "color" => "red" }
end
context "when assigned" do
......@@ -925,9 +925,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:metadata => { "color" => "red" })
content_type: "image/png",
acl: :public_read,
metadata: { "color" => "red" })
@dummy.save
end
......@@ -940,14 +940,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and storage class set using the header name" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_headers => { "x-amz-storage-class" => "reduced_redundancy" }
s3_headers: { "x-amz-storage-class" => "reduced_redundancy" }
end
context "when assigned" do
......@@ -964,9 +964,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:storage_class => "reduced_redundancy")
content_type: "image/png",
acl: :public_read,
storage_class: "reduced_redundancy")
@dummy.save
end
......@@ -981,13 +981,13 @@ describe Paperclip::Storage::S3 do
[nil, false, ''].each do |tech|
before do
rebuild_model(
:storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"},
:s3_server_side_encryption => tech)
s3_server_side_encryption: tech)
end
context "when assigned" do
......@@ -1004,8 +1004,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read)
content_type: "image/png",
acl: :public_read)
@dummy.save
end
......@@ -1019,14 +1019,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and using AES256 encryption" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_server_side_encryption => :aes256
s3_server_side_encryption: :aes256
end
context "when assigned" do
......@@ -1043,9 +1043,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:server_side_encryption => 'AES256')
content_type: "image/png",
acl: :public_read,
server_side_encryption: 'AES256')
@dummy.save
end
......@@ -1058,14 +1058,14 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and storage class set using the :storage_class option" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_storage_class => :reduced_redundancy
s3_storage_class: :reduced_redundancy
end
context "when assigned" do
......@@ -1082,9 +1082,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:storage_class => :reduced_redundancy)
content_type: "image/png",
acl: :public_read,
storage_class: :reduced_redundancy)
@dummy.save
end
......@@ -1102,8 +1102,8 @@ describe Paperclip::Storage::S3 do
ENV['S3_SECRET'] = 'pathname_secret'
rails_env('test') do
rebuild_model :storage => :s3,
:s3_credentials => Pathname.new(fixture_file('s3.yml'))
rebuild_model storage: :s3,
s3_credentials: Pathname.new(fixture_file('s3.yml'))
Dummy.delete_all
@dummy = Dummy.new
......@@ -1124,8 +1124,8 @@ describe Paperclip::Storage::S3 do
ENV['S3_SECRET'] = 'env_secret'
rails_env('test') do
rebuild_model :storage => :s3,
:s3_credentials => File.new(fixture_file('s3.yml'))
rebuild_model storage: :s3,
s3_credentials: File.new(fixture_file('s3.yml'))
Dummy.delete_all
......@@ -1143,10 +1143,10 @@ describe Paperclip::Storage::S3 do
context "S3 Permissions" do
context "defaults to :public_read" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
}
......@@ -1166,8 +1166,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read)
content_type: "image/png",
acl: :public_read)
@dummy.save
end
......@@ -1180,14 +1180,14 @@ describe Paperclip::Storage::S3 do
context "string permissions set" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:s3_credentials => {
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => :private
s3_permissions: :private
end
context "when assigned" do
......@@ -1204,8 +1204,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :private)
content_type: "image/png",
acl: :private)
@dummy.save
end
......@@ -1218,19 +1218,19 @@ describe Paperclip::Storage::S3 do
context "hash permissions set" do
before do
rebuild_model :storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
rebuild_model storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
styles: {
thumb: "80x80>"
},
:s3_credentials => {
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => {
:original => :private,
:thumb => :public_read
s3_permissions: {
original: :private,
thumb: :public_read
}
end
......@@ -1249,8 +1249,8 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => style == :thumb ? :public_read : :private)
content_type: "image/png",
acl: style == :thumb ? :public_read : :private)
end
@dummy.save
end
......@@ -1265,17 +1265,17 @@ describe Paperclip::Storage::S3 do
context "proc permission set" do
before do
rebuild_model(
:storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
styles: {
thumb: "80x80>"
},
:s3_credentials => {
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_permissions => lambda {|attachment, style|
s3_permissions: lambda {|attachment, style|
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
}
)
......@@ -1309,17 +1309,17 @@ describe Paperclip::Storage::S3 do
context "An attachment with S3 storage and metadata set using a proc as headers" do
before do
rebuild_model(
:storage => :s3,
:bucket => "testing",
:path => ":attachment/:style/:basename.:extension",
:styles => {
:thumb => "80x80>"
storage: :s3,
bucket: "testing",
path: ":attachment/:style/:basename.:extension",
styles: {
thumb: "80x80>"
},
:s3_credentials => {
s3_credentials: {
'access_key_id' => "12345",
'secret_access_key' => "54321"
},
:s3_headers => lambda {|attachment|
s3_headers: lambda {|attachment|
{'Content-Disposition' => "attachment; filename=\"#{attachment.name}\""}
}
)
......@@ -1329,7 +1329,7 @@ describe Paperclip::Storage::S3 do
before do
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.stubs(:name => 'Custom Avatar Name.png')
@dummy.stubs(name: 'Custom Avatar Name.png')
@dummy.avatar = @file
end
......@@ -1341,9 +1341,9 @@ describe Paperclip::Storage::S3 do
object = stub
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
object.expects(:write).with(anything,
:content_type => "image/png",
:acl => :public_read,
:content_disposition => 'attachment; filename="Custom Avatar Name.png"')
content_type: "image/png",
acl: :public_read,
content_disposition: 'attachment; filename="Custom Avatar Name.png"')
end
@dummy.save
end
......
......@@ -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::AttachmentContentTypeValidator do
def build_validator(options)
@validator = Paperclip::Validators::AttachmentContentTypeValidator.new(options.merge(
:attributes => :avatar
attributes: :avatar
))
end
context "with a nil content type" do
before do
build_validator :content_type => "image/jpg"
@dummy.stubs(:avatar_content_type => nil)
build_validator content_type: "image/jpg"
@dummy.stubs(avatar_content_type: nil)
@validator.validate(@dummy)
end
......@@ -27,8 +27,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with :allow_nil option" do
context "as true" do
before do
build_validator :content_type => "image/png", :allow_nil => true
@dummy.stubs(:avatar_content_type => nil)
build_validator content_type: "image/png", allow_nil: true
@dummy.stubs(avatar_content_type: nil)
@validator.validate(@dummy)
end
......@@ -39,8 +39,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as false" do
before do
build_validator :content_type => "image/png", :allow_nil => false
@dummy.stubs(:avatar_content_type => nil)
build_validator content_type: "image/png", allow_nil: false
@dummy.stubs(avatar_content_type: nil)
@validator.validate(@dummy)
end
......@@ -52,8 +52,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with a failing validation" do
before do
build_validator :content_type => "image/png", :allow_nil => false
@dummy.stubs(:avatar_content_type => nil)
build_validator content_type: "image/png", allow_nil: false
@dummy.stubs(avatar_content_type: nil)
@validator.validate(@dummy)
end
......@@ -69,8 +69,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with a successful validation" do
before do
build_validator :content_type => "image/png", :allow_nil => false
@dummy.stubs(:avatar_content_type => "image/png")
build_validator content_type: "image/png", allow_nil: false
@dummy.stubs(avatar_content_type: "image/png")
@validator.validate(@dummy)
end
......@@ -83,8 +83,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with :allow_blank option" do
context "as true" do
before do
build_validator :content_type => "image/png", :allow_blank => true
@dummy.stubs(:avatar_content_type => "")
build_validator content_type: "image/png", allow_blank: true
@dummy.stubs(avatar_content_type: "")
@validator.validate(@dummy)
end
......@@ -95,8 +95,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as false" do
before do
build_validator :content_type => "image/png", :allow_blank => false
@dummy.stubs(:avatar_content_type => "")
build_validator content_type: "image/png", allow_blank: false
@dummy.stubs(avatar_content_type: "")
@validator.validate(@dummy)
end
......@@ -110,8 +110,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with an allowed type" do
context "as a string" do
before do
build_validator :content_type => "image/jpg"
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: "image/jpg"
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -122,8 +122,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as an regexp" do
before do
build_validator :content_type => /^image\/.*/
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: /^image\/.*/
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -134,8 +134,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as a list" do
before do
build_validator :content_type => ["image/png", "image/jpg", "image/jpeg"]
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: ["image/png", "image/jpg", "image/jpeg"]
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -148,8 +148,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with a disallowed type" do
context "as a string" do
before do
build_validator :content_type => "image/png"
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: "image/png"
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -161,8 +161,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as a regexp" do
before do
build_validator :content_type => /^text\/.*/
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: /^text\/.*/
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -175,8 +175,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with :message option" do
context "without interpolation" do
before do
build_validator :content_type => "image/png", :message => "should be a PNG image"
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: "image/png", message: "should be a PNG image"
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -187,8 +187,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with interpolation" do
before do
build_validator :content_type => "image/png", :message => "should have content type %{types}"
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator content_type: "image/png", message: "should have content type %{types}"
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -204,8 +204,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with an allowed type" do
context "as a string" do
before do
build_validator :not => "image/gif"
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator not: "image/gif"
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -216,8 +216,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as an regexp" do
before do
build_validator :not => /^text\/.*/
@dummy.stubs(:avatar_content_type => "image/jpg")
build_validator not: /^text\/.*/
@dummy.stubs(avatar_content_type: "image/jpg")
@validator.validate(@dummy)
end
......@@ -228,8 +228,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as a list" do
before do
build_validator :not => ["image/png", "image/jpg", "image/jpeg"]
@dummy.stubs(:avatar_content_type => "image/gif")
build_validator not: ["image/png", "image/jpg", "image/jpeg"]
@dummy.stubs(avatar_content_type: "image/gif")
@validator.validate(@dummy)
end
......@@ -242,8 +242,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with a disallowed type" do
context "as a string" do
before do
build_validator :not => "image/png"
@dummy.stubs(:avatar_content_type => "image/png")
build_validator not: "image/png"
@dummy.stubs(avatar_content_type: "image/png")
@validator.validate(@dummy)
end
......@@ -255,8 +255,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "as a regexp" do
before do
build_validator :not => /^text\/.*/
@dummy.stubs(:avatar_content_type => "text/plain")
build_validator not: /^text\/.*/
@dummy.stubs(avatar_content_type: "text/plain")
@validator.validate(@dummy)
end
......@@ -269,8 +269,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with :message option" do
context "without interpolation" do
before do
build_validator :not => "image/png", :message => "should not be a PNG image"
@dummy.stubs(:avatar_content_type => "image/png")
build_validator not: "image/png", message: "should not be a PNG image"
@dummy.stubs(avatar_content_type: "image/png")
@validator.validate(@dummy)
end
......@@ -281,8 +281,8 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "with interpolation" do
before do
build_validator :not => "image/png", :message => "should not have content type %{types}"
@dummy.stubs(:avatar_content_type => "image/png")
build_validator not: "image/png", message: "should not have content type %{types}"
@dummy.stubs(avatar_content_type: "image/png")
@validator.validate(@dummy)
end
......@@ -296,7 +296,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
context "using the helper" do
before do
Dummy.validates_attachment_content_type :avatar, :content_type => "image/jpg"
Dummy.validates_attachment_content_type :avatar, content_type: "image/jpg"
end
it "add the validator to the class" do
......@@ -307,16 +307,16 @@ describe Paperclip::Validators::AttachmentContentTypeValidator 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 :content_type was given" do
build_validator :content_type => "image/jpg"
build_validator content_type: "image/jpg"
end
it "not raise argument error if :not was given" do
build_validator :not => "image/jpg"
build_validator not: "image/jpg"
end
end
end
......@@ -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