Permalink
Browse files

test that #public_path still starts with a slash if the attachment is…

… stored outside of the public directory
  • Loading branch information...
1 parent e90425d commit 65ec4495741aac37c7df71999ada1e40c8582cea @technoweenie technoweenie committed Mar 25, 2010
Showing with 17 additions and 1 deletion.
  1. +3 −1 lib/attachment_fu.rb
  2. +14 −0 spec/attachment_fu_spec.rb
View
@@ -217,7 +217,9 @@ def has_attachment?
def public_path(thumbnail = nil)
return nil if !has_attachment?
- File.join(attachment_path, *partitioned_path(thumbnailed_filename(thumbnail))).sub(/^public\//, '/')
+ p = File.join(attachment_path, *partitioned_path(thumbnailed_filename(thumbnail))).sub(/^public\//, '/')
+ p.insert(0, '/') unless p[0..0] == '/'
+ p
end
def full_path(thumbnail = nil)
View
@@ -9,6 +9,10 @@ class QueuedAsset < ActiveRecord::Base
is_faux_attachment :queued => true
end
+ class PrivateAsset < ActiveRecord::Base
+ is_faux_attachment :path => 'foo'
+ end
+
describe "AttachmentFu" do
describe "pending creation" do
before do
@@ -96,6 +100,16 @@ class QueuedAsset < ActiveRecord::Base
end
end
+ describe "being created outside of public path" do
+ it "creates public_path from record id and attachment_path" do
+ asset = PrivateAsset.new :filename => 'foo.bar'
+ def asset.attachment_path_id # fake-out #has_attachment?
+ 55
+ end
+ asset.public_path.should == "/foo/0000/0055/foo.bar"
+ end
+ end
+
describe "being created" do
before :all do
@file = File.join(File.dirname(__FILE__), 'guinea_pig.rb')

0 comments on commit 65ec449

Please sign in to comment.