Rails

fixture時にint型の値にNULLが入らない

2008/02/03

Railsではcsvやyamlで作られたテストデータを読み込むfixtureという機能があります。

アプリケーションを作っているときに毎度ユーザなどを作るのは面倒なので、テストデータを作っておいて、migrate時に読み込ませたりしているのですが、どうもint型でnullを入れようとすると0になってしまう現象が起きてしまいます。

調べてみたらパッチとしてずいぶん前からあるみたいです。

Null values in a CSV format fixture show up a 0 in the test database

activerecord/lib/fixtures.rb の read_csv_fixture_files メソッドの

row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }

を、

row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell == nil ? nil : cell.to_s.strip }

に変えるだけ。

でも本体はなるべくいじりたくないので、どうしようかな。


related posts


tags

, , ,


have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« FastCGIインストール on x86_64
» ハン・ベニンク来日公演 @ super deluxe