Sha256: 177e96b0295bf13b92032c93d92a410b77181fb0ca920b2b80165cc39983bd67

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

module MiscHelpers
  def store_translations(locale, translations, &block)
    begin
      I18n.backend.store_translations locale, translations
      yield
    ensure
      I18n.reload!
    end
  end

  def assert_no_select(selector, value = nil)
    assert_select(selector, :text => value, :count => 0)
  end

  def swap(object, new_values)
    old_values = {}
    new_values.each do |key, value|
      old_values[key] = object.send key
      object.send :"#{key}=", value
    end
    yield
  ensure
    old_values.each do |key, value|
      object.send :"#{key}=", value
    end
  end

  def with_concat_form_for(object, &block)
    concat simple_form_for(object, &block)
  end

  def with_concat_custom_form_for(object, &block)
    concat custom_form_for(object, &block)
  end

  def custom_form_for(object, *args, &block)
    simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
  end

  def custom_mapping_form_for(object, *args, &block)
    simple_form_for(object, *(args << { :builder => CustomMapTypeFormBuilder }), &block)
  end

  def with_concat_custom_mapping_form_for(object, &block)
    concat custom_mapping_form_for(object, &block)
  end
end

class CustomFormBuilder < SimpleForm::FormBuilder
  def input(attribute_name, *args, &block)
    super(attribute_name, *(args << { :input_html => { :class => 'custom' } }), &block)
  end
end

class CustomMapTypeFormBuilder < SimpleForm::FormBuilder
  map_type :custom_type, :to => SimpleForm::Inputs::StringInput
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
simple_form-1.5.2 test/support/misc_helpers.rb
simple_form-1.5.1 test/support/misc_helpers.rb
simple_form-1.5.0 test/support/misc_helpers.rb
simple_form-1.4.2 test/support/misc_helpers.rb
simple_form-1.4.1 test/support/misc_helpers.rb
simple_form-1.4.0 test/support/misc_helpers.rb