From dbc542c4d790c869db16eaa6bf7eb18c8a12a246 Mon Sep 17 00:00:00 2001 From: dinedine Date: Fri, 20 Aug 2010 18:24:59 +0200 Subject: [PATCH] fix bugs with acts_as_tree + fix cucumber tests --- app/controllers/admin/pages_controller.rb | 2 +- app/controllers/application_controller.rb | 10 +++++----- app/models/extensions/page/tree.rb | 5 ++++- app/models/page.rb | 3 --- app/models/site.rb | 2 +- app/views/admin/pages/_form.html.haml | 3 ++- config/locales/admin_ui_en.yml | 1 + config/locales/admin_ui_fr.yml | 1 + features/admin/pages.feature | 8 ++++---- features/step_definitions/page_steps.rb | 7 ++----- public/stylesheets/admin/formtastic_changes.css | 2 ++ 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 208cacdb..a6676c88 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -11,7 +11,7 @@ module Admin def new @page = current_site.pages.build - @page.parts << PagePart.build_body_part + # @page.parts << PagePart.build_body_part end def sort diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3083b5cf..6e5f9df7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,9 +3,9 @@ class ApplicationController < ActionController::Base protected - rescue_from Exception, :with => :render_error - - def render_error - render :template => "/admin/errors/500", :layout => 'admin/box', :status => 500 - end + # rescue_from Exception, :with => :render_error + # + # def render_error + # render :template => "/admin/errors/500", :layout => 'admin/box', :status => 500 + # end end diff --git a/app/models/extensions/page/tree.rb b/app/models/extensions/page/tree.rb index db67d642..8e69341c 100644 --- a/app/models/extensions/page/tree.rb +++ b/app/models/extensions/page/tree.rb @@ -44,7 +44,10 @@ module Models end def hacked_descendants - return [] if new_record? + # workorund for mongoid unexpected behavior + _new_record_var = self.instance_variable_get(:@new_record) + _new_record = _new_record_var != false + return [] if _new_record self.class.all_in(path_field => [self._id]).order_by tree_order end diff --git a/app/models/page.rb b/app/models/page.rb index 81b72cc4..72263a90 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -17,9 +17,6 @@ class Page field :layout_template # FIXME: added for liquid inheritance - # allows newly pages to have a default body - attr_accessor :body - ## associations ## referenced_in :site diff --git a/app/models/site.rb b/app/models/site.rb index 40ea383a..b01f011c 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -83,7 +83,7 @@ class Site self.pages.create({ :slug => slug, :title => I18n.t("attributes.defaults.pages.#{slug}.title"), - :body => I18n.t("attributes.defaults.pages.#{slug}.body"), + :layout_template => I18n.t("attributes.defaults.pages.#{slug}.body"), :published => true }) end diff --git a/app/views/admin/pages/_form.html.haml b/app/views/admin/pages/_form.html.haml index 70787104..657a2b26 100644 --- a/app/views/admin/pages/_form.html.haml +++ b/app/views/admin/pages/_form.html.haml @@ -21,8 +21,9 @@ = f.input :cache_strategy, :as => :select, :collection => options_for_page_cache_strategy, :include_blank => false -= f.foldable_inputs :name => :code do += f.foldable_inputs :name => :layout_template do = f.custom_input :value, :css => 'code full', :with_label => false do + = f.label :layout_template %code{ :class => 'html' } = f.text_area :layout_template / .more diff --git a/config/locales/admin_ui_en.yml b/config/locales/admin_ui_en.yml index 5ecd3340..e9cd0e8f 100644 --- a/config/locales/admin_ui_en.yml +++ b/config/locales/admin_ui_en.yml @@ -245,6 +245,7 @@ en: information: General information meta: SEO Metadata code: Code + layout_template: Layout credentials: Credentials language: Language sites: Sites diff --git a/config/locales/admin_ui_fr.yml b/config/locales/admin_ui_fr.yml index a4ff64eb..db3e14e1 100644 --- a/config/locales/admin_ui_fr.yml +++ b/config/locales/admin_ui_fr.yml @@ -244,6 +244,7 @@ fr: information: Informations générales meta: SEO Metadata code: Code + layout_template: Gabarit credentials: Informations de connexion language: Langue sites: Sites diff --git a/features/admin/pages.feature b/features/admin/pages.feature index 266055cb..a200e241 100644 --- a/features/admin/pages.feature +++ b/features/admin/pages.feature @@ -18,16 +18,16 @@ Scenario: Creating a valid page And I fill in "Title" with "Test" And I fill in "Slug" with "test" And I select "Home page" from "Parent" - And I fill in "Layout Template" with "Lorem ipsum...." + And I fill in "Layout template" with "Lorem ipsum...." And I press "Create" Then I should see "Page was successfully created." - And I should have "Lorem ipsum...." in the test page layout + And I should have "Lorem ipsum...." in the test page Scenario: Updating a valid page When I go to pages And I follow "Home page" And I fill in "Title" with "Home page !" - And I fill in "Layout Template" with "My new content is here" + And I fill in "Layout template" with "My new content is here" And I press "Update" Then I should see "Page was successfully updated." - And I should have "My new content is here" in the index page layout + And I should have "My new content is here" in the index page diff --git a/features/step_definitions/page_steps.rb b/features/step_definitions/page_steps.rb index f4b1b91f..6b6bdc79 100644 --- a/features/step_definitions/page_steps.rb +++ b/features/step_definitions/page_steps.rb @@ -42,14 +42,11 @@ When /^I view the rendered page at "([^"]*)"$/ do |path| end # checks to see if a string is in the slug -Then /^I should have "(.*)" in the (.*) page (.*)$/ do |content, page_slug, part_slug| +Then /^I should have "(.*)" in the (.*) page$/ do |content, page_slug| page = @site.pages.where(:slug => page_slug).first raise "Could not find page: #{page_slug}" unless page - part = page.parts.where(:slug => part_slug).first - raise "Could not find part: #{part_slug} within page: #{page_slug}" unless part - - part.value.should == content + page.layout_template.should == content end # checks if the rendered body matches a string diff --git a/public/stylesheets/admin/formtastic_changes.css b/public/stylesheets/admin/formtastic_changes.css index 60392ba0..b5207dee 100644 --- a/public/stylesheets/admin/formtastic_changes.css +++ b/public/stylesheets/admin/formtastic_changes.css @@ -137,6 +137,8 @@ form.formtastic fieldset ol li p.inline-errors { font-size: 0.7em !important; } +form.formtastic fieldset ol li.code label { display: none; } + form.formtastic fieldset ol li.code p.inline-errors { display: block; float: right;