-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #378 from unepwcmc/refresh-cta
Make CTAs as CMS components
- Loading branch information
Showing
17 changed files
with
325 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class Admin::CallToActionsController < Comfy::Admin::Cms::BaseController | ||
before_action :build_cta, :only => [:new, :create] | ||
before_action :load_cta, :only => [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@ctas = CallToAction.page(params[:page]) | ||
end | ||
|
||
def show | ||
render | ||
end | ||
|
||
def new | ||
render | ||
end | ||
|
||
def edit | ||
render | ||
end | ||
|
||
def create | ||
@cta.save! | ||
flash[:success] = 'Call To Action created' | ||
redirect_to action: :show, id: @cta | ||
rescue ActiveRecord::RecordInvalid | ||
flash.now[:danger] = 'Failed to create Call To Action' | ||
render action: :new | ||
end | ||
|
||
def update | ||
@cta.update_attributes!(cta_params) | ||
flash[:success] = 'Call To Action updated' | ||
redirect_to action: :show, id: @cta | ||
rescue ActiveRecord::RecordInvalid | ||
flash.now[:danger] = 'Failed to update Call To Action' | ||
render action: :edit | ||
end | ||
|
||
def destroy | ||
@cta.destroy | ||
flash[:success] = 'Call To Action deleted' | ||
redirect_to action: :index | ||
end | ||
|
||
protected | ||
|
||
def build_cta | ||
@cta = CallToAction.new(cta_params) | ||
end | ||
|
||
def load_cta | ||
@cta = CallToAction.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
flash[:danger] = 'Call To Action not found' | ||
redirect_to action: :index | ||
end | ||
|
||
def cta_params | ||
params.fetch(:call_to_action, {}).permit(:css_class, :title, :summary, :url, :updated) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CallToAction < ActiveRecord::Base | ||
self.table_name = "comfy_cms_call_to_actions" | ||
|
||
validates :title, | ||
presence: true, | ||
length: {maximum: 75}, | ||
allow_nil: false | ||
validates :summary, | ||
presence: true, | ||
length: {maximum: 150}, | ||
allow_nil: false | ||
validates :url, | ||
presence: true, | ||
length: {maximum: 255}, | ||
allow_nil: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<p>The title may have up to 75 characters and the description may have up to 150.</p> | ||
|
||
<%= form.text_field :css_class, maxlength: 75 %> | ||
<%= form.text_field :title, maxlength: 75 %> | ||
<%= form.text_field :summary, maxlength: 150 %> | ||
<%= form.text_field :url, maxlength: 255 %> | ||
<%= form.check_box :updated %> | ||
<%= form.form_group class: 'form-actions' do %> | ||
<%= form.submit class: 'btn btn-primary' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="page-header"> | ||
<h2>Edit Call To Action</h2> | ||
</div> | ||
<%= comfy_form_with model: @cta, url: {action: :update} do |form| %> | ||
<%= render form %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div class="page-header"> | ||
<%= link_to 'New Call To Action', new_admin_call_to_action_path, class: 'btn btn-secondary float-right', title: 'Create new call to action' %> | ||
<h2>Call To Actions</h2> | ||
</div> | ||
|
||
<table class="table table-hover table-bordered wrap"> | ||
<tr> | ||
<th class="wrap">Class (Max characters: 75)</th> | ||
<th class="wrap">Title (Max characters: 75)</th> | ||
<th class="wrap">Summary (Max characters: 150)</th> | ||
<th class="wrap">Url</th> | ||
<th>Updated</th> | ||
<th></th> | ||
</tr> | ||
<% @ctas.each do |cta| %> | ||
<tr> | ||
<td class="wrap"><%= cta.css_class %></td> | ||
<td class="wrap"><%= cta.title %></td> | ||
<td class="wrap"><%= cta.summary %></td> | ||
<td class="wrap"><%= cta.url %></td> | ||
<td><%= cta.updated.to_s %></td> | ||
<td> | ||
<div class="btn-group btn-group-sm"> | ||
<%= link_to 'Edit', edit_admin_call_to_action_path(cta), :class => 'btn btn-outline-secondary' %> | ||
<%= link_to 'Delete', admin_call_to_action_path(cta), :method => :delete, :data => { :confirm => 'Are you sure?' }, :class => 'btn btn-danger' %> | ||
</div> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="page-header"> | ||
<h2>New Call To Action</h2> | ||
</div> | ||
<%= comfy_form_with model: @cta, url: {action: :create} do |form| %> | ||
<%= render form %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div class="page-header"> | ||
<h2>Call To Action</h2> | ||
</div> | ||
<p> | ||
<strong>CSS Class:</strong> | ||
<%= @cta.css_class %> | ||
</p> | ||
<p> | ||
<strong>Title:</strong> | ||
<%= @cta.title %> | ||
</p> | ||
<p> | ||
<strong>Summary:</strong> | ||
<%= @cta.summary %> | ||
</p> | ||
<p> | ||
<strong>Url:</strong> | ||
<%= @cta.url %> | ||
</p> | ||
<p> | ||
<strong>Updated:</strong> | ||
<%= @cta.updated.to_s %> | ||
</p> | ||
<%= link_to 'View all', admin_call_to_actions_path, class: 'btn btn-primary' %> |
5 changes: 5 additions & 0 deletions
5
app/views/comfy/admin/cms/partials/_navigation_inner.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- %li= active_link_to 'HomeCarouselSlides', admin_home_carousel_slides_path --> | ||
|
||
<li class="nav-item"> | ||
<%= link_to 'Call To Actions', admin_call_to_actions_path, class: 'nav-link', title: 'View Call to Actions' %> | ||
</li> |
2 changes: 0 additions & 2 deletions
2
app/views/comfy/admin/cms/partials/_navigation_inner.html.haml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<section class="cta--api container"> | ||
<div class="cta__container bg--grey-black"> | ||
<div class="cta__content"> | ||
<h2 class="h2-big-white"><%= t('ctas.api.title') %></h2> | ||
<p class="text-intro"><%= t('ctas.api.intro') %></p> | ||
<%= link_to t('ctas.api.button'), t('ctas.api.url'), target: '_blank', class: 'button--outline-white' %> | ||
<h2 class="h2-big-white"><%= cta_api.title %></h2> | ||
<p class="text-intro"><%= cta_api.summary %></p> | ||
|
||
<%= link_to t('ctas.api.button'), cta_api.url, target: '_blank', class: 'button--outline-white' %> | ||
</div> | ||
</div> | ||
</section> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<section class="cta--live-report bg--grey-xdark"> | ||
<section class="cta--<%= cta_live_report.css_class %> bg--grey-xdark"> | ||
<div class="container cta__container"> | ||
<div class="cta__content"> | ||
<span class="cta__ribbon"><%= t('global.status.updated') %></span> | ||
<% if cta_live_report.updated %> | ||
<span class="cta__ribbon"><%= t('global.status.updated') %></span> | ||
<% end %> | ||
|
||
<div> | ||
<h2 class="cta__title h2-big"><%= t('ctas.live_report.title') %></h2> | ||
<p class="text-intro"><%= t('ctas.live_report.intro') %></p> | ||
<h2 class="cta__title h2-big"><%= cta_live_report.title %></h2> | ||
<p class="text-intro"><%= cta_live_report.summary %></p> | ||
</div> | ||
|
||
<%= link_to t('ctas.live_report.button'), t('ctas.live_report.url'), target: '_blank', class: 'button--accent' %> | ||
<%= link_to t('ctas.live_report.button'), cta_live_report.url, target: '_blank', class: 'button--accent' %> | ||
</div> | ||
</div> | ||
</section> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
test/controllers/admin/call_to_actions_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require_relative '../../test_helper' | ||
|
||
class Admin::CallToActionsControllerTest < ActionController::TestCase | ||
|
||
def setup | ||
@cta = FactoryGirl.create(:call_to_action) | ||
@site = ::Comfy::Cms::Site.create(label: 'test', identifier: 'test', hostname: 'localhost') | ||
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("#{ComfortableMexicanSofa::AccessControl::AdminAuthentication.username}:#{ComfortableMexicanSofa::AccessControl::AdminAuthentication.password}") | ||
end | ||
|
||
def test_get_index | ||
get :index | ||
assert_response :success | ||
assert assigns(:ctas) | ||
assert_template :index | ||
end | ||
|
||
def test_get_show | ||
get :show, params: {id: @cta} | ||
assert_response :success | ||
assert assigns(:cta) | ||
assert_template :show | ||
end | ||
|
||
def test_get_show_failure | ||
get :show, params: {id: 'invalid'} | ||
assert_response :redirect | ||
assert_redirected_to action: :index | ||
assert_equal 'Call To Action not found', flash[:danger] | ||
end | ||
|
||
def test_get_new | ||
get :new | ||
assert_response :success | ||
assert assigns(:cta) | ||
assert_template :new | ||
end | ||
|
||
def test_get_edit | ||
get :edit, params: {id: @cta} | ||
assert_response :success | ||
assert assigns(:cta) | ||
assert_template :edit | ||
end | ||
|
||
def test_creation | ||
assert_difference 'CallToAction.count' do | ||
post :create, params: { | ||
call_to_action: { | ||
title: 'test title', | ||
summary: 'test summary', | ||
url: 'test url' | ||
} | ||
} | ||
cta = CallToAction.last | ||
assert_response :redirect | ||
assert_redirected_to admin_call_to_action_path(cta) | ||
assert_equal 'Call To Action created', flash[:success] | ||
end | ||
end | ||
|
||
def test_creation_failure | ||
assert_no_difference 'CallToAction.count' do | ||
post :create, params: {call_to_action: {}} | ||
assert_response :success | ||
assert_template :new | ||
assert_equal 'Failed to create Call To Action', flash[:danger] | ||
end | ||
end | ||
|
||
def test_update | ||
put :update, params: { | ||
id: @cta, | ||
call_to_action: { | ||
title: 'Updated' | ||
} | ||
} | ||
assert_response :redirect | ||
assert_redirected_to action: :show, id: @cta | ||
assert_equal 'Call To Action updated', flash[:success] | ||
@cta.reload | ||
assert_equal 'Updated', @cta.title | ||
end | ||
|
||
def test_update_failure | ||
put :update, params: { | ||
id: @cta, | ||
call_to_action: { | ||
title: '' | ||
} | ||
} | ||
assert_response :success | ||
assert_template :edit | ||
assert_equal 'Failed to update Call To Action', flash[:danger] | ||
@cta.reload | ||
refute_equal '', @cta.title | ||
end | ||
|
||
def test_destroy | ||
assert_difference 'CallToAction.count', -1 do | ||
delete :destroy, params: {id: @cta} | ||
assert_response :redirect | ||
assert_redirected_to action: :index | ||
assert_equal 'Call To Action deleted', flash[:success] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryGirl.define do | ||
factory :call_to_action do | ||
css_class 'css_class' | ||
title 'Title' | ||
summary 'Summary' | ||
url 'URL' | ||
updated false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require_relative '../test_helper' | ||
|
||
class CallToActionTest < ActiveSupport::TestCase | ||
|
||
def test_fixtures_validity | ||
CallToAction.all.each do |cta| | ||
assert cta.valid?, cta.errors.inspect | ||
end | ||
end | ||
|
||
def test_validation | ||
cta = CallToAction.new | ||
assert cta.invalid? | ||
assert_equal [:title, :summary, :url], cta.errors.keys | ||
end | ||
|
||
def test_creation | ||
assert_difference 'CallToAction.count' do | ||
CallToAction.create( | ||
css_class: 'css_class', | ||
title: 'test title', | ||
summary: 'test summary', | ||
url: 'test url' | ||
) | ||
end | ||
end | ||
|
||
end |