Sha256: e74eade7e91c51a17837d038376a794426395af6a37c936c6206777ce53224c3

Contents?: true

Size: 1.09 KB

Versions: 52

Compression:

Stored size: 1.09 KB

Contents

# include in a test class and define a #model_class instance method

module PrerenderedEntityTests
  def test_duplicate_slug_not_allowed
    model_class.create(slug: "my-slug")
    second = model_class.create(slug: "my-slug")

    refute second.valid?
    assert_equal 1, model_class.count
  end

  def test_has_no_govspeak_fields
    assert_equal [], model_class::GOVSPEAK_FIELDS
  end

  def test_create_or_update_by_slug
    slug = "a-slug"
    original_body = "Original body"

    version1_attrs= {
      slug: slug,
      body: original_body,
    }

    created = model_class.create_or_update_by_slug!(version1_attrs)

    assert created.is_a?(model_class)
    assert created.persisted?

    version2_attrs = version1_attrs.merge(
      body: "Updated body",
    )

    version2 = model_class.create_or_update_by_slug!(version2_attrs)

    assert version2.persisted?
    assert_equal "Updated body", version2.body
  end

  def test_find_by_slug
    created = model_class.create!(slug: "find-by-this-slug")
    found = model_class.find_by_slug("find-by-this-slug")

    assert_equal created, found
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
govuk_content_models-28.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-27.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-27.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-27.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-26.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-26.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-26.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-25.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-24.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-24.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-24.0.1 test/models/prerendered_entity_tests.rb
govuk_content_models-24.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-23.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-22.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-22.1.2 test/models/prerendered_entity_tests.rb
govuk_content_models-22.1.1 test/models/prerendered_entity_tests.rb
govuk_content_models-22.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-22.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-21.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-20.2.0 test/models/prerendered_entity_tests.rb