Two main frameworks dominate the Ruby testing world: Rspec and MiniTest. RSpec is a very expressive testing framework with many great features and helpers to make tests readable. When writing RSpec tests, here are just a few not so obvious hints that could make tests even easier to write, read, and maintain. Assuming a system exists with Books and Authors, let’s utilize these hints to make testing
It can be hard to open the Strong Parameters door and let permitted values into your Rails 4 app. Last week I banged my head against the wall for a few hours trying to figure out how to whitelist input values for my Rails 4 app using the Strong Parameters feature. Calling permit when you have a simple attributes hash for a single new object is straightforward, but figuring out how to call permit f
Class methods (4) from_trusted_xml from_xml typecast_xml_value (<= v3.2.13) unrename_keys (<= v3.2.13) Instance methods (51) as_json assert_valid_keys compact (<= v5.2.3) compact! (<= v5.2.3) compact_blank compact_blank! deep_dup deep_merge deep_merge! (<= v7.0.0) deep_merge? deep_stringify_keys deep_stringify_keys! deep_symbolize_keys deep_symbolize_keys! deep_transform_keys deep_transform_keys!
# File activesupport/lib/active_support/core_ext/hash/conversions.rb, line 133 def from_trusted_xml(xml) from_xml xml, [] end Returns a Hash containing a collection of pairs when the key is the node name and the value is its content xml = <<-XML <?xml version="1.0" encoding="UTF-8"?> <hash> <foo type="integer">1</foo> <bar type="integer">2</bar> </hash> XML hash = Hash.from_xml(xml) # => {"hash"=>
Hash Selector Patternという記事を読んでいたら、コメントにdeviseのafter_sign_in_path_forをHashで華麗に書いてあるコードがあって、「おおっ」と思ったのでした。というわけで今日はRubyの話。 こんなコード ユーザーのタイプに応じてログイン後のページを変える場合、大体こんな感じのif分岐になると思います(もしくはcase文とか)。 def after_sign_in_path_for(resource) if resource.kind_of?(AdminUser) admin_dashboard_path elsif resource.kind_of?(Customer) customer_root_path elsif resource.kind_of?(Staff) staff_root_path elsif resource.kind
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く