test/milton/attachment_test.rb in citrusbyte-milton-0.3.4 vs test/milton/attachment_test.rb in citrusbyte-milton-0.3.5
- old
+ new
@@ -30,11 +30,41 @@
end
end
context "setting options" do
context "defaults" do
+ class DefaultAttachment < ActiveRecord::Base
+ is_attachment
+ end
+
should "use :disk as default storage" do
assert_equal :disk, Attachment.milton_options[:storage]
+ end
+
+ should "use #{Rails.root}/public/default_attachments as default disk storage root" do
+ assert_equal File.join(Rails.root, 'public', 'default_attachments'), DefaultAttachment.milton_options[:storage_options][:root]
+ end
+
+ should "use 0755 as default mode for new disk files" do
+ assert_equal 0755, DefaultAttachment.milton_options[:storage_options][:chmod]
+ end
+
+ should "raise LoadError if storage engine could not be required" do
+ assert_raise LoadError do
+ class BadStorageAttachment < ActiveRecord::Base
+ is_attachment :storage => :foo
+ end
+ end
+ end
+
+ should "raise helpful LoadError if storage engine could not be required" do
+ begin
+ class BadStorageAttachment < ActiveRecord::Base
+ is_attachment :storage => :foo
+ end
+ rescue LoadError => e
+ assert_equal "No 'foo' storage found for Milton (failed to require milton/storage/foo_file)", e.message
+ end
end
end
context "inheritence" do
class FooImage < Image