require 'spec_helper' RSpec.describe InstDataShipper::Dumper do let(:dumper) { TestDumper.new } let(:context) { { incremental_since: 1.day.ago.iso8601, } } before :each do allow(dumper).to receive(:batch_context).and_return(context) end describe "#auto_enqueue_from_schema" do it "makes the expected calls" do expect(dumper).to receive(:import_local_table).with(InstDataShipper::DumpBatch, schema_name: "local_table_test") dumper.send(:enqueue_table_from_schema, "local_table_test") end it "enqueues all tables with a sourcer" do expect(dumper).to receive(:enqueue_table_from_schema).with(hash_including(warehouse_name: "test_table")) expect(dumper).to receive(:enqueue_table_from_schema).with(hash_including(warehouse_name: "local_table_test")) allow(dumper).to receive(:enqueue_table_from_schema) dumper.send(:auto_enqueue_from_schema) end it "doesn't try to enqueue a table with no sourcer" do expect(dumper).to_not receive(:enqueue_table_from_schema).with(hash_including(warehouse_name: "incremental_table")) allow(dumper).to receive(:enqueue_table_from_schema) dumper.send(:auto_enqueue_from_schema) end end describe "#table_is_incremental?" do it "usually returns as the table defines" do expect(dumper.table_is_incremental?("test_table")).to be false expect(dumper.table_is_incremental?("incremental_table")).to be true end it "returns false if incremental_since is nil" do context[:incremental_since] = nil expect(dumper.table_is_incremental?("incremental_table")).to be false end it "returns false if table is forced to full" do context[:force_full_tables] = ["incremental_table"] expect(dumper.table_is_incremental?("incremental_table")).to be false end it "supports a proc for the if: option" do dumper.instance_variable_set(:@proc_incremental, true) expect(dumper.table_is_incremental?("proc_incremental_table")).to be true dumper.instance_variable_set(:@proc_incremental, false) expect(dumper.table_is_incremental?("proc_incremental_table")).to be false end end end