开发者

How can I write an RSpec test for link_to_add_fields helper from Railscast 197

开发者 https://www.devze.com 2023-01-16 17:27 出处:网络
I used the approach details in Railscast espisode #197 on how to add dynamic input fields, but I\'m not sure how to write an RSpec test for it.Suggestions?

I used the approach details in Railscast espisode #197 on how to add dynamic input fields, but I'm not sure how to write an RSpec test for it. Suggestions?

def link_to_add_fields(name, f, association, path, *args)
  new_object = f.object.class.reflect_on_association(association).klass.new
  fields 开发者_运维技巧= f.semantic_fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
    render(path + association.to_s.singularize + "_fields", :builder => builder)
  end
  link_to_function(name, "add_fields(this, \"#{association}\", \"#{escape_javascript(fields.html_safe)}\")", *args)
end


Look into rspec request specs (or cucumber) because you seek to test the behaviour of a certain function. This way you don't have to concern yourself with the underlying implementation of methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号