Rails3がリリースされてから公式サイトのRailsのドキュメントがRails3のものに変わってしまった。
でもRails2のドキュメントも残っていた。
Ruby on Rails Documentation
でもRails2のドキュメントも残っていた。
Ruby on Rails Documentation
Modified: Thu Aug 19 22:56:35 +0000 2010
Webで見つけた気になるものをメモしたり、それにコメントしたりするブログ。
Modified: Thu Aug 19 22:56:35 +0000 2010
The change you wanted was rejected. Maybe you tried to change something you didn't have access to.
# Generates a select field for years that defaults to the current year that # has ascending year values select_year(Date.today, :start_year => 1992, :end_year => 2007)
N_()は実は何もしないメソッド。rgettext(poファイル抽出時)にそれが翻訳対象文字列であることを伝えるためのメソッドで、実際の翻訳はsay_hello_world内の_()で行っている。
gemからインストールできます。
gem install redgreen
このgemを使うと、テストで「.」(=通過)には緑、「F」は赤で表示されるようになります。便利ですね。
def assert_not_select(css_selector, text, message = nil)
assert_select(css_selector, {:text => text, :count => 0}, message)
end
render :text => ERB::Util.html_escape(params[:value])
Don't use it. It's deprecated in 1.2 in favor of assert_select.
このサイトくらいしか見つからなかった。このサイトが参考にしたらしいサイトはリンク切れ。
あとは公式リファレンス見て調べるか。
deliveries - Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.
# テスト時に配送したメールの配列を保存する。
ActionMailer::Base.deliveries = []
tasksテーブルに入っている列の数だけクエリが生成することになり、パフォーマンス的に大変よろしくありません。先にprojectsテーブルからもデータを取得しておけば、クエリの発行回数を減らすことができます。この、「先にデータを取得しておく」ことを eager loading というらしいです。
で、そこでRailsとTDD(BDD)の話なんかしたので、一週間で思ったことをつらつらと。たぶん不正確というか、理解の足りないところもいろいろあるので、そのへんのツッコミをいただけると感謝です。
各 assertion の最後の引数 message はテストが失敗したときに表示される メッセージ
Ruby on RailsでURLエンコード・デコードする
ただ、一つ気になっていたのは、idが85969009とか、巨大な整数になることです。しかし、今日知ったのですが、これはラベルの文字列のハッシュだったんですね。これは、実に便利で、この例は
'Rosaceae'.hash.abs -> 85969009 なのですが、(私のシステムの場合ですが)
Family.find('Rosaceae'.hash.abs)と書けるわけです。
Alternatively, you may enable auto-instantiation of the fixture data. For instance, take the following tests:
test "find_alt_method_1" do
assert_equal "Ruby on Rails", @web_sites['rubyonrails']['name']
end
test "find_alt_method_2" do
assert_equal "Ruby on Rails", @rubyonrails.news
end
In order to use these methods to access fixtured data within your testcases, you must specify one of the following in your ActiveSupport::TestCase-derived class:
* to fully enable instantiated fixtures (enable alternate methods 1 and 2 above)
self.use_instantiated_fixtures = true
* create only the hash for the fixtures, do not ‘find’ each instance (enable alternate method 1 only)
self.use_instantiated_fixtures = :no_instances
Add a few more monkeys and pirates and break this into multiple files, and it gets pretty hard to keep track of what‘s going on. Let‘s use labels instead of IDs:
### in pirates.yml
reginald:
name: Reginald the Pirate
monkey: george
### in monkeys.yml
george:
name: George the Monkey
pirate: reginald
Some times you don‘t care about the content of the fixtures as much as you care about the volume. In these cases, you can mix ERb in with your YAML or CSV fixtures to create a bunch of fixtures for load testing, like:
<% for i in 1..1000 %>
fix_<%= i %>:
id: <%= i %>
name: guy_<%= 1 %>
<% end %>
It was deprecated at 2.2.2
- "assert_valid is deprecated. Use assert record.valid? instead"