Sha256: 2904538c283118f14643baf401575925f5f7d9831f87a1f7e79a1dd5d1e8b380

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

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

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
paper_trail_without_deprecated-3.0.0.beta1 test/unit/serializers/json_test.rb
paper_trail-3.0.0.beta1 test/unit/serializers/json_test.rb
paper_trail-2.7.2 test/unit/serializers/json_test.rb
paper_trail-2.7.1 test/unit/serializers/json_test.rb