test/skip_test.rb in representable-2.2.2 vs test/skip_test.rb in representable-2.2.3
- old
+ new
@@ -1,10 +1,10 @@
require 'test_helper'
class SkipParseTest < MiniTest::Spec
representer! do
- property :title
+ property :title, skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment == "skip me" }
property :band,
skip_parse: lambda { |fragment, opts| opts[:skip?] and fragment["name"].nil? }, class: OpenStruct do
property :name
end
@@ -15,20 +15,35 @@
end
let (:song) { OpenStruct.new.extend(representer) }
# do parse.
- it { song.from_hash({"band" => {"name" => "Mute 98"}}, skip?: true).band.name.must_equal "Mute 98" }
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}]}, skip?: true).airplays[0].station.must_equal "JJJ" }
+ it do
+ song.from_hash({
+ "title" => "Victim Of Fate",
+ "band" => {"name" => "Mute 98"},
+ "airplays" => [{"station" => "JJJ"}]
+ }, skip?: true)
+ song.title.must_equal "Victim Of Fate"
+ song.band.name.must_equal "Mute 98"
+ song.airplays[0].station.must_equal "JJJ"
+ end
+
# skip parsing.
- it { song.from_hash({"band" => {}}, skip?: true).band.must_equal nil }
- # skip_parse is _per item_.
let (:airplay) { OpenStruct.new(station: "JJJ") }
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}, {}]}, skip?: true).airplays.must_equal [airplay] }
- # it skips parsing of items as if they hadn't been in the document.
- it { song.from_hash({"airplays" => [{"station" => "JJJ"}, {}, {"station" => "JJJ"}]}, skip?: true).airplays.must_equal [airplay, airplay] }
+ it do
+ song.from_hash({
+ "title" => "skip me",
+ "band" => {},
+ "airplays" => [{"station" => "JJJ"}, {}],
+ }, skip?: true)
+
+ song.title.must_equal nil
+ song.band.must_equal nil
+ song.airplays.must_equal [airplay]
+ end
end
class SkipRenderTest < MiniTest::Spec
representer! do
property :title
\ No newline at end of file