Sha256: 7626db84c33fba17bfd4732e8b6335cd784452d3a097c924a5369f34f46911e1

Contents?: true

Size: 974 Bytes

Versions: 9

Compression:

Stored size: 974 Bytes

Contents

require_relative "../spec_helper"

describe "Sorting Expressions" do

    include TestingModels

    def teardown
        TestModel.instance_variable_set(:@sorting_expressions, nil)
    end

    def test_assert_adds_sorting_expression
        refute TestModel.has_sorting_expression?('foo')
        TestModel.export_sort 'foo' do | query, dir |
            query
        end
        assert TestModel.has_sorting_expression?('foo')
    end

    def test_sorting_by_field
        query = TestModel.where(name: 'bar')
        query = TestModel.append_sort_to_query(query, 'name', :asc)
        assert_match 'ORDER BY name ASC', query.to_sql
    end

    def test_sorting_by_block
        query = TestModel.where(name: 'bar')
        TestModel.export_sort :test do | q, dir |
            q.order(:name => 'desc')
        end
        query = TestModel.append_sort_to_query(query, 'test', :asc)
        assert_match 'ORDER BY "test_models"."name" DESC', query.to_sql
    end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hippo-fw-0.9.9 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.8 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.7 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.6 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.5 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.4 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.3 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.2 spec/server/concerns/sorting_expressions_spec.rb
hippo-fw-0.9.1 spec/server/concerns/sorting_expressions_spec.rb