Sha256: 6c0d1a7326d41cd80eb47180f170022081d9cd5fe1d89e0a254a144bc115321b

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

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

module HasFilter
  class FilterChainTest < ActiveSupport::TestCase
    include HasFilter
    include HasFilter::TestHelper
    
    def setup
      @chain = HasFilterArticle.filter_chain
    end

    test 'builds a filter chain with an initial set' do
      assert_equal 'Set', @chain.first.class.name.demodulize
    end
    
    test 'properly duplicates instances when adjusting its size' do
      @chain.send :adjust_size, 2
      first, second = *@chain[0, 2]
      assert_not_equal first.object_id, second.object_id 
      assert_not_equal first.first.object_id, second.first.object_id 
      assert_equal first.object_id, first.first.set.object_id 
      assert_equal second.object_id, second.first.set.object_id 
    end
  end
  
  class FilterSetTest < ActiveSupport::TestCase
    def setup
      @chain = HasFilterArticle.filter_chain
    end

    test 'set has a text filter for each attribute' do
      set = HasFilterArticle.filter_chain.first
      assert_equal %w(body excerpt title), set[0..2].map(&:attribute).map(&:to_s).sort
    end
    
    test 'sorts text filters to the top, not changing their order, followed by the rest ordered by priority' do
      expected = ['Text', 'Text', 'Text', 'Tagged', 'State', 'Categorized']
      assert_equal expected, @chain.first.map{ |filter| filter.class.name.demodulize }
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
adva-0.1.4 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva-0.1.3 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva-0.1.2 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva-0.1.1 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva-0.1.0 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva_cms-0.0.1 vendor/gems/has_filter/test/has_filter/filter_chain_test.rb
adva-0.0.1 adva_cms/vendor/gems/has_filter/test/has_filter/filter_chain_test.rb