Show custom pages in public site
This commit is contained in:
@@ -2,7 +2,11 @@ class PagesController < ApplicationController
|
|||||||
skip_authorization_check
|
skip_authorization_check
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
if @custom_page = SiteCustomization::Page.published.find_by(slug: params[:id])
|
||||||
|
render action: :custom_page
|
||||||
|
else
|
||||||
render action: params[:id]
|
render action: params[:id]
|
||||||
|
end
|
||||||
rescue ActionView::MissingTemplate
|
rescue ActionView::MissingTemplate
|
||||||
head 404
|
head 404
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class SiteCustomization::Page < ActiveRecord::Base
|
|||||||
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||||
|
|
||||||
scope :published, -> { where(status: 'published').order('id DESC') }
|
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
|
def url
|
||||||
"/#{slug}"
|
"/#{slug}"
|
||||||
|
|||||||
@@ -2,19 +2,12 @@
|
|||||||
Admin - <%= t("admin.menu.site_customization.pages") %>
|
Admin - <%= t("admin.menu.site_customization.pages") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="legislation-admin legislation-process-index">
|
<%= link_to t("admin.site_customization.pages.index.create"), new_admin_site_customization_page_path, class: "button float-right margin-right" %>
|
||||||
<div class="row">
|
<h2 class="inline-block"><%= t("admin.site_customization.pages.index.title") %></h2>
|
||||||
<div class="small-12 medium-9 column">
|
|
||||||
<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>
|
<h3><%= page_entries_info @pages %></h3>
|
||||||
|
|
||||||
<table class="stack">
|
<table class="cms_page_list">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><%= t("admin.site_customization.pages.page.title") %></th>
|
<th><%= t("admin.site_customization.pages.page.title") %></th>
|
||||||
@@ -33,7 +26,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><%= I18n.l page.created_at, format: :short %></td>
|
<td><%= I18n.l page.created_at, format: :short %></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">
|
<td class="small">
|
||||||
<span class="icon-eye"></span>
|
<span class="icon-eye"></span>
|
||||||
<%= link_to t("admin.site_customization.pages.index.see_page"), page.url %>
|
<%= link_to t("admin.site_customization.pages.index.see_page"), page.url %>
|
||||||
@@ -48,5 +41,3 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<%= paginate @pages %>
|
<%= paginate @pages %>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|||||||
15
app/views/pages/custom_page.html.erb
Normal file
15
app/views/pages/custom_page.html.erb
Normal 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>
|
||||||
@@ -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.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.facts"), participation_facts_path %></li>
|
||||||
<li><%= link_to t("pages.more_info.other.world"), participation_world_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>
|
</ul>
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ ignore_unused:
|
|||||||
- 'views.pagination.*' # kaminari
|
- 'views.pagination.*' # kaminari
|
||||||
- 'shared.suggest.*'
|
- 'shared.suggest.*'
|
||||||
- 'invisible_captcha.*'
|
- 'invisible_captcha.*'
|
||||||
|
- 'admin.site_customization.pages.page.status_*'
|
||||||
# - '{devise,kaminari,will_paginate}.*'
|
# - '{devise,kaminari,will_paginate}.*'
|
||||||
# - 'simple_form.{yes,no}'
|
# - 'simple_form.{yes,no}'
|
||||||
# - 'simple_form.{placeholders,hints,labels}.*'
|
# - 'simple_form.{placeholders,hints,labels}.*'
|
||||||
|
|||||||
@@ -508,3 +508,5 @@ en:
|
|||||||
status: Status
|
status: Status
|
||||||
title: Title
|
title: Title
|
||||||
updated_at: Updated at
|
updated_at: Updated at
|
||||||
|
status_draft: Draft
|
||||||
|
status_published: Published
|
||||||
|
|||||||
@@ -508,3 +508,5 @@ es:
|
|||||||
status: Estado
|
status: Estado
|
||||||
title: Título
|
title: Título
|
||||||
updated_at: Última actualización
|
updated_at: Última actualización
|
||||||
|
status_draft: Borrador
|
||||||
|
status_published: Publicada
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ Rails.application.routes.draw do
|
|||||||
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
|
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||||
|
|
||||||
namespace :site_customization do
|
namespace :site_customization do
|
||||||
resources :pages
|
resources :pages, except: [:show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,48 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Admin custom pages' do
|
feature "Admin custom pages" do
|
||||||
|
|
||||||
background do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Index" do
|
scenario "Index" do
|
||||||
scenario 'Displaying custom pages' do
|
|
||||||
custom_page = create(:site_customization_page)
|
custom_page = create(:site_customization_page)
|
||||||
visit admin_site_customization_pages_path
|
visit admin_site_customization_pages_path
|
||||||
|
|
||||||
expect(page).to have_content(custom_page.title)
|
expect(page).to have_content(custom_page.title)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context 'Create' do
|
context "Create" do
|
||||||
scenario 'Valid custom page' do
|
scenario "Valid custom page" do
|
||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
within('#side_menu') do
|
within("#side_menu") do
|
||||||
click_link "Custom Pages"
|
click_link "Custom Pages"
|
||||||
end
|
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"
|
click_link "Create new page"
|
||||||
|
|
||||||
fill_in 'site_customization_page_title', with: 'An example custom 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_subtitle", with: "Page subtitle"
|
||||||
fill_in 'site_customization_page_slug', with: 'example-page'
|
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_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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'Update' do
|
context "Update" do
|
||||||
scenario 'Valid custom page' do
|
scenario "Valid custom page" do
|
||||||
custom_page = create(:site_customization_page, title: 'An example custom page')
|
custom_page = create(:site_customization_page, title: "An example custom page")
|
||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
within('#side_menu') do
|
within("#side_menu") do
|
||||||
click_link "Custom Pages"
|
click_link "Custom Pages"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -52,11 +50,20 @@ feature 'Admin custom pages' do
|
|||||||
|
|
||||||
expect(page).to have_selector("h2", text: "An example custom page")
|
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"
|
click_button "Update Custom page"
|
||||||
|
|
||||||
expect(page).to have_content "Page updated successfully"
|
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
|
||||||
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
|
end
|
||||||
|
|||||||
102
spec/features/site_customization/custom_pages_spec.rb
Normal file
102
spec/features/site_customization/custom_pages_spec.rb
Normal 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
|
||||||
Reference in New Issue
Block a user