Sha256: ebe57a0df20a825c5a208cbaa682650a9b51036b46056e315c54e492261e4129

Contents?: true

Size: 1.16 KB

Versions: 85

Compression:

Stored size: 1.16 KB

Contents

module MuckFormMacros
  def 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 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

ActiveSupport::TestCase.extend(MuckFormMacros)
Test::Unit::TestCase.extend(MuckFormMacros)
ActionController::TestCase.extend(MuckFormMacros)

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
muck-engine-3.5.0 lib/test/shoulda_macros/forms.rb
muck-engine-3.4.0 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.18 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.17 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.16 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.15 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.14 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.13 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.12 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.11 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.10 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.9 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.8 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.7 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.6 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.5 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.4 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.3 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.2 lib/test/shoulda_macros/forms.rb
muck-engine-3.3.1 lib/test/shoulda_macros/forms.rb