spec/examples/generic_adapter_examples.rb in apartment-1.2.0 vs spec/examples/generic_adapter_examples.rb in apartment-2.0.0
- old
+ new
@@ -6,10 +6,29 @@
before {
Apartment.prepend_environment = false
Apartment.append_environment = false
}
+ describe "#init" do
+ it "should not retain a connection after railtie" do
+ # this test should work on rails >= 4, the connection pool code is
+ # completely different for 3.2 so we'd have to have a messy conditional..
+ unless Rails::VERSION::MAJOR < 4
+ ActiveRecord::Base.connection_pool.disconnect!
+
+ Apartment::Railtie.config.to_prepare_blocks.map(&:call)
+
+ num_available_connections = Apartment.connection_class.connection_pool
+ .instance_variable_get(:@available)
+ .instance_variable_get(:@queue)
+ .size
+
+ expect(num_available_connections).to eq(1)
+ end
+ end
+ end
+
#
# Creates happen already in our before_filter
#
describe "#create" do
@@ -37,10 +56,26 @@
expect(subject.current).not_to eq(db2)
subject.switch(db2){ expect(User.count).to eq(@count + 1) }
end
+
+ it "should raise error when the schema.rb is missing unless Apartment.use_sql is set to true" do
+ next if Apartment.use_sql
+
+ subject.drop(db1)
+ begin
+ Dir.mktmpdir do |tmpdir|
+ Apartment.database_schema_file = "#{tmpdir}/schema.rb"
+ expect {
+ subject.create(db1)
+ }.to raise_error(Apartment::FileNotFound)
+ end
+ ensure
+ Apartment.remove_instance_variable(:@database_schema_file)
+ end
+ end
end
describe "#drop" do
it "should remove the db" do
subject.drop db1
@@ -80,26 +115,9 @@
subject.switch!(db2)
expect {
subject.switch(db1){ subject.drop(db2) }
}.to_not raise_error
- end
-
- it "warns if no block is given, but calls switch!" do
- expect(Apartment::Deprecation).to receive(:warn)
-
- subject.switch(db1)
- expect(subject.current).to eq(db1)
- end
- end
-
- describe "#process" do
- it "is deprecated" do
- expect(Apartment::Deprecation).to receive(:warn)
-
- subject.process(db1) do
- expect(subject.current).to eq(db1)
- end
end
end
describe "#reset" do
it "should reset connection" do