forked from bellmyer/seed
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jaime Bellmyer
committed
Jan 6, 2010
1 parent
6029fc2
commit 1e98375
Showing
2 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |