Ticket #7307: dont_call_unsupported_methods_on_included_associations.diff
| File dont_call_unsupported_methods_on_included_associations.diff, 2.4 kB (added by manfred, 1 year ago) |
|---|
-
test/xml_serialization_test.rb
old new 1 1 require 'abstract_unit' 2 2 require 'fixtures/post' 3 3 require 'fixtures/author' 4 require 'fixtures/tagging' 4 5 5 6 class Contact < ActiveRecord::Base 6 7 # mock out self.columns so no pesky db is needed for these tests … … 143 144 assert_equal first_xml_size, second_xml_size 144 145 end 145 146 146 147 147 def test_include_uses_association_name 148 xml = authors(:david).to_xml :include=>:hello_posts, :indent =>0148 xml = authors(:david).to_xml :include=>:hello_posts, :indent => 0 149 149 assert_match %r{<hello-posts>}, xml 150 150 assert_match %r{<post>}, xml 151 151 assert_match %r{<sti-post>}, xml 152 152 end 153 154 def test_methods_are_called_on_object 155 xml = authors(:david).to_xml :methods => :label, :indent => 0 156 assert_match %r{<label>.*</label>}, xml 157 end 158 159 def test_should_not_call_methods_on_associations_that_dont_respond 160 xml = authors(:david).to_xml :include=>:hello_posts, :methods => :label, :indent => 2 161 assert !authors(:david).hello_posts.first.respond_to?(:label) 162 assert_match %r{^ <label>.*</label>}, xml 163 assert_no_match %r{^ <label>}, xml 164 end 153 165 end -
test/fixtures/author.rb
old new 67 67 @post_log = [] 68 68 end 69 69 70 def label 71 "#{id}-#{name}" 72 end 73 70 74 private 71 75 def log_before_adding(object) 72 76 @post_log << "before_adding#{object.id}" -
lib/active_record/xml_serialization.rb
old new 178 178 end 179 179 180 180 def serializable_method_attributes 181 Array(options[:methods]).collect { |name| MethodAttribute.new(name.to_s, @record) } 181 Array(options[:methods]).inject([]) do |method_attributes, name| 182 method_attributes << MethodAttribute.new(name.to_s, @record) if @record.respond_to?(name.to_s) 183 method_attributes 184 end 182 185 end 183 186 184 185 187 def add_attributes 186 188 (serializable_attributes + serializable_method_attributes).each do |attribute| 187 189 add_tag(attribute)