test/integration_test.rb in thoughtbot-paperclip-2.1.5 vs test/integration_test.rb in thoughtbot-paperclip-2.2.0
- old
+ new
@@ -27,10 +27,12 @@
"5k.png"), 'rb')
@dummy.avatar = @file
assert @dummy.save
end
+ teardown { @file.close }
+
should "create its thumbnails properly" do
assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
end
context "redefining its attachment styles" do
@@ -47,10 +49,52 @@
assert_match /\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
end
end
end
+ context "A model with attachments scoped under an id" do
+ setup do
+ rebuild_model :styles => { :large => "100x100",
+ :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')
+ @dummy.avatar = @file
+ end
+
+ teardown { @file.close }
+
+ context "when saved" do
+ setup do
+ @dummy.save
+ @saved_path = @dummy.avatar.path(:large)
+ end
+
+ should "have a large file in the right place" do
+ assert File.exists?(@dummy.avatar.path(:large))
+ end
+
+ context "and deleted" do
+ setup do
+ @dummy.avatar = nil
+ @dummy.save
+ end
+
+ should "not have a large file in the right place anymore" do
+ assert ! File.exists?(@saved_path)
+ end
+
+ should "not have its next two parent directories" do
+ assert ! File.exists?(File.dirname(@saved_path))
+ assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
+ end
+ end
+ end
+ end
+
context "A model with no attachment validation" do
setup do
rebuild_model :styles => { :large => "300x300>",
:medium => "100x100",
:thumb => ["32x32#", :gif] },
@@ -207,11 +251,11 @@
expected.close
@dummy.avatar = @bad_file
assert ! @dummy.valid?
@dummy.avatar = nil
- assert @dummy.valid?
+ assert @dummy.valid?, @dummy.errors.inspect
end
should "know the difference between good files, bad files, not files, and nil when validating" do
Dummy.validates_attachment_presence :avatar
@d2 = Dummy.find(@dummy.id)
@@ -259,9 +303,28 @@
assert !@dummy.avatar?
end
end
+ end
+
+ context "A model with an attachments association and a Paperclip attachment" do
+ setup do
+ Dummy.class_eval do
+ has_many :attachments, :class_name => 'Dummy'
+ end
+
+ @dummy = Dummy.new
+ @dummy.avatar = File.new(File.join(File.dirname(__FILE__),
+ "fixtures",
+ "5k.png"), 'rb')
+ end
+
+ should "should not error when saving" do
+ assert_nothing_raised do
+ @dummy.save!
+ end
+ end
end
if ENV['S3_TEST_BUCKET']
def s3_files_for attachment
[:thumb, :medium, :large, :original].inject({}) do |files, style|