class Test::Unit::TestCase
# Shoulda helper for testing Paperclip
def self.should_have_attached_file(attachment)
klass = self.name.gsub(/Test$/, '').constantize
context "To support a paperclip attachment named #{attachment}, #{klass}" do
should_have_db_column("#{attachment}_file_name", :type => :string)
should_have_db_column("#{attachment}_content_type", :type => :string)
should_have_db_column("#{attachment}_file_size", :type => :integer)
end
should "have a paperclip attachment named ##{attachment}" do
assert klass.new.respond_to?(attachment.to_sym),
"@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
end
end
# Shoulda helper for acts_as_taggable_on_steroids
def self.should_act_as_taggable_on_steroids
klass = self.name.gsub(/Test$/, '').constantize
should "include ActsAsTaggableOnSteroids methods" do
assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::ClassMethods)
assert klass.extended_by.include?(ActiveRecord::Acts::Taggable::SingletonMethods)
assert klass.include?(ActiveRecord::Acts::Taggable::InstanceMethods)
end
should_have_many :taggings, :tags
end
def self.should_act_as_ferret(*fields)
klass = self.name.gsub(/Test$/, '').constantize
should "include ActsAsFerret methods" do
assert klass.extended_by.include?(ActsAsFerret::ClassMethods)
assert klass.include?(ActsAsFerret::InstanceMethods)
assert klass.include?(ActsAsFerret::MoreLikeThis::InstanceMethods)
assert klass.include?(ActsAsFerret::ResultAttributes)
end
fields.each do |f|
should "create an index for field named #{f}" do
assert klass.aaf_configuration[:fields].include?(f)
end
end
end
def self.should_act_as_list
klass = self.name.gsub(/Test$/, '').constantize
context "To support acts_as_list" do
should_have_db_column('position', :type => :integer)
end
should "include ActsAsList methods" do
assert klass.include?(ActiveRecord::Acts::List::InstanceMethods)
end
should_have_instance_methods :acts_as_list_class, :position_column, :scope_condition
end
end