forked from locomotivecms/engine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make the editable elements more robust when working with localization…
… + write tests to prove it
- Loading branch information
Didier Lafforgue
committed
Mar 21, 2012
1 parent
e2f60f2
commit ab5a475
Showing
10 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module Locomotive | ||
module Liquid | ||
class PageNotFound < ::Liquid::Error; end | ||
|
||
class PageNotTranslated < ::Liquid::Error; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
describe Locomotive::Liquid::Tags::Extends do | ||
|
||
before(:each) do | ||
@home = FactoryGirl.build(:page, :raw_template => 'Hello world') | ||
@home.send :serialize_template | ||
@home.instance_variable_set(:@template, nil) | ||
|
||
@site = FactoryGirl.build(:site) | ||
@site.stubs(:pages).returns([@home]) | ||
end | ||
|
||
it 'works' do | ||
lambda { | ||
page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) | ||
parse('parent', page) | ||
}.should_not raise_error | ||
end | ||
|
||
context '#errors' do | ||
|
||
it 'raises an error if the source page does not exist' do | ||
lambda { | ||
@site.pages.expects(:where).with(:fullpath => 'foo').returns([]) | ||
parse('foo') | ||
}.should raise_error(Locomotive::Liquid::PageNotFound, "Page with fullpath 'foo' was not found") | ||
end | ||
|
||
it 'raises an error if the source page is not translated' do | ||
lambda { | ||
::Mongoid::Fields::I18n.with_locale 'fr' do | ||
page = FactoryGirl.build(:page, :slug => 'sub_page_1', :parent => @home) | ||
parse('parent', page) | ||
end | ||
}.should raise_error(Locomotive::Liquid::PageNotTranslated, "Page with fullpath 'parent' was not translated") | ||
end | ||
|
||
end | ||
|
||
def parse(source = 'index', page = nil) | ||
page ||= @home | ||
Liquid::Template.parse("{% extends #{source} %}", { :site => @site, :page => page }) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters