team_users_controller_test.rb revision 0b611cf877554b1aa910fa23099220f2d1d15e89
58N/Arequire 'test_helper'
58N/A
58N/Aclass TeamUsersControllerTest < ActionController::TestCase
58N/A
58N/A should_map_nested_resources :teams, :team_users,
58N/A :as => 'users',
58N/A :except => [:new, :show, :edit, :delete]
58N/A
58N/A context 'teams' do
58N/A setup do
58N/A @admin = FactoryGirl.create :user # team admin
58N/A @user = FactoryGirl.create :user
58N/A @team = FactoryGirl.create :team,
58N/A :admin_user => @admin
58N/A end
58N/A
58N/A context 'on GET to index' do
58N/A context 'as admin' do
830N/A setup do
58N/A sign_in @admin
58N/A get :index, :team_id => @team.to_param
58N/A end
850N/A
58N/A should render_template 'relation_list/_relation_list'
830N/A should render_template :index
850N/A should respond_with :success
830N/A end
58N/A
128N/A context 'as user' do
58N/A setup do
128N/A sign_in @user
58N/A get :index, :team_id => @team.to_param
850N/A end
58N/A should set_the_flash.to(/not authorized/)
58N/A should redirect_to("root path"){ :root }
58N/A end
58N/A end
892N/A
850N/A context 'adding a user' do
850N/A context 'by admin' do
850N/A setup do
867N/A sign_in @admin
850N/A xhr :post, :create,
850N/A :team_id => @team.id,
850N/A :team_user => {:user_id => @user.id}
850N/A end
58N/A
874N/A should render_template 'team_users/_team_user'
850N/A should respond_with :success
850N/A end
850N/A end
850N/A
850N/A context 'with one user' do
850N/A context 'removing the last user' do
850N/A setup do
866N/A sign_in @admin
850N/A xhr :delete, :destroy,
866N/A :team_id => @team.id,
850N/A :id => @team.team_users.first.id
850N/A end
830N/A
850N/A should 'return a helpful error message' do
867N/A assert_match /What the hell/, response.body
58N/A end
892N/A
892N/A should respond_with :unprocessable_entity
892N/A end
892N/A end
892N/A
892N/A context 'with two users' do
874N/A setup do
874N/A @team_user = @team.team_users.create! :user => @user
874N/A end
874N/A
874N/A context 'setting the admin flag' do
874N/A setup do
874N/A sign_in @admin
58N/A xhr :put, :update,
144N/A :team_id => @team.id,
:id => @team_user.id,
:team_user => {:admin => 1}
end
should render_template 'team_users/_team_user'
should respond_with :success
end
context 'team admin deleting other user' do
setup do
sign_in @admin
xhr :delete, :destroy,
:team_id => @team.id,
:id => @team_user.id
end
should respond_with :success
end
end
end
end