I have a protected method in controller and need to write the test case for it. The method is
def source
@source.present? ? @source.class : Association.reflect_on_association(source.to_sym).klass
end
where @source will be an object and source will be a string.
I have no idea how to write the test case for this method.
edit
Here is what I am trying
subject { @controller }
describe '#source' do
let(:source_object) { create :program_type}
describe "Object is not present" do
it 'should reflect on association and return the reflection class' do
subject.stubs(:source_identifier).returns("program_type")
subject.send(:source).must_equal ProgramType
end
end
describe "Object is present" do
it 'should return the class of the object' do
subject.send(:source).must_equal source_object.class
end
end
end
Thanks in advance.