Sha256: ab73ab7334da244e637a4ed643e77a97ce90c41a990de13f76b61c73238c9ea6

Contents?: true

Size: 1001 Bytes

Versions: 22

Compression:

Stored size: 1001 Bytes

Contents

require 'test_helper'
require 'custom_json_serializer'

class MixinJsonTest < ActiveSupport::TestCase

  setup do
    # Setup a hash with random values, ensuring some values are nil
    @hash = {}
    (1..4).each do |i|
      @hash["key#{i}"] = [Faker::Lorem.word, nil].sample
    end
    @hash['tkey'] = nil
    @hash[''] = 'foo'
    @hash_as_json = @hash.to_json
  end

  context '`load` class method' do
    should 'exist' do
      assert CustomJsonSerializer.respond_to?(:load)
    end

    should '`deserialize` JSON to Ruby, removing pairs with `blank` keys or values' do
      assert_equal @hash.reject { |k,v| k.blank? || v.blank? }, CustomJsonSerializer.load(@hash_as_json)
    end
  end

  context '`dump` class method' do
    should 'exist' do
      assert CustomJsonSerializer.respond_to?(:dump)
    end

    should '`serialize` Ruby to JSON, removing pairs with `nil` values' do
      assert_equal @hash.reject { |k,v| v.nil? }.to_json, CustomJsonSerializer.dump(@hash)
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
paper_trail-4.2.0 test/unit/serializers/mixin_json_test.rb
paper_trail-4.1.0 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.2 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.1 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.9 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.0 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.0.rc2 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.0.rc1 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.8 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.7 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.0.beta2 test/unit/serializers/mixin_json_test.rb
paper_trail-4.0.0.beta1 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.6 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.5 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.2 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.1 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.0 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.0.rc2 test/unit/serializers/mixin_json_test.rb
paper_trail-3.0.0.rc1 test/unit/serializers/mixin_json_test.rb
paper_trail_without_deprecated-3.0.0.beta1 test/unit/serializers/mixin_json_test.rb