Skip to content
This repository
Browse code

Revert "Merge pull request #9206 from ranjaykrishna/use_define_method"

This reverts commit 1fc6876, reversing
changes made to 0268b5d.

Reason: failing test

  1) Error:
test_valid_column(ActiveRecord::ConnectionAdapters::SQLite3AdapterTest):
NoMethodError: undefined method `column' for
    test/cases/adapters/sqlite3/sqlite3_adapter_test.rb:29:in
`test_valid_column'
  • Loading branch information...
commit 8aa4603a5adaa56c818a7bd1c0b761b4ecca3d3e 1 parent a159f47
Jon Leighton authored February 15, 2013
31  activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -252,12 +252,15 @@ def column(name, type, options = {})
252 252
         self
253 253
       end
254 254
 
255  
-      [:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
256  
-        define_method column_type do |*args|
257  
-          options = args.extract_options!
258  
-          column_names = args
259  
-          column_names.each { |name| column(name, column_type, options) }
260  
-        end
  255
+      %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
  256
+        class_eval <<-EOV, __FILE__, __LINE__ + 1
  257
+          def #{column_type}(*args)                                   # def string(*args)
  258
+            options = args.extract_options!                           #   options = args.extract_options!
  259
+            column_names = args                                       #   column_names = args
  260
+            type = :'#{column_type}'                                  #   type = :string
  261
+            column_names.each { |name| column(name, type, options) }  #   column_names.each { |name| column(name, type, options) }
  262
+          end                                                         # end
  263
+        EOV
261 264
       end
262 265
 
263 266
       # Adds index options to the indexes hash, keyed by column name
@@ -483,13 +486,15 @@ def remove_references(*args)
483 486
       #
484 487
       #  t.string(:goat)
485 488
       #  t.string(:goat, :sheep)
486  
-      [:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].each do |column_type|
487  
-        define_method column_type do |*args|
488  
-          options = args.extract_options!
489  
-          args.each do |name|
490  
-            @base.add_column(@table_name, name, column_type, options)
491  
-          end
492  
-        end  
  489
+      %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
  490
+        class_eval <<-EOV, __FILE__, __LINE__ + 1
  491
+          def #{column_type}(*args)                                          # def string(*args)
  492
+            options = args.extract_options!                                  #   options = args.extract_options!
  493
+            args.each do |name|                                              #   column_names.each do |name|
  494
+              @base.add_column(@table_name, name, :#{column_type}, options)  #     @base.add_column(@table_name, name, :string, options)
  495
+            end                                                              #   end
  496
+          end                                                                # end
  497
+        EOV
493 498
       end
494 499
 
495 500
       private

0 notes on commit 8aa4603

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