Sha256: 5d56116c9b9439e04f302edaae8d5cdaf034270d187c1089dd6eae62064190cd

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

module PushType
  class PrimitivesTest < ActiveSupport::TestCase

    describe 'Base' do
      let(:primitive) { PushType::Primitives::Base.new(val) }
      let(:val)       { 'abcde' }

      it { primitive.value.must_equal val }
      it { primitive.to_json.must_equal val }
    end

    describe 'ArrayType' do
      let(:primitive) { PushType::Primitives::ArrayType }
      let(:val)       { ['a', 'b', nil, '', 'c'] }

      it { primitive.to_json(val).must_equal ['a', 'b', 'c'] }
    end

    describe 'BooleanType' do
      let(:primitive) { PushType::Primitives::BooleanType }

      it { primitive.to_json(nil).must_equal nil }
      it { primitive.to_json(false).must_equal false }
      it { primitive.to_json(0).must_equal false }
      it { primitive.to_json('').must_equal false }
      it { primitive.to_json('false').must_equal false }
      it { primitive.to_json(true).must_equal true }
      it { primitive.to_json(1).must_equal true }
      it { primitive.to_json('true').must_equal true }
    end

    describe 'NumberType' do
      let(:primitive) { PushType::Primitives::NumberType }
      let(:val)       { '123.45' }

      it { primitive.to_json(val).must_equal 123.45 }
    end

    describe 'ObjectType' do
      let(:primitive) { PushType::Primitives::ObjectType }
      let(:val)       { { foo: 'bar', baz: ['a', 'b'] } }

      it { primitive.to_json(val).must_equal({ 'foo' => 'bar', 'baz' => ['a', 'b'] }) }
      it { primitive.to_json({}).must_equal({}) }
    end

    describe 'StringType' do
      let(:primitive) { PushType::Primitives::StringType }
      let(:val)       { 12345 }

      it { primitive.to_json(val).must_equal '12345' }
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
push_type_core-0.10.0 test/lib/push_type/primitives_test.rb
push_type_core-0.10.0.beta.5 test/lib/push_type/primitives_test.rb
push_type_core-0.10.0.beta.3 test/lib/push_type/primitives_test.rb
push_type_core-0.9.5 test/lib/push_type/primitives_test.rb
push_type_core-0.9.3 test/lib/push_type/primitives_test.rb
push_type_core-0.9.2 test/lib/push_type/primitives_test.rb
push_type_core-0.9.1 test/lib/push_type/primitives_test.rb
push_type_core-0.9.0 test/lib/push_type/primitives_test.rb
push_type_core-0.9.0.beta.4 test/lib/push_type/primitives_test.rb
push_type_core-0.9.0.beta.3 test/lib/push_type/primitives_test.rb
push_type_core-0.9.0.beta.2 test/lib/push_type/primitives_test.rb
push_type_core-0.8.2 test/lib/push_type/primitives_test.rb
push_type_core-0.8.1 test/lib/push_type/primitives_test.rb
push_type_core-0.8.0 test/lib/push_type/primitives_test.rb
push_type_core-0.8.0.beta.3 test/lib/push_type/primitives_test.rb
push_type_core-0.8.0.beta.2 test/lib/push_type/primitives_test.rb