Sha256: a170223809f5303e9105578bd01e04d95bcc7314a3e51fbfb46033fa292ee862

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

require 'test_helper'

module PagesCms
  class PageTest < ActiveSupport::TestCase

    def setup
      @page = pages_cms_pages(:one)

      # todo find a way to require this helper file
      def slugged_path(page)
        if page.class == String
          "/#{page}"
        else
          mount = page.account.mount_location
          if mount == '/'
            "/#{page.slug}"
          else
            "/#{mount}/#{page.slug}"
          end
        end
      end

    end

    test 'valid page' do
      assert @page.valid?, "Errors: #{@page.errors.full_messages.to_sentence} Slug:#{@page.slug}"
      assert_equal '/different', slugged_path(@page)
    end

    test 'slug gets parameterized' do
      page = Page.new(account_id: 1, title: 'really cool')
      page.save
      assert_equal page.slug, 'really-cool'

      assert_equal '/really-cool', slugged_path(page)
    end

    test 'slug stores parent path and child path' do
      page = Page.new(account_id: 2, title: 'test page')
      assert page.valid?
      page.save
      assert_equal 'test-page', page.slug

      child = Page.new(account_id: 2, title: 'test page child', parent_id: page.id)
      assert child.valid?
      child.save
      assert_not child.parent.nil?
      assert_equal 'test-page/test-page-child', child.slug

      assert_equal '/account_two/test-page/test-page-child', slugged_path(child)
    end

    test 'different slug names' do
      page1 = Page.new(account_id: 1, title: 'Duplicate')
      page2 = Page.new(account_id: 1, title: 'Duplicate')
      assert page1.valid?
      page1.save
      assert_not page2.valid?, "#{page2.errors.full_messages}"
    end

    test 'page with no account' do
      page = Page.new(title: 'really cool')
      assert_not page.valid?
    end

    test 'update page' do
      @page.update(draft: true)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pages_cms-2.4.2 test/models/pages_cms/page_test.rb
pages_cms-2.3.2 test/models/pages_cms/page_test.rb
pages_cms-2.3.1 test/models/pages_cms/page_test.rb
pages_cms-2.3.0 test/models/pages_cms/page_test.rb