Sha256: 4ed1c0c935592a1801aad7a84d3720ae5c05b94cd7d526883345d72ee3f7eaaa

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

# == Schema Information
#
# Table name: sites
#
#  id         :integer          not null, primary key
#  title      :string(255)
#  slug       :string(255)
#  created_at :datetime
#  updated_at :datetime
#

require 'rails_helper'

# ===============================
# Note: This model is used to test the base functionality of Superslug. The Page
# model is used to test how a model acts within the context of an object of
# another model.
# ===============================

RSpec.describe Site, :type => :model do

  it 'replaces single spaces with hyphens' do
    site = create(:site, :title => 'Hello World 01')
    expect(site.slug).to eq('hello-world-01')
  end

  it 'replaces multiple spaces with one hyphen' do
    site = create(:site, :title => 'Hello   World  02')
    expect(site.slug).to eq('hello-world-02')
  end

  it 'replaces multiple hyphens with one hyphen' do
    site = create(:site, :title => 'Hello-- --World----03')
    expect(site.slug).to eq('hello-world-03')
  end

  it 'will append the id if the slug already exists' do
    create(:site, :title => 'Hello World 04')
    site = create(:site, :title => 'Hello World 04')
    expect(site.slug).to eq("hello-world-04-#{site.id}")
  end

  it 'will not change the slug if the record is updated' do
    site = create(:site, :title => 'Hello World 05')
    site.update(:title => 'Goodbye World 06')
    expect(site.slug).to eq("hello-world-05")
  end

  it 'ignores weirdo characters' do
    site = create(:site, :title => 'Hello World 07!@#$%^*()[]{}+=|\/?<>,.;:\'"`~')
    expect(site.slug).to eq('hello-world-07')
  end

  it 'replaces ampersands with "and"' do
    site = create(:site, :title => 'Hello & World 08')
    expect(site.slug).to eq('hello-and-world-08')
  end

  it 'removes trailing spaces' do
    site = create(:site, :title => 'Hello World 09 ')
    expect(site.slug).to eq('hello-world-09')
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
superslug-1.3.1 test/spec/models/site_spec.rb
superslug-1.3.0 test/spec/models/site_spec.rb