diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
commit | eaad37485fe59d0306c37cc038dda6d210052910 (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /test/functional/phone_numbers_controller_test.rb | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) | |
parent | b80bd744ad873f6fc43018bc4bfb90677de167bd (diff) |
Merge branch 'develop'
Diffstat (limited to 'test/functional/phone_numbers_controller_test.rb')
-rw-r--r-- | test/functional/phone_numbers_controller_test.rb | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/test/functional/phone_numbers_controller_test.rb b/test/functional/phone_numbers_controller_test.rb new file mode 100644 index 0000000..ab0a4b2 --- /dev/null +++ b/test/functional/phone_numbers_controller_test.rb @@ -0,0 +1,115 @@ +require 'test_helper' + +class PhoneNumbersControllerTest < ActionController::TestCase + + setup do + @tenant = Factory.create(:tenant) + @user = Factory.create(:user) + + @tenant.tenant_memberships.create(:user_id => @user.id) + + @user.update_attributes!(:current_tenant_id => @tenant.id) + + @private_phone_book = @user.phone_books.first + + @private_phone_book_entry = Factory.create( + :phone_book_entry, + :phone_book => @private_phone_book + ) + @phone_number = Factory.create( + :phone_number, + :phone_numberable => @private_phone_book_entry + ) + + @expected_status_if_not_authorized = :redirect + end + + + test "should get index" do + session[:user_id] = @user.id + get :index, phone_book_entry_id: @private_phone_book_entry.id + assert_response :success + assert_not_nil assigns(:phone_numbers) + end + + test "should not get index (not logged in)" do + get :index, phone_book_entry_id: @private_phone_book_entry.id + assert_response @expected_status_if_not_authorized + end + + test "should get new" do + session[:user_id] = @user.id + get :new, phone_book_entry_id: @private_phone_book_entry.id + assert_response :success + end + + # test "should not get new (not logged in)" do + # get :new, phone_book_entry_id: @private_phone_book_entry.id + # assert_response @expected_status_if_not_authorized + # end + + # test "should create phone_number" do + # session[:user_id] = @user.id + # assert_difference('PhoneNumber.count') do + # post :create, phone_book_entry_id: @private_phone_book_entry.id, phone_number: @phone_number.attributes + # end + # assert_redirected_to( phone_book_entry_phone_number_path( assigns(:phone_number))) + # end + # + # test "should not create phone_number (not logged in)" do + # assert_no_difference('PhoneNumber.count') do + # post :create, phone_book_entry_id: @private_phone_book_entry.id, phone_number: @phone_number.attributes + # end + # assert_response @expected_status_if_not_authorized + # end + + test "should show phone_number" do + session[:user_id] = @user.id + get :show, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + assert_response :success + end + + test "should not show phone_number (not logged in)" do + get :show, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + assert_response @expected_status_if_not_authorized + end + + + test "should get edit" do + session[:user_id] = @user.id + get :edit, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + assert_response :success + end + + test "should not get edit (not logged in)" do + get :edit, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + assert_response @expected_status_if_not_authorized + end + + test "should update phone_number" do + session[:user_id] = @user.id + put :update, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param, phone_number: @phone_number.attributes + assert_redirected_to( phone_book_entry_phone_number_path( assigns(:phone_number))) + end + + test "should not update phone_number (not logged in)" do + put :update, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param, phone_number: @phone_number.attributes + assert_response @expected_status_if_not_authorized + end + + test "should destroy phone_number" do + session[:user_id] = @user.id + assert_difference('PhoneNumber.count', -1) do + delete :destroy, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + end + assert_redirected_to( phone_book_entry_phone_numbers_path() ) + end + + test "should not destroy phone_number (not logged in)" do + assert_no_difference('PhoneNumber.count') do + delete :destroy, phone_book_entry_id: @private_phone_book_entry.id, id: @phone_number.to_param + end + assert_response @expected_status_if_not_authorized + end + +end |