Changeset 7156
- Timestamp:
- 06/30/07 03:31:48 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/xml_serialization.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/author.rb (modified) (1 diff)
- trunk/activerecord/test/xml_serialization_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r7137 r7156 1 1 *SVN* 2 3 * Don't call unsupported methods on associated objects when using :include, :method with to_xml #7307, [manfred, jwilger] 2 4 3 5 * Define collection singular ids method for has_many :through associations. #8763 [lifofifo] trunk/activerecord/lib/active_record/xml_serialization.rb
r7144 r7156 179 179 180 180 def serializable_method_attributes 181 Array(options[:methods]).collect { |name| MethodAttribute.new(name.to_s, @record) } 182 end 183 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 185 end 184 186 185 187 def add_attributes trunk/activerecord/test/fixtures/author.rb
r5305 r7156 68 68 end 69 69 70 def label 71 "#{id}-#{name}" 72 end 73 70 74 private 71 75 def log_before_adding(object) trunk/activerecord/test/xml_serialization_test.rb
r7144 r7156 2 2 require 'fixtures/post' 3 3 require 'fixtures/author' 4 require 'fixtures/tagging' 4 5 5 6 class Contact < ActiveRecord::Base … … 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 type="array">}, 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