/
optimizable_spec.rb
35 lines (25 loc) · 1.18 KB
/
optimizable_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# encoding: utf-8
require 'spec_helper'
describe Optimizer::Relation::Operation::Insertion::ProjectionLeft, '#optimizable?' do
subject { object.optimizable? }
let(:object) { described_class.new(relation) }
let(:relation) { left.insert(right) }
let(:right) { Relation.new([ [ :id, Integer ] ], [ [ 2 ] ].each) }
before do
object.operation.should be_kind_of(Relation::Operation::Insertion)
end
context 'when the left is a projection, and removed attributes are optional' do
let(:header) { [ [ :id, Integer ], [ :name, String, { :required => false } ] ] }
let(:left) { Relation.new(header, [ [ 1, 'John Doe' ] ].each).project([ :id ]) }
it { should be(true) }
end
context 'when the left is a projection, and removed attributes are required' do
let(:header) { [ [ :id, Integer ], [ :name, String ] ] }
let(:left) { Relation.new(header, [ [ 1, 'John Doe' ] ].each).project([ :id ]) }
it { should be(false) }
end
context 'when the left is not a projection' do
let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
it { should be(false) }
end
end