Commit 301c33eac44b4c80a8daabac857d20b1c9e1bafe

Authored by Antonio Terceiro
1 parent 871c6a7d

ActionItem916: enhancements to migration

Showing 1 changed file with 176 additions and 1 deletions   Show diff stats
db/migrate/059_add_birth_date_to_person.rb
... ... @@ -36,9 +36,11 @@ class AddBirthDateToPerson < ActiveRecord::Migration
36 36  
37 37 def self.up
38 38 add_column :profiles, :birth_date, :date
39   - Person.find(:all).select{|p| p.type = 'Person'}.each do |p|
  39 + offset = 0
  40 + while p = Person.find(:first, :conditions => "type = 'Person'", :order => 'id', :offset => offset)
40 41 p.birth_date = ConvertDates.convert(p.data[:birth_date].to_s)
41 42 p.save
  43 + offset += 1
42 44 end
43 45 end
44 46  
... ... @@ -51,6 +53,172 @@ if $PROGRAM_NAME == __FILE__
51 53 require File.dirname(__FILE__) + '/../../test/test_helper'
52 54  
53 55 class ConvertDatesTest < Test::Unit::TestCase
  56 + SAMPLE = [
  57 + "",
  58 + "06/06/1973",
  59 + "08/02/1981",
  60 + "",
  61 + "06/01/1955",
  62 + "06 de dezembro ",
  63 + "",
  64 + "01/10/2980",
  65 + "06/03/68",
  66 + "21/07/1975",
  67 + "13/11/1985",
  68 + "",
  69 + "17/11/2007",
  70 + "",
  71 + "19/10/1982",
  72 + "",
  73 + "22/07/1973",
  74 + "17/02",
  75 + "",
  76 + "24/03/1966",
  77 + "02-07-62",
  78 + "11/071987",
  79 + "10/01/1978",
  80 + "04/07/1981",
  81 + "",
  82 + "14/06/00",
  83 + "06/05",
  84 + "21/12/1941",
  85 + "04/04",
  86 + "02.01.1956",
  87 + "",
  88 + "06/02/1986",
  89 + "11/03/1981",
  90 + "17.08.1956",
  91 + "",
  92 + "",
  93 + "",
  94 + "14/12/1981",
  95 + "29/10/1962",
  96 + "13/01/1982",
  97 + "14/07/1984",
  98 + "",
  99 + "05/02/1976",
  100 + "",
  101 + "02-07-1962",
  102 + "15/11/1976",
  103 + "06/10/1970",
  104 + "",
  105 + "23/ 12/ 1999",
  106 + "10/05/1972",
  107 + "26/06/1951",
  108 + "19/11/1954",
  109 + "14/03/2002",
  110 + "",
  111 + "",
  112 + "",
  113 + "17/06/1979",
  114 + "07/08/1976",
  115 + "19/09/1990",
  116 + "21/06/1958",
  117 + "",
  118 + "09/10/1968",
  119 + "17/11/1984",
  120 + "21/02/1989",
  121 + "18 de março",
  122 + "",
  123 + "23/03/1984",
  124 + "18/08/1969",
  125 + "01/07/1991",
  126 + "22/02/1981",
  127 + "02/05/1984",
  128 + "",
  129 + "19/10/1988",
  130 + "04 de maio",
  131 + "",
  132 + "",
  133 + "",
  134 + "",
  135 + "25/09/1985",
  136 + "29/04/1991",
  137 + "",
  138 + "21/09/1975",
  139 + "15/06/1976",
  140 + "23/04/1983",
  141 + "15/08/1981",
  142 + "15/06/1972",
  143 + "",
  144 + "",
  145 + "AGOSTO",
  146 + "01/02",
  147 + "",
  148 + "24/10/1980",
  149 + "11/07/1976",
  150 + "",
  151 + "",
  152 + "01/02",
  153 + "",
  154 + "",
  155 + "",
  156 + "",
  157 + "03/09/1982",
  158 + "",
  159 + "",
  160 + "13/03/1985",
  161 + "",
  162 + "",
  163 + "03/10/1974",
  164 + "14.08.1981",
  165 + "",
  166 + "14/11/1979",
  167 + "",
  168 + "",
  169 + "30/07/1981",
  170 + "",
  171 + "",
  172 + "13/09/1979",
  173 + "14/06/1978",
  174 + "05/09/1957",
  175 + "",
  176 + "",
  177 + "03/09/1982",
  178 + "12/01/1987",
  179 + "13/03/1986",
  180 + "9/12/80",
  181 + "21/12/1982",
  182 + "15/12/85",
  183 + "07/05/84",
  184 + "21/10/1983",
  185 + "4/07/1984",
  186 + "17/04/1977",
  187 + "9 junio 86",
  188 + "12 diciembre 1983",
  189 + "25/04/1959",
  190 + "08/08/1972",
  191 + "12/01/1986",
  192 + "13/09/1979",
  193 + "19/01/1986",
  194 + "05/04/1982",
  195 + "24/12/1958",
  196 + "07 / 05 / 1956",
  197 + "02/05/1984",
  198 + "14/06/1980",
  199 + "03/09/1982",
  200 + "12/01/1987",
  201 + "13/03/1986",
  202 + "9/12/80",
  203 + "21/12/1982",
  204 + "15/12/85",
  205 + "07/05/84",
  206 + "21/10/1983",
  207 + "4/07/1984",
  208 + "17/04/1977",
  209 + "9 junio 86",
  210 + "12 diciembre 1983",
  211 + "25/04/1959",
  212 + "08/08/1972",
  213 + "12/01/1986",
  214 + "13/09/1979",
  215 + "19/01/1986",
  216 + "05/04/1982",
  217 + "24/12/1958",
  218 + "07 / 05 / 1956",
  219 + "02/05/1984",
  220 + "14/06/1980"
  221 + ]
54 222  
55 223 should 'convert with slash' do
56 224 date = AddBirthDateToPerson::ConvertDates.convert('10/01/2009')
... ... @@ -121,6 +289,13 @@ if $PROGRAM_NAME == __FILE__
121 289 assert_nil AddBirthDateToPerson::ConvertDates.convert('70/05/1987')
122 290 end
123 291  
  292 + SAMPLE.each_with_index do |string,i|
  293 + should "convert sample #{i} (#{string})" do
  294 + result = AddBirthDateToPerson::ConvertDates.convert(string)
  295 + assert(result.nil? || result.is_a?(Date))
  296 + end
  297 + end
  298 +
124 299 end
125 300  
126 301 end
... ...