Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0' into feature/refactor_taggings
Browse files Browse the repository at this point in the history
  • Loading branch information
seawolf committed Jul 11, 2015
2 parents f3db280 + 9174434 commit 2cba22c
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Gemfile.next
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ruby '2.2.2'
# Application
gem 'airbrake', '~> 4.0.0'
gem 'rails', '~> 4.0.0'
gem 'unicorn'
gem 'puma'

# Views
gem 'jquery-rails', '~> 3.1.2'
Expand Down
25 changes: 0 additions & 25 deletions app/controllers/admin/shop_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,6 @@ def destroy
redirect_to admin_shop_index_path
end

def update_delivery_opts
new_opts = params[:delivery_opts]
content = StaticContent.find_by_page_and_part("shop", "delivery_opts")
if content
content.body = new_opts
if content.save
flash[:info] = I18n.t('admin.update_successful', :page => "delivery")
else
flash[:error] = I18n.t('admin.update_failed', :page => "delivery")
end
else
content = StaticContent.new
content.page = "shop"
content.part = "delivery_opts"
content.body = new_opts
if content.save
flash[:info] = I18n.t('admin.create_successful', :page => "delivery")
else
flash[:error] = I18n.t('admin.create_failed', :page => "delivery")
end
end

redirect_to admin_shop_index_path
end

def move_to_portfolio
source = begin
ShopItem.find_by_id(params[:id])
Expand Down
30 changes: 30 additions & 0 deletions app/controllers/admin/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@ def update_about
render :edit_about
end

def edit_delivery_info
@body_text = StaticContent.load("delivery_info", "text")
end

def update_delivery_info
body_text = params[:content]
content = StaticContent.find_by_page_and_part("delivery_info", "text")
if content
content.body = body_text
if content.save
flash[:info] = I18n.t('admin.update_successful', :page => "delivery info")
else
flash[:error] = I18n.t('admin.update_failed', :page => "delivery info")
end
else
content = StaticContent.new
content.page = "delivery_info"
content.part = "text"
content.body = body_text
if content.save
flash[:info] = I18n.t('admin.create_successful', :page => "delivery info")
else
flash[:error] = I18n.t('admin.create_failed', :page => "delivery info")
end
end

@body_text = content.body
render :edit_delivery_info
end

def edit_contact
@email_address = StaticContent.load("contact", "email")
@body_text = StaticContent.load("contact", "text")
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/shop_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class ShopController < ApplicationController
def index
@delivery_opts = StaticContent.load("shop", "delivery_opts")

if params[:category]
@items = []
@titles = []
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def about
@body_text = StaticContent.load("about", "text")
end

def delivery_info
@body_text = StaticContent.load("delivery_info", "text")
end

def contact
@contact_email = StaticContent.load("contact", "email")
@body_text = StaticContent.load("contact", "text")
Expand Down
9 changes: 1 addition & 8 deletions app/views/admin/shop/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,4 @@
</tbody>
</table>

<%= link_to I18n.t('admin.shop.create'), new_admin_shop_path, { class: "btn btn-primary", type: "button" } %>

<%= form_tag admin_shop_update_delivery_opts_path, id: "delivery-opts-admin" do %>
<h3><%= I18n.t('shop.delivery_opts') %></h3>
<%= text_area_tag :delivery_opts, @delivery_opts, class: "tinymce" %>
<br />
<%= submit_tag I18n.t('admin.shop.update_delivery_opts'), { class: "btn btn-success" } %>
<%- end -%>
<%= link_to I18n.t('admin.shop.create'), new_admin_shop_path, { class: "btn btn-primary", type: "button" } %>
5 changes: 5 additions & 0 deletions app/views/admin/static_pages/edit_delivery_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2><%= t('admin.page_editing') + I18n.t('page_titles.delivery_info') -%></h2>
<%= form_tag admin_content_delivery_info_path do %>
<%= text_area_tag :content, @body_text, class: "tinymce span11", rows: 20 %>
<%= submit_tag "Save", class: "span3" %>
<% end %>
1 change: 1 addition & 0 deletions app/views/layouts/_admin_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<li class="<%= "active" if active_action?("static_pages", "edit_home") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.home'), admin_content_home_path -%></li>
<li class="<%= "active" if active_action?("static_pages", "edit_about") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.about'), admin_content_about_path -%></li>
<li class="<%= "active " if active_action?("shop") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.shop'), admin_shop_index_path -%></li>
<li class="<%= "active" if active_action?("static_pages", "delivery_info") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.delivery_info'), admin_content_delivery_info_path -%></li>
<li class="<%= "active " if active_action?("portfolio") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.portfolio'), admin_portfolio_index_path -%></li>
<!--li class="<%= "active " if active_action?("blog") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.blog'), "#" -%></li-->
<li class="<%= "active" if active_action?("static_pages", "edit_contact") -%>"><%= link_to I18n.t('admin.page_editing') + I18n.t('page_titles.contact'), admin_content_contact_path -%></li>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/_public_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<li class="<%= "active" if active_action?("static_pages", "about") -%>"><%= link_to I18n.t('page_titles.about'), about_path -%></li>
<li class="<%= "active " if active_action?("shop") -%>"><%= link_to I18n.t('page_titles.shop'), shop_index_path -%></li>
<%= render partial: "shop_categories" if active_action?("shop") -%>
<li class="<%= "active" if active_action?("static_pages", "delivery_info") -%>"><%= link_to I18n.t('page_titles.delivery_info'), delivery_info_path -%></li>
<li class="<%= "active " if active_action?("portfolio") -%>"><%= link_to I18n.t('page_titles.portfolio'), portfolio_index_path -%></li>
<%= render partial: "portfolio_categories" if active_action?("portfolio") -%>
<!--li class="<%= "active " if active_action?("blog") -%>"><%= link_to I18n.t('page_titles.blog'), root_path -%></li-->
Expand Down
5 changes: 0 additions & 5 deletions app/views/shop/_index_categories.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@
<p><%= I18n.t('shop.none_found') %></p>
<%- end -%>
</div>

<div id="delivery-opts" class="span11">
<h3><%= I18n.t('shop.delivery_opts') %></h3>
<%= raw(@delivery_opts) %>
</div>
3 changes: 3 additions & 0 deletions app/views/static_pages/delivery_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- content_for :title do I18n.t('page_titles.delivery_info') end -%>

<%= raw(@body_text) -%>
3 changes: 1 addition & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en:
page_titles:
home: "Home"
about: "About Me"
delivery_info: "Purchase and Delivery Info"
shop: "For Sale"
shop_category: "For Sale - %{category}"
portfolio_category: "Past Work - %{category}"
Expand All @@ -21,7 +22,6 @@ en:
shop:
subhead_categories: "Click on a category to see the items inside."
subhead_category: "Click on a item to see more photos, information and pricing."
delivery_opts: "Delivery Options"
quantity_available: "%{q} available, "
none_found: "Sorry, no items were found."
none_found_category: "Sorry, no items were found in that category."
Expand Down Expand Up @@ -60,5 +60,4 @@ en:
edit: "Edit"
update: "Update"
destroy: "Remove"
update_delivery_opts: "Update Delivery Options"
move: "Move to Portfolio"
16 changes: 9 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
post "make_contact" => "static_pages#make_contact"

get "about" => "static_pages#about"
get "delivery_info" => "static_pages#delivery_info"

resources :portfolio
get 'portfolio/category/:category', to: 'portfolio#index', as: :portfolio_item_category
Expand All @@ -18,18 +19,19 @@

get "admin" => "application#admin"
namespace :admin do
get "content/home", controller: :static_pages, action: :edit_home
post "content/home", controller: :static_pages, action: :update_home
get "content/about", controller: :static_pages, action: :edit_about
post "content/about", controller: :static_pages, action: :update_about
get "content/contact", controller: :static_pages, action: :edit_contact
post "content/contact", controller: :static_pages, action: :update_contact
get "content/home", controller: :static_pages, action: :edit_home
post "content/home", controller: :static_pages, action: :update_home
get "content/about", controller: :static_pages, action: :edit_about
post "content/about", controller: :static_pages, action: :update_about
get "content/delivery_info", controller: :static_pages, action: :edit_delivery_info
post "content/delivery_info", controller: :static_pages, action: :update_delivery_info
get "content/contact", controller: :static_pages, action: :edit_contact
post "content/contact", controller: :static_pages, action: :update_contact

resources :portfolio
get 'portfolio/:id/move_to_shop' => 'portfolio#move_to_shop', as: 'move_portfolio_to_shop'

resources :shop
post "shop/update_delivery_opts", controller: :shop, action: :update_delivery_opts
get 'shop/:id/move_to_portfolio' => 'shop#move_to_portfolio', as: 'move_shop_to_portfolio'
end

Expand Down
3 changes: 2 additions & 1 deletion config/tinymce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ theme_advanced_toolbar_align: left
theme_advanced_statusbar_location: bottom
plugins:
- table
- fullscreen
- image
- link
25 changes: 0 additions & 25 deletions spec/controllers/admin/shop_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,6 @@
end
end

context "POST update_delivery_opts" do
it "should create delivery options when none exist" do
StaticContent.delete_all
post :update_delivery_opts, { "delivery_opts" => "New Content" }
flash[:info].should == "Successfully created delivery content."
c = StaticContent.last
c.page.should == "shop"
c.part.should == "delivery_opts"
c.body.should == "New Content"
response.should redirect_to(admin_shop_index_path)
end

it "should update delivery options when some exist" do
StaticContent.delete_all
post :update_delivery_opts, { "delivery_opts" => "New Content" }
post :update_delivery_opts, { "delivery_opts" => "Newer Content" }
flash[:info].should == "Successfully updated delivery content."
c = StaticContent.last
c.page.should == "shop"
c.part.should == "delivery_opts"
c.body.should == "Newer Content"
response.should redirect_to(admin_shop_index_path)
end
end

context "GET move_to_portfolio" do
before(:each) do
PortfolioItem.delete_all
Expand Down
55 changes: 55 additions & 0 deletions spec/controllers/admin/static_pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
end
end

describe "GET 'edit_delivery_info'" do
it "should redirect to the login page" do
get 'edit_delivery_info'
response.should redirect_to new_user_session_path
end
end

describe "GET 'edit_contact'" do
it "should redirect to the login page" do
get 'edit_contact'
Expand All @@ -38,6 +45,13 @@
end
end

describe "POST 'update_delivery_info'" do
it "should redirect to the login page" do
post 'update_delivery_info'
response.should redirect_to new_user_session_path
end
end

describe "POST 'update_contact'" do
it "should redirect to the login page" do
post 'update_contact'
Expand Down Expand Up @@ -79,6 +93,19 @@
end
end

describe "GET 'edit_delivery_info'" do
it "should render the template" do
get 'edit_delivery_info'
response.should be_success
response.should render_template :edit_delivery_info
end

it "should load the body text" do
StaticContent.should_receive(:load).with("delivery_info", "text").once
get 'edit_delivery_info'
end
end

describe "GET 'edit_contact'" do
it "should render the template" do
get 'edit_contact'
Expand Down Expand Up @@ -149,6 +176,34 @@
end
end

describe "POST 'update_delivery_info'" do
it "should not redirect to the login page" do
post 'update_delivery_info'
response.should_not redirect_to new_user_session_path
end

it "should set a new body text" do
StaticContent.delete_all
post 'update_delivery_info', { "content" => "New Content" }
flash[:info].should == "Successfully created delivery info content."
c = StaticContent.last
c.page.should == "delivery_info"
c.part.should == "text"
c.body.should == "New Content"
end

it "should update the body text" do
StaticContent.delete_all
post 'update_delivery_info', { "content" => "New Content" }
post 'update_delivery_info', { "content" => "Newer Content" }
flash[:info].should == "Successfully updated delivery info content."
c = StaticContent.last
c.page.should == "delivery_info"
c.part.should == "text"
c.body.should == "Newer Content"
end
end

describe "POST 'update_contact'" do
it "should not redirect to the login page" do
post 'update_contact'
Expand Down
17 changes: 16 additions & 1 deletion spec/controllers/static_pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end
end

describe "GET #about" do
describe "GET #about" do
before :each do
get :about
end
Expand All @@ -31,6 +31,21 @@
end
end

describe "GET #delivery_info" do
before :each do
get :delivery_info
end

it "should exist" do
response.code.should == "200"
lambda { get :about }.should_not raise_error(ActionController::RoutingError)
end

it "should display the Delivery Info page" do
response.should render_template("delivery_info")
end
end

describe "GET #contact" do
before :each do
get :contact
Expand Down

0 comments on commit 2cba22c

Please sign in to comment.