Sha256: 4528d747179bacc59b44296fc53aa0469f2a731122d1e207e7a07e1de3949758

Contents?: true

Size: 1.56 KB

Versions: 22

Compression:

Stored size: 1.56 KB

Contents

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

describe HammerCLIForeman::DependencyResolver do

  let(:api) do ApipieBindings::API.new({
    :apidoc_cache_dir => 'test/unit/data',
    :apidoc_cache_name => 'test_api',
    :dry_run => true})
  end

  before :each do
    HammerCLIForeman.stubs(:foreman_api).returns(api)
  end

  let(:resolver) { HammerCLIForeman::DependencyResolver.new }

  describe "for resource" do

    it "returns empty array for an independent resource" do
      resource = api.resource(:users)
      _(resolver.resource_dependencies(resource)).must_equal []
    end

    it "returns list of dependent resources" do
      resource = api.resource(:comments)

      resources = resolver.resource_dependencies(resource).map(&:name).sort_by{ |sym| sym.to_s }
      expected = [:posts, :users]
      _(resources).must_equal expected.sort_by{ |sym| sym.to_s }
    end
  end

  describe "for action" do

    it "returns empty array for an independent action" do
      action = HammerCLIForeman.foreman_resource!(:users).action(:index)
      _(resolver.action_dependencies(action)).must_equal []
    end

    it "returns list of dependent resources" do
      action = HammerCLIForeman.foreman_resource!(:comments).action(:create)
      resources = resolver.action_dependencies(action).map(&:name).sort_by{ |sym| sym.to_s }
      expected = [:posts, :users]
      _(resources).must_equal expected.sort_by{|sym| sym.to_s}
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
hammer_cli_foreman-3.13.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.12.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.10.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.9.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.8.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.7.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.5.1 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.6.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.5.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.4.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.3.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.2.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.5.2 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.1.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-3.0.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.5.1 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.5.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.3.2 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.4.0 test/unit/dependency_resolver_test.rb
hammer_cli_foreman-2.3.1 test/unit/dependency_resolver_test.rb