Testing scopes with proxy_options in Rails 3

Greetings
I’m converting an rails 2 app to rails 3 and am having a time trying to
update tests on some named_scopes. I’ve search and searched and cannot
find anything that explains what I need to do. We are not using rspec
so I need to know if there is another way to convert these named scopes.

The problem seems to be with the proxy_options.

My Test:

class ClassInstructorTest < ActiveSupport::TestCase
test “named_scope :find_instructor_for_a_course” do
expected = { :select => “instr_id, netid”,
:conditions => [“crs_no = ? AND
term = ? AND
class_type = ? AND
class_no = ?”, ‘HA5503’, ‘F10’, ‘LEC’, 1]
}
assert_equal expected,
ClassInstructor.find_instructor_for_a_course(‘HA5503’, ‘F10’, ‘LEC’,
1).proxy_options
end
end

I get the following error when running my test:

  1. Error:
    test_named_scope_:find_instructor_for_a_course(ClassInstructorTest):
    NoMethodError: undefined method proxy_options' for [#<ClassInstructor instr_id: "SMITH", netid: "hms25">]:ActiveRecord::Relation /test/unit/class_instructor_test.rb:10:intest_named_scope_:find_instructor_for_a_course’

Can anyone show me how to rewrite this test?
Thanks in advance.
–jc

I figured out that I needed to change how I was testing my scope.
Another forum site had this post by a guy named Ian (thanks Ian).

Ideally your unit tests should treat models (classes) and instances thereof as
black boxes. After all, it’s not really the implementation you care about but the
behavior of the interface.

So instead of testing that the scope is implemented in a particular way (i.e.
with a particular set of conditions), try testing that it behaves correctly—that
it returns instances it should and doesn’t return instances it shouldn’t.


This led me to believe I needed to change to testing the behavior not
the stucture. I kept my scope the same but changed my test to the
following. It works, is a good test of the data tested and the results
expected. In the test, I create an array of the instructor’s name and
netid and compare that to an array of the name and netid returned by my
scope.

require ‘test_helper’
class ClassInstructorTest < ActiveSupport::TestCase
test “named_scope :find_instructor_for_a_course returns name and
netid” do
expected = [‘HOLLIS’, ‘rbh25’]
assert_equal expected,
[ClassInstructor.find_instructor_for_a_course(‘HA5503’, ‘F10’, ‘LEC’,
1).first.instr_id,
ClassInstructor.find_instructor_for_a_course(‘HA5503’,
‘F10’, ‘LEC’, 1).first.netid]
end
end