spec/unit/migrator_spec.rb in apartment-0.23.0 vs spec/unit/migrator_spec.rb in apartment-0.23.1

- old
+ new

@@ -1,90 +1,37 @@ require 'spec_helper' require 'apartment/migrator' -describe Apartment::Migrator, database: :postgresql do +describe Apartment::Migrator do - let(:schema_name){ Apartment::Test.next_db } - let(:version){ 20110613152810 } # note this is brittle! I've literally just taken the version of the one migration I made... don't change this version + let(:tenant){ Apartment::Test.next_db } - before do - ActiveRecord::Base.establish_connection config - Apartment::Database.stub(:config).and_return config # Use postgresql config for this test - @original_schema = ActiveRecord::Base.connection.schema_search_path - # Necessary because the JDBC adapter returns $user in the search path - @original_schema.gsub!(/"\$user",/, '') if defined?(JRUBY_VERSION) + # Don't need a real switch here, just testing behaviour + before { Apartment::Database.adapter.stub(:connect_to_new) } - Apartment.configure do |config| - config.use_schemas = true - config.excluded_models = [] - config.database_names = [schema_name] - end + describe "::migrate" do + it "processes and migrates" do + expect(Apartment::Database).to receive(:process).with(tenant).and_call_original + expect(ActiveRecord::Migrator).to receive(:migrate) - Apartment::Database.create schema_name # create the schema - migrations_path = Rails.root + ActiveRecord::Migrator.migrations_path # tell AR where the real migrations are - ActiveRecord::Migrator.stub(:migrations_path).and_return(migrations_path) + Apartment::Migrator.migrate(tenant) + end end - after do - Apartment::Test.drop_schema(schema_name) + describe "::run" do + it "processes and runs" do + expect(Apartment::Database).to receive(:process).with(tenant).and_call_original + expect(ActiveRecord::Migrator).to receive(:run).with(:up, anything, 1234) + + Apartment::Migrator.run(:up, tenant, 1234) + end end - # reset db - after(:all){ Apartment::Test.load_schema } + describe "::rollback" do + it "processes and rolls back" do + expect(Apartment::Database).to receive(:process).with(tenant).and_call_original + expect(ActiveRecord::Migrator).to receive(:rollback).with(anything, 2) - context "postgresql" do - context "using schemas" do - - describe "#migrate" do - it "should connect to new db, then reset when done" do - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{schema_name}"}).once - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{@original_schema}"}).once - Apartment::Migrator.migrate(schema_name) - end - - it "should migrate db" do - ActiveRecord::Migrator.should_receive(:migrate) - Apartment::Migrator.migrate(schema_name) - end - end - - describe "#run" do - context "up" do - - it "should connect to new db, then reset when done" do - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{schema_name}"}).once - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{@original_schema}"}).once - Apartment::Migrator.run(:up, schema_name, version) - end - - it "should migrate to a version" do - ActiveRecord::Migrator.should_receive(:run).with(:up, anything, version) - Apartment::Migrator.run(:up, schema_name, version) - end - end - - describe "down" do - - it "should connect to new db, then reset when done" do - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{schema_name}"}).once - ActiveRecord::Base.connection.should_receive(:schema_search_path=).with(%{"#{@original_schema}"}).once - Apartment::Migrator.run(:down, schema_name, version) - end - - it "should migrate to a version" do - ActiveRecord::Migrator.should_receive(:run).with(:down, anything, version) - Apartment::Migrator.run(:down, schema_name, version) - end - end - end - - describe "#rollback" do - let(:steps){ 3 } - - it "should rollback the db" do - ActiveRecord::Migrator.should_receive(:rollback).with(anything, steps) - Apartment::Migrator.rollback(schema_name, steps) - end - end + Apartment::Migrator.rollback(tenant, 2) end end -end +end \ No newline at end of file