spec/lib/locomotive/liquid/drops/site_spec.rb in locomotive_cms-2.5.5 vs spec/lib/locomotive/liquid/drops/site_spec.rb in locomotive_cms-2.5.6.rc1

- old
+ new

@@ -1,32 +1,42 @@ require 'spec_helper' describe Locomotive::Liquid::Drops::Site do - before(:each) do - @site = FactoryGirl.build(:site) - page_1 = FactoryGirl.build(:page, site: @site) - page_2 = FactoryGirl.build(:page, site: @site, title: 'About us', slug: 'about_us') - @site.stubs(:pages).returns([page_1, page_2]) - end + let(:site) { FactoryGirl.create(:site) } + let(:root_page) { site.pages.root.first } + let(:about_us_page) { add_page('About us') } + let(:contact_page) { add_page('Contact') } - context '#pages' do + before { about_us_page && contact_page } - it 'has access to all the pages' do - render_template('{{ site.pages.size }}').should == '2' + describe '.pages' do + + let(:template) { '' } + subject { render_template(template) } + + describe 'display the number of pages' do + + let(:template) { '{{ site.pages.size }}' } + it { should eq '4' } + end - it 'loops thru the pages' do - render_template('{% for page in site.pages %}{{ page.title }} {% endfor %}').should == 'Home page About us ' + describe 'display the title of all the pages' do + + let(:template) { '{% for page in site.pages %}{{ page.title }} {% endfor %}' } + it { should eq 'Home page Page not found About us Contact ' } + end end def render_template(template = '', assigns = {}) - assigns = { - 'site' => @site - }.merge(assigns) + assigns = { 'site' => site }.merge(assigns) + Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { site: site })) + end - Liquid::Template.parse(template).render(::Liquid::Context.new({}, assigns, { site: @site })) + def add_page(title) + FactoryGirl.create(:page, site: site, parent: root_page, title: title, slug: nil) end end