Permalink
Browse files

execute extras

  • Loading branch information...
1 parent bd439a9 commit 240cae90bb306845fef52c8fa8438e4510c295ad @rcarver committed Jun 12, 2012
Showing with 32 additions and 4 deletions.
  1. +2 −0 lib/mysql_inspector/access.rb
  2. +2 −2 lib/mysql_inspector/dump.rb
  3. +1 −1 test/helper.rb
  4. +27 −1 test/mysql_inspector/dump_test.rb
@@ -23,6 +23,8 @@ def tables
end
def drop_all_tables
+ return if table_names.empty?
+
pipe_to_mysql without_foreign_keys("DROP TABLE #{table_names.join(',')}")
end
@@ -57,7 +57,7 @@ def write!(access)
}
}
File.open(@info_file, "w") { |f| f.print(Time.now.utc.to_s) }
- @extras.each { |extra| extra.write!(dir, access) }
+ @extras.each { |extra| extra.write!(access) }
rescue
FileUtils.rm_rf(dir) # note this does not remove all the dirs that may have been created.
raise
@@ -74,7 +74,7 @@ def load!(access)
schema = tables.map { |t| t.to_sql }.join(";")
access.drop_all_tables
access.load(schema)
- @extras.each { |extra| extra.load!(dir, access) }
+ @extras.each { |extra| extra.load!(access) }
end
end
View
@@ -63,7 +63,7 @@ def drop_mysql_database
#
# Returns a MysqlInspector:Access.
def access
- MysqlInspector::Access.new(database_name, "root", nil, "mysql")
+ (@access ||= {})[database_name] ||= MysqlInspector::Access.new(database_name, "root", nil, "mysql")
end
let(:config) { MysqlInspector::Config.new }
@@ -2,8 +2,10 @@
describe MysqlInspector::Dump do
+ let(:extras) { [] }
+
subject do
- MysqlInspector::Dump.new(tmpdir)
+ MysqlInspector::Dump.new(tmpdir, *extras)
end
describe "before written" do
@@ -58,4 +60,28 @@
proc { subject.write!(access) }.must_raise MysqlInspector::Access::Error
end
end
+
+ describe "extras" do
+
+ let(:extra) { MiniTest::Mock.new }
+
+ before do
+ create_mysql_database
+ end
+ after do
+ extra.verify
+ end
+
+ it "writes extras" do
+ extra.expect :write!, nil, [access]
+ extras << extra
+ subject.write!(access)
+ end
+ it "loads extras" do
+ extra = MiniTest::Mock.new
+ extra.expect :load!, nil, [access]
+ extras << extra
+ subject.load!(access)
+ end
+ end
end

0 comments on commit 240cae9

Please sign in to comment.