This project is archived and is in readonly mode.
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
-
Trevor Squires May 6th, 2008 @ 08:37 PM
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.
-
duncanbeevers May 6th, 2008 @ 09:32 PM
I think giving the method a different name is appropriate, and at a minimum the tests should be carried over.
-
Repository May 11th, 2008 @ 08:35 PM
- State changed from new to resolved
(from [0b8b582e0668416c6e6760e97a64b9fa3507782c]) Add test for named_scope#proxy_options. [#97 state:resolved]
-
Pratik May 11th, 2008 @ 08:42 PM
And just for the records, I had changed the patch to remove scope_options and use existing proxy_options instead.
Thanks.
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
- 3720 Failures in uniqueness_validation_test for ActiveRecord I think this is related to this ticket: https://rails.lig...