Sha256: 5d3aca7340c61bc2df31116f294154dbdad3a15bb6775df867a0ed4d536e216f

Contents?: true

Size: 1.91 KB

Versions: 14

Compression:

Stored size: 1.91 KB

Contents

require 'date'

require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

describe Arsenicum::Queueing::Serializer do
  subject{Object.new.extend(Arsenicum::Queueing::Serializer)}

  describe [:serialize_object, :restore_object] do

    shared_examples_for :serialize_restore do
      specify{expect(subject.restore_object subject.serialize_object worker).to eq(worker)}
    end

    context :target_is_raw do
      shared_examples_for :raw_object do
        specify{expect(subject.serialize_object worker).to eq({type: 'raw', value: worker.inspect})}
        it_should_behave_like :serialize_restore
      end

      context :target_is_integer do
        let(:worker){1}
        it_should_behave_like :raw_object
      end

      context :target_is_float do
        let(:worker){1.3}
        it_should_behave_like :raw_object
      end

      context :target_is_string do
        let(:worker){"string"}
        it_should_behave_like :raw_object
      end

      context :target_is_true do
        let(:worker){true}
        it_should_behave_like :raw_object
      end

      context :target_is_false do
        let(:worker){false}
        it_should_behave_like :raw_object
      end

      context :target_is_nil do
        let(:worker){nil}
        it_should_behave_like :raw_object
      end

    end

    context :time_like do
      shared_examples_for :date_time do
        let(:worker){target_type.now}
        specify{expect(subject.serialize_object worker).to eq({type: 'datetime', value: worker.strftime('%Y-%m-%dT%H:%M:%S %Z %z')})}
        specify{expect(subject.restore_object(subject.serialize_object worker).to_i).to eq(worker.to_time.to_i)}
      end

      context :target_is_datetime do
        let(:target_type){DateTime}
        it_should_behave_like :date_time
      end

      context :target_is_time do
        let(:target_type){Time}
        it_should_behave_like :date_time
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
arsenicum-0.4.2 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.4.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.4 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.3.1.2 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.3.1.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.3.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.3.0 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.2.1.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.2.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.2 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.1.3 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.1.2 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.1.1 spec/arsenicum/queueing/serializer_spec.rb
arsenicum-0.1.0 spec/arsenicum/queueing/serializer_spec.rb