Sha256: 4a75647aea1c0a76d54e9590512dc87cc2423ed8fd5d50453cf9ea20a8d53f8c

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

require 'test_helper'

class UsergroupsControllerTest < ActionController::TestCase
  def test_index
    get :index, {}, set_session_user
    assert_template 'index'
  end

  def test_new
    get :new, {}, set_session_user
    assert_template 'new'
  end

  def test_create_invalid
    Usergroup.any_instance.stubs(:valid?).returns(false)
    post :create, {}, set_session_user
    assert_template 'new'
  end

  def test_create_valid
    Usergroup.any_instance.stubs(:valid?).returns(true)
    post :create, {}, set_session_user
    assert_redirected_to usergroups_url
  end

  def test_edit
    get :edit, {:id => Usergroup.first}, set_session_user
    assert_template 'edit'
  end

  def test_update_invalid
    Usergroup.any_instance.stubs(:valid?).returns(false)
    put :update, {:id => Usergroup.first, :usergroup => {:user_ids => ["",""], :usergroup_ids => ["",""]} }, set_session_user
    assert_template 'edit'
  end

  def test_update_valid
    Usergroup.any_instance.stubs(:valid?).returns(true)
    put :update, {:id => Usergroup.first, :usergroup => {:user_ids => ["",""], :usergroup_ids => ["",""]} }, set_session_user
    assert_redirected_to usergroups_url
  end

  def test_destroy
    usergroup = Usergroup.first
    delete :destroy, {:id => usergroup}, set_session_user
    assert_redirected_to usergroups_url
    assert !Usergroup.exists?(usergroup.id)
  end

  def setup_user
    @request.session[:user] = users(:one).id
    users(:one).roles       = [Role.find_by_name('Anonymous'), Role.find_by_name('Viewer')]
  end

  test 'user with viewer rights should fail to edit a usergroup' do
    setup_user
    get :edit, {:id => Usergroup.first.id}, set_session_user.merge(:user => users(:one).id)
    assert_equal @response.status, 403
  end

  test 'user with viewer rights should succeed in viewing usergroups' do
    setup_user
    get :index, {}, set_session_user
    assert_response :success
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/test/functional/usergroups_controller_test.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/test/functional/usergroups_controller_test.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/test/functional/usergroups_controller_test.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/test/functional/usergroups_controller_test.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/test/functional/usergroups_controller_test.rb