Sha256: f2fe78e79dbfd6ae0ef5152c252a0f99686cda50b9de0c81b02ca657a20c160a

Contents?: true

Size: 1.85 KB

Versions: 8

Compression:

Stored size: 1.85 KB

Contents

require 'test_helper'

module Shipit
  class TaskDefinitionsTest < ActiveSupport::TestCase
    setup do
      @definition = TaskDefinition.new(
        'restart',
        'action' => 'Restart application',
        'description' => 'Restart app and job servers',
        'steps' => ['touch tmp/restart'],
        'allow_concurrency' => true,
        'variables' => [
          {'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1'},
          {'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0'},
          {'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' '},
          {'name' => 'NODEFAULT', 'title' => 'Variable without default'},
        ],
      )
    end

    test ".load returns nil if payload is nil or blank" do
      assert_nil TaskDefinition.load('')
      assert_nil TaskDefinition.load(nil)
    end

    test ".dump returns nil if given nil" do
      assert_nil TaskDefinition.dump(nil)
    end

    test "#variables" do
      assert_equal 4, @definition.variables.size
      assert_equal 3, @definition.variables_with_defaults.size
    end

    test "serialization works" do
      as_json = {
        id: 'restart',
        action: 'Restart application',
        description: 'Restart app and job servers',
        steps: ['touch tmp/restart'],
        checklist: [],
        allow_concurrency: true,
        variables: [
          {'name' => 'FOO', 'title' => 'Set to 0 to foo', 'default' => '1', 'select' => nil},
          {'name' => 'BAR', 'title' => 'Set to 1 to bar', 'default' => '0', 'select' => nil},
          {'name' => 'WALRUS', 'title' => 'Use with caution', 'default' => ' ', 'select' => nil},
          {'name' => 'NODEFAULT', 'title' => 'Variable without default', 'default' => '', 'select' => nil},
        ],
      }
      assert_equal as_json, TaskDefinition.load(TaskDefinition.dump(@definition)).as_json
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shipit-engine-0.22.0 test/models/task_definitions_test.rb
shipit-engine-0.21.0 test/models/task_definitions_test.rb
shipit-engine-0.20.1 test/models/task_definitions_test.rb
shipit-engine-0.20.0 test/models/task_definitions_test.rb
shipit-engine-0.19.0 test/models/task_definitions_test.rb
shipit-engine-0.18.1 test/models/task_definitions_test.rb
shipit-engine-0.18.0 test/models/task_definitions_test.rb
shipit-engine-0.17.0 test/models/task_definitions_test.rb