hornbeck / blerb-core

blerb running on merb-core

This URL has Read+Write access

blerb-core / spec / controllers / articles_spec.rb
100644 54 lines (41 sloc) 1.665 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require File.join(File.dirname(__FILE__), 'controller_spec_helper.rb')
 
describe Articles do
  include DefaultSpecHelper
  include ArticleSpecHelper
  include DefaultControllerHelper
 
  it_should_behave_like "default controller behavior"
 
  describe "#index" do
    it "should find all articles and place them in @articles" do
      Article.should_receive(:all).and_return []
      dispatch_to(Articles, :index).assigns(:articles).should == []
    end
    
    it "should find all articles by reverse date" do
      Article.should_receive(:all).with(:order => 'created_at desc')
      
      dispatch_to(Articles, :index)
    end
  end
  
  describe "#show" do
    before(:each) do
      @article = mock_model Article,
        {
          :title => "Merb + Blerb = Superb!",
          :slug => "merb-blerb-superb",
          :created_at => Time.now,
          :body => "",
          :comments => []
        }
    end
    
    it "should find the first article by the slug" do
      Article.should_receive(:with_slug).with(@article.slug).and_return @article
      
      dispatch_to(Articles, :show, :id => @article.slug)
    end
    
    it "should find the first article and place it in @article" do
      Article.should_receive(:with_slug).and_return @article
      
      dispatch_to(Articles, :show, :id => @article.slug).assigns(:article).should == @article
    end
    
    it "should raise a NotFound error if the slug id does not find an article" do
      Article.should_receive(:with_slug).and_return nil
      
      lambda { dispatch_to(Articles, :show, :id => @article.slug) }.should raise_error(Merb::ControllerExceptions::NotFound)
    end
  end
end