Sha256: c7c01fea6c9709737d8ef38093141deeb85adcf3d88beea83acb271de9ab555f

Contents?: true

Size: 1.91 KB

Versions: 29

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8
require 'test_helper'

class ListColumnHelpersTest < ActionView::TestCase
  include ActiveScaffold::Helpers::ListColumnHelpers
  include ActiveScaffold::Helpers::ViewHelpers
  include ::ERB::Util

  def setup
    @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub)
    @column.form_ui = :select
    @record = stub(:a => 'value_2')
    @config = stub(:list => stub(:empty_field_text => '-', :association_join_text => ', '), :actions => [:list])
    @association_column = ActiveScaffold::DataStructures::Column.new(:b, ModelStub)
    @association_column.stubs(:association).returns(stub(:collection? => true))
  end

  def test_options_for_select_list_ui_for_simple_column
    @column.options[:options] = [:value_1, :value_2, :value_3]
    assert_equal 'Value 2', format_column_value(@record, @column)

    @column.options[:options] = %w(value_1 value_2 value_3)
    assert_equal 'value_2', format_column_value(@record, @column)

    @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)]
    assert_equal 'text_2', format_column_value(@record, @column)

    @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]]
    assert_equal 'Text 2', format_column_value(@record, @column)
  end

  def test_association_join_text
    value = [1, 2, 3, 4].map(&:to_s)
    value.each { |v| v.stubs(:to_label).returns(v) }
    assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size)
    @config.list.stubs(:association_join_text => ',<br/>')
    assert_equal '1,&lt;br/&gt;2,&lt;br/&gt;3,&lt;br/&gt;… (4)', format_association_value(value, @association_column, value.size)
    @config.list.stubs(:association_join_text => ',<br/>'.html_safe)
    assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size)
  end

  private

  def active_scaffold_config
    @config
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.42 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.41.1 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.41 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.40 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.39 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.38 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.37 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.36 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.35 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.34 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.33 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.32 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.31 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.30 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.29 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.28 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.27 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.26 test/helpers/list_column_helpers_test.rb
active_scaffold-3.4.25 test/helpers/list_column_helpers_test.rb