Custom content blocks for top_links and footer
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -30,4 +30,5 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
.ruby-gemset
|
.ruby-gemset
|
||||||
|
|
||||||
public/sitemap.xml
|
public/sitemap.xml
|
||||||
|
public/system/
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomization::BaseController
|
||||||
|
load_and_authorize_resource :content_block, class: "SiteCustomization::ContentBlock"
|
||||||
|
|
||||||
|
def index
|
||||||
|
@content_blocks = SiteCustomization::ContentBlock.order(:name, :locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
if @content_block.save
|
||||||
|
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.create.notice')
|
||||||
|
else
|
||||||
|
flash.now[:error] = t('admin.site_customization.content_blocks.create.error')
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @content_block.update(content_block_params)
|
||||||
|
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.update.notice')
|
||||||
|
else
|
||||||
|
flash.now[:error] = t('admin.site_customization.content_blocks.update.error')
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@content_block.destroy
|
||||||
|
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.destroy.notice')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def content_block_params
|
||||||
|
params.require(:site_customization_content_block).permit(
|
||||||
|
:name,
|
||||||
|
:locale,
|
||||||
|
:body
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -51,4 +51,8 @@ module ApplicationHelper
|
|||||||
def image_path_for(filename)
|
def image_path_for(filename)
|
||||||
SiteCustomization::Image.image_path_for(filename) || filename
|
SiteCustomization::Image.image_path_for(filename) || filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content_block(name, locale)
|
||||||
|
SiteCustomization::ContentBlock.block_for(name, locale)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ module Abilities
|
|||||||
|
|
||||||
can :manage, SiteCustomization::Page
|
can :manage, SiteCustomization::Page
|
||||||
can :manage, SiteCustomization::Image
|
can :manage, SiteCustomization::Image
|
||||||
|
can :manage, SiteCustomization::ContentBlock
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
11
app/models/site_customization/content_block.rb
Normal file
11
app/models/site_customization/content_block.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class SiteCustomization::ContentBlock < ActiveRecord::Base
|
||||||
|
VALID_BLOCKS = %w(top_links footer)
|
||||||
|
|
||||||
|
validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) }
|
||||||
|
validates :name, presence: true, uniqueness: { scope: :locale }, inclusion: { in: VALID_BLOCKS }
|
||||||
|
|
||||||
|
def self.block_for(name, locale)
|
||||||
|
locale ||= I18n.default_locale
|
||||||
|
find_by(name: name, locale: locale).try(:body)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -134,5 +134,11 @@
|
|||||||
<span class="icon-settings"></span><%= t("admin.menu.site_customization.images") %>
|
<span class="icon-settings"></span><%= t("admin.menu.site_customization.images") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "content_blocks" %>>
|
||||||
|
<%= link_to admin_site_customization_content_blocks_path do %>
|
||||||
|
<span class="icon-settings"></span><%= t("admin.menu.site_customization.content_blocks") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<%= form_for [:admin, @content_block], html: {class: "edit_page", data: {watch_changes: true}} do |f| %>
|
||||||
|
|
||||||
|
<% if @content_block.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>
|
||||||
|
<%= @content_block.errors.count %>
|
||||||
|
<%= t("admin.site_customization.content_blocks.errors.form.error", count: @content_block.errors.count) %>
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= f.label :name %>
|
||||||
|
<%= f.select :name, SiteCustomization::ContentBlock::VALID_BLOCKS, label: false %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 column">
|
||||||
|
<%= f.label :locale %>
|
||||||
|
<%= f.select :locale, I18n.available_locales, label: false %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= f.label :body %>
|
||||||
|
<%= f.text_area :body, label: false, rows: 10 %>
|
||||||
|
<%= f.submit class: "button success" %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
Admin - <%= t("admin.menu.site_customization.content_blocks") %> - <%= @content_block.name %> (<%= @content_block.locale %>)
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to admin_site_customization_content_blocks_path, class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.site_customization.content_blocks.edit.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= button_to t("admin.site_customization.content_blocks.index.delete"), admin_site_customization_content_block_path(@content_block), method: :delete, class: "button hollow alert float-right margin-right" %>
|
||||||
|
|
||||||
|
<div class="row margin-top">
|
||||||
|
<h2><%= t("admin.site_customization.content_blocks.edit.title") %></h2>
|
||||||
|
<%= render 'form' %>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
Admin - <%= t("admin.menu.site_customization.content_blocks") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to t("admin.site_customization.content_blocks.index.create"), new_admin_site_customization_content_block_path, class: "button float-right margin-right" %>
|
||||||
|
<h2 class="inline-block"><%= t("admin.site_customization.content_blocks.index.title") %></h2>
|
||||||
|
|
||||||
|
<table class="cms_page_list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.site_customization.content_blocks.content_block.name") %></th>
|
||||||
|
<th><%= t("admin.site_customization.content_blocks.content_block.body") %></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @content_blocks.each do |content_block| %>
|
||||||
|
<tr id="<%= dom_id(content_block) %>">
|
||||||
|
<td><%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %></td>
|
||||||
|
<td><%= content_block.body %></td>
|
||||||
|
<td>
|
||||||
|
<%= button_to t("admin.site_customization.content_blocks.index.delete"),
|
||||||
|
admin_site_customization_content_block_path(content_block),
|
||||||
|
method: :delete, class: "button hollow alert" %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<% provide :title do %>
|
||||||
|
Admin - <%= t("admin.menu.site_customization.content_blocks") %> - <%= t("admin.site_customization.content_blocks.new.title") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= link_to admin_site_customization_content_blocks_path, class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.site_customization.content_blocks.new.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="row margin-top">
|
||||||
|
<h2><%= t("admin.site_customization.content_blocks.new.title") %></h2>
|
||||||
|
<%= render 'form' %>
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<footer>
|
<footer>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 large-4 column">
|
<div class="small-12 large-4 column">
|
||||||
<h1 class="logo">
|
<h1 class="logo">
|
||||||
<%= link_to t("layouts.header.open_gov", open: "#{t('layouts.header.open')}").html_safe %>
|
<%= link_to t("layouts.header.open_gov", open: "#{t('layouts.header.open')}").html_safe %>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
<div class="small-12 medium-4 column">
|
||||||
<h2>
|
<h2>
|
||||||
<%= link_to t("layouts.footer.transparency_title"), t("layouts.footer.transparency_url") %>
|
<%= link_to t("layouts.footer.transparency_title"), setting['transparency_url'].presence || t("layouts.footer.transparency_url") %>
|
||||||
</h2>
|
</h2>
|
||||||
<p><%= t("layouts.footer.transparency_text") %></p>
|
<p><%= t("layouts.footer.transparency_text") %></p>
|
||||||
</div>
|
</div>
|
||||||
@@ -96,4 +96,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= raw content_block("footer", I18n.locale) %>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
<ul class="no-bullet external-links">
|
<ul class="no-bullet external-links">
|
||||||
<li>
|
<li>
|
||||||
<%= link_to t("layouts.header.external_link_transparency"),
|
<%= link_to t("layouts.header.external_link_transparency"),
|
||||||
t("layouts.header.external_link_transparency_url"),
|
setting['transparency_url'].presence || t("layouts.header.external_link_transparency_url"),
|
||||||
target: "_blank",
|
target: "_blank",
|
||||||
title: t('shared.target_blank_html') %>
|
title: t('shared.target_blank_html') %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to t("layouts.header.external_link_opendata"),
|
<%= link_to t("layouts.header.external_link_opendata"),
|
||||||
t("layouts.header.external_link_opendata_url"),
|
setting['opendata_url'].presence || t("layouts.header.external_link_opendata_url"),
|
||||||
target: "_blank",
|
target: "_blank",
|
||||||
title: t('shared.target_blank_html') %>
|
title: t('shared.target_blank_html') %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<% if setting['blog_url'] %>
|
<% if setting['blog_url'] %>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to setting['blog_url'], title: t('shared.target_blank_html'), target: "_blank" do %>
|
<%= link_to t("layouts.header.external_link_blog"),
|
||||||
<%= t("layouts.header.external_link_blog") %>
|
setting['blog_url'],
|
||||||
<% end %>
|
target: "_blank",
|
||||||
|
title: t('shared.target_blank_html') %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<%= raw content_block("top_links", I18n.locale) %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ en:
|
|||||||
site_customization/image:
|
site_customization/image:
|
||||||
one: Custom image
|
one: Custom image
|
||||||
other: Custom images
|
other: Custom images
|
||||||
|
site_customization/content_block:
|
||||||
|
one: Custom content block
|
||||||
|
other: Custom content blocks
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
@@ -119,6 +122,13 @@ en:
|
|||||||
updated_at: Updated at
|
updated_at: Updated at
|
||||||
more_info_flag: Show in more information page
|
more_info_flag: Show in more information page
|
||||||
print_content_flag: Print content button
|
print_content_flag: Print content button
|
||||||
|
site_customization/image:
|
||||||
|
name: Name
|
||||||
|
image: Image
|
||||||
|
site_customization/content_block:
|
||||||
|
name: Name
|
||||||
|
locale: locale
|
||||||
|
body: Body
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ es:
|
|||||||
site_customization/image:
|
site_customization/image:
|
||||||
one: Imagen
|
one: Imagen
|
||||||
other: Imágenes
|
other: Imágenes
|
||||||
|
site_customization/content_block:
|
||||||
|
one: Bloque
|
||||||
|
other: Bloques
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
@@ -114,6 +117,13 @@ es:
|
|||||||
updated_at: última actualización
|
updated_at: última actualización
|
||||||
more_info_flag: Mostrar en la página de más información
|
more_info_flag: Mostrar en la página de más información
|
||||||
print_content_flag: Botón de imprimir contenido
|
print_content_flag: Botón de imprimir contenido
|
||||||
|
site_customization/image:
|
||||||
|
name: Nombre
|
||||||
|
image: Imagen
|
||||||
|
site_customization/content_block:
|
||||||
|
name: Nombre
|
||||||
|
locale: Idioma
|
||||||
|
body: Contenido
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ en:
|
|||||||
site_customization:
|
site_customization:
|
||||||
pages: Custom Pages
|
pages: Custom Pages
|
||||||
images: Custom Images
|
images: Custom Images
|
||||||
|
content_blocks: Custom content blocks
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderators
|
title: Moderators
|
||||||
@@ -479,6 +480,31 @@ en:
|
|||||||
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:
|
site_customization:
|
||||||
|
content_blocks:
|
||||||
|
create:
|
||||||
|
notice: Content block created successfully
|
||||||
|
error: Content block couldn't be created
|
||||||
|
update:
|
||||||
|
notice: Content block updated successfully
|
||||||
|
error: Content block couldn't be updated
|
||||||
|
destroy:
|
||||||
|
notice: Content block deleted successfully
|
||||||
|
edit:
|
||||||
|
title: Editing content block
|
||||||
|
back: Back
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
index:
|
||||||
|
create: Create new content block
|
||||||
|
delete: Delete
|
||||||
|
title: Content blocks
|
||||||
|
new:
|
||||||
|
back: Back
|
||||||
|
title: Create new content block
|
||||||
|
content_block:
|
||||||
|
body: Body
|
||||||
|
name: Name
|
||||||
images:
|
images:
|
||||||
index:
|
index:
|
||||||
title: Custom images
|
title: Custom images
|
||||||
@@ -493,7 +519,7 @@ en:
|
|||||||
pages:
|
pages:
|
||||||
create:
|
create:
|
||||||
notice: Page created successfully
|
notice: Page created successfully
|
||||||
error: Process couldn't be created
|
error: Page couldn't be created
|
||||||
update:
|
update:
|
||||||
notice: Page updated successfully
|
notice: Page updated successfully
|
||||||
error: Page couldn't be updated
|
error: Page couldn't be updated
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ es:
|
|||||||
site_customization:
|
site_customization:
|
||||||
pages: Personalizar páginas
|
pages: Personalizar páginas
|
||||||
images: Personalizar imágenes
|
images: Personalizar imágenes
|
||||||
|
content_blocks: Personalizar bloques
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderadores
|
title: Moderadores
|
||||||
@@ -479,6 +480,31 @@ es:
|
|||||||
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:
|
site_customization:
|
||||||
|
content_blocks:
|
||||||
|
create:
|
||||||
|
notice: Bloque creado correctamente
|
||||||
|
error: No se ha podido crear el bloque
|
||||||
|
update:
|
||||||
|
notice: Bloque actualizado correctamente
|
||||||
|
error: No se ha podido actualizar el bloque
|
||||||
|
destroy:
|
||||||
|
notice: Bloque borrado correctamente
|
||||||
|
edit:
|
||||||
|
title: Editar bloque
|
||||||
|
back: Volver
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
index:
|
||||||
|
create: Crear nuevo bloque
|
||||||
|
delete: Borrar
|
||||||
|
title: Bloques
|
||||||
|
new:
|
||||||
|
back: Volver
|
||||||
|
title: Crear nuevo bloque
|
||||||
|
content_block:
|
||||||
|
body: Contenido
|
||||||
|
name: Nombre
|
||||||
images:
|
images:
|
||||||
index:
|
index:
|
||||||
title: Personalizar imágenes
|
title: Personalizar imágenes
|
||||||
|
|||||||
@@ -226,6 +226,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :site_customization do
|
namespace :site_customization do
|
||||||
resources :pages, except: [:show]
|
resources :pages, except: [:show]
|
||||||
resources :images, only: [:index, :update, :destroy]
|
resources :images, only: [:index, :update, :destroy]
|
||||||
|
resources :content_blocks, except: [:show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class CreateSiteCustomizationContentBlocks < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :site_customization_content_blocks do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :locale
|
||||||
|
t.text :body
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :site_customization_content_blocks, [:name, :locale], unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
12
db/schema.rb
12
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: 20170322145702) do
|
ActiveRecord::Schema.define(version: 20170324101716) 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,16 @@ ActiveRecord::Schema.define(version: 20170322145702) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "site_customization_content_blocks", force: :cascade do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "locale"
|
||||||
|
t.text "body"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "site_customization_content_blocks", ["name", "locale"], name: "index_site_customization_content_blocks_on_name_and_locale", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "site_customization_images", force: :cascade do |t|
|
create_table "site_customization_images", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "image_file_name"
|
t.string "image_file_name"
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ Setting["facebook_handle"] = nil
|
|||||||
Setting["youtube_handle"] = nil
|
Setting["youtube_handle"] = nil
|
||||||
Setting["telegram_handle"] = nil
|
Setting["telegram_handle"] = nil
|
||||||
Setting["blog_url"] = nil
|
Setting["blog_url"] = nil
|
||||||
|
Setting["transparency_url"] = nil
|
||||||
|
Setting["opendata_url"] = "/opendata"
|
||||||
|
|
||||||
# Public-facing URL of the app.
|
# Public-facing URL of the app.
|
||||||
Setting["url"] = "http://example.com"
|
Setting["url"] = "http://example.com"
|
||||||
|
|||||||
@@ -468,4 +468,10 @@ FactoryGirl.define do
|
|||||||
more_info_flag true
|
more_info_flag true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :site_customization_content_block, class: 'SiteCustomization::ContentBlock' do
|
||||||
|
name "top_links"
|
||||||
|
locale "en"
|
||||||
|
body "Some top links content"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
107
spec/features/admin/site_customization/content_blocks_spec.rb
Normal file
107
spec/features/admin/site_customization/content_blocks_spec.rb
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature "Admin custom content blocks" do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Index" do
|
||||||
|
block = create(:site_customization_content_block)
|
||||||
|
visit admin_site_customization_content_blocks_path
|
||||||
|
|
||||||
|
expect(page).to have_content(block.name)
|
||||||
|
expect(page).to have_content(block.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Create" do
|
||||||
|
scenario "Valid custom block" do
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom content blocks"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_content "footer (es)"
|
||||||
|
|
||||||
|
click_link "Create new content block"
|
||||||
|
|
||||||
|
select "footer", from: "site_customization_content_block_name"
|
||||||
|
select "es", from: "site_customization_content_block_locale"
|
||||||
|
fill_in "site_customization_content_block_body", with: "Some custom content"
|
||||||
|
|
||||||
|
click_button "Create Custom content block"
|
||||||
|
|
||||||
|
expect(page).to have_content "footer (es)"
|
||||||
|
expect(page).to have_content "Some custom content"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Invalid custom block" do
|
||||||
|
block = create(:site_customization_content_block)
|
||||||
|
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom content blocks"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content "top_links (en)"
|
||||||
|
|
||||||
|
click_link "Create new content block"
|
||||||
|
|
||||||
|
select "top_links", from: "site_customization_content_block_name"
|
||||||
|
select "en", from: "site_customization_content_block_locale"
|
||||||
|
fill_in "site_customization_content_block_body", with: "Some custom content"
|
||||||
|
|
||||||
|
click_button "Create Custom content block"
|
||||||
|
|
||||||
|
expect(page).to have_content "Content block couldn't be created"
|
||||||
|
expect(page).to have_content "has already been taken"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Update" do
|
||||||
|
scenario "Valid custom block" do
|
||||||
|
block = create(:site_customization_content_block)
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom content blocks"
|
||||||
|
end
|
||||||
|
|
||||||
|
click_link "top_links (en)"
|
||||||
|
|
||||||
|
fill_in "site_customization_content_block_body", with: "Some other custom content"
|
||||||
|
click_button "Update Custom content block"
|
||||||
|
|
||||||
|
expect(page).to have_content "Content block updated successfully"
|
||||||
|
expect(page).to have_content "Some other custom content"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Delete" do
|
||||||
|
scenario "From index page" do
|
||||||
|
block = create(:site_customization_content_block)
|
||||||
|
visit admin_site_customization_content_blocks_path
|
||||||
|
|
||||||
|
expect(page).to have_content("#{block.name} (#{block.locale})")
|
||||||
|
expect(page).to have_content(block.body)
|
||||||
|
|
||||||
|
click_button "Delete"
|
||||||
|
|
||||||
|
expect(page).to_not have_content("#{block.name} (#{block.locale})")
|
||||||
|
expect(page).to_not have_content(block.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "From edit page" do
|
||||||
|
block = create(:site_customization_content_block)
|
||||||
|
visit edit_admin_site_customization_content_block_path(block)
|
||||||
|
|
||||||
|
click_button "Delete"
|
||||||
|
|
||||||
|
expect(page).to_not have_content("#{block.name} (#{block.locale})")
|
||||||
|
expect(page).to_not have_content(block.body)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
33
spec/features/site_customization/content_blocks_spec.rb
Normal file
33
spec/features/site_customization/content_blocks_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature "Custom content blocks" do
|
||||||
|
scenario "top links" do
|
||||||
|
create(:site_customization_content_block, name: "top_links", locale: "en", body: "content for top links")
|
||||||
|
create(:site_customization_content_block, name: "top_links", locale: "es", body: "contenido para top links")
|
||||||
|
|
||||||
|
visit "/?locale=en"
|
||||||
|
|
||||||
|
expect(page).to have_content("content for top links")
|
||||||
|
expect(page).to_not have_content("contenido para top links")
|
||||||
|
|
||||||
|
visit "/?locale=es"
|
||||||
|
|
||||||
|
expect(page).to have_content("contenido para top links")
|
||||||
|
expect(page).to_not have_content("content for top links")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "footer" do
|
||||||
|
create(:site_customization_content_block, name: "footer", locale: "en", body: "content for footer")
|
||||||
|
create(:site_customization_content_block, name: "footer", locale: "es", body: "contenido para footer")
|
||||||
|
|
||||||
|
visit "/?locale=en"
|
||||||
|
|
||||||
|
expect(page).to have_content("content for footer")
|
||||||
|
expect(page).to_not have_content("contenido para footer")
|
||||||
|
|
||||||
|
visit "/?locale=es"
|
||||||
|
|
||||||
|
expect(page).to have_content("contenido para footer")
|
||||||
|
expect(page).to_not have_content("content for footer")
|
||||||
|
end
|
||||||
|
end
|
||||||
20
spec/models/site_customization/content_block_spec.rb
Normal file
20
spec/models/site_customization/content_block_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe SiteCustomization::ContentBlock, type: :model do
|
||||||
|
let(:block) { build(:site_customization_content_block) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(block).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "name is unique per locale" do
|
||||||
|
create(:site_customization_content_block, name: "top_links", locale: "en")
|
||||||
|
invalid_block = build(:site_customization_content_block, name: "top_links", locale: "en")
|
||||||
|
|
||||||
|
expect(invalid_block).to be_invalid
|
||||||
|
expect(invalid_block.errors.full_messages).to include("Name has already been taken")
|
||||||
|
|
||||||
|
valid_block = build(:site_customization_content_block, name: "top_links", locale: "es")
|
||||||
|
expect(valid_block).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user