brookr (owner)

Revisions

gist: 80112 Download_button fork
public
Public Clone URL: git://gist.github.com/80112.git
Embed All Files: show embed
Text only #
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require File.dirname(__FILE__) + '/../test_helper'
 
class SurveysControllerTest < ActionController::TestCase
 
  context 'GET to index' do
    setup do
      @staff = Factory(:staff)
      session['staff'] = @staff.id
      get :index
    end
 
    should_respond_with :success
    should_render_template :index
  end
 
  context 'GET to new' do
    setup do
      @staff = Factory(:staff)
      session['staff'] = @staff.id
 
      get :new
    end
 
    should_respond_with :success
    should_render_template :new
    should_assign_to :survey
  end
 
  context 'POST to create with valid parameters' do
    setup do
      post :create, :survey => Factory.attributes_for(:survey)
      @survey = Survey.find(:all).last
    end
 
    should_change 'Survey.count', :by => 1
    should_set_the_flash_to /created/i
    should_redirect_to( 'survey_path(@survey)' ) {}
  end
 
  context 'GET to show for existing survey' do
    setup do
      @survey = Factory(:survey)
      @staff = Factory(:staff)
      get :show, :id => @survey.to_param
    end
 
    should_respond_with :success
    should_render_template :show
    should_assign_to( :survey ) { @survey }
  end
 
  context 'GET to edit for existing survey' do
    setup do
      @survey = Factory(:survey)
      @staff = Factory(:staff)
      get :edit, :id => @survey.survey_link.to_param
    end
 
    should_respond_with :success
    should_render_template :edit
    should_assign_to (:survey) { @survey }
  end
 
  context 'PUT to update for existing survey' do
    setup do
      @survey = Factory(:survey)
      @staff = Factory(:staff)
      put :update, :id => @survey.to_param,
        :survey => Factory.attributes_for(:survey)
    end
 
    should_set_the_flash_to /updated/i
    should_redirect_to( 'survey_path(@survey)' ) {}
  end
  
  context 'given a survey' do
    setup do
      @survey = Factory(:survey)
    end
    
    context 'DELETE to destroy' do
      setup do
        delete :destroy, :id => @survey.to_param
      end
 
      should_change 'Survey.count', :from => 1, :to => 0
      should_set_the_flash_to /deleted/i
      should_redirect_to( 'surveys_path' ) {}
    end
  end
  
 
end