Sha256: 8d22e3bde6dc369b801fac52aecff3a5a0a4a1d6c80c2a18e9de3fe16a77cc42

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
# 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 creates buttons' do
    with_button_for :post, :submit
    assert_select 'form input.button[type=submit][value="Save Post"]'
  end

  test 'builder creates 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 does 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 creates 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 uses the default class from the configuration" do
    swap SimpleForm, 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

10 entries across 10 versions & 1 rubygems

Version Path
simple_form-5.2.0 test/form_builder/button_test.rb
simple_form-5.1.0 test/form_builder/button_test.rb
simple_form-5.0.3 test/form_builder/button_test.rb
simple_form-5.0.2 test/form_builder/button_test.rb
simple_form-5.0.1 test/form_builder/button_test.rb
simple_form-5.0.0 test/form_builder/button_test.rb
simple_form-4.1.0 test/form_builder/button_test.rb
simple_form-4.0.1 test/form_builder/button_test.rb
simple_form-4.0.0 test/form_builder/button_test.rb
simple_form-3.5.1 test/form_builder/button_test.rb