Sha256: bc1dcb2d6a5b15a8474df03eaf515b88d4bc780d1d44dd3d282a5ea660a7c8e1

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'

describe Hari::Serialization do

  class TestSerialization
    include Hari::Serialization

    property :name
    property :male,   type: Boolean, default: true
    property :active, type: Boolean
  end

  class TestObject < Hari::Object

    property :test, type: Boolean

  end

  it 'adds serialization skills to class' do
    object = TestSerialization.new(name: 'Chuck')
    object.to_hash.should eq('name' => 'Chuck', 'male' => true, 'active' => false)
    object.attribute(:name).should eq('Chuck')
    object.has_attribute?(:name).should be_true
    object.has_attribute?(:nome).should be_false
    object.attribute(:active).should be_false
    object.attribute(:male).should be_true

    object.to_json.should eq('{"name":"Chuck","male":true,"active":false}')

    from_json = TestSerialization.from_json('{"name":"Chuck","male":true,"active":false}')
    from_json.name.should eq('Chuck')
    from_json.male.should be_true
    from_json.male?.should be_true
    from_json.active?.should be_false

    object = TestObject.new(test: true)
    object.test.should be_true
    object.test?.should be_true
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hari-0.0.5 spec/hari/serialization_spec.rb