From 1e983756155752e2f6899107f03d5ea8e8f1c5a1 Mon Sep 17 00:00:00 2001 From: Jaime Bellmyer Date: Tue, 5 Jan 2010 22:00:32 -0600 Subject: [PATCH] added unit tests for documents --- test/shoulda_macros/attachment_fu_macros.rb | 28 +++++++++++++ test/unit/document_test.rb | 46 +++++++++++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 test/shoulda_macros/attachment_fu_macros.rb diff --git a/test/shoulda_macros/attachment_fu_macros.rb b/test/shoulda_macros/attachment_fu_macros.rb new file mode 100644 index 0000000..68da594 --- /dev/null +++ b/test/shoulda_macros/attachment_fu_macros.rb @@ -0,0 +1,28 @@ +class Test::Unit::TestCase + class << self + def should_validate_as_attachment + klass = self.name.gsub(/Test$/, '').constantize + + context "validate as attachment" do + should_validate_presence_of :size, :content_type, :filename + + should "validate with :attachment_attributes_valid?" do + callback_chain = klass.validate_callback_chain + assert callback_chain.map(&:method).include?(:attachment_attributes_valid?) + end + end + end + + def should_have_attachment(options = {}) + klass = self.name.gsub(/Test$/, '').constantize + + context "should have attachment options" do + options.each do |key, val| + should "have the correct options for key #{key}" do + assert val, klass.attachment_options[key] + end + end + end + end + end +end diff --git a/test/unit/document_test.rb b/test/unit/document_test.rb index 3fb49b8..3dab2f0 100644 --- a/test/unit/document_test.rb +++ b/test/unit/document_test.rb @@ -1,8 +1,48 @@ require 'test_helper' class DocumentTest < ActiveSupport::TestCase - # Replace this with your real tests. - def test_truth - assert true + should_belong_to :component, :article + + should_validate_presence_of :name + should_validate_as_attachment + + should_have_attachment :max_size => 20.megabytes, + :content_type => [ + 'application/pdf', + 'application/msword', + 'application/msexcel', + 'application/vnd.ms-excel', + 'application/vnd.ms-powerpoint', + 'application/octet-stream', + 'text/rtf', + 'text/plain', + 'video/mpeg', + 'video/quicktime', + 'video/x-msvideo', + 'audio/x-wav', + 'audio/mpeg' + ], + :storage => :file_system + + context "ORDER_OPTIONS" do + should "include Created Descending" do + assert Document::ORDER_OPTIONS.include?(['Created Descending', 'created_at DESC']) + end + + should "include Created Ascending" do + assert Document::ORDER_OPTIONS.include?(['Created Ascending', 'created_at ASC']) + end + + should "include Name Descending" do + assert Document::ORDER_OPTIONS.include?(['Name Descending', 'name DESC']) + end + + should "include Name Ascending" do + assert Document::ORDER_OPTIONS.include?(['Name Ascending', 'name ASC']) + end + + should "have four options" do + assert_equal 4, Document::ORDER_OPTIONS.size + end end end