Sha256: 94ebe67d659c71ef786713f916f855912d4b8cf5b8f9b5ef87e87a64c652c2b8

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'helper'

class TestValidation < Test::Unit::TestCase
  setup do
    @api = GeekierFactory.factorize(File.join(File.dirname(File.expand_path(__FILE__)), 'mock_definition.json'))
    @action = @api.available_actions["test api"].first
  end

  test "should complain if all mandatory parameters are missing" do
    assert_raise GeekierFactory::Action::AttributesMissing do
      @action.call
    end
  end

  test "should complain if any one mandatory parameter is missing" do
    params = {:q1 => 'a', :b1 => 'b', :action => 'c'}
    params.keys.each do |mp|
      hsh = params.dup
      hsh.delete(mp)
      assert_raise GeekierFactory::Action::AttributesMissing do
        @action.call hsh
      end
    end
  end

  test "should complain if any non-mandatory path parameter is missing (because I don't know yet what to do when those are missing)" do
    params = {:q1 => 'a', :b1 => 'b', :action => 'c'}
    assert_raise GeekierFactory::Action::AttributesMissing do
      @action.call params
    end
  end
  
  test "should complain if a parameter is the wrong type" do
    params = {:q1 => 'a', :b1 => 'b', :action => 'c'}
    wrong_values = [{}, 4, true, nil, [], Object.new]
    wrong_values.each do |wval|
      assert_raise GeekierFactory::Action::ValidationException do
        @action.call params.merge(:format => wval)
      end
    end
  end
  
  test "should complain if a parameter is not included in a list" do
    params = {:q1 => 'a', :b1 => 'b', :action => 'c'}
    assert_raise GeekierFactory::Action::ValidationException do
      @action.call params.merge(:format => 'xml')
    end
  end
  
  test "should complain if a parameter is not included in a range" do
    params = {:q1 => 'a', :b1 => 'b', :action => 'c', :format => 'json'}
    assert_raise GeekierFactory::Action::ValidationException do
      @action.call params.merge(:b3 => 7)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geekier_factory-0.1.5 test/test_validation.rb