This project is archived and is in readonly mode.

#97 ✓resolved
duncanbeevers

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

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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages