Skip to content

Commit

Permalink
refactoring numeric db tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrobertson committed May 31, 2012
1 parent 567f294 commit 2c15e0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/apartment/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def reset
#
def connect_to_new(database = nil)
return reset if database.nil?
ActiveRecord::Base.connection.schema_search_path = database
ActiveRecord::Base.connection.schema_search_path = database.to_s

rescue ActiveRecord::StatementInvalid
raise SchemaNotFound, "The schema #{database.inspect} cannot be found."
Expand Down
28 changes: 17 additions & 11 deletions spec/examples/schema_adapter_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@
end

context "numeric database names" do
let(:db){ 1234 }
it "should allow them" do
expect {
subject.create(1234)
subject.create(db)
}.to_not raise_error
database_names.should include("1234")
database_names.should include(db.to_s)
end

after{ subject.drop(1234) }
after{ subject.drop(db) }
end

end
Expand All @@ -67,15 +68,17 @@
end

context "numeric database names" do
let(:db){ 1234 }

it "should be able to drop them" do
subject.create(1234)
subject.create(db)
expect {
subject.drop(1234)
subject.drop(db)
}.to_not raise_error
database_names.should_not include("1234")
database_names.should_not include(db.to_s)
end

after { subject.drop(1234) rescue nil }
after { subject.drop(db) rescue nil }
end
end

Expand Down Expand Up @@ -118,15 +121,18 @@
end

context "numeric databases" do
let(:db){ 1234 }

it "should connect to them" do
subject.create(1234)
subject.create(db)
expect {
subject.switch(1234)
connection.schema_search_path.should start_with '1234'
subject.switch(db)
}.to_not raise_error

connection.schema_search_path.should start_with db.to_s
end

after{ subject.drop(1234) }
after{ subject.drop(db) }
end
end

Expand Down

0 comments on commit 2c15e0a

Please sign in to comment.