Commit 81704d1d by Jon Yurek

Verified :url interpolation. Added FakeModel for testing. Fixed default_options…

Verified :url interpolation. Added FakeModel for testing. Fixed default_options merging race test problem.
parent 3eb7844c
......@@ -7,7 +7,7 @@ module Paperclip
def self.default_options
@default_options ||= {
:url => "/system/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public:url",
:styles => {},
:default_url => "/:attachment/:style/missing.png",
:default_style => :original,
......@@ -16,7 +16,7 @@ module Paperclip
}
end
attr_reader :name, :instance, :styles, :default_style, :convert_options, :queued_for_write
attr_reader :name, :instance, :styles, :default_style, :convert_options, :queued_for_write, :options
# Creates an Attachment object. +name+ is the name of the attachment,
# +instance+ is the ActiveRecord object instance it's attached to, and
......
......@@ -5,6 +5,14 @@ class Dummy
end
class AttachmentTest < Test::Unit::TestCase
should "return the path based on the url by default" do
@attachment = attachment :url => "/:class/:id/:basename"
@model = @attachment.instance
@model.id = 1234
@model.avatar_file_name = "fake.jpg"
assert_equal "#{RAILS_ROOT}/public/fake_models/1234/fake", @attachment.path
end
context "Attachment default_options" do
setup do
rebuild_model
......@@ -456,6 +464,7 @@ class AttachmentTest < Test::Unit::TestCase
context "An attachment" do
setup do
@old_defaults = Paperclip::Attachment.default_options.dup
Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
})
......@@ -468,7 +477,10 @@ class AttachmentTest < Test::Unit::TestCase
"5k.png"), 'rb')
end
teardown { @file.close }
teardown do
@file.close
Paperclip::Attachment.default_options.merge!(@old_defaults)
end
should "raise if there are not the correct columns when you try to assign" do
@other_attachment = Paperclip::Attachment.new(:not_here, @instance)
......
......@@ -81,3 +81,22 @@ def temporary_rails_env(new_env)
Object.const_set("RAILS_ENV", old_env)
end
end
class FakeModel
attr_accessor :avatar_file_name,
:avatar_file_size,
:avatar_last_updated,
:avatar_content_type,
:id
def errors
@errors ||= []
end
def run_callbacks
end
end
def attachment options
Paperclip::Attachment.new(:avatar, FakeModel.new, options)
end
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