aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/association_proxy_test.rb
blob: 55d8da4c4e4e0fbc983b40d882d5d6c3caa127e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require "cases/helper"

module ActiveRecord
  module Associations
    class AsssociationProxyTest < ActiveRecord::TestCase
      class FakeOwner
        attr_accessor :new_record
        alias :new_record? :new_record

        def initialize
          @new_record = false
        end
      end

      class FakeReflection < Struct.new(:options, :klass)
        def initialize options = {}, klass = nil
          super
        end

        def check_validity!
          true
        end
      end

      class FakeTarget
      end

      class FakeTargetProxy < AssociationProxy
        def association_scope
          true
        end

        def find_target
          FakeTarget.new
        end
      end

      def test_method_missing_error
        reflection = FakeReflection.new({}, Object.new)
        owner      = FakeOwner.new
        proxy      = FakeTargetProxy.new(owner, reflection)

        exception = assert_raises(NoMethodError) do
          proxy.omg
        end

        assert_match('omg', exception.message)
        assert_match(FakeTarget.name, exception.message)
      end
    end
  end
end