nmerouze (owner)

Revisions

gist: 31749 Download_button fork
public
Public Clone URL: git://gist.github.com/31749.git
Ruby
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
describe PostsController do
  
  integrate_views
  
  describe 'GET /index' do
    
    before(:each) do
      get :index
    end
    
    it "should be successful" do
      response.should be_success
    end
    
    it "should render template 'index'" do
      response.should render_template("index")
      response.should have_tag("h1")
    end
    
  end
  
  describe 'GET /index.xml' do
    
    before(:each) do
      request.env["HTTP_ACCEPT"] = "application/xml"
      get :index
    end
    
    it "should be successful" do
      response.should be_success
    end
    
    it "should render all posts as xml" do
      response.body.should include('<?xml version="1.0" encoding="UTF-8"?>')
    end
    
  end
  
  describe "POST /posts" do
    
    describe "with valid parameters" do
      
      before(:each) do
        post :create, :post => { :title => 'Cool' }
      end
 
      it "should be redirected" do
        response.should be_redirect
      end
      
      it "should redirect to the created post" do
        response.should redirect_to(post_url(1))
      end
      
    end
    
    describe "with invalid parameters" do
      
      before(:each) do
        post :create, :post => {}
      end
 
      it "should not be redirected" do
        response.should_not be_redirect
      end
      
      it "should render template 'new'" do
        response.should render_template("new")
        response.should have_tag("h1")
      end
      
    end
    
  end
 
end