Skip to content
This repository
Browse code

Add a test for #drop_attached_file

  • Loading branch information...
commit 693b5280c0679751ad12d8e862b509750c981e9d 1 parent b922111
Daniel Schierbeck authored December 12, 2011

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. 30  test/schema_test.rb
30  test/schema_test.rb
@@ -7,6 +7,7 @@ class MockSchema
7 7
   def initialize(table_name = nil)
8 8
     @table_name = table_name
9 9
     @columns = {}
  10
+    @deleted_columns = []
10 11
   end
11 12
 
12 13
   def column(name, type)
@@ -14,13 +15,19 @@ def column(name, type)
14 15
   end
15 16
 
16 17
   def remove_column(table_name, column_name)
  18
+    return if @table_name && @table_name != table_name
17 19
     @columns.delete(column_name)
  20
+    @deleted_columns.push(column_name)
18 21
   end
19 22
 
20 23
   def has_column?(column_name)
21 24
     @columns.key?(column_name)
22 25
   end
23 26
 
  27
+  def deleted_column?(column_name)
  28
+    @deleted_columns.include?(column_name)
  29
+  end
  30
+
24 31
   def type_of(column_name)
25 32
     @columns[column_name]
26 33
   end
@@ -65,4 +72,27 @@ class SchemaTest < Test::Unit::TestCase
65 72
       assert_equal :datetime, @schema.type_of(:avatar_updated_at)
66 73
     end
67 74
   end
  75
+
  76
+  context "Migrating down" do
  77
+    setup do
  78
+      @schema = MockSchema.new(:users)
  79
+      @schema.drop_attached_file :users, :avatar
  80
+    end
  81
+
  82
+    should "remove the file_name column" do
  83
+      assert @schema.deleted_column?(:avatar_file_name)
  84
+    end
  85
+
  86
+    should "remove the content_type column" do
  87
+      assert @schema.deleted_column?(:avatar_content_type)
  88
+    end
  89
+
  90
+    should "remove the file_size column" do
  91
+      assert @schema.deleted_column?(:avatar_file_size)
  92
+    end
  93
+
  94
+    should "remove the updated_at column" do
  95
+      assert @schema.deleted_column?(:avatar_updated_at)
  96
+    end
  97
+  end
68 98
 end

0 notes on commit 693b528

Please sign in to comment.
Something went wrong with that request. Please try again.