/shoulda_macros/should_be_child_to.rb
http://acts-crummy.googlecode.com/ · Ruby · 31 lines · 27 code · 4 blank · 0 comment · 1 complexity · 04b3c1292d16a2b1e035907f70611f83 MD5 · raw file
- module Shoulda
- module ActiveRecord
- module Matchers
- def be_child_to(name)
- AssociationMatcher.new(:is_child_to, name)
- end
-
- class AssociationMatcher
- protected
- alias_method :old_macro_description, :macro_description
-
- def macro_description
- @macro.to_s == 'is_child_to' ? 'be child to' : old_macro_description
- end
- end
- end
-
- module Macros
- def should_be_child_to(association)
- matcher = be_child_to(association)
- should matcher.description do
- mock_parent = mock
- mock_inst = subject.class.new
- mock_inst.expects(association).with.returns(mock_parent)
-
- assert_same mock_parent, mock_inst.parent
- end
- end
- end
- end
- end