| | 175 | def test_should_allow_custom_procs |
|---|
| | 176 | proc = Proc.new do |options| |
|---|
| | 177 | options[:builder].tag!('wasCustomized', true) |
|---|
| | 178 | end |
|---|
| | 179 | @xml = authors(:david).to_xml(:procs => [proc]) |
|---|
| | 180 | assert_match %r{<wasCustomized>true</wasCustomized>}, @xml |
|---|
| | 181 | end |
|---|
| | 182 | |
|---|
| | 183 | def test_custom_procs_arent_applied_to_associations |
|---|
| | 184 | author = authors(:david) |
|---|
| | 185 | author_proc = Proc.new do |options| |
|---|
| | 186 | options[:builder].label(author.label) |
|---|
| | 187 | end |
|---|
| | 188 | @xml = author.to_xml(:procs => [author_proc], :include => :posts) |
|---|
| | 189 | assert_match Regexp.new("<label>#{author.label}</label>"), @xml |
|---|
| | 190 | |
|---|
| | 191 | # find the xml for the posts association: |
|---|
| | 192 | posts_xml = %r{<posts type="array">.*</posts>}m.match(@xml).to_s |
|---|
| | 193 | # The posts xml shouldn't have be altered by the author proc: |
|---|
| | 194 | assert_no_match Regexp.new("<label>#{author.label}</label>"), posts_xml |
|---|
| | 195 | end |
|---|
| | 196 | |
|---|
| | 197 | |
|---|