Sha256: 421bffd0c79f1c0b5f0016d4b3d6b82e76a3eb00f2d25a0cb3441547804907e2

Contents?: true

Size: 810 Bytes

Versions: 23

Compression:

Stored size: 810 Bytes

Contents

require_relative 'helper'

class User < DTO.new(:first_name, :last_name)
end

class DTOTest < Minitest::Test
  def setup
    @user = User.new(first_name: 'John', last_name: 'Doe', another: 'Yeah!')
  end

  def test_accessors
    assert_equal 'John', @user.first_name
    assert_equal 'Doe', @user.last_name
    refute @user.respond_to? :another
  end

  def test_to_json
    assert_equal({ first_name: 'John', last_name: 'Doe' }.to_json, @user.to_json)
    another = Class.new(DTO.new :first_name, :childs )
    with_childs = another.new(first_name: 'Jess', childs: [ 'Albert', 'Margo' ])
    assert_equal({ first_name: 'Jess', childs: ['Albert', 'Margo']}.to_json, with_childs.to_json)
  end

  def test_to_s
    expected = "first_name: John, last_name: Doe" 
    assert_equal expected, @user.to_s
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mxhero-api-1.2.9 test/test_dto.rb
mxhero-api-1.2.8 test/test_dto.rb
mxhero-api-1.2.7 test/test_dto.rb
mxhero-api-1.2.6 test/test_dto.rb
mxhero-api-1.2.5 test/test_dto.rb
mxhero-api-1.2.4 test/test_dto.rb
mxhero-api-1.2.3 test/test_dto.rb
mxhero-api-1.2.2 test/test_dto.rb
mxhero-api-1.2.1 test/test_dto.rb
mxhero-api-1.2.0 test/test_dto.rb
mxhero-api-1.1.4 test/test_dto.rb
mxhero-api-1.1.3 test/test_dto.rb
mxhero-api-1.1.2 test/test_dto.rb
mxhero-api-1.1.1 test/test_dto.rb
mxhero-api-1.1.0 test/test_dto.rb
mxhero-api-1.0.5 test/test_dto.rb
mxhero-api-1.0.4 test/test_dto.rb
mxhero-api-1.0.3 test/test_dto.rb
mxhero-api-1.0.2 test/test_dto.rb
mxhero-api-1.0.1 test/test_dto.rb