Show custom pages in public site

This commit is contained in:
Amaia Castro
2017-03-17 13:36:00 +01:00
parent 255b57cc85
commit 54fab919e5
11 changed files with 167 additions and 38 deletions

View File

@@ -2,7 +2,11 @@ class PagesController < ApplicationController
skip_authorization_check
def show
if @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id])
render action: :custom_page
else
render action: params[:id]
end
rescue ActionView::MissingTemplate
head 404
end

View File

@@ -7,6 +7,7 @@ class SiteCustomization::Page < ActiveRecord::Base
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
scope :published, -> { where(status: 'published').order('id DESC') }
scope :with_more_info_flag, -> { where(status: 'published', more_info_flag: true).order('id ASC') }
def url
"/#{slug}"

View File

@@ -2,19 +2,12 @@
Admin - <%= t("admin.menu.site_customization.pages") %>
<% end %>
<div class="legislation-admin legislation-process-index">
<div class="row">
<div class="small-12 medium-9 column">
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button float-right margin-right" %>
<h2 class="inline-block"><%= t("admin.site_customization.pages.index.title") %></h2>
</div>
<div class="small-12 medium-3 column legislation-process-new">
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button" %>
</div>
</div>
<h3><%= page_entries_info @pages %></h3>
<table class="stack">
<table class="cms_page_list">
<thead>
<tr>
<th><%= t("admin.site_customization.pages.page.title") %></th>
@@ -33,7 +26,7 @@
</td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= I18n.l page.created_at, format: :short %></td>
<td><%= t("admin.legislation.processes.process.status_#{page.status}") %></td>
<td><%= t("admin.site_customization.pages.page.status_#{page.status}") %></td>
<td class="small">
<span class="icon-eye"></span>
<%= link_to t("admin.site_customization.pages.index.see_page"), page.url %>
@@ -48,5 +41,3 @@
</table>
<%= paginate @pages %>
</div>

View File

@@ -0,0 +1,15 @@
<% provide :title do %><%= @custom_page.title %><% end %>
<div class="row margin-top">
<div class="small-12 medium-9 column">
<h1><%= @custom_page.title %></h1>
<h2><%= @custom_page.subtitle %></h2>
<%= raw @custom_page.content %>
</div>
<div class="small-12 medium-3 column">
<%= render '/shared/print' if @custom_page.print_content_flag %>
</div>
</div>

View File

@@ -4,4 +4,8 @@
<li><%= link_to t("pages.more_info.other.how_to_use", org_name: setting['org_name']), faq_path %></li>
<li><%= link_to t("pages.more_info.other.facts"), participation_facts_path %></li>
<li><%= link_to t("pages.more_info.other.world"), participation_world_path %></li>
<% SiteCustomization::Page.with_more_info_flag.each do |custom_page| %>
<li><%= link_to custom_page.title, page_path(custom_page.slug) %></li>
<% end %>
</ul>

View File

@@ -152,6 +152,7 @@ ignore_unused:
- 'views.pagination.*' # kaminari
- 'shared.suggest.*'
- 'invisible_captcha.*'
- 'admin.site_customization.pages.page.status_*'
# - '{devise,kaminari,will_paginate}.*'
# - 'simple_form.{yes,no}'
# - 'simple_form.{placeholders,hints,labels}.*'

View File

@@ -508,3 +508,5 @@ en:
status: Status
title: Title
updated_at: Updated at
status_draft: Draft
status_published: Published

View File

@@ -508,3 +508,5 @@ es:
status: Estado
title: Título
updated_at: Última actualización
status_draft: Borrador
status_published: Publicada

View File

@@ -224,7 +224,7 @@ Rails.application.routes.draw do
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
namespace :site_customization do
resources :pages
resources :pages, except: [:show]
end
end

View File

@@ -1,50 +1,48 @@
require 'rails_helper'
feature 'Admin custom pages' do
feature "Admin custom pages" do
background do
admin = create(:administrator)
login_as(admin.user)
end
context "Index" do
scenario 'Displaying custom pages' do
scenario "Index" do
custom_page = create(:site_customization_page)
visit admin_site_customization_pages_path
expect(page).to have_content(custom_page.title)
end
end
context 'Create' do
scenario 'Valid custom page' do
context "Create" do
scenario "Valid custom page" do
visit admin_root_path
within('#side_menu') do
within("#side_menu") do
click_link "Custom Pages"
end
expect(page).to_not have_content 'An example custom page'
expect(page).to_not have_content "An example custom page"
click_link "Create new page"
fill_in 'site_customization_page_title', with: 'An example custom page'
fill_in 'site_customization_page_subtitle', with: 'Page subtitle'
fill_in 'site_customization_page_slug', with: 'example-page'
fill_in 'site_customization_page_content', with: 'This page is about...'
fill_in "site_customization_page_title", with: "An example custom page"
fill_in "site_customization_page_subtitle", with: "Page subtitle"
fill_in "site_customization_page_slug", with: "example-page"
fill_in "site_customization_page_content", with: "This page is about..."
click_button 'Create Custom page'
click_button "Create Custom page"
expect(page).to have_content 'An example custom page'
expect(page).to have_content "An example custom page"
end
end
context 'Update' do
scenario 'Valid custom page' do
custom_page = create(:site_customization_page, title: 'An example custom page')
context "Update" do
scenario "Valid custom page" do
custom_page = create(:site_customization_page, title: "An example custom page")
visit admin_root_path
within('#side_menu') do
within("#side_menu") do
click_link "Custom Pages"
end
@@ -52,11 +50,20 @@ feature 'Admin custom pages' do
expect(page).to have_selector("h2", text: "An example custom page")
fill_in 'site_customization_page_title', with: 'Another example custom page'
fill_in "site_customization_page_title", with: "Another example custom page"
click_button "Update Custom page"
expect(page).to have_content "Page updated successfully"
expect(page).to have_content 'Another example custom page'
expect(page).to have_content "Another example custom page"
end
end
scenario "Index" do
custom_page = create(:site_customization_page, title: "An example custom page")
visit edit_admin_site_customization_page_path(custom_page)
click_button "Delete"
expect(page).to_not have_content("An example custom page")
end
end

View File

@@ -0,0 +1,102 @@
require 'rails_helper'
feature "Custom Pages" do
context "Override existing page" do
scenario "See default content when custom page is not published" do
custom_page = create(:site_customization_page,
slug: "conditions",
title: "Custom conditions",
content: "New text for conditions page",
print_content_flag: true
)
visit custom_page.url
expect(page).to have_title("Terms of use")
expect(page).to have_selector("h1", text: "Terms and conditions of use")
expect(page).to have_content("Página de información sobre las condiciones de uso, privacidad y protección de datos personales.")
expect(page).to have_content("Print this info")
end
scenario "See custom content when custom page is published" do
custom_page = create(:site_customization_page, :published,
slug: "conditions",
title: "Custom conditions",
content: "New text for conditions page",
print_content_flag: true
)
visit custom_page.url
expect(page).to have_title("Custom conditions")
expect(page).to have_selector("h1", text: "Custom conditions")
expect(page).to have_content("New text for conditions page")
expect(page).to have_content("Print this info")
end
end
context "New custom page" do
context "Draft" do
scenario "See page" do
custom_page = create(:site_customization_page,
slug: "other-slug",
title: "Custom page",
content: "Text for new custom page",
print_content_flag: false
)
visit custom_page.url
expect(page.status_code).to eq(404)
end
end
context "Published" do
scenario "See page" do
custom_page = create(:site_customization_page, :published,
slug: "other-slug",
title: "Custom page",
content: "Text for new custom page",
print_content_flag: false
)
visit custom_page.url
expect(page).to have_title("Custom page")
expect(page).to have_selector("h1", text: "Custom page")
expect(page).to have_content("Text for new custom page")
expect(page).to_not have_content("Print this info")
end
scenario "Listed in more information page" do
custom_page = create(:site_customization_page, :published,
slug: "another-slug", title: "Another custom page",
subtitle: "Subtitle for custom page",
more_info_flag: true
)
visit more_info_path
expect(page).to have_content("Another custom page")
end
scenario "Not listed in more information page" do
custom_page = create(:site_customization_page, :published,
slug: "another-slug", title: "Another custom page",
subtitle: "Subtitle for custom page",
more_info_flag: false
)
visit more_info_path
expect(page).to_not have_content("Another custom page")
visit custom_page.url
expect(page).to have_title("Another custom page")
expect(page).to have_selector("h1", text: "Another custom page")
expect(page).to have_content("Subtitle for custom page")
end
end
end
end