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

class UsersControllerTest < ActionController::TestCase
  setup do
    @tenant = FactoryGirl.create(:tenant)
    @user  = FactoryGirl.create(:user)
    
    @tenant.tenant_memberships.create(:user_id => @user.id)
    
    @user.update_attributes!(:current_tenant_id => @tenant.id)
    
    @expected_status_if_not_authorized = :redirect
  end
  
  test "should get index" do
    session[:user_id] = @user.id
    get :index
    assert_response :success
    assert_not_nil assigns(:users)
  end
  
  test "should get new" do
    session[:user_id] = nil
    get :new
    assert_response :success
  end

  # TODO Fix Test
  #
  # test "should create user" do
  #   session[:user_id] = nil
  #   assert_difference('User.count') do
  #     post :create, user: FactoryGirl.build(:user).attributes
  #   end
  # 
  # #  assert_redirected_to user_path(assigns(:user))
  # end
  
  test "should show user" do
    session[:user_id] = @user.id
    get :show, id: @user.to_param
    assert_response :success
  end
  
  
  test "should get edit" do
    session[:user_id] = @user.id
    get :edit, id: @user.to_param
    assert_response :success
  end
  
  test "should update user" do
    session[:user_id] = @user.id
    put :update, id: @user.to_param, user: @user.attributes
    assert_redirected_to user_path(assigns(:user))
  end
  
  test "should not destroy itself" do
    assert_no_difference('User.count') do
      delete :destroy, id: @user.to_param
    end
  
#    assert_redirected_to users_path
  end
end