Sha256: 90c2e2433f48bf473cdf55e14f73844d316fdba395fe0f6e39b18e9162fec244

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class SortingTest < Presenting::Test
  def setup
    @s = Presenting::Sorting.new
  end
  
  def test_assigning_a_simple_set_of_fields
    @s.fields = [:a]
    assert_equal 1, @s.fields.size
    
    assert_equal 'a', @s.fields[0].name
    assert_equal 'a', @s.fields[0].sql
  end
  
  def test_assigning_fields_with_custom_sql
    @s.fields = {:a => 'users.a'}
    assert_equal 1, @s.fields.size
    
    assert_equal 'a', @s.fields[0].name
    assert_equal 'users.a', @s.fields[0].sql
  end
  
  def test_assigning_default_sql
    @s.fields = {:a => 'users.a'}
    @s.default = [:a, 'desc']
    assert_equal "users.a DESC", @s.default
  end
  
  def test_the_default_default
    @s.fields = {:a => 'users.a'}
    assert_equal 'users.a ASC', @s.default
  end
  
  def test_generating_sorting_sql
    @s.fields = {:a => 'users.a', :b => 'users.b'}
    
    assert_equal 'users.a DESC', @s.to_sql({'a' => 'desc'})
  end
  
  def test_generating_sort_sql_with_no_known_fields
    @s.fields = {:a => 'users.a', :b => 'users.b'}
    @s.default = [:b, 'desc']
    
    assert_equal 'users.b DESC', @s.to_sql(nil)
  end
end

class SortingFieldTest < Presenting::Test
  def setup
    @f = Presenting::Sorting::Field.new
  end

  def test_assigning_a_symbol_name
    @f.name = :foo
    assert_equal 'foo', @f.name
  end
  
  def test_sql_defaults_to_name
    @f.name = :foo
    assert_equal 'foo', @f.sql
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
presenting-3.0.0 test/sorting_test.rb
presenting-2.1.0 test/sorting_test.rb
presenting-2.0.3 test/sorting_test.rb
presenting-2.0.2 test/sorting_test.rb
presenting-2.0.1 test/sorting_test.rb