category_spec.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. require File.dirname(__FILE__) + '/../spec_helper'
  2. describe 'Given the results of Category.find_all_with_article_counters' do
  3.   before(:each) { @cats = Category.find_all_with_article_counters }
  4.   it "Categories should be sorted by category.position" do
  5.     @cats.should == @cats.sort_by { |c| c.position }
  6.   end
  7.   it "Counts should be correct" do
  8.     @cats.each do |cat|
  9.       cat.article_counter.should == cat.published_articles.size
  10.     end
  11.   end
  12. end
  13. describe 'Given the fixtures' do
  14.   it 'find gets the order right' do
  15.     cats = Category.find(:all)
  16.     cats.should == cats.sort_by { |c| c.position }
  17.     Category.reorder(cats.reverse.collect { |c| c.id })
  18.     Category.find(:all).should == cats.reverse
  19.   end
  20.   it 'can still override order in find' do
  21.     cats = Category.find(:all, :order => 'name ASC')
  22.     cats.should == cats.sort_by {|c| c.name}
  23.     Category.find(:all).should_not == cats
  24.   end
  25.   it '.reorder_alpha puts categories in alphabetical order' do
  26.     Category.find(:all).should_not == Category.find(:all, :order => :name)
  27.     Category.reorder_alpha
  28.     Category.find(:all).should == Category.find(:all, :order => :name)
  29.   end
  30.   it 'A category knows its url' do
  31.     categories(:software).permalink_url.should ==
  32.       'http://myblog.net/category/software'
  33.   end
  34. end