Sha256: 5e60da577a67ee633683fd7f64b1a941b4a85fb2c02d3ac12815687c469d0f27

Contents?: true

Size: 1.08 KB

Versions: 62

Compression:

Stored size: 1.08 KB

Contents

require 'test_helper'
require 'topic_validator'

class TopicValidatorTest < ActiveSupport::TestCase
  class Record
    include Mongoid::Document

    field :primary_topic, type: String
    field :additional_topics, type: Array

    validates_with TopicValidator
  end

  should "allow tagging to a variety of unique topics" do
    record = Record.new(
      primary_topic: 'oil-and-gas/exploration',
      additional_topics: [
        'oil-and-gas/fields-and-wells',
        'oil-and-gas/licensing'
      ]
    )

    assert record.valid?
  end

  should "be invalid if there's duplicates in the additional topic list" do
    record = Record.new(
      additional_topics: [
        'oil-and-gas/fields-and-wells',
        'oil-and-gas/fields-and-wells'
      ]
    )

    refute record.valid?
  end

  should "be invalid if the primary topic is in the additional topic list" do
    record = Record.new(
      primary_topic: 'oil-and-gas/fields-and-wells',
      additional_topics: [
        'oil-and-gas/fields-and-wells',
        'oil-and-gas/licensing'
      ]
    )

    refute record.valid?
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
govuk_content_models-41.1.1 test/validators/topic_validator_test.rb
govuk_content_models-41.1.0 test/validators/topic_validator_test.rb
govuk_content_models-41.0.0 test/validators/topic_validator_test.rb
govuk_content_models-40.0.0 test/validators/topic_validator_test.rb
govuk_content_models-39.0.0 test/validators/topic_validator_test.rb
govuk_content_models-38.0.0 test/validators/topic_validator_test.rb
govuk_content_models-37.0.0 test/validators/topic_validator_test.rb
govuk_content_models-36.0.0 test/validators/topic_validator_test.rb
govuk_content_models-35.0.1 test/validators/topic_validator_test.rb
govuk_content_models-35.0.0 test/validators/topic_validator_test.rb
govuk_content_models-34.0.0 test/validators/topic_validator_test.rb
govuk_content_models-33.0.0 test/validators/topic_validator_test.rb
govuk_content_models-32.3.1 test/validators/topic_validator_test.rb
govuk_content_models-32.3.0 test/validators/topic_validator_test.rb
govuk_content_models-32.2.0 test/validators/topic_validator_test.rb
govuk_content_models-32.1.0 test/validators/topic_validator_test.rb
govuk_content_models-32.0.0 test/validators/topic_validator_test.rb
govuk_content_models-31.4.0 test/validators/topic_validator_test.rb
govuk_content_models-31.3.0 test/validators/topic_validator_test.rb
govuk_content_models-31.2.2 test/validators/topic_validator_test.rb