C0 code coverage information
Generated on Tue Jun 09 17:50:05 +0900 2009 with
rcov 0.8.1.2
Code reported as executed by Ruby looks like
this... and this: this line is also marked as
covered. Lines considered as run by rcov, but
not reported by Ruby, look like this, and
this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not
executed.
1 #
-*- coding: utf-8 -*- 2
require 'nested_ajax/form_builder' 3 4
module NestedAjax 5 module
FormBuilder 6 module
BelongsToField 7
8 def
belongs_to_field(association_name, options = {}, &block) 9 reflection =
object.class.reflections[association_name.to_sym] 10 raise ArgumentError,
"association not found - #{association_name}" unless reflection
11 unless
reflection.macro == :belongs_to 12 raise ArgumentError, "#{association_name} of
#{object.class.name} is not defined with belongs_to but
#{reflection.macro}" 13 end 14 url = @template.url_for(options[:url] || {:controller
=> options[:controller], :action => options[:action] || 'names'})
15 base_id =
"#{object.class.name}_#{object.object_id}_#{association_name}"
16 reflection_name =
nil 17 if object
18 if reflection_obj =
object.send(association_name) 19 if reflection_obj.respond_to?(:name_for_nested_ajax)
20 reflection_name =
reflection_obj.name_for_nested_ajax 21 end 22 reflection_name ||= reflection_obj.inspect 23 end 24 end 25 foreign_key_name =
reflection.association_foreign_key 26 result = "\n" 27 result << "\n"
<< @template.tag(:input, :type => :text, :id =>
"#{base_id}_display", :value => reflection_name) 28 result << "\n"
<< @template.content_tag(:div, '', :id =>
"#{base_id}_results", :class => 'auto_complete') 29 #
hiddenにしたいんだけど、hiddenだとdisabledが効かないよう
ので、敢えて普通のtype="text"を指定した上で非表
にしています。 30 result << "\n" <<
text_field(foreign_key_name, :id => "#{base_id}_fk", :style
=> 'display:none;') 31 auto_complete_options = { 32 :method => 'get', 33 :paramName =>
options[:param_name] || 'name', 34 :tokens => (options[:tokens] || []).to_json,
35 :frequency =>
options[:frequency] || 0.4, 36 :minChars => options[:min_chars] || 1, 37 :indicator =>
options[:indicator] || "#{base_id}_indicator", 38 :defaultParams =>
options[:default_params], 39 :callback => options[:build_parameter], 40 :afterUpdateElement =>
options[:after_update_element], 41 } 42 unless options[:indicator] 43 result << "\n"
<< @template.tag(:img, :id => "#{base_id}_indicator",
:src => '/images/nested_ajax_indicator.gif', :style =>
'display:none;') 44 end
45
update_element_function = %{ 46 function(selected){ 47 $("#{base_id}_display").value =
selected.firstChild.nodeValue; 48 $("#{base_id}_fk").value =
selected.lastChild.innerHTML.stripTags(); 49 } 50 }.split(/$/).map(&:strip).join 51 auto_complete_options =
auto_complete_options.to_json.gsub(/\}$/, ", updateElement:
#{update_element_function}}") 52 result << "\n" <<
@template.javascript_tag(%{ 53 new Ajax.Autocompleter('#{base_id}_display',
'#{base_id}_results', '#{url}', 54 #{auto_complete_options}) 55
}.split(/$/).map(&:strip).join) 56 57
if block_given? 58
@template.concat(result) 59 on_click_link_to_new = %{ 60
$("#{base_id}_display").disable(); 61
$("#{base_id}_fk").disable(); 62 }.split(/$/).map(&:strip).join 63 belongs_to_pane_options =
{:link_to_new => {:success => on_click_link_to_new} }.update(options
|| {}) 64
self.pane.belongs_to(association_name, belongs_to_pane_options, &block)
65 end 66 67 result 68 end 69 70 end 71 end 72 end
Generated using the rcov
code coverage analysis tool for Ruby version 0.8.1.2.