From a1cbdf9ed88abc1a3d1d06ee676812be0668c608 Mon Sep 17 00:00:00 2001 From: did Date: Fri, 2 Mar 2012 08:37:54 -0800 Subject: [PATCH] page templates were not updated if a related snippet got modified (BUG) --- app/models/locomotive/snippet.rb | 4 +++- doc/TODO | 4 ++++ spec/models/locomotive/snippet_spec.rb | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/models/locomotive/snippet.rb b/app/models/locomotive/snippet.rb index 0721183b..a6fa66d7 100644 --- a/app/models/locomotive/snippet.rb +++ b/app/models/locomotive/snippet.rb @@ -44,7 +44,9 @@ module Locomotive def update_templates return unless (self.site rescue false) # not run if the site is being destroyed - pages = self.site.pages.any_in(:snippet_dependencies => [self.slug]).to_a + pages = ::I18n.with_locale(::Mongoid::Fields::I18n.locale) do + pages = self.site.pages.any_in(:snippet_dependencies => [self.slug]).to_a + end pages.each do |page| self._change_snippet_inside_template(page.template.root) diff --git a/doc/TODO b/doc/TODO index e20784fa..3e305331 100644 --- a/doc/TODO +++ b/doc/TODO @@ -160,6 +160,10 @@ REFACTORING: - move content_type and content_instances in the CustomFields plugin (much more appropriate) BUGS: + x mode author: settings KO + editable elements non visibles + x locales pour le locomotive editor => KO + - impossible de sauvegarder une page + NICE TO HAVE: - export site diff --git a/spec/models/locomotive/snippet_spec.rb b/spec/models/locomotive/snippet_spec.rb index e8fcd670..274fee6e 100644 --- a/spec/models/locomotive/snippet_spec.rb +++ b/spec/models/locomotive/snippet_spec.rb @@ -49,6 +49,29 @@ describe Locomotive::Snippet do end + context '#i18n' do + + before :each do + Mongoid::Fields::I18n.with_locale(:fr) do + @snippet = FactoryGirl.create(:snippet, :site => @site, :slug => 'my_localized_test_snippet', :template => 'a testing template') + @page = FactoryGirl.create(:page, :site => @site, :slug => 'my_localized_test_snippet', :raw_template => "{% block main %}{% include 'my_localized_test_snippet' %}{% endblock %}") + end + end + + it 'returns the snippet dependencies depending on the UI locale' do + Mongoid::Fields::I18n.with_locale(:fr) { @page.snippet_dependencies.should_not be_empty } + Mongoid::Fields::I18n.with_locale(:en) { @page.snippet_dependencies.should be_nil } + end + + it 'updates the templates with the new snippet' do + Mongoid::Fields::I18n.with_locale(:fr) do + @snippet.update_attributes(:template => 'a new template') + Locomotive::Page.find(@page.id).render({}).should == 'a new template' + end + end + + end + end end