Sha256: 840f5858187ffcbe74550edd31c8c8fb9ef4a07a94d4de7944f77bad5ad9c6e5
Contents?: true
Size: 1.1 KB
Versions: 37
Compression:
Stored size: 1.1 KB
Contents
module ShouldaFormMacros def self.should_have_form(opts) model = self.name.gsub(/ControllerTest$/, '').singularize.downcase model = model[model.rindex('::')+2..model.size] if model.include?('::') http_method, hidden_http_method = form_http_method opts[:method] should "have a #{model} form" do assert_select "form[action=?][method=#{http_method}]", eval(opts[:action]) do if hidden_http_method assert_select "input[type=hidden][name=_method][value=#{hidden_http_method}]" end opts[:fields].each do |attribute, type| attribute = attribute.is_a?(Symbol) ? "#{model}[#{attribute.to_s}]" : attribute assert_select "input[type=#{type.to_s}][name=?]", attribute end assert_select "input[type=submit]" end end end def self.form_http_method(http_method) http_method = http_method.nil? ? 'post' : http_method.to_s if http_method == "post" || http_method == "get" return http_method, nil else return "post", http_method end end end class ActiveSupport::TestCase extend ShouldaFormMacros end
Version data entries
37 entries across 37 versions & 5 rubygems