Skip to content

Commit

Permalink
added unit tests for documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Bellmyer committed Jan 6, 2010
1 parent 6029fc2 commit 1e98375
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
28 changes: 28 additions & 0 deletions 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
46 changes: 43 additions & 3 deletions 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

0 comments on commit 1e98375

Please sign in to comment.