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