Sha256: 79a023def758b371d2b396586e5ff97b0b801075505d57714cd1d32c1a6f03fe

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

require 'test_helper'

require 'netzke/ar_ext'

class ArExtTest < ActiveSupport::TestCase
  fixtures :cities, :countries, :continents

  test "default column and field configs" do
    cc = Book.default_column_config(:title)
    
    assert_equal("Title", cc[:label])
    assert_equal(:text_field, cc[:editor])
    assert(!cc[:height])

    cc = Book.default_column_config({:name => :amount, :label => 'AMOUNT'})
    
    assert_equal("AMOUNT", cc[:label])
    assert_equal(:number_field, cc[:editor])
    
    cc = Book.default_column_config(:genre_id)
    assert_equal("genre__name", cc[:name])
    assert_equal(:combo_box, cc[:editor])

    cc = Book.default_column_config(:genre__popular)
    assert_equal(:checkbox, cc[:editor])
    
    cc = Book.default_column_config(:title)
    
    # cc = Book.default_field_config(:title)
    # assert(cc[:height])
  end
  
  test "choices for column" do
    # TODO: test virtual columns, too
    cities = City.choices_for("name")
    assert_equal(3, cities.size)
    assert(cities.include?('Cordoba') && cities.include?('Buenos Aires'))

    countries = City.choices_for("country__name")
    assert_equal(2, countries.size)
    assert(countries.include?('Spain') && countries.include?('Argentina'))
    
    continents = City.choices_for("country__continent__name")
    assert_equal(2, continents.size)
    assert(continents.include?('Europe') && continents.include?('South America'))
    
    cities = City.choices_for("name", "Co")
    assert_equal(2, cities.size)
    assert(cities.include?('Cordoba') && cities.include?('Concordia'))
  end

  test "to array" do
    b = Book.create({:title => 'Rayuela', :genre_id => 200, :amount => 1000})
    columns = [:recent, {:name => :title}, {:name => :amount}, :genre_id]
    assert_equal(['Yes', 'Rayuela', 1000, 200], b.to_array(columns))
  end
  
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
netzke-basepack-0.2.2 test/ar_ext_test.rb
netzke-basepack-0.3.0 test/ar_ext_test.rb
netzke-basepack-0.3.1 test/ar_ext_test.rb
netzke-basepack-0.3.10 test/ar_ext_test.rb
netzke-basepack-0.3.3 test/ar_ext_test.rb
netzke-basepack-0.3.3.1 test/ar_ext_test.rb
netzke-basepack-0.3.4 test/ar_ext_test.rb
netzke-basepack-0.3.5 test/ar_ext_test.rb
netzke-basepack-0.3.6 test/ar_ext_test.rb
netzke-basepack-0.3.7 test/ar_ext_test.rb
netzke-basepack-0.3.8 test/ar_ext_test.rb
netzke-basepack-0.3.9 test/ar_ext_test.rb
netzke-basepack-0.3.9.1 test/ar_ext_test.rb