Sha256: 4b8730eb19671148130508ea1fb9404728f9aeea9f44574d95368e6b9ebc6a01

Contents?: true

Size: 1007 Bytes

Versions: 21

Compression:

Stored size: 1007 Bytes

Contents

require 'spec_helper'

describe ::Protobuf::ActiveRecord::Transformer do
  let(:callable) { lambda { |proto| proto.name } }
  let(:proto) { ::UserMessage.new(:name => 'test', :nullify => ['name']) }
  let(:options) { {} }

  subject { described_class.new(callable, options) }

  describe '#call' do
    it 'calls the callable' do
      result = subject.call(proto)
      expect(result).to eq('test')
    end
  end

  describe '#nullify?' do
    context 'no nullify_on set' do
      it 'returns false' do
        expect(subject.nullify?(proto)).to eq(false)
      end
    end

    context 'nullify_on name' do
      let(:options) { { :nullify_on => :name } }

      context 'invalid message' do
        let(:proto) { ::UserSearchMessage.new }

        it 'returns false' do
          expect(subject.nullify?(proto)).to eq(false)
        end
      end

      context 'valid message' do
        it 'returns true' do
          expect(subject.nullify?(proto)).to eq(true)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
protobuf-activerecord-3.6.0 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.5.1 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.5.0 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.4 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.4.pre spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.3 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.2 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.1 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.4.0 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.8 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.7 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.6 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.5 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.4 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.3 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.2 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.1 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.3.0 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.2.2 spec/protobuf/active_record/transformer_spec.rb
protobuf-activerecord-3.2.1 spec/protobuf/active_record/transformer_spec.rb