Sha256: 56d3a8e7a4a8844f04aae1a99afd9a9a05e206d5286c925c38ccd4f994406ba9

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8

require 'spec_helper'

# Test that tuple enumerators are not frozen

class MutableEnumerator < Enumerator
  attr_reader :mutable_array

  def initialize(tuples)
    @mutable_array = []
    super() do |yielder|
      tuples.each do |tuple|
        @mutable_array << tuple
        yielder << tuple
      end
    end
  end
end

describe Relation do
  context 'with a tuple enumerator' do
    let(:relation)   { Relation.new([[:id, Integer]], enumerator) }
    let(:enumerator) { MutableEnumerator.new(tuples)              }
    let(:tuples)     { [[1], [2]]                                 }

    context 'when the enumerator is materialized' do
      it 'does not freeze the enumerator' do
        expect { relation.materialize }
          .to_not change(enumerator, :frozen?).from(false)
      end

      it 'allows the array to be mutated' do
        expect { relation.materialize }
          .to change(enumerator, :mutable_array).from([]).to(tuples)
      end
    end

    context 'when the enumerator is materialized and restricted' do
      it 'does not freeze the enumerator' do
        expect { relation.restrict(id: 1).materialize }
          .to_not change(enumerator, :frozen?).from(false)
      end

      it 'allows the array to be mutated' do
        expect { relation.restrict(id: 1).materialize }
          .to change(enumerator, :mutable_array).from([]).to(tuples)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.2.0 spec/integration/axiom/relation/mutable_enumerator_spec.rb
axiom-0.1.1 spec/integration/axiom/relation/mutable_enumerator_spec.rb