Sha256: 8a8aeac1898a1be36fa44b0fdb281d9a81d2644ba498ca80bc795ba2ae17a001

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

require 'test_helper'

class CommonParametersControllerTest < 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
    CommonParameter.any_instance.stubs(:valid?).returns(false)
    post :create, {}, set_session_user
    assert_template 'new'
  end

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

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

  def test_update_invalid
    CommonParameter.any_instance.stubs(:valid?).returns(false)
    put :update, {:id => CommonParameter.first}, set_session_user
    assert_template 'edit'
  end

  def test_update_valid
    CommonParameter.any_instance.stubs(:valid?).returns(true)
    put :update, {:id => CommonParameter.first}, set_session_user
    assert_redirected_to common_parameters_url
  end

  def test_destroy
    common_parameter = CommonParameter.first
    delete :destroy, {:id => common_parameter}, set_session_user
    assert_redirected_to common_parameters_url
    assert !CommonParameter.exists?(common_parameter.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

  context 'user with viewer rights' do

    def user_with_viewer_rights_should_fail_to_edit_a_common_parameter
      setup_user
      get :edit, {:id => CommonParameter.first.id}
      assert @response.status == '403 Forbidden'
    end

    def user_with_viewer_rights_should_succeed_in_viewing_common_parameters
      setup_user
      get :index
      assert_response :success
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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