File: reader_writer_test.rb

package info (click to toggle)
ruby-representable 3.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 896 kB
  • sloc: ruby: 6,432; makefile: 3
file content (19 lines) | stat: -rw-r--r-- 666 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'test_helper'

class ReaderWriterTest < BaseTest
  representer! do
    property :name,
      :writer => lambda { |options| options[:doc]["title"] = "#{options[:user_options][:nr]}) #{options[:input]}" },
      :reader => lambda { |options| self.name = options[:doc]["title"].split(") ").last }
  end

  subject { OpenStruct.new(:name => "Disorder And Disarray").extend(representer) }

  it "uses :writer when rendering" do
    subject.to_hash(user_options: {nr: 14}).must_equal({"title" => "14) Disorder And Disarray"})
  end

  it "uses :reader when parsing" do
    subject.from_hash({"title" => "15) The Wars End"}).name.must_equal "The Wars End"
  end
end