Admin for custom pages
This commit is contained in:
10
app/controllers/admin/site_customization/base_controller.rb
Normal file
10
app/controllers/admin/site_customization/base_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class Admin::SiteCustomization::BaseController < Admin::BaseController
|
||||||
|
helper_method :namespace
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def namespace
|
||||||
|
"admin"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
44
app/controllers/admin/site_customization/pages_controller.rb
Normal file
44
app/controllers/admin/site_customization/pages_controller.rb
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::BaseController
|
||||||
|
load_and_authorize_resource :page, class: "SiteCustomization::Page"
|
||||||
|
|
||||||
|
def index
|
||||||
|
@pages = SiteCustomization::Page.order('slug').page(params[:page])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
if @page.save
|
||||||
|
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.create.notice', link: @page.slug.html_safe)
|
||||||
|
else
|
||||||
|
flash.now[:error] = t('admin.site_customization.pages.create.error')
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @page.update(page_params)
|
||||||
|
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.update.notice', link: @page.slug.html_safe)
|
||||||
|
else
|
||||||
|
flash.now[:error] = t('admin.site_customization.pages.update.error')
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@page.destroy
|
||||||
|
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.destroy.notice')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def page_params
|
||||||
|
params.require(:site_customization_page).permit(
|
||||||
|
:slug,
|
||||||
|
:title,
|
||||||
|
:subtitle,
|
||||||
|
:content,
|
||||||
|
:more_info_flag,
|
||||||
|
:print_content_flag,
|
||||||
|
:status
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -51,6 +51,8 @@ module Abilities
|
|||||||
|
|
||||||
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
can [:search, :edit, :update, :create, :index, :destroy], Banner
|
||||||
can [:index, :create, :edit, :update, :destroy], Geozone
|
can [:index, :create, :edit, :update, :destroy], Geozone
|
||||||
|
|
||||||
|
can :manage, SiteCustomization::Page
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
5
app/models/site_customization.rb
Normal file
5
app/models/site_customization.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module SiteCustomization
|
||||||
|
def self.table_name_prefix
|
||||||
|
'site_customization_'
|
||||||
|
end
|
||||||
|
end
|
||||||
14
app/models/site_customization/page.rb
Normal file
14
app/models/site_customization/page.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class SiteCustomization::Page < ActiveRecord::Base
|
||||||
|
VALID_STATUSES = %w(draft published)
|
||||||
|
|
||||||
|
validates :slug, uniqueness: { case_sensitive: false },
|
||||||
|
format: { with: /\A[0-9a-zA-Z\-_]*\Z/, message: :slug_format }
|
||||||
|
validates :title, presence: true
|
||||||
|
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||||
|
|
||||||
|
scope :published, -> { where(status: 'published').order('id DESC') }
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/#{slug}"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -122,5 +122,11 @@
|
|||||||
<span class="icon-stats"></span><%= t("admin.menu.stats") %>
|
<span class="icon-stats"></span><%= t("admin.menu.stats") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "pages" %>>
|
||||||
|
<%= link_to admin_site_customization_pages_path do %>
|
||||||
|
<span class="icon-settings"></span><%= t("admin.menu.site_customization.pages") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
52
app/views/admin/site_customization/pages/_form.html.erb
Normal file
52
app/views/admin/site_customization/pages/_form.html.erb
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<%= form_for [:admin, @page], html: {class: "edit_page", data: {watch_changes: true}} do |f| %>
|
||||||
|
|
||||||
|
<% if @page.errors.any? %>
|
||||||
|
|
||||||
|
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
||||||
|
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<strong>
|
||||||
|
<%= @page.errors.count %>
|
||||||
|
<%= t("admin.site_customization.pages.errors.form.error", count: @page.errors.count) %>
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="small-12 medium-9 column">
|
||||||
|
|
||||||
|
<%= f.label :title %>
|
||||||
|
<%= f.text_field :title, label: false %>
|
||||||
|
|
||||||
|
<%= f.label :subtitle %>
|
||||||
|
<%= f.text_field :subtitle, label: false, size: 80, maxlength: 80 %>
|
||||||
|
|
||||||
|
<%= f.label :slug %>
|
||||||
|
<%= f.text_field :slug, label: false, size: 80, maxlength: 80 %>
|
||||||
|
|
||||||
|
<div class="ckeditor margin-top">
|
||||||
|
<%= f.label :content %>
|
||||||
|
<%= f.cktext_area :content, label: false, cols: 80, rows: 10, ckeditor: { language: I18n.locale } %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-3 column">
|
||||||
|
<div class="page_edit">
|
||||||
|
<h4><%= t("admin.site_customization.pages.form.options") %></h4>
|
||||||
|
<%= f.check_box :more_info_flag %>
|
||||||
|
<%= f.check_box :print_content_flag %>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<h4><%= f.label :status %></h4>
|
||||||
|
<% ::SiteCustomization::Page::VALID_STATUSES.each do |status| %>
|
||||||
|
<%= f.radio_button :status, status, label: false %>
|
||||||
|
<%= f.label "status_#{status}", t("admin.site_customization.pages.status_#{status}") %>
|
||||||
|
<br/>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= f.submit class: "button success" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
15
app/views/admin/site_customization/pages/edit.html.erb
Normal file
15
app/views/admin/site_customization/pages/edit.html.erb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
Admin - <%= t("admin.menu.site_customization.pages") %> - <%= @page.title %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to admin_site_customization_pages_path, class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.site_customization.pages.edit.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= button_to t("admin.site_customization.pages.index.delete"), admin_site_customization_page_path(@page), method: :delete, class: "button hollow alert float-right margin-right" %>
|
||||||
|
|
||||||
|
<div class="row margin-top">
|
||||||
|
<h2><%= t("admin.site_customization.pages.edit.title", page_title: @page.title) %></h2>
|
||||||
|
<%= render 'form' %>
|
||||||
|
</div>
|
||||||
52
app/views/admin/site_customization/pages/index.html.erb
Normal file
52
app/views/admin/site_customization/pages/index.html.erb
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
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">
|
||||||
|
<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">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.site_customization.pages.page.title") %></th>
|
||||||
|
<th><%= t("admin.site_customization.pages.page.created_at") %></th>
|
||||||
|
<th><%= t("admin.site_customization.pages.page.updated_at") %></th>
|
||||||
|
<th><%= t("admin.site_customization.pages.page.status") %></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @pages.each do |page| %>
|
||||||
|
<tr id="<%= dom_id(page) %>">
|
||||||
|
<td>
|
||||||
|
<%= link_to page.title, edit_admin_site_customization_page_path(page) %>
|
||||||
|
</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 class="small">
|
||||||
|
<span class="icon-eye"></span>
|
||||||
|
<%= link_to t("admin.site_customization.pages.index.see_page"), page.url %>
|
||||||
|
</td>
|
||||||
|
<td class="small">
|
||||||
|
<span class="icon-x"></span>
|
||||||
|
<%= link_to t("admin.site_customization.pages.index.delete"), admin_site_customization_page_path(page), method: :delete %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @pages %>
|
||||||
|
|
||||||
|
</div>
|
||||||
14
app/views/admin/site_customization/pages/new.html.erb
Normal file
14
app/views/admin/site_customization/pages/new.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
Admin - <%= t("admin.menu.site_customization.pages") %> - <%= t("admin.site_customization.pages.new.title") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to admin_site_customization_pages_path, class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.site_customization.pages.new.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="row margin-top">
|
||||||
|
<h2><%= t("admin.site_customization.pages.new.title") %></h2>
|
||||||
|
<%= render 'form' %>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -40,6 +40,9 @@ en:
|
|||||||
spending_proposal:
|
spending_proposal:
|
||||||
one: "Spending proposal"
|
one: "Spending proposal"
|
||||||
other: "Spending proposals"
|
other: "Spending proposals"
|
||||||
|
site_customization/page:
|
||||||
|
one: Custom page
|
||||||
|
other: Custom pages
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
@@ -103,6 +106,16 @@ en:
|
|||||||
signable_type: "Signable type"
|
signable_type: "Signable type"
|
||||||
signable_id: "Signable ID"
|
signable_id: "Signable ID"
|
||||||
document_numbers: "Documents numbers"
|
document_numbers: "Documents numbers"
|
||||||
|
site_customization/page:
|
||||||
|
content: Content
|
||||||
|
created_at: Created at
|
||||||
|
subtitle: Subtitle
|
||||||
|
slug: Slug
|
||||||
|
status: Status
|
||||||
|
title: Title
|
||||||
|
updated_at: Updated at
|
||||||
|
more_info_flag: Show in more information page
|
||||||
|
print_content_flag: Print content button
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
@@ -134,3 +147,7 @@ en:
|
|||||||
document_number:
|
document_number:
|
||||||
not_in_census: 'Not verified by Census'
|
not_in_census: 'Not verified by Census'
|
||||||
already_voted: 'Already voted this proposal'
|
already_voted: 'Already voted this proposal'
|
||||||
|
site_customization/page:
|
||||||
|
attributes:
|
||||||
|
slug:
|
||||||
|
slug_format: "must be letters, numbers, _ and -"
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ es:
|
|||||||
spending_proposal:
|
spending_proposal:
|
||||||
one: "Propuesta de inversión"
|
one: "Propuesta de inversión"
|
||||||
other: "Propuestas de inversión"
|
other: "Propuestas de inversión"
|
||||||
|
site_customization/page:
|
||||||
|
one: Página
|
||||||
|
other: Páginas
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
@@ -98,6 +101,16 @@ es:
|
|||||||
signable_type: "Tipo de hoja de firmas"
|
signable_type: "Tipo de hoja de firmas"
|
||||||
signable_id: "ID Propuesta ciudadana/Propuesta inversión"
|
signable_id: "ID Propuesta ciudadana/Propuesta inversión"
|
||||||
document_numbers: "Números de documentos"
|
document_numbers: "Números de documentos"
|
||||||
|
site_customization/page:
|
||||||
|
content: Contenido
|
||||||
|
created_at: Creada
|
||||||
|
subtitle: Subtítulo
|
||||||
|
slug: Slug
|
||||||
|
status: Estado
|
||||||
|
title: Título
|
||||||
|
updated_at: última actualización
|
||||||
|
more_info_flag: Mostrar en la página de más información
|
||||||
|
print_content_flag: Botón de imprimir contenido
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
@@ -129,3 +142,7 @@ es:
|
|||||||
document_number:
|
document_number:
|
||||||
not_in_census: 'No verificado por Padrón'
|
not_in_census: 'No verificado por Padrón'
|
||||||
already_voted: 'Ya ha votado esta propuesta'
|
already_voted: 'Ya ha votado esta propuesta'
|
||||||
|
site_customization/page:
|
||||||
|
attributes:
|
||||||
|
slug:
|
||||||
|
slug_format: "deber ser letras, números, _ y -"
|
||||||
|
|||||||
@@ -207,6 +207,8 @@ en:
|
|||||||
spending_proposals: Spending proposals
|
spending_proposals: Spending proposals
|
||||||
stats: Statistics
|
stats: Statistics
|
||||||
signature_sheets: Signature Sheets
|
signature_sheets: Signature Sheets
|
||||||
|
site_customization:
|
||||||
|
pages: Custom Pages
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderators
|
title: Moderators
|
||||||
@@ -475,3 +477,34 @@ en:
|
|||||||
phone_not_given: Phone not given
|
phone_not_given: Phone not given
|
||||||
sms_code_not_confirmed: Has not confirmed the sms code
|
sms_code_not_confirmed: Has not confirmed the sms code
|
||||||
title: Incomplete verifications
|
title: Incomplete verifications
|
||||||
|
site_customization:
|
||||||
|
pages:
|
||||||
|
create:
|
||||||
|
notice: 'Page created successfully.'
|
||||||
|
error: Process couldn't be created
|
||||||
|
update:
|
||||||
|
notice: 'Page updated successfully.'
|
||||||
|
error: Page couldn't be updated
|
||||||
|
destroy:
|
||||||
|
notice: Page deleted successfully
|
||||||
|
edit:
|
||||||
|
title: Editing %{page_title}
|
||||||
|
back: Back
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
form:
|
||||||
|
options: Options
|
||||||
|
index:
|
||||||
|
create: Create new page
|
||||||
|
delete: Delete
|
||||||
|
title: Custom Pages
|
||||||
|
see_page: See page
|
||||||
|
new:
|
||||||
|
back: Back
|
||||||
|
title: Create new custom page
|
||||||
|
page:
|
||||||
|
created_at: Created at
|
||||||
|
status: Status
|
||||||
|
title: Title
|
||||||
|
updated_at: Updated at
|
||||||
|
|||||||
@@ -207,6 +207,8 @@ es:
|
|||||||
spending_proposals: Propuestas de inversión
|
spending_proposals: Propuestas de inversión
|
||||||
stats: Estadísticas
|
stats: Estadísticas
|
||||||
signature_sheets: Hojas de firmas
|
signature_sheets: Hojas de firmas
|
||||||
|
site_customization:
|
||||||
|
pages: Páginas
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderadores
|
title: Moderadores
|
||||||
@@ -475,3 +477,34 @@ es:
|
|||||||
phone_not_given: No ha dado su teléfono
|
phone_not_given: No ha dado su teléfono
|
||||||
sms_code_not_confirmed: No ha introducido su código de seguridad
|
sms_code_not_confirmed: No ha introducido su código de seguridad
|
||||||
title: Verificaciones incompletas
|
title: Verificaciones incompletas
|
||||||
|
site_customization:
|
||||||
|
pages:
|
||||||
|
create:
|
||||||
|
notice: 'Página creada correctamente.'
|
||||||
|
error: No se ha podido crear la página
|
||||||
|
update:
|
||||||
|
notice: 'Página actualizada correctamente.s'
|
||||||
|
error: No se ha podido actualizar la página
|
||||||
|
destroy:
|
||||||
|
notice: Página eliminada correctamente
|
||||||
|
edit:
|
||||||
|
title: Editar %{page_title}
|
||||||
|
back: Volver
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
form:
|
||||||
|
options: Opciones
|
||||||
|
index:
|
||||||
|
create: Crear nueva página
|
||||||
|
delete: Borrar
|
||||||
|
title: Páginas
|
||||||
|
see_page: Ver página
|
||||||
|
new:
|
||||||
|
back: Back
|
||||||
|
title: Página nueva
|
||||||
|
page:
|
||||||
|
created_at: Creada
|
||||||
|
status: Estado
|
||||||
|
title: Título
|
||||||
|
updated_at: Última actualización
|
||||||
|
|||||||
@@ -222,6 +222,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
|
resources :geozones, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||||
|
|
||||||
|
namespace :site_customization do
|
||||||
|
resources :pages
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :moderation do
|
namespace :moderation do
|
||||||
|
|||||||
15
db/migrate/20170316174351_create_site_customization_pages.rb
Normal file
15
db/migrate/20170316174351_create_site_customization_pages.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class CreateSiteCustomizationPages < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :site_customization_pages do |t|
|
||||||
|
t.string :slug, null: false
|
||||||
|
t.string :title, null: false
|
||||||
|
t.string :subtitle
|
||||||
|
t.text :content
|
||||||
|
t.boolean :more_info_flag
|
||||||
|
t.boolean :print_content_flag
|
||||||
|
t.string :status, default: 'draft'
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
db/schema.rb
14
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170114154421) do
|
ActiveRecord::Schema.define(version: 20170316174351) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -439,6 +439,18 @@ ActiveRecord::Schema.define(version: 20170114154421) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "site_customization_pages", force: :cascade do |t|
|
||||||
|
t.string "slug", null: false
|
||||||
|
t.string "title", null: false
|
||||||
|
t.string "subtitle"
|
||||||
|
t.text "content"
|
||||||
|
t.boolean "more_info_flag"
|
||||||
|
t.boolean "print_content_flag"
|
||||||
|
t.string "status", default: "draft"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "spending_proposals", force: :cascade do |t|
|
create_table "spending_proposals", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
|
|||||||
@@ -450,4 +450,22 @@ FactoryGirl.define do
|
|||||||
signature_sheet
|
signature_sheet
|
||||||
sequence(:document_number) { |n| "#{n}A" }
|
sequence(:document_number) { |n| "#{n}A" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :site_customization_page, class: 'SiteCustomization::Page' do
|
||||||
|
slug "example-page"
|
||||||
|
title "Example page"
|
||||||
|
subtitle "About an example"
|
||||||
|
content "This page is about..."
|
||||||
|
more_info_flag false
|
||||||
|
print_content_flag false
|
||||||
|
status 'draft'
|
||||||
|
|
||||||
|
trait :published do
|
||||||
|
status "published"
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :display_in_more_info do
|
||||||
|
more_info_flag true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
62
spec/features/admin/site_customization/pages_spec.rb
Normal file
62
spec/features/admin/site_customization/pages_spec.rb
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Admin custom pages' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Index" do
|
||||||
|
scenario 'Displaying custom pages' 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
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within('#side_menu') do
|
||||||
|
click_link "Custom Pages"
|
||||||
|
end
|
||||||
|
|
||||||
|
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...'
|
||||||
|
|
||||||
|
click_button 'Create 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')
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within('#side_menu') do
|
||||||
|
click_link "Custom Pages"
|
||||||
|
end
|
||||||
|
|
||||||
|
click_link "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'
|
||||||
|
click_button "Update Custom page"
|
||||||
|
|
||||||
|
expect(page).to have_content "Page updated successfully"
|
||||||
|
expect(page).to have_content 'Another example custom page'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
spec/models/site_customization/page_spec.rb
Normal file
14
spec/models/site_customization/page_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe SiteCustomization::Page, type: :model do
|
||||||
|
let(:custom_page) { build(:site_customization_page) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(custom_page).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is invalid if slug has symbols" do
|
||||||
|
custom_page = build(:site_customization_page, slug: "as/as*la")
|
||||||
|
expect(custom_page).to be_invalid
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user