fix issue #427 + make the content types API features more predictable
This commit is contained in:
parent
5f9c46b42c
commit
3f1380408e
2
Gemfile
2
Gemfile
@ -51,4 +51,6 @@ group :test do
|
|||||||
gem 'json_spec'
|
gem 'json_spec'
|
||||||
|
|
||||||
gem 'database_cleaner'
|
gem 'database_cleaner'
|
||||||
|
|
||||||
|
# gem 'debugger', :git => 'git://github.com/cldwalker/debugger.git'
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module Locomotive
|
|||||||
load_and_authorize_resource :class => Locomotive::ContentType
|
load_and_authorize_resource :class => Locomotive::ContentType
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@content_types = current_site.content_types
|
@content_types = current_site.content_types.order_by([[:name, :asc]])
|
||||||
respond_with(@content_types)
|
respond_with(@content_types)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,14 +88,14 @@ Feature: Content Types
|
|||||||
Then the JSON response should be an array
|
Then the JSON response should be an array
|
||||||
And the JSON response should have 2 entries
|
And the JSON response should have 2 entries
|
||||||
And the JSON should have the following:
|
And the JSON should have the following:
|
||||||
| 1/name | "Employees" |
|
| 0/name | "Employees" |
|
||||||
| 1/slug | "employees" |
|
| 0/slug | "employees" |
|
||||||
| 1/entries_custom_fields/0/label | "Name" |
|
| 0/entries_custom_fields/0/label | "Name" |
|
||||||
| 1/entries_custom_fields/0/name | "name" |
|
| 0/entries_custom_fields/0/name | "name" |
|
||||||
| 1/entries_custom_fields/0/type | "string" |
|
| 0/entries_custom_fields/0/type | "string" |
|
||||||
| 1/entries_custom_fields/1/label | "Position" |
|
| 0/entries_custom_fields/1/label | "Position" |
|
||||||
| 1/entries_custom_fields/1/name | "position" |
|
| 0/entries_custom_fields/1/name | "position" |
|
||||||
| 1/entries_custom_fields/1/type | "string" |
|
| 0/entries_custom_fields/1/type | "string" |
|
||||||
|
|
||||||
Scenario: Creating new content type as a Designer
|
Scenario: Creating new content type as a Designer
|
||||||
Given I have a "designer" API token
|
Given I have a "designer" API token
|
||||||
@ -127,14 +127,14 @@ Feature: Content Types
|
|||||||
Then the JSON response should be an array
|
Then the JSON response should be an array
|
||||||
And the JSON response should have 2 entries
|
And the JSON response should have 2 entries
|
||||||
And the JSON should have the following:
|
And the JSON should have the following:
|
||||||
| 1/name | "Employees" |
|
| 0/name | "Employees" |
|
||||||
| 1/slug | "employees" |
|
| 0/slug | "employees" |
|
||||||
| 1/entries_custom_fields/0/label | "Name" |
|
| 0/entries_custom_fields/0/label | "Name" |
|
||||||
| 1/entries_custom_fields/0/name | "name" |
|
| 0/entries_custom_fields/0/name | "name" |
|
||||||
| 1/entries_custom_fields/0/type | "string" |
|
| 0/entries_custom_fields/0/type | "string" |
|
||||||
| 1/entries_custom_fields/1/label | "Position" |
|
| 0/entries_custom_fields/1/label | "Position" |
|
||||||
| 1/entries_custom_fields/1/name | "position" |
|
| 0/entries_custom_fields/1/name | "position" |
|
||||||
| 1/entries_custom_fields/1/type | "string" |
|
| 0/entries_custom_fields/1/type | "string" |
|
||||||
|
|
||||||
Scenario: Creating new content type as an Author
|
Scenario: Creating new content type as an Author
|
||||||
Given I have an "author" API token
|
Given I have an "author" API token
|
||||||
|
@ -18,14 +18,7 @@ module Locomotive
|
|||||||
|
|
||||||
def parse_parent_template
|
def parse_parent_template
|
||||||
if @template_name == 'parent'
|
if @template_name == 'parent'
|
||||||
if @context[:cached_parent]
|
@context[:parent_page] = @context[:cached_parent] || @context[:page].parent
|
||||||
@context[:parent_page] = @context[:cached_parent] #.clone # parent must not be modified
|
|
||||||
|
|
||||||
@context[:cached_parent].instance_variable_set(:@template, nil) # force to reload the template
|
|
||||||
@context[:cached_parent] = nil
|
|
||||||
else
|
|
||||||
@context[:parent_page] = @context[:page].parent
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
locale = ::Mongoid::Fields::I18n.locale
|
locale = ::Mongoid::Fields::I18n.locale
|
||||||
|
|
||||||
@ -40,7 +33,8 @@ module Locomotive
|
|||||||
|
|
||||||
raise PageNotTranslated.new("Page with fullpath '#{@template_name}' was not translated") if parent_template.nil?
|
raise PageNotTranslated.new("Page with fullpath '#{@template_name}' was not translated") if parent_template.nil?
|
||||||
|
|
||||||
@context[:parent_page].instance_variable_set(:@template, parent_template)
|
# force the page to restore the original version of its template (from the serialized version)
|
||||||
|
@context[:parent_page].instance_variable_set(:@template, nil)
|
||||||
|
|
||||||
parent_template
|
parent_template
|
||||||
end
|
end
|
||||||
|
88
spec/models/locomotive/extensions/page/render_spec.rb
Normal file
88
spec/models/locomotive/extensions/page/render_spec.rb
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Locomotive::Extensions::Page::Render do
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
Locomotive::Site.any_instance.stubs(:create_default_pages!).returns(true)
|
||||||
|
@site = FactoryGirl.create(:site)
|
||||||
|
@home = FactoryGirl.create(:page, :site => @site, :raw_template =>
|
||||||
|
"""
|
||||||
|
Hello world
|
||||||
|
{% block header %}Home header{% endblock %}
|
||||||
|
{% block main %}My home page{% endblock %}
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the home page' do
|
||||||
|
render(@home).should == 'Hello world, Home header, My home page'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#inheritance' do
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@inner = FactoryGirl.create(:sub_page, :slug => 'innerpage', :site => @site, :raw_template =>
|
||||||
|
"""
|
||||||
|
{% extends parent %}
|
||||||
|
{% block header %}Inner header{% endblock %}
|
||||||
|
{% block main %}Inner page{% endblock %}
|
||||||
|
""")
|
||||||
|
@contact = FactoryGirl.create(:sub_page, :slug => 'contact', :site => @site, :raw_template =>
|
||||||
|
"""
|
||||||
|
{% extends 'innerpage' %}
|
||||||
|
{% block header %}Contact header{% endblock %}
|
||||||
|
{% block main %}Contact page{% endblock %}
|
||||||
|
""")
|
||||||
|
@about = FactoryGirl.create(:sub_page, :slug => 'about', :site => @site, :raw_template =>
|
||||||
|
"""
|
||||||
|
{% extends 'innerpage' %}
|
||||||
|
{% block main %}About page{% endblock %}
|
||||||
|
""")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the inner page' do
|
||||||
|
render(@inner).should == 'Hello world, Inner header, Inner page'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the contact page' do
|
||||||
|
render(@contact).should == 'Hello world, Contact header, Contact page'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the contact page' do
|
||||||
|
render(@about).should == 'Hello world, Inner header, About page'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when parent page got modified' do
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@home.raw_template = """
|
||||||
|
Hello world (UPDATED)
|
||||||
|
{% block header %}Home header (UPDATED){% endblock %}
|
||||||
|
{% block main %}My home page (UPDATED){% endblock %}
|
||||||
|
"""
|
||||||
|
@home.save & @home.reload
|
||||||
|
@inner = Locomotive::Page.find(@inner._id)
|
||||||
|
@contact = Locomotive::Page.find(@contact._id)
|
||||||
|
@about = Locomotive::Page.find(@about._id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'reflects changes on the inner page' do
|
||||||
|
render(@inner).should == 'Hello world (UPDATED), Inner header, Inner page'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'reflects changes on the contact page' do
|
||||||
|
render(@contact).should == 'Hello world (UPDATED), Contact header, Contact page'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'reflects changes on the about page' do
|
||||||
|
render(@about).should == 'Hello world (UPDATED), Inner header, About page'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def render(page)
|
||||||
|
page.render(::Liquid::Context.new({}, {}, {}, false)).strip.gsub(/(\s{2,})/, ', ')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user