spec/unit/entities/page_spec.rb in locomotivecms_steam-0.1.2.pre.beta vs spec/unit/entities/page_spec.rb in locomotivecms_steam-1.0.0.pre.alpha
- old
+ new
@@ -1,50 +1,56 @@
require 'spec_helper'
-describe 'Locomotive::Steam::Entities::Page' do
+describe Locomotive::Steam::Page do
- it 'builds an empty page' do
- build_page.should_not be_nil
- end
+ let(:attributes) { {} }
+ let(:page) { described_class.new(attributes) }
describe '#index?' do
- it { build_page(fullpath: {en: 'index'}).should be_index }
- it { build_page(fullpath: {en: 'about'}).should_not be_index }
- it { build_page(fullpath: {en: 'products/index'}).should_not be_index }
- end
- describe '#index_or_404?' do
- it { build_page(fullpath: {en: 'index'}).should be_index_or_404 }
- it { build_page(fullpath: {en: 'about'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: 'products/index'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: 'products/404'}).should_not be_index_or_404 }
- it { build_page(fullpath: {en: '404'}).should be_index_or_404 }
- end
+ let(:attributes) { { fullpath: { en: 'foo/index' } } }
- describe '#depth' do
- it { build_page(fullpath: {en: 'index'}).depth.should eq 0 }
- it { build_page(fullpath: {en: '404'}).depth.should eq 0 }
- it { build_page(fullpath: {en: 'about'}).depth.should eq 1 }
- it { build_page(fullpath: {en: 'about/me'}).depth.should eq 2 }
- it { build_page(fullpath: {en: 'about/index'}).depth.should eq 2 }
- it { build_page(fullpath: {en: 'about/the/team'}).depth.should eq 3 }
- end
+ subject { page.index? }
+ it { is_expected.to eq false }
- describe '#fullpath=' do
- context 'when the page has no slug yet' do
- it 'also sets the slug' do
- build_page(fullpath: {en: 'this/is/the/page_full_path'}).slug[:en].should eq 'page_full_path'
- end
+ context 'true' do
+ let(:attributes) { { fullpath: { en: 'index' } } }
+ it { is_expected.to eq true }
end
- context 'when the slug is already set' do
- it 'keeps the original slug' do
- build_page(fullpath: {en: 'this/is/the/page_full_path'}, slug: {en: 'the_slug'}).slug[:en].should eq 'the_slug'
- end
+ end
+
+ describe '#not_found?' do
+
+ let(:attributes) { { fullpath: { en: 'index' } } }
+
+ subject { page.not_found? }
+ it { is_expected.to eq false }
+
+ context 'true' do
+ let(:attributes) { { fullpath: { en: '404' } } }
+ it { is_expected.to eq true }
end
+
end
- def build_page(attributes = {})
- Locomotive::Steam::Entities::Page.new(attributes)
+ describe '#valid?' do
+
+ subject { page.valid? }
+ it { is_expected.to eq true }
+
+ end
+
+ describe '#content_type_id' do
+
+ let(:attributes) { { target_klass_name: '42' } }
+ subject { page.content_type_id }
+
+ it { is_expected.to eq '42' }
+
+ context 'with a Locomotive Engine class name like' do
+ let(:attributes) { { target_klass_name: 'Locomotive::ContentEntryBigNumber' } }
+ it { is_expected.to eq 'BigNumber' }
+ end
end
end