Sha256: e9ad4b546d09fe463154047a2b1a171d86e46aaa7109f796e0f4ab634f241bfb
Contents?: true
Size: 1.97 KB
Versions: 1
Compression:
Stored size: 1.97 KB
Contents
require 'test_helper' class FilterPipelineTest < MiniTest::Spec let(:block1) { lambda { |input, options| "1: #{input}" } } let(:block2) { lambda { |input, options| "2: #{input}" } } subject { Representable::Pipeline[block1, block2] } it { subject.call("Horowitz", {}).must_equal "2: 1: Horowitz" } end class FilterTest < MiniTest::Spec representer! do property :title property :track, :parse_filter => lambda { |input, options| "#{input.downcase},#{options[:doc]}" }, :render_filter => lambda { |val, options| "#{val.upcase},#{options[:doc]},#{options[:options][:user_options]}" } end # gets doc and options. it { song = OpenStruct.new.extend(representer).from_hash("title" => "VULCAN EARS", "track" => "Nine") song.title.must_equal "VULCAN EARS" song.track.must_equal "nine,{\"title\"=>\"VULCAN EARS\", \"track\"=>\"Nine\"}" } it { OpenStruct.new("title" => "vulcan ears", "track" => "Nine").extend(representer).to_hash.must_equal( {"title"=>"vulcan ears", "track"=>"NINE,{\"title\"=>\"vulcan ears\"},{}"}) } describe "#parse_filter" do representer! do property :track, :parse_filter => [ lambda { |input, options| "#{input}-1" }, lambda { |input, options| "#{input}-2" }], :render_filter => [ lambda { |val, options| "#{val}-1" }, lambda { |val, options| "#{val}-2" }] end # order matters. it { OpenStruct.new.extend(representer).from_hash("track" => "Nine").track.must_equal "Nine-1-2" } it { OpenStruct.new("track" => "Nine").extend(representer).to_hash.must_equal({"track"=>"Nine-1-2"}) } end end # class RenderFilterTest < MiniTest::Spec # representer! do # property :track, :render_filter => [lambda { |val, options| "#{val}-1" } ] # property :track, :render_filter => [lambda { |val, options| "#{val}-2" } ], :inherit => true # end # it { OpenStruct.new("track" => "Nine").extend(representer).to_hash.must_equal({"track"=>"Nine-1-2"}) } # end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
representable-3.0.4 | test/filter_test.rb |