Sha256: 384a335a7e325ea16516661eef16bfa467abdd63d89251ad49436b1cc544af37

Contents?: true

Size: 1.09 KB

Versions: 32

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
    refute model_class.const_defined?(: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

32 entries across 32 versions & 1 rubygems

Version Path
govuk_content_models-34.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-33.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-32.3.1 test/models/prerendered_entity_tests.rb
govuk_content_models-32.3.0 test/models/prerendered_entity_tests.rb
govuk_content_models-32.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-32.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-32.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-31.4.0 test/models/prerendered_entity_tests.rb
govuk_content_models-31.3.0 test/models/prerendered_entity_tests.rb
govuk_content_models-31.2.2 test/models/prerendered_entity_tests.rb
govuk_content_models-31.2.1 test/models/prerendered_entity_tests.rb
govuk_content_models-31.2.0 test/models/prerendered_entity_tests.rb
govuk_content_models-31.1.0 test/models/prerendered_entity_tests.rb
govuk_content_models-31.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-30.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-29.1.2 test/models/prerendered_entity_tests.rb
govuk_content_models-29.0.1 test/models/prerendered_entity_tests.rb
govuk_content_models-29.0.0 test/models/prerendered_entity_tests.rb
govuk_content_models-28.10.0 test/models/prerendered_entity_tests.rb
govuk_content_models-28.9.0 test/models/prerendered_entity_tests.rb