Created
August 18, 2008 15:45
-
-
Save rich/5988 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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