Sha256: 7c6bdf63da5a16b25268516ac729de7c49b00dc3b35a032c5214abe51d601dab

Contents?: true

Size: 1.23 KB

Versions: 31

Compression:

Stored size: 1.23 KB

Contents

require File.join(File.dirname(__FILE__), '../test_helper')

describe HammerCLIForeman::OptionSources::IdsParams do
  describe "get_options" do
    class IdsParamsTestCommand < HammerCLIForeman::CreateCommand
      resource :users
      build_options
    end

    let(:cmd) { IdsParamsTestCommand.new("", { :adapter => :csv, :interactive => false }) }
    let(:ids_params_source) { HammerCLIForeman::OptionSources::IdsParams.new(cmd) }

    it "skips param when set" do
      cmd.stubs(:get_resource_ids).returns(nil)
      cmd.expects(:get_resource_ids).with { |res| res.name == :locations }.never
      option_data = { 'option_location_ids' => [3], 'option_location_names' => 'test' }
      params = ids_params_source.get_options([], option_data)
      params.must_equal option_data
    end

    it "resolves param when unset" do
      cmd.stubs(:get_resource_ids).returns(nil)
      cmd.expects(:get_resource_ids).with { |res| res.name == :locations }.returns([1])
      option_data = { 'option_location_ids' => nil, 'option_location_names' => 'test' }
      expected_data = { 'option_location_ids' => [1], 'option_location_names' => 'test' }
      params = ids_params_source.get_options([], option_data)
      params.must_equal expected_data
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
hammer_cli_foreman-2.1.3 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.1.2 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.1.1 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.1.0 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.0.2 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.0.1 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-2.0.0 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.7 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.6 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.5 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.4 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.3 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.2 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.18.2 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.1 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.18.1 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.19.0 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.17.2 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.18.0 test/unit/option_sources/ids_params_test.rb
hammer_cli_foreman-0.17.1 test/unit/option_sources/ids_params_test.rb