PageRenderTime 26ms CodeModel.GetById 12ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 1module Shoulda
 2  module ActiveRecord
 3    module Matchers
 4      def be_child_to(name)
 5        AssociationMatcher.new(:is_child_to, name)
 6      end
 7
 8      class AssociationMatcher
 9        protected
10        alias_method :old_macro_description, :macro_description
11
12        def macro_description
13          @macro.to_s == 'is_child_to' ? 'be child to' : old_macro_description
14        end
15      end
16    end
17
18    module Macros
19      def should_be_child_to(association)
20        matcher = be_child_to(association)
21        should matcher.description do
22          mock_parent = mock
23          mock_inst = subject.class.new
24          mock_inst.expects(association).with.returns(mock_parent)
25          
26          assert_same mock_parent, mock_inst.parent
27        end
28      end
29    end
30  end
31end