Sha256: 5ac10f6d56ee8ea1efef85ae70573d8cd12fa16d8ce1884b41b2f2cc577503e8

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# encoding: UTF-8
require 'test_helper'

class ButtonTest < ActionView::TestCase
  def with_button_for(object, *args)
    with_concat_form_for(object) do |f|
      f.button(*args)
    end
  end

  test 'builder should create buttons' do
    with_button_for :post, :submit
    assert_select 'form input.button[type=submit][value=Save Post]'
  end

  test 'builder should create buttons with options' do
    with_button_for :post, :submit, :class => 'my_button'
    assert_select 'form input.button.my_button[type=submit][value=Save Post]'
  end

  test 'builder should not modify the options hash' do
    options = { :class => 'my_button' }
    with_button_for :post, :submit, options
    assert_select 'form input.button.my_button[type=submit][value=Save Post]'
    assert_equal({ :class => 'my_button' }, options)
  end

  test 'builder should create buttons for records' do
    @user.new_record!
    with_button_for @user, :submit
    assert_select 'form input.button[type=submit][value=Create User]'
  end

  test "builder should use the default class from the configuration" do
    swap SimpleFormWithClientValidation, :button_class => 'btn' do
      with_button_for :post, :submit
      assert_select 'form input.btn[type=submit][value=Save Post]'
    end
  end

  if ActionView::Helpers::FormBuilder.method_defined?(:button)
    test "allows to use Rails button helper when available" do
      with_button_for :post, :button, 'Save!'
      assert_select 'form button.button[type=submit]', 'Save!'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_form_with_client_validation-0.0.2 test/form_builder/button_test.rb
simple_form_with_client_validation-0.0.0 test/form_builder/button_test.rb