This project is archived and is in readonly mode.

#97 ✓resolved

Enhancement: Add scope_options inspection method to named_scope

Reported by duncanbeevers | May 3rd, 2008 @ 05:52 AM

When generating complex options hashes for named scopes, it can be difficult to test that the scopes are generated correctly. By providing insight into the generated options, we can test the scope without having to instantiate records.

class Shirt < ActiveRecord::Base
  named_scope :colored, lambda { |color|
    { :conditions => { :color => color } }
class ShirtTest < Test::Unit
  def test_colored_scope
    red_scope = { :conditions => { :colored => 'red' } }
    blue_scope = { :conditions => { :colored => 'blue' } }
    assert_equal red_scope, Shirt.colored('red').scope_options
    assert_equal blue_scope, Shirt.colored('blue').scope_options

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket


Referenced by