1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/test/unit/serializers/json_test.rb

40 lines
1 KiB
Ruby

require 'test_helper'
class JsonTest < ActiveSupport::TestCase
setup do
# Setup a hash with random values
@hash = {}
(1..4).each do |i|
@hash["key#{i}"] = Faker::Lorem.word
end
@hash_as_json = @hash.to_json
# Setup an array of random words
@array = []
(rand(5) + 4).times { @array << Faker::Lorem.word }
@array_as_json = @array.to_json
end
context '`load` class method' do
should 'exist' do
assert PaperTrail::Serializers::Json.respond_to?(:load)
end
should '`deserialize` JSON to Ruby' do
assert_equal @hash, PaperTrail::Serializers::Json.load(@hash_as_json)
assert_equal @array, PaperTrail::Serializers::Json.load(@array_as_json)
end
end
context '`dump` class method' do
should 'exist' do
assert PaperTrail::Serializers::Json.respond_to?(:dump)
end
should '`serialize` Ruby to JSON' do
assert_equal @hash_as_json, PaperTrail::Serializers::Json.dump(@hash)
assert_equal @array_as_json, PaperTrail::Serializers::Json.dump(@array)
end
end
end