Sha256: 6f5ff0e62cf2c236c9178a10af65beca8d767c83705811e4a31ac9c17e9e21a4

Contents?: true

Size: 690 Bytes

Versions: 8

Compression:

Stored size: 690 Bytes

Contents

require "test_helper"
require "reform/form/coercion"

class CoercionTest < MiniTest::Spec
  it "allows coercion" do
    form = Class.new(Reform::Form) do
      include Reform::Form::Coercion

      property :written_at, :type => DateTime
    end.new(OpenStruct.new(:written_at => "31/03/1981"))

    form.written_at.must_be_kind_of DateTime
    form.written_at.must_equal DateTime.parse("Tue, 31 Mar 1981 00:00:00 +0000")
  end

  it "allows coercion in validate" do
    form = Class.new(Reform::Form) do
      include Reform::Form::Coercion

      property :id, :type => Integer
    end.new(OpenStruct.new())

    form.validate("id" => "1")
    form.to_hash.must_equal("id" => 1)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reform-0.2.7 test/coercion_test.rb
reform-0.2.6 test/coercion_test.rb
reform-0.2.5 test/coercion_test.rb
reform-0.2.4 test/coercion_test.rb
reform-0.2.3 test/coercion_test.rb
reform-0.2.2 test/coercion_test.rb
reform-0.2.1 test/coercion_test.rb
reform-0.2.0 test/coercion_test.rb