Permalink
Browse files

Add table manager tests

  • Loading branch information...
Sutto committed Aug 6, 2009
1 parent e12d3b2 commit 808e1adc260821a41b7222e606f7e7752e67cc03
Showing with 38 additions and 6 deletions.
  1. +10 −6 lib/reversible_data/table_manager.rb
  2. +28 −0 test/table_manager_test.rb
@@ -1,19 +1,23 @@
module ReversibleData
class TableManager
- def initialize(*names)
- @names = names.map { |n| n.to_sym }
+ attr_reader :managed_tables
+
+ def initialize(*managed_tables)
+ @managed_tables = managed_tables.map { |n| n.to_sym }.freeze
end
def up!
- @names.each do |name|
- table.up! unless (table = table_for(name)).nil?
+ @managed_tables.each do |name|
+ table = table_for(name)
+ table.up! unless table.nil?
end
end
def down!
- @names.each do |name|
- table.down! unless (table = table_for(name)).nil?
+ @managed_tables.each do |name|
+ table = table_for(name)
+ table.down! unless table.nil?
end
end
View
@@ -0,0 +1,28 @@
+require 'test_helper'
+
+class TableManagerTest < Test::Unit::TestCase
+ context 'table managers in general' do
+
+ setup do
+ @table_a = ReversibleData.add(:a) { |t| t.string :name }
+ @table_b = ReversibleData.add(:b) { |t| t.string :name }
+ @table_c = ReversibleData.add(:c) { |t| t.string :name }
+ @manager = ReversibleData::TableManager.new(:a, :b, :c)
+ end
+
+ should 'let you create a manager for a set of tables' do
+ assert_equal [:a, :b, :c], @manager.managed_tables
+ end
+
+ should 'let you run up! on all managed tables' do
+ [@table_a, @table_b, @table_c].each { |t| mock(t).up! }
+ @manager.up!
+ end
+
+ should 'let you run down! on all managed tables' do
+ [@table_a, @table_b, @table_c].each { |t| mock(t).down! }
+ @manager.down!
+ end
+
+ end
+end

0 comments on commit 808e1ad

Please sign in to comment.