forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
activerecord/lib/active_record/tasks/oracle_database_tasks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module ActiveRecord | ||
module Tasks # :nodoc: | ||
class OracleDatabaseTasks # :nodoc: | ||
delegate :connection, :establish_connection, to: ActiveRecord::Base | ||
|
||
def initialize(configuration) | ||
@configuration = configuration | ||
end | ||
|
||
def create | ||
$stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' | ||
end | ||
|
||
def drop | ||
$stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' | ||
end | ||
|
||
def purge | ||
establish_connection(:test) | ||
connection.structure_drop.split(";\n\n").each { |ddl| connection.execute(ddl) } | ||
end | ||
|
||
def charset | ||
$stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch' | ||
end | ||
|
||
def structure_dump(filename) | ||
establish_connection(configuration) | ||
File.open(filename, "w:utf-8") { |f| f << connection.structure_dump } | ||
end | ||
|
||
def structure_load(filename) | ||
establish_connection(configuration) | ||
IO.read(filename).split(";\n\n").each { |ddl| connection.execute(ddl) } | ||
end | ||
|
||
private | ||
|
||
def configuration | ||
@configuration | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require 'cases/helper' | ||
|
||
module ActiveRecord | ||
module OracleSetupper | ||
def setup | ||
@database = 'db.oracle' | ||
@connection = stub :connection | ||
@configuration = { | ||
'adapter' => 'oracle', | ||
'database' => @database | ||
} | ||
ActiveRecord::Base.stubs(:connection).returns(@connection) | ||
ActiveRecord::Base.stubs(:establish_connection).returns(true) | ||
end | ||
end | ||
|
||
class OracleDBCreateTest < ActiveRecord::TestCase | ||
include OracleSetupper | ||
|
||
def test_db_retrieves_create | ||
message = capture(:stderr) do | ||
ActiveRecord::Tasks::DatabaseTasks.create @configuration | ||
end | ||
assert_match(/not supported/, message) | ||
end | ||
end | ||
|
||
class OracleDBDropTest < ActiveRecord::TestCase | ||
include OracleSetupper | ||
|
||
def test_db_retrieves_drop | ||
message = capture(:stderr) do | ||
ActiveRecord::Tasks::DatabaseTasks.drop @configuration | ||
end | ||
assert_match(/not supported/, message) | ||
end | ||
end | ||
|
||
class OracleDBCharsetAndCollationTest < ActiveRecord::TestCase | ||
include OracleSetupper | ||
|
||
def test_db_retrieves_collation | ||
assert_raise NoMethodError do | ||
ActiveRecord::Tasks::DatabaseTasks.collation @configuration | ||
end | ||
end | ||
|
||
def test_db_retrieves_charset | ||
message = capture(:stderr) do | ||
ActiveRecord::Tasks::DatabaseTasks.charset @configuration | ||
end | ||
assert_match(/not supported/, message) | ||
end | ||
end | ||
|
||
class OracleStructureDumpTest < ActiveRecord::TestCase | ||
include OracleSetupper | ||
|
||
def setup | ||
super | ||
@connection.stubs(:structure_dump).returns("select sysdate from dual;") | ||
end | ||
|
||
def test_structure_dump | ||
filename = "oracle.sql" | ||
ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename) | ||
assert File.exists?(filename) | ||
ensure | ||
FileUtils.rm_f(filename) | ||
end | ||
end | ||
|
||
class OracleStructureLoadTest < ActiveRecord::TestCase | ||
include OracleSetupper | ||
|
||
def test_structure_load | ||
filename = "oracle.sql" | ||
|
||
open(filename, 'w') { |f| f.puts("select sysdate from dual;") } | ||
@connection.stubs(:execute).with("select sysdate from dual;\n") | ||
ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename) | ||
ensure | ||
FileUtils.rm_f(filename) | ||
end | ||
end | ||
end |