Sha256: ae6e8c43d51e96d3e9e36469ab087166181a3d156d2bde14d196734df49ae035

Contents?: true

Size: 1.97 KB

Versions: 26

Compression:

Stored size: 1.97 KB

Contents

#
# Copyright 2012 Mortar Data Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'
require 'fakefs/spec_helpers'
require 'mortar/local/sqoop'
require 'launchy'


module Mortar::Local
  describe Sqoop do

    context "prepare query" do

      it "adds a where clause if none exists" do
        sqoop = Mortar::Local::Sqoop.new
        expect(sqoop.prep_query("SELECT * FROM customers")).to eq("SELECT * FROM customers WHERE \$CONDITIONS")
      end

      it "wraps existing where clause and appends condition" do
        original = "SELECT * FROM customers WHERE customer_id = 1"
        expected = "SELECT * FROM customers WHERE (customer_id = 1) AND \$CONDITIONS"
        sqoop = Mortar::Local::Sqoop.new
        expect(sqoop.prep_query(original)).to eq(expected)
      end

      it "wraps a complex where clause and appends condition" do
        original = "SELECT * FROM customers WHERE (customer_id = 1 and customer_name = 'tom') or customer_id=2"
        expected = "SELECT * FROM customers WHERE ((customer_id = 1 and customer_name = 'tom') or customer_id=2) AND \$CONDITIONS"
        sqoop = Mortar::Local::Sqoop.new
        expect(sqoop.prep_query(original)).to eq(expected)
      end

      it "does nothing if the user was polite enough to supply the clause themselves" do
        query = "SELECT * FROM customers WHERE (customer_id = 1) AND \$CONDITIONS"
        sqoop = Mortar::Local::Sqoop.new
        expect(sqoop.prep_query(query)).to eq(query)
      end


    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mortar-0.15.36 spec/mortar/local/sqoop_spec.rb
mortar-0.15.35 spec/mortar/local/sqoop_spec.rb
mortar-0.15.34 spec/mortar/local/sqoop_spec.rb
mortar-0.15.33 spec/mortar/local/sqoop_spec.rb
mortar-0.15.32 spec/mortar/local/sqoop_spec.rb
mortar-0.15.31 spec/mortar/local/sqoop_spec.rb
mortar-0.15.30 spec/mortar/local/sqoop_spec.rb
mortar-0.15.29 spec/mortar/local/sqoop_spec.rb
mortar-0.15.28 spec/mortar/local/sqoop_spec.rb
mortar-0.15.27 spec/mortar/local/sqoop_spec.rb
mortar-0.15.26 spec/mortar/local/sqoop_spec.rb
mortar-0.15.25 spec/mortar/local/sqoop_spec.rb
mortar-0.15.24 spec/mortar/local/sqoop_spec.rb
mortar-0.15.23 spec/mortar/local/sqoop_spec.rb
mortar-0.15.22 spec/mortar/local/sqoop_spec.rb
mortar-0.15.21 spec/mortar/local/sqoop_spec.rb
mortar-0.15.20 spec/mortar/local/sqoop_spec.rb
mortar-0.15.19 spec/mortar/local/sqoop_spec.rb
mortar-0.15.18 spec/mortar/local/sqoop_spec.rb
mortar-0.15.17 spec/mortar/local/sqoop_spec.rb