Search
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby
All Projects
Ruby
Overview
Activity
Roadmap
Issues
Repository
Download (975 Bytes)
Bug #12219
ยป json_create_test.rb
kek.forums@gmail.com (Petr Novak)
, 03/26/2016 12:00 PM
require
'json'
require
'minitest'
require
'minitest/autorun'
require
'minitest/reporters'
class
JsonCreateTest
<
Minitest
::
Test
def
test_extended_json
a
=
A
.
new
(
666
)
assert
A
.
json_creatable?
json
=
JSON
.
generate
(
a
)
a_again
=
JSON
.
parse
(
json
,
:create_additions
=>
true
)
assert_kind_of
a
.
class
,
a_again
assert_equal
a
,
a_again
end
def
test_extended_json_symbolize
a
=
A
.
new
(
666
)
assert
A
.
json_creatable?
json
=
JSON
.
generate
(
a
)
a_again
=
JSON
.
parse
(
json
,
:create_additions
=>
true
,
symbolize_names:
true
)
assert_kind_of
a
.
class
,
a_again
assert_equal
a
,
a_again
end
end
class
A
def
initialize
(
a
)
@a
=
a
end
attr_reader
:a
def
==
(
other
)
a
==
other
.
a
end
def
self
.
json_create
(
object
)
new
(
*
object
[
'args'
])
end
def
to_json
(
*
args
)
{
'json_class'
=>
self
.
class
.
name
,
'args'
=>
[
@a
],
}.
to_json
(
*
args
)
end
end
(1-1/1)
Loading...