Class: SortingTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb

Overview

require ‘test/model_stub’

Instance Method Summary collapse

Instance Method Details

#setupObject



5
6
7
8
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 5

def setup
  @columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b, :c, :d)
  @sorting = ActiveScaffold::DataStructures::Sorting.new(@columns)
end

#test_addObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 10

def test_add
  @sorting.add :a, 'ASC'
  # test adding by symbol
  assert @sorting.sorts_on?(:a)
  # test adding an uppercase string direction
  assert_equal 'ASC', @sorting.direction_of(:a)

  @sorting.add 'b', :ASC
  # test adding by string
  assert @sorting.sorts_on?(:b)
  # test adding an uppercase symbol direction
  assert_equal 'ASC', @sorting.direction_of(:b)

  @sorting.add @columns[:c], 'desc'
  # test adding by object
  assert @sorting.sorts_on?(:c)
  # test adding a lowercase string direction
  assert_equal 'DESC', @sorting.direction_of(:c)

  @sorting << [:d, :desc]
  # testing adding with the alias
  assert @sorting.sorts_on?(:d)
  assert_equal 'DESC', @sorting.direction_of(:d)

  @sorting.clear

  # test adding without a direction (test default)
  @sorting.add :a
  assert_equal 'ASC', @sorting.direction_of(:a)

  # test adding a bad column
  assert_raises ArgumentError do
    @sorting.add :foo
  end

  # test adding a bad direction
  assert_raises ArgumentError do
    @sorting.add :b, :FOO
  end
end

#test_direction_ofObject



71
72
73
74
75
76
77
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 71

def test_direction_of
  @sorting.add :a, 'ASC'
  @sorting.add :b, :DESC

  assert_equal 'ASC', @sorting.direction_of(:a)
  assert_equal 'DESC', @sorting.direction_of(:b)
end

#test_setObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 51

def test_set
  @sorting.add :a, 'ASC'
  assert @sorting.sorts_on?(:a)

  @sorting.set :b, 'DESC'
  assert @sorting.instance_variable_get('@clauses').size == 1
  assert !@sorting.sorts_on?(:a)
  assert @sorting.sorts_on?(:b)
  assert_equal 'DESC', @sorting.direction_of(:b)
end

#test_sorts_by_methodObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 79

def test_sorts_by_method
  @columns[:a].sort_by :method => proc{0}

  #test pure method sorting: true
  @sorting.add :a
  assert @sorting.sorts_by_method?

  #test mixed sql/method sorting: raise error
  assert_raise ArgumentError do
    @sorting.add :b
  end
  
  #test pure sql sorting: false
  @sorting.clear
  @sorting.add :b
  assert !@sorting.sorts_by_method?
end

#test_sorts_onObject



62
63
64
65
66
67
68
69
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/test/data_structures/sorting_test.rb', line 62

def test_sorts_on
  @sorting.add :a
  @sorting.add :b

  assert @sorting.sorts_on?(:a)
  assert @sorting.sorts_on?(:b)
  assert !@sorting.sorts_on?(:c)
end