Sha256: 86117707b6f4c83c240952988f759d8dc59bf5f3c83551d162c8731acc52a157

Contents?: true

Size: 1.77 KB

Versions: 12

Compression:

Stored size: 1.77 KB

Contents

require 'test_helper'

require 'netzke/active_record/basepack'

class ActiveRecordBasepackTest < 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(:textfield, cc[:editor])
  #   assert(!cc[:height])
  # 
  #   cc = Book.default_column_config({:name => :amount, :label => 'AMOUNT'})
  #   
  #   assert_equal("AMOUNT", cc[:label])
  #   assert_equal(:numberfield, cc[:editor])
  #   
  #   cc = Book.default_column_config(:genre_id)
  #   assert_equal("genre__name", cc[:name])
  #   assert_equal(:combobox, cc[:editor])
  # 
  #   cc = Book.default_column_config(:genre__popular)
  #   assert_equal(:checkbox, cc[:editor])
  # end
  
  test "choices for column" do
    cities = City.options_for("name")
    assert_equal(3, cities.size)
    assert(cities.include?('Cordoba') && cities.include?('Buenos Aires'))

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

  test "to array" do
    Book.send(:include, Netzke::ActiveRecord::DataAccessor)
    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

12 entries across 12 versions & 2 rubygems

Version Path
skozlov-netzke-basepack-0.5.0 test/unit/active_record_basepack_test.rb
skozlov-netzke-basepack-0.5.1 test/unit/active_record_basepack_test.rb
skozlov-netzke-basepack-0.5.2 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.8 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.7 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.6 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.5.1 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.5 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.4 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.3 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.1 test/unit/active_record_basepack_test.rb
netzke-basepack-0.5.2 test/unit/active_record_basepack_test.rb