Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Enhancement: Add scope_options inspection method to named_scope

#97

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 } }
  }
end
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
  end
end

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

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Trevor Squires
    Trevor Squires

    The method you are looking for already exists:

    Shirt.colored('red').proxy_options

    Unless you're asking for the name to be changed/aliased to scope_options you should probably close off this ticket.

    May 6th, 2008 @ 08:37 PM

  2. duncanbeevers
    duncanbeevers

    I think giving the method a different name is appropriate, and at a minimum the tests should be carried over.

    May 6th, 2008 @ 09:32 PM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [0b8b582e0668416c6e6760e97a64b9fa3507782c]) Add test for named_scope#proxy_options. [#97 state:resolved]

    http://github.com/rails/rails/co...

    May 11th, 2008 @ 08:35 PM

  4. Pratik
    Pratik

    And just for the records, I had changed the patch to remove scope_options and use existing proxy_options instead.

    Thanks.

    May 11th, 2008 @ 08:42 PM