summaryrefslogtreecommitdiff
path: root/test/functional/sip_accounts_controller_test.rb
blob: e079718d8fd8d9faa21a42f21462f0af8c7309b1 (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
require 'test_helper'

class SipAccountsControllerTest < ActionController::TestCase
  
  setup do
    @tenant = FactoryGirl.create(:tenant)
    @user = FactoryGirl.create(:user)
    @tenant.tenant_memberships.create(:user_id => @user.id)
    @sip_account    = @user.sip_accounts.create( FactoryGirl.build(:sip_account).attributes )
    
    @parent_param = @sip_account.sip_accountable_type.foreign_key.to_sym
    @parent_id    = @sip_account.sip_accountable.id
  end
  
  test "should get index" do
    session[:user_id] = @user.id
    get :index,
      @parent_param => @parent_id
    assert_response :success
    assert_not_nil assigns(:sip_accounts)
  end
  
  test "should get new" do
    session[:user_id] = @user.id
    get :new,
      @parent_param => @parent_id
    assert_response :success
  end
  
  test "should create sip_account" do
    session[:user_id] = @user.id
    assert_difference('SipAccount.count') do
      post :create,
        @parent_param => @parent_id,
        sip_account: FactoryGirl.attributes_for(:sip_account)
    end
  end
  
  test "should show sip_account" do
    session[:user_id] = @user.id
    get :show,
      @parent_param => @parent_id,
      id: @sip_account.to_param
    assert_response :success
  end
  
  test "should get edit" do
    session[:user_id] = @user.id
    get :edit,
      @parent_param => @parent_id,
      id: @sip_account.to_param
    assert_response :success
  end
  
  test "should update sip_account" do
    session[:user_id] = @user.id
    put :update,
      @parent_param => @parent_id,
      id: @sip_account.to_param,
      sip_account: @sip_account.attributes
    # TODO Find the right redirect/answer.
    #assert_redirected_to method( :"#{@sip_account.sip_accountable_type.underscore}_sip_account_path" ).( @sip_account.sip_accountable, @sip_account )
  end
  
  test "should destroy sip_account" do
    session[:user_id] = @user.id
    assert_difference('SipAccount.count', -1) do
      delete :destroy,
        @parent_param => @parent_id,
        id: @sip_account.to_param
    end
    # TODO Find the right redirect/answer.
    #assert_redirected_to method( :"#{@sip_account.sip_accountable_type.underscore}_sip_accounts_path" ).( @sip_account.sip_accountable )
  end
  
end