Sha256: cc6ec994860b312237e048009e1015655293fa3140d4d2a6d2bffc6dbe479881

Contents?: true

Size: 825 Bytes

Versions: 9

Compression:

Stored size: 825 Bytes

Contents

require 'spec_helper'
require 'simple_command'

describe 'Mutations - defaults' do

  class DefaultCommand < Mutations::Command
    required do
      string :name, :default => "Bob Jones"
    end

    def execute
      inputs
    end
  end

  it "should have a default if no value is passed" do
    outcome = DefaultCommand.run
    assert_equal true, outcome.success?
    assert_equal ({"name" => "Bob Jones"}), outcome.result
  end

  it "should have the passed value if a value is passed" do
    outcome = DefaultCommand.run(:name => "Fred")
    assert_equal true, outcome.success?
    assert_equal ({"name" => "Fred"}), outcome.result
  end

  it "should be an error if nil is passed on a required field with a default" do
    outcome = DefaultCommand.run(:name => nil)
    assert_equal false, outcome.success?
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mutations-0.9.0 spec/default_spec.rb
mutations-0.8.3 spec/default_spec.rb
mutations-0.8.2 spec/default_spec.rb
mutations-0.8.1 spec/default_spec.rb
mutations-0.8.0 spec/default_spec.rb
mutations-0.7.2 spec/default_spec.rb
mutations-0.7.1 spec/default_spec.rb
mutations-0.7.0 spec/default_spec.rb
mutations-0.6.0 spec/default_spec.rb