Sha256: 78b001cfd180b392d7d74f45c85bd714c5e50bee1c2fc666678be4eb4affd5bb

Contents?: true

Size: 1.65 KB

Versions: 9

Compression:

Stored size: 1.65 KB

Contents

require "test_helper"

module Godmin
  module ResourceService
    class FiltersTest < ActiveSupport::TestCase
      def setup
        @article_service = Fakes::ArticleService.new
      end

      def test_calls_one_filter
        @article_service.apply_filters({ title: "foobar" }, :resources)
        assert_equal [:resources, "foobar"], @article_service.called_methods[:filters][:title]
      end

      def test_calls_multiple_filters
        @article_service.apply_filters({ title: "foobar", country: "Sweden" }, :resources)
        assert_equal [:resources, "foobar"], @article_service.called_methods[:filters][:title]
        assert_equal [:resources, "Sweden"], @article_service.called_methods[:filters][:country]
      end

      def test_calls_filter_when_present_multiselect
        @article_service.apply_filters({ tags: ["Banana"] }, :resources)
        assert_equal [:resources, ["Banana"]], @article_service.called_methods[:filters][:tags]
      end

      def test_does_not_call_filter_when_empty_multiselect
        @article_service.apply_filters({ tags: [""] }, :resources)
        assert_equal nil, @article_service.called_methods[:filters][:tags]
      end

      def test_filter_map_with_default_options
        expected_filter_map = { as: :string, option_text: "to_s", option_value: "id", collection: nil }
        assert_equal expected_filter_map, @article_service.filter_map[:title]
      end

      def test_filter_map_with_custom_options
        expected_filter_map = { as: :select, option_text: "to_s", option_value: "id", collection: %w(Sweden Canada) }
        assert_equal expected_filter_map, @article_service.filter_map[:country]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
godmin-1.3.1 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-1.3.0 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-1.2.0 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-1.1.0 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-1.0.0 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-0.12.4 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-0.12.3 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-0.12.2 test/lib/godmin/resources/resource_service/filters_test.rb
godmin-0.12.1 test/lib/godmin/resources/resource_service/filters_test.rb