Skip to content

Instantly share code, notes, and snippets.

@rich
Created August 18, 2008 15:45
Show Gist options
  • Select an option

  • Save rich/5988 to your computer and use it in GitHub Desktop.

Select an option

Save rich/5988 to your computer and use it in GitHub Desktop.
module ActsAsCommentable
module Shoulda
def should_be_commentable
should_have_many :comments
should_have_class_methods :find_comments_for, :find_comments_by_user
should_have_instance_methods :add_comment, :comments_ordered_by_submitted
end
end
end
Test::Unit::TestCase.extend(ActsAsCommentable::Shoulda)
module ActsAsTaggableOn
module Shoulda
def should_be_taggable
should_be_taggable_on(:tags)
end
def should_be_taggable_on(*args)
klass = self.name.gsub(/Test$/, '').constantize
args.flatten! if args
args.compact! if args
for tag_type in args
tag_type = tag_type.to_s
context "Class #{klass.name} with tag #{tag_type}" do
should_have_class_methods :taggable?, "caching_#{tag_type.singularize}_list?".to_sym, "#{tag_type.singularize}_counts".to_sym
should_have_instance_methods "#{tag_type.singularize}_list".to_sym, "#{tag_type.singularize}_list=".to_sym, "#{tag_type.singularize}_counts".to_sym, "#{tag_type}_from".to_sym, "find_related_#{tag_type}".to_sym, "find_related_on_#{tag_type}".to_sym, "find_related_#{tag_type}_for".to_sym
base_assoc = "#{tag_type.singularize}_taggings".to_sym
should_have_many base_assoc
should_have_many tag_type.to_sym, :through => base_assoc
end
end
end
end
end
Test::Unit::TestCase.extend(ActsAsTaggableOn::Shoulda)
module SaltySlugs
module Shoulda
def should_be_slugged(*args)
klass = self.name.gsub(/Test$/, '').constantize
options = args.extract_options!
slug_column = options[:slug_column] || 'slug'
source_column = options[:source_column] || 'title'
context "Class #{klass.name} with a slug" do
should_have_db_column slug_column
should_have_instance_methods source_column
end
end
end
end
Test::Unit::TestCase.extend(SaltySlugs::Shoulda)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment