Title / Description
Code require 'test_helper' class CategoryTest < ActiveSupport::TestCase should have_many(:articles) context "The Category class" do should "return a list of categories in order" do second = Factory(:category, :position => 2) first = Factory(:category, :position => 1) third = Factory(:category, :position => 3) assert_equal [first, second, third], Category.by_position end should "return a list of only those categories that have published articles" do used = Factory(:category) also_used = Factory(:category) unused = Factory(:category) unpublished = Factory(:category) 3.times { Factory(:published_article, :category => used) } 2.times { Factory(:published_article, :category => also_used) } Factory(:unpublished_article, :category => unpublished) assert_equal [used, also_used], Category.used end end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code