|
|
|
|
現在のDBの内容から test/fixtures/*.yml を作成する方法。基本的には、
ActiveRecordClass.find(:all).collect{|record| record.attributes.to_yaml} |
でいいんだけど、topfunky のプラグインを使ってみる。
% ruby script/plugin install http://topfunky.net/svn/plugins/ar_fixtures |
% ruby script/runner "Group.to_fixture" |
/usr/share/tdiary/tdiary/regex_rules/syntax-ruby:3:in `require': no such file to load -- syntax/convertors/html (LoadError) from /usr/share/tdiary/tdiary/regex_rules/syntax-ruby:3
% ruby script/runner "Group.habtm_to_fixture" |
/usr/share/tdiary/tdiary/regex_rules/syntax-ruby:3:in `require': no such file to load -- syntax/convertors/html (LoadError) from /usr/share/tdiary/tdiary/regex_rules/syntax-ruby:3
从 ’w’)<テストの作成が楽になるね。
(*1) Group.to_fixture で自動的にはびたむ用の fixture も作成されます。
desc "Save fixtures from the current environment's database"
task :save_fixtures => :environment do
Dir["app/models/*.rb"].each{|i| eval File.basename(i, '.rb').classify}
Object.subclasses_of(ActiveRecord::Base).each{|klass| klass.to_fixture rescue p klass.name}
end |
从*’w’)<クゥ〜ン♪
| JRuby | Rails | Berryz | ℃-ute | エッグ | jQuery |
| 前 | 2006年 2月 |
次 | ||||
| 日 | 月 | 火 | 水 | 木 | 金 | 土 |
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | ||||
そんなやつおらんやろー
最後のRake Taskですが、SessionのActiveRecordStoreを使っていなかった場合、例外でこけるので、<br>Object.subclasses_of(ActiveRecord::Base).each{|klass| klass.to_fixture rescue p klass.name}<br>という感じにするといいかと存じます。
仰せの通りです!あざーす