Sha256: ce9912eca929392ef6e337d01254afc9dfd156de9f6533d910bbb810bac9b7aa

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

describe "Dataset#replace_select_with_alias" do
  before do
    @dataset = Sequel.mock.from(:test)
  end

  it "should do nothing if aliased columns are not present" do
    replaced_sql = @dataset.select(:a).replace_select_with_alias(Sequel.as("5", :b)).sql
    expect(replaced_sql).to eq("SELECT a FROM test")
  end

  it "should select all if no select are present" do
    replaced_sql = @dataset.replace_select_with_alias(Sequel.as("1", :a)).sql
    expect(replaced_sql).to eq("SELECT * FROM test")
  end

  it "should replace the currently selected columns with matching alias" do
    replaced_sql = @dataset.select(:a, :b).replace_select_with_alias(Sequel.as("1", :a), Sequel.as("2", :b)).sql
    expect(replaced_sql).to eq("SELECT '1' AS a, '2' AS b FROM test")
  end

  it "should leave unaliased columns untouched" do
    replaced_sql = @dataset.select(:a, :b).replace_select_with_alias(Sequel.as("1", :a)).sql
    expect(replaced_sql).to eq("SELECT '1' AS a, b FROM test")
  end

  it "should accept a block that yields a virtual row" do
    replaced_sql = @dataset.select(:a, :b).replace_select_with_alias { |o| Sequel.as("1", o.a) }.sql
    expect(replaced_sql).to eq("SELECT '1' AS a, b FROM test")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequel_replace_select_with_alias-0.0.2 spec/sequel_replace_select_with_alias_spec.rb
sequel_replace_select_with_alias-0.0.1 spec/sequel_replace_select_with_alias_spec.rb