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 ...@@ -7,7 +7,7 @@ module Paperclip
def self.default_options def self.default_options
@default_options ||= { @default_options ||= {
:url => "/system/:attachment/:id/:style/:basename.:extension", :url => "/system/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:attachment/:id/:style/:basename.:extension", :path => ":rails_root/public:url",
:styles => {}, :styles => {},
:default_url => "/:attachment/:style/missing.png", :default_url => "/:attachment/:style/missing.png",
:default_style => :original, :default_style => :original,
...@@ -16,7 +16,7 @@ module Paperclip ...@@ -16,7 +16,7 @@ module Paperclip
} }
end 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, # Creates an Attachment object. +name+ is the name of the attachment,
# +instance+ is the ActiveRecord object instance it's attached to, and # +instance+ is the ActiveRecord object instance it's attached to, and
......
...@@ -5,6 +5,14 @@ class Dummy ...@@ -5,6 +5,14 @@ class Dummy
end end
class AttachmentTest < Test::Unit::TestCase 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 context "Attachment default_options" do
setup do setup do
rebuild_model rebuild_model
...@@ -456,6 +464,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -456,6 +464,7 @@ class AttachmentTest < Test::Unit::TestCase
context "An attachment" do context "An attachment" do
setup do setup do
@old_defaults = Paperclip::Attachment.default_options.dup
Paperclip::Attachment.default_options.merge!({ Paperclip::Attachment.default_options.merge!({
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
}) })
...@@ -468,7 +477,10 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -468,7 +477,10 @@ class AttachmentTest < Test::Unit::TestCase
"5k.png"), 'rb') "5k.png"), 'rb')
end 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 should "raise if there are not the correct columns when you try to assign" do
@other_attachment = Paperclip::Attachment.new(:not_here, @instance) @other_attachment = Paperclip::Attachment.new(:not_here, @instance)
......
...@@ -81,3 +81,22 @@ def temporary_rails_env(new_env) ...@@ -81,3 +81,22 @@ def temporary_rails_env(new_env)
Object.const_set("RAILS_ENV", old_env) Object.const_set("RAILS_ENV", old_env)
end end
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