Commit df4fd988 by Prem Sichanugrist

Refactor test to use fixture helper

parent 8fb03315
......@@ -7,7 +7,7 @@ class Dummy; end
class AttachmentTest < Test::Unit::TestCase
should "process :original style first" do
file = File.new(File.join(File.dirname(__FILE__), "fixtures", "50x50.png"), 'rb')
file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
dummy = Dummy.new
dummy.avatar = file
......@@ -20,7 +20,7 @@ class AttachmentTest < Test::Unit::TestCase
end
should "not delete styles that don't get reprocessed" do
file = File.new(File.join(File.dirname(__FILE__), "fixtures", "50x50.png"), 'rb')
file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>',
:large => '500x>',
:original => '42x42#' }
......@@ -202,9 +202,7 @@ class AttachmentTest < Test::Unit::TestCase
rebuild_model :path => ":id.omg/:id-bbq/:idwhat/:id_partition.wtf"
@dummy = Dummy.new
@dummy.stubs(:id).returns(1024)
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
end
......@@ -418,9 +416,7 @@ class AttachmentTest < Test::Unit::TestCase
setup do
rebuild_model :path => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummyA = Dummy.new(:other => 'a')
@dummyA.avatar = @file
@dummyB = Dummy.new(:other => 'b')
......@@ -815,7 +811,7 @@ class AttachmentTest < Test::Unit::TestCase
@instance = Dummy.new
@instance.stubs(:id).returns 123
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "uppercase.PNG"), 'rb')
@file = File.new(fixture_file("uppercase.PNG"), 'rb')
styles = {:styles => { :large => ["400x400", :jpg],
:medium => ["100x100", :jpg],
......@@ -852,7 +848,7 @@ class AttachmentTest < Test::Unit::TestCase
@instance = Dummy.new
@instance.stubs(:id).returns 123
@attachment = Paperclip::Attachment.new(:avatar, @instance)
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
end
teardown do
......@@ -1046,7 +1042,7 @@ class AttachmentTest < Test::Unit::TestCase
end
rebuild_class
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
end
teardown { @file.close }
......@@ -1167,7 +1163,7 @@ class AttachmentTest < Test::Unit::TestCase
setup do
rebuild_model :preserve_files => true
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
@dummy.save!
@attachment = @dummy.avatar
......@@ -1191,7 +1187,7 @@ class AttachmentTest < Test::Unit::TestCase
setup do
rebuild_model
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
@dummy.save!
@attachment = @dummy.avatar
......
......@@ -101,7 +101,7 @@ class GeometryTest < Test::Unit::TestCase
end
should "be generated from a file" do
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
file = fixture_file("5k.png")
file = File.new(file, 'rb')
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
assert @geo.height > 0
......@@ -109,7 +109,7 @@ class GeometryTest < Test::Unit::TestCase
end
should "be generated from a file path" do
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
file = fixture_file("5k.png")
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
assert @geo.height > 0
assert @geo.width > 0
......@@ -141,7 +141,7 @@ class GeometryTest < Test::Unit::TestCase
begin
ENV['PATH'] = ''
assert_raises(Paperclip::Errors::CommandNotFoundError) do
file = File.join(File.dirname(__FILE__), "fixtures", "5k.png")
file = fixture_file("5k.png")
@geo = Paperclip::Geometry.from_file(file)
end
ensure
......
......@@ -7,7 +7,7 @@ class IntegrationTest < Test::Unit::TestCase
context "Many models at once" do
setup do
rebuild_model
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
300.times do |i|
Dummy.create! :avatar => @file
end
......@@ -27,9 +27,7 @@ class IntegrationTest < Test::Unit::TestCase
setup do
rebuild_model :styles => { :thumb => "50x50#" }
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
assert @dummy.save
end
......@@ -88,9 +86,7 @@ class IntegrationTest < Test::Unit::TestCase
File.delete(@thumb_path) if File.exists?(@thumb_path)
rebuild_model :styles => { :thumb => "50x50#" }
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
end
......@@ -119,9 +115,7 @@ class IntegrationTest < Test::Unit::TestCase
File.delete(@thumb_large_path) if File.exists?(@thumb_large_path)
rebuild_model :styles => { :thumb_small => "50x50#", :thumb_large => "60x60#" }
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar.post_processing = false
@dummy.avatar = @file
......@@ -158,9 +152,7 @@ class IntegrationTest < Test::Unit::TestCase
setup do
rebuild_model :styles => { :original => "2x2#" }
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
end
......@@ -177,9 +169,7 @@ class IntegrationTest < Test::Unit::TestCase
:medium => "50x50" },
:path => ":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy = Dummy.new
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy.avatar = @file
end
......@@ -286,7 +276,7 @@ class IntegrationTest < Test::Unit::TestCase
setup do
rebuild_model
@dummy = Dummy.new
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@umask = File.umask(umask)
end
......@@ -312,8 +302,8 @@ class IntegrationTest < Test::Unit::TestCase
:url => "/:attachment/:class/:style/:id/:basename.:extension",
:path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension"
@dummy = Dummy.new
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@bad_file = File.new(fixture_file("bad.png"), 'rb')
assert @dummy.avatar = @file
assert @dummy.valid?, @dummy.errors.full_messages.join(", ")
......@@ -410,7 +400,7 @@ class IntegrationTest < Test::Unit::TestCase
context "that is assigned its file from another Paperclip attachment" do
setup do
@dummy2 = Dummy.new
@file2 = File.new(File.join(FIXTURES_DIR, "12k.png"), 'rb')
@file2 = File.new(fixture_file("12k.png"), 'rb')
assert @dummy2.avatar = @file2
@dummy2.save
end
......@@ -437,7 +427,7 @@ class IntegrationTest < Test::Unit::TestCase
has_many :attachments, :class_name => 'Dummy'
end
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -458,7 +448,7 @@ class IntegrationTest < Test::Unit::TestCase
rebuild_model @settings
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
@dummy = Dummy.create! :avatar => @file
end
......
......@@ -60,7 +60,7 @@ class PaperclipTest < Test::Unit::TestCase
context "Paperclip.each_instance_with_attachment" do
setup do
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
d1 = Dummy.create(:avatar => @file)
d2 = Dummy.create
d3 = Dummy.create(:avatar => @file)
......@@ -131,7 +131,7 @@ class PaperclipTest < Test::Unit::TestCase
context "An ActiveRecord model with an 'avatar' attachment" do
setup do
rebuild_model :path => "tmp/:class/omg/:style.:extension"
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
end
teardown { @file.close }
......
......@@ -5,7 +5,7 @@ unless ENV["S3_BUCKET"].blank?
class S3LiveTest < Test::Unit::TestCase
context "when assigning an S3 attachment directly to another model" do
setup do
@s3_credentials = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@s3_credentials = File.new(fixture_file("s3.yml"))
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
......@@ -40,7 +40,7 @@ unless ENV["S3_BUCKET"].blank?
context "Generating an expiring url on a nonexistant attachment" do
setup do
@s3_credentials = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@s3_credentials = File.new(fixture_file("s3.yml"))
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
......@@ -57,7 +57,7 @@ unless ENV["S3_BUCKET"].blank?
context "Using S3 for real, an attachment with S3 storage" do
setup do
@s3_credentials = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@s3_credentials = File.new(fixture_file("s3.yml"))
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
......@@ -99,7 +99,7 @@ unless ENV["S3_BUCKET"].blank?
context "An attachment that uses S3 for storage and has spaces in file name" do
setup do
@s3_credentials = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@s3_credentials = File.new(fixture_file("s3.yml"))
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
......@@ -139,7 +139,7 @@ unless ENV["S3_BUCKET"].blank?
context "An attachment that uses S3 for storage and uses AES256 encryption" do
setup do
@s3_credentials = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@s3_credentials = File.new(fixture_file("s3.yml"))
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_BUCKET"],
......
......@@ -670,7 +670,7 @@ class S3Test < Test::Unit::TestCase
context "when assigned" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -709,7 +709,7 @@ class S3Test < Test::Unit::TestCase
context "when assigned" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -748,7 +748,7 @@ class S3Test < Test::Unit::TestCase
context "when assigned" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -787,7 +787,7 @@ class S3Test < Test::Unit::TestCase
context "when assigned" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......@@ -826,7 +826,7 @@ class S3Test < Test::Unit::TestCase
context "when assigned" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), '..', 'fixtures', '5k.png'), 'rb')
@file = File.new(fixture_file('5k.png'), 'rb')
@dummy = Dummy.new
@dummy.avatar = @file
end
......
......@@ -36,7 +36,7 @@ class ThumbnailTest < Test::Unit::TestCase
context "An image" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
@file = File.new(fixture_file("5k.png"), 'rb')
end
teardown { @file.close }
......@@ -296,7 +296,7 @@ class ThumbnailTest < Test::Unit::TestCase
context "A multipage PDF" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "twopage.pdf"), 'rb')
@file = File.new(fixture_file("twopage.pdf"), 'rb')
end
teardown { @file.close }
......@@ -329,7 +329,7 @@ class ThumbnailTest < Test::Unit::TestCase
context "An animated gif" do
setup do
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "animated.gif"), 'rb')
@file = File.new(fixture_file("animated.gif"), 'rb')
end
teardown { @file.close }
......
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