summaryrefslogtreecommitdiff
path: root/test/functional/phone_book_entries_controller_test.rb
blob: b340f0fb2b84c1469511e5b2afc66e1afc7f92a6 (plain)
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
96
97
98
99
100
101
102
103
require 'test_helper'

class PhoneBookEntriesControllerTest < ActionController::TestCase
  
  setup do
    @user1 = FactoryGirl.create(:user)
    pb = @user1.phone_books.first
    @user1_phone_book_entry = FactoryGirl.create(
      :phone_book_entry,
      :phone_book_id => pb.id
    )
    
    @expected_status_if_not_authorized = :redirect
  end

  test "should not get index (not logged in)" do
    get :index
    assert_response @expected_status_if_not_authorized
  end
  
  test "should get index" do
    session[:user_id] = @user1.id
    get :index
    assert_response :success
    assert_not_nil assigns(:phone_book_entries)
  end
  
  
#   test "should get new" do
#     get :new
#     assert_response :success
#   end
  
  test "should not have a route for new" do
    assert_raises(ActionController::RoutingError) {
      get :new
    }
  end
  
# 
#   test "should create phone_book_entry" do
#     assert_difference('PhoneBookEntry.count') do
#       post :create, phone_book_entry: @user1_phone_book_entry.attributes
#     end
# 
#     assert_redirected_to phone_book_entry_path(assigns(:phone_book_entry))
#   end
# 
   test "should not show phone_book_entry (not logged in)" do
     get :show, id: @user1_phone_book_entry.to_param
     assert_response @expected_status_if_not_authorized
   end
   
   test "should show phone_book_entry without nesting" do
     session[:user_id] = @user1.id
     get :show, id: @user1_phone_book_entry.to_param
     assert_response :success
   end
   
   test "should show phone_book_entry nested in phone_book" do
     session[:user_id] = @user1.id
     get :show, phone_book_id: @user1_phone_book_entry.phone_book.id, id: @user1_phone_book_entry.to_param
     assert_response :success
   end
# 
#   test "should get edit" do
#     get :edit, id: @user1_phone_book_entry.to_param
#     assert_response :success
#   end
  
  test "should not have a route for edit" do
    assert_raises(ActionController::RoutingError) {
      get :edit, id: @user1_phone_book_entry.to_param
    }
  end
  
# 
#   test "should update phone_book_entry" do
#     put :update, id: @user1_phone_book_entry.to_param, phone_book_entry: @user1_phone_book_entry.attributes
#     assert_redirected_to phone_book_entry_path(assigns(:phone_book_entry))
#   end
  
  test "should not have a route for update" do
    assert_raises(ActionController::RoutingError) {
      put :update, id: @user1_phone_book_entry.to_param, phone_book_entry: @user1_phone_book_entry.attributes
    }
  end
  
# 
#   test "should destroy phone_book_entry" do
#     assert_difference('PhoneBookEntry.count', -1) do
#       delete :destroy, id: @user1_phone_book_entry.to_param
#     end
#     assert_redirected_to phone_book_entries_path
#   end
  
  test "should not have a route for destroy" do
    assert_raises(ActionController::RoutingError) {
      delete :destroy, id: @user1_phone_book_entry.to_param
    }
  end
  
end