2015-11-12 10:16:49 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Gitlab::SQL::Union, lib: true do
|
2015-11-12 10:16:49 -05:00
|
|
|
describe '#to_sql' do
|
|
|
|
it 'returns a String joining relations together using a UNION' do
|
|
|
|
rel1 = User.where(email: 'alice@example.com')
|
|
|
|
rel2 = User.where(email: 'bob@example.com')
|
|
|
|
union = described_class.new([rel1, rel2])
|
|
|
|
|
|
|
|
sql1 = rel1.reorder(nil).to_sql
|
|
|
|
sql2 = rel2.reorder(nil).to_sql
|
|
|
|
|
2015-11-18 07:31:18 -05:00
|
|
|
expect(union.to_sql).to eq("#{sql1}\nUNION\n#{sql2}")
|
2015-11-12 10:16:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|