Sha256: 9d0fd95e6682c0fe76144fb8249ec6a510f3b5aaa13e7afc604c2ba60307383a

Contents?: true

Size: 677 Bytes

Versions: 7

Compression:

Stored size: 677 Bytes

Contents

require 'test_helper'
require 'roar/coercion'

class CoercionFeatureTest < MiniTest::Spec
  describe "Coercion" do
    class ImmigrantSong
      include Roar::JSON
      include Roar::Coercion

      property :composed_at, :type => DateTime, :default => "May 12th, 2012"

      attr_accessor :composed_at
      def composed_at=(v) # in ruby 2.2, #label= is not there, all at sudden. what *is* that?
        @composed_at = v
      end
    end

    it "coerces into the provided type" do
      song = ImmigrantSong.new.from_json("{\"composed_at\":\"November 18th, 1983\"}")
      assert_equal DateTime.parse("Fri, 18 Nov 1983 00:00:00 +0000"), song.composed_at
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roar-1.0.4 test/coercion_feature_test.rb
roar-1.0.3 test/coercion_feature_test.rb
roar-1.0.2 test/coercion_feature_test.rb
roar-1.0.1 test/coercion_feature_test.rb
roar-1.0.0 test/coercion_feature_test.rb
roar-1.0.0.beta2 test/coercion_feature_test.rb
roar-1.0.0.beta1 test/coercion_feature_test.rb