Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add a test for #drop_attached_file
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Dec 12, 2011
1 parent b922111 commit 693b528
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/schema_test.rb
Expand Up @@ -7,20 +7,27 @@ class MockSchema
def initialize(table_name = nil)
@table_name = table_name
@columns = {}
@deleted_columns = []
end

def column(name, type)
@columns[name] = type
end

def remove_column(table_name, column_name)
return if @table_name && @table_name != table_name
@columns.delete(column_name)
@deleted_columns.push(column_name)
end

def has_column?(column_name)
@columns.key?(column_name)
end

def deleted_column?(column_name)
@deleted_columns.include?(column_name)
end

def type_of(column_name)
@columns[column_name]
end
Expand Down Expand Up @@ -65,4 +72,27 @@ class SchemaTest < Test::Unit::TestCase
assert_equal :datetime, @schema.type_of(:avatar_updated_at)
end
end

context "Migrating down" do
setup do
@schema = MockSchema.new(:users)
@schema.drop_attached_file :users, :avatar
end

should "remove the file_name column" do
assert @schema.deleted_column?(:avatar_file_name)
end

should "remove the content_type column" do
assert @schema.deleted_column?(:avatar_content_type)
end

should "remove the file_size column" do
assert @schema.deleted_column?(:avatar_file_size)
end

should "remove the updated_at column" do
assert @schema.deleted_column?(:avatar_updated_at)
end
end
end

0 comments on commit 693b528

Please sign in to comment.