Sha256: 56784822ade5ea898d335404139da7efd3d91aa19f22fef91cb7bb7cdf7b8515

Contents?: true

Size: 2 KB

Versions: 21

Compression:

Stored size: 2 KB

Contents

require 'test_helper'

module Shipit
  class VariableDefinitionTest < ActiveSupport::TestCase
    setup do
      @attributes = {
        "name" => "Variable name",
        "title" => "Variable title",
        "default" => "Variable default",
      }
      @select = %w(var1 var2 var3)
    end

    test "#initialize sets up the expected values" do
      subject = Shipit::VariableDefinition.new(@attributes)

      assert_equal "Variable name", subject.name
      assert_equal "Variable title", subject.title
      assert_equal "Variable default", subject.default
      assert_nil subject.select
      assert subject.default_provided?
    end

    test "#initialize name is required" do
      assert_raises KeyError do
        @attributes.delete("name")
        Shipit::VariableDefinition.new(@attributes)
      end
    end

    test "#initialize stringifies the default" do
      @attributes["default"] = :value
      subject = Shipit::VariableDefinition.new(@attributes)

      assert_equal "value", subject.default
    end

    test "#initialize sets the select if present" do
      @attributes["select"] = @select
      subject = Shipit::VariableDefinition.new(@attributes)

      assert_equal @select, subject.select
    end

    test "#initialize sets nil for select if the array is empty" do
      @attributes["select"] = []
      subject = Shipit::VariableDefinition.new(@attributes)

      assert_nil subject.select
    end

    test "#default_provided?" do
      attributes = {
        "name" => "Variable name",
        "title" => "Variable title",
      }
      subject = Shipit::VariableDefinition.new(attributes)
      refute subject.default_provided?
    end

    test "#to_h returns hash version" do
      assert_equal @attributes.merge("select" => nil), Shipit::VariableDefinition.new(@attributes).to_h
    end

    test "#to_h returns hash version that includes select" do
      assert_equal @attributes.merge("select" => @select), Shipit::VariableDefinition.new(@attributes.merge("select" => @select)).to_h
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 test/unit/variable_definition_test.rb
shipit-engine-0.30.0 test/unit/variable_definition_test.rb
shipit-engine-0.29.0 test/unit/variable_definition_test.rb
shipit-engine-0.28.1 test/unit/variable_definition_test.rb
shipit-engine-0.28.0 test/unit/variable_definition_test.rb
shipit-engine-0.27.1 test/unit/variable_definition_test.rb
shipit-engine-0.27.0 test/unit/variable_definition_test.rb
shipit-engine-0.26.0 test/unit/variable_definition_test.rb
shipit-engine-0.25.1 test/unit/variable_definition_test.rb
shipit-engine-0.25.0 test/unit/variable_definition_test.rb
shipit-engine-0.24.0 test/unit/variable_definition_test.rb
shipit-engine-0.23.1 test/unit/variable_definition_test.rb
shipit-engine-0.23.0 test/unit/variable_definition_test.rb
shipit-engine-0.22.0 test/unit/variable_definition_test.rb
shipit-engine-0.21.0 test/unit/variable_definition_test.rb
shipit-engine-0.20.1 test/unit/variable_definition_test.rb
shipit-engine-0.20.0 test/unit/variable_definition_test.rb
shipit-engine-0.19.0 test/unit/variable_definition_test.rb
shipit-engine-0.18.1 test/unit/variable_definition_test.rb
shipit-engine-0.18.0 test/unit/variable_definition_test.rb