From cab61ddb7c7e91c65a64537186ecad3cf3806524 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 11 Oct 2012 16:21:33 +1100 Subject: [PATCH] CMS content on home page --- .../spree/orders_controller_decorator.rb | 4 +-- .../shared/_products_by_distributor.html.haml | 2 ++ spec/factories.rb | 36 +++++++++++++++++++ spec/requests/consumer/cms_spec.rb | 23 ++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 spec/requests/consumer/cms_spec.rb diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index 895633d8c5..96f717e99f 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -1,6 +1,6 @@ Spree::OrdersController.class_eval do - before_filter :populate_order_distributor, :only => :populate - after_filter :populate_variant_attributes, :only => :populate + before_filter :populate_order_distributor, :only => :populate + after_filter :populate_variant_attributes, :only => :populate def populate_order_distributor @distributor = params[:distributor_id].present? ? Spree::Distributor.find(params[:distributor_id]) : nil diff --git a/app/views/spree/shared/_products_by_distributor.html.haml b/app/views/spree/shared/_products_by_distributor.html.haml index c7f2200ae2..ea5de13e9c 100644 --- a/app/views/spree/shared/_products_by_distributor.html.haml +++ b/app/views/spree/shared/_products_by_distributor.html.haml @@ -1,3 +1,5 @@ += cms_page_content(:content, Cms::Page.find_by_full_path('/')) + - if @products #products= render 'spree/shared/products', :products => @products, :taxon => @taxon - else diff --git a/spec/factories.rb b/spec/factories.rb index a227cef574..8d5106241a 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -76,3 +76,39 @@ FactoryGirl.modify do country { Spree::Country.find_by_name 'Australia' || Spree::Country.first } end end + + +# -- CMS +FactoryGirl.define do + factory :cms_site, :class => Cms::Site do + identifier 'site' + label 'site' + hostname 'localhost' + end + + factory :cms_layout, :class => Cms::Layout do + site { Cms::Site.first || create(:cms_site) } + label 'layout' + identifier 'layout' + content '{{ cms:page:content:text }}' + end + + factory :cms_page, :class => Cms::Page do + site { Cms::Site.first || create(:cms_site) } + label 'page' + slug 'page' + layout { Cms::Layout.first || create(:cms_layout) } + + # Pass content through to block, where it is stored + after(:create) do |cms_page, evaluator| + cms_page.blocks.first.update_attribute(:content, evaluator.content) + cms_page.save! # set_cached_content + end + end + + factory :cms_block, :class => Cms::Block do + page { Cms::Page.first || create(:cms_page) } + identifier 'block' + content 'hello, block' + end +end diff --git a/spec/requests/consumer/cms_spec.rb b/spec/requests/consumer/cms_spec.rb new file mode 100644 index 0000000000..633e5e1809 --- /dev/null +++ b/spec/requests/consumer/cms_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +feature %q{ + In order to learn about food + As a user of the site + I want to see static content pages +} do + include AuthenticationWorkflow + include WebHelper + + + scenario "viewing the home page" do + # Given a CMS home page + cms_page = create(:cms_page, content: 'Home page content') + + # When I visit the home page + visit spree.root_path + + # Then I should see my content + page.should have_content 'Home page content' + end + +end