Sha256: 8c0a5d834fd95382d176c73b6a545812628721bd4c1a728d1af68db425910c1f
Contents?: true
Size: 822 Bytes
Versions: 2
Compression:
Stored size: 822 Bytes
Contents
require 'test_helper' require 'roar/coercion' require 'roar/decorator' class CoercionFeatureTest < MiniTest::Spec describe "Coercion" do class SongDecorator < Roar::Decorator include Roar::JSON include Roar::Coercion property :composed_at, type: Types::JSON::DateTime, default: "May 12th, 2012" end class ImmigrantSong 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 decorator = SongDecorator.new(song) decorator.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
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
blacklight-spotlight-3.6.0.beta8 | vendor/bundle/ruby/3.2.0/gems/roar-1.2.0/test/coercion_feature_test.rb |
roar-1.2.0 | test/coercion_feature_test.rb |