mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
commit
18b08964f4
16
.rubocop.yml
Normal file
16
.rubocop.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
Metrics/LineLength:
|
||||||
|
Max: 120
|
||||||
|
|
||||||
|
Documentation:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
AllCops:
|
||||||
|
Include:
|
||||||
|
- '**/Rakefile'
|
||||||
|
- '**/config.ru'
|
||||||
|
Exclude:
|
||||||
|
- 'db/**/*'
|
||||||
|
- 'config/**/*'
|
||||||
|
- 'script/**/*'
|
||||||
|
- 'bin/**/*'
|
||||||
|
- !ruby/regexp /old_and_unused\.rb$/
|
||||||
1
Gemfile
1
Gemfile
@ -47,6 +47,7 @@ end
|
|||||||
|
|
||||||
group :test, :development do
|
group :test, :development do
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
|
gem 'rubocop'
|
||||||
gem 'pry'
|
gem 'pry'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
18
Gemfile.lock
18
Gemfile.lock
@ -35,6 +35,9 @@ GEM
|
|||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
addressable (2.3.8)
|
addressable (2.3.8)
|
||||||
arel (5.0.1.20140414130214)
|
arel (5.0.1.20140414130214)
|
||||||
|
ast (2.1.0)
|
||||||
|
astrolabe (1.3.1)
|
||||||
|
parser (~> 2.2)
|
||||||
aws-sdk (2.1.29)
|
aws-sdk (2.1.29)
|
||||||
aws-sdk-resources (= 2.1.29)
|
aws-sdk-resources (= 2.1.29)
|
||||||
aws-sdk-core (2.1.29)
|
aws-sdk-core (2.1.29)
|
||||||
@ -149,6 +152,8 @@ GEM
|
|||||||
nokogiri (1.6.6.2)
|
nokogiri (1.6.6.2)
|
||||||
mini_portile (~> 0.6.0)
|
mini_portile (~> 0.6.0)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
|
parser (2.2.3.0)
|
||||||
|
ast (>= 1.1, < 3.0)
|
||||||
pg (0.18.3)
|
pg (0.18.3)
|
||||||
poltergeist (1.7.0)
|
poltergeist (1.7.0)
|
||||||
capybara (~> 2.1)
|
capybara (~> 2.1)
|
||||||
@ -159,6 +164,7 @@ GEM
|
|||||||
activerecord (>= 3.0)
|
activerecord (>= 3.0)
|
||||||
powder (0.3.0)
|
powder (0.3.0)
|
||||||
thor (>= 0.11.5)
|
thor (>= 0.11.5)
|
||||||
|
powerpack (0.1.1)
|
||||||
pry (0.10.2)
|
pry (0.10.2)
|
||||||
coderay (~> 1.1.0)
|
coderay (~> 1.1.0)
|
||||||
method_source (~> 0.8.1)
|
method_source (~> 0.8.1)
|
||||||
@ -187,6 +193,7 @@ GEM
|
|||||||
activesupport (= 4.1.13)
|
activesupport (= 4.1.13)
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
thor (>= 0.18.1, < 2.0)
|
thor (>= 0.18.1, < 2.0)
|
||||||
|
rainbow (2.0.0)
|
||||||
rake (10.4.2)
|
rake (10.4.2)
|
||||||
redcarpet (3.3.3)
|
redcarpet (3.3.3)
|
||||||
responders (1.1.2)
|
responders (1.1.2)
|
||||||
@ -208,6 +215,13 @@ GEM
|
|||||||
rspec-mocks (~> 3.3.0)
|
rspec-mocks (~> 3.3.0)
|
||||||
rspec-support (~> 3.3.0)
|
rspec-support (~> 3.3.0)
|
||||||
rspec-support (3.3.0)
|
rspec-support (3.3.0)
|
||||||
|
rubocop (0.34.2)
|
||||||
|
astrolabe (~> 1.3)
|
||||||
|
parser (>= 2.2.2.5, < 3.0)
|
||||||
|
powerpack (~> 0.1)
|
||||||
|
rainbow (>= 1.99.1, < 3.0)
|
||||||
|
ruby-progressbar (~> 1.4)
|
||||||
|
ruby-progressbar (1.7.5)
|
||||||
ruby_parser (3.7.1)
|
ruby_parser (3.7.1)
|
||||||
sexp_processor (~> 4.1)
|
sexp_processor (~> 4.1)
|
||||||
sass (3.4.19)
|
sass (3.4.19)
|
||||||
@ -300,6 +314,7 @@ DEPENDENCIES
|
|||||||
rails_12factor
|
rails_12factor
|
||||||
redcarpet
|
redcarpet
|
||||||
rspec-rails
|
rspec-rails
|
||||||
|
rubocop
|
||||||
ruby_parser
|
ruby_parser
|
||||||
sass-rails (~> 5.0.0)
|
sass-rails (~> 5.0.0)
|
||||||
shoulda
|
shoulda
|
||||||
@ -314,6 +329,3 @@ DEPENDENCIES
|
|||||||
uglifier
|
uglifier
|
||||||
unf
|
unf
|
||||||
will_paginate
|
will_paginate
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.10.6
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
class Admin::AdminController < ApplicationController
|
module Admin
|
||||||
|
class AdminController < ApplicationController
|
||||||
layout 'admin/layouts/admin'
|
layout 'admin/layouts/admin'
|
||||||
before_filter :authenticate_admin_user!
|
before_filter :authenticate_admin_user!
|
||||||
before_filter :admin_menu
|
before_filter :admin_menu
|
||||||
@ -13,3 +14,4 @@ class Admin::AdminController < ApplicationController
|
|||||||
pages: '' }
|
pages: '' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class Admin::AdminUsersController < Admin::AdminController
|
module Admin
|
||||||
|
class AdminUsersController < Admin::AdminController
|
||||||
def index
|
def index
|
||||||
@admin_users = AdminUser.all
|
@admin_users = AdminUser.all
|
||||||
end
|
end
|
||||||
@ -25,14 +25,12 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
def create
|
def create
|
||||||
@admin_user = AdminUser.new(permitted_params)
|
@admin_user = AdminUser.new(permitted_params)
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @admin_user.save
|
if @admin_user.save
|
||||||
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
|
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
|
||||||
else
|
else
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@admin_user = AdminUser.find(params[:id])
|
@admin_user = AdminUser.find(params[:id])
|
||||||
@ -51,7 +49,7 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
|
|
||||||
if @admin_user.update_with_password(permitted_params)
|
if @admin_user.update_with_password(permitted_params)
|
||||||
sign_in @admin_user, bypass: true
|
sign_in @admin_user, bypass: true
|
||||||
redirect_to admin_dashboard_path, notice: "Password updated!"
|
redirect_to admin_dashboard_path, notice: 'Password updated!'
|
||||||
else
|
else
|
||||||
render :edit_password
|
render :edit_password
|
||||||
end
|
end
|
||||||
@ -62,5 +60,5 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
def permitted_params
|
def permitted_params
|
||||||
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
|
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class Admin::CategoriesController < Admin::AdminController
|
module Admin
|
||||||
|
class CategoriesController < Admin::AdminController
|
||||||
def index
|
def index
|
||||||
@categories = Category.all
|
@categories = Category.all
|
||||||
end
|
end
|
||||||
@ -44,5 +44,5 @@ class Admin::CategoriesController < Admin::AdminController
|
|||||||
def permitted_params
|
def permitted_params
|
||||||
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
|
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,26 +1,19 @@
|
|||||||
class Admin::ConfirmationsController < ::Devise::PasswordsController
|
module Admin
|
||||||
layout "admin/layouts/login"
|
class ConfirmationsController < ::Devise::PasswordsController
|
||||||
|
layout 'admin/layouts/login'
|
||||||
|
|
||||||
skip_before_filter(:authenticate_user!)
|
skip_before_filter(:authenticate_user!)
|
||||||
|
|
||||||
def update
|
def update
|
||||||
with_unconfirmed_confirmable do
|
with_unconfirmed_confirmable do
|
||||||
if @confirmable.has_no_password?
|
if @confirmable.has_no_password?
|
||||||
@confirmable.attempt_set_password(params[:admin_user])
|
update_password
|
||||||
if @confirmable.valid?
|
|
||||||
do_confirm
|
|
||||||
else
|
else
|
||||||
do_show
|
self.class.add_error_on(self, :email, :password_already_set)
|
||||||
@confirmable.errors.clear #so that we wont render :new
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self.class.add_error_on(self, :email, :password_allready_set)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@confirmable.errors.empty?
|
render_with_scope :new unless confirmable.errors.empty?
|
||||||
render_with_scope :new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ -31,8 +24,19 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
do_confirm
|
do_confirm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if !@confirmable.errors.empty?
|
|
||||||
render_with_scope :new
|
render_with_scope :new unless @confirmable.errors.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def update_password
|
||||||
|
@confirmable.attempt_set_password(params[:admin_user])
|
||||||
|
if @confirmable.valid?
|
||||||
|
do_confirm
|
||||||
|
else
|
||||||
|
do_show
|
||||||
|
@confirmable.errors.clear # so that we won't render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -40,9 +44,8 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
|
|
||||||
def with_unconfirmed_confirmable
|
def with_unconfirmed_confirmable
|
||||||
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
|
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
|
||||||
if !@confirmable.new_record?
|
|
||||||
@confirmable.only_if_unconfirmed {yield}
|
@confirmable.only_if_unconfirmed { yield } unless @confirmable.new_record?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_show
|
def do_show
|
||||||
@ -58,3 +61,4 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
sign_in_and_redirect(resource_name, @confirmable)
|
sign_in_and_redirect(resource_name, @confirmable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,2 +1,4 @@
|
|||||||
class Admin::DashboardController < Admin::AdminController
|
module Admin
|
||||||
|
class DashboardController < Admin::AdminController
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class Admin::PagesController < Admin::AdminController
|
module Admin
|
||||||
|
class PagesController < Admin::AdminController
|
||||||
def index
|
def index
|
||||||
@pages = Page.all
|
@pages = Page.all
|
||||||
end
|
end
|
||||||
@ -49,5 +49,5 @@ class Admin::PagesController < Admin::AdminController
|
|||||||
def permitted_params
|
def permitted_params
|
||||||
params.require(:page).permit(:name, :title, :content)
|
params.require(:page).permit(:name, :title, :content)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
class Admin::PasswordsController < ::Devise::PasswordsController
|
module Admin
|
||||||
layout "admin/layouts/login"
|
class PasswordsController < ::Devise::PasswordsController
|
||||||
|
layout 'admin/layouts/login'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
class Admin::PhotosController < Admin::AdminController
|
module Admin
|
||||||
before_filter :get_categories
|
class PhotosController < Admin::AdminController
|
||||||
|
before_filter :categories
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@photos = Photo.paginate(page: params[:page], per_page: 16)
|
@photos = Photo.paginate(page: params[:page], per_page: 16)
|
||||||
@ -42,12 +43,13 @@ class Admin::PhotosController < Admin::AdminController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_categories
|
def categories
|
||||||
@categories = Category.all
|
@categories = Category.all
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_params
|
def permitted_params
|
||||||
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured, :enabled, :taken_at, category_ids: [])
|
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured,
|
||||||
|
:enabled, :taken_at, category_ids: [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
class Admin::RegistrationsController < ::Devise::RegistrationsController
|
module Admin
|
||||||
layout "admin/layouts/login"
|
class RegistrationsController < ::Devise::RegistrationsController
|
||||||
|
layout 'admin/layouts/login'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
class Admin::SessionsController < ::Devise::SessionsController
|
module Admin
|
||||||
layout "admin/layouts/login"
|
class SessionsController < ::Devise::SessionsController
|
||||||
|
layout 'admin/layouts/login'
|
||||||
|
|
||||||
before_filter :check_https
|
before_filter :check_https
|
||||||
|
|
||||||
@ -10,3 +11,4 @@ class Admin::SessionsController < ::Devise::SessionsController
|
|||||||
flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https'
|
flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
class Admin::UnlocksController < ::Devise::UnlocksController
|
module Admin
|
||||||
layout "admin/layouts/login"
|
class UnlocksController < ::Devise::UnlocksController
|
||||||
|
layout 'admin/layouts/login'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,16 +3,15 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
||||||
|
|
||||||
def after_sign_in_path_for(resource_or_scope)
|
def after_sign_in_path_for(*)
|
||||||
admin_dashboard_path
|
admin_dashboard_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sign_out_path_for(resource_or_scope)
|
def after_sign_out_path_for(*)
|
||||||
new_admin_user_session_path
|
new_admin_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_404
|
def render_404
|
||||||
render 'errors/not_found', status: :not_found
|
render 'errors/not_found', status: :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,5 +26,4 @@ class CategoriesController < ApplicationController
|
|||||||
format.xml { render xml: @category }
|
format.xml { render xml: @category }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,9 +7,9 @@ class ContactsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@contact = Contact.new(params[:contact])
|
@contact = Contact.new(params[:contact])
|
||||||
if @contact.save
|
if @contact.save
|
||||||
redirect_to(:new_contact, notice: t("contact.thanks"))
|
redirect_to(:new_contact, notice: t('contact.thanks'))
|
||||||
else
|
else
|
||||||
flash[:alert] = t("contact.invalid")
|
flash[:alert] = t('contact.invalid')
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
class PhotosController < ApplicationController
|
class PhotosController < ApplicationController
|
||||||
def index
|
def index
|
||||||
if params[:category_id]
|
if params[:category_id]
|
||||||
@category = Category.find_by_id(params[:category_id])
|
for_category(params[:category_id])
|
||||||
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
|
|
||||||
@page_title = @category.name
|
|
||||||
else
|
else
|
||||||
@photos = Photo.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
|
all
|
||||||
@page_title = 'All Photos'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@num_blank = 11 - @photos.length
|
@num_blank = 11 - @photos.length
|
||||||
@ -25,4 +22,19 @@ class PhotosController < ApplicationController
|
|||||||
head :not_found
|
head :not_found
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def for_category(category_id)
|
||||||
|
@category = Category.find_by_id(category_id)
|
||||||
|
@photos = @category.photos.enabled.order { taken_at.desc }
|
||||||
|
.paginate(page: params[:page], per_page: 11)
|
||||||
|
@page_title = @category.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def all
|
||||||
|
@photos = Photo.enabled.order { taken_at.desc }
|
||||||
|
.paginate(page: params[:page], per_page: 11)
|
||||||
|
@page_title = 'All Photos'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
module Admin::AdminHelper
|
module Admin
|
||||||
def inputs_field_set &block
|
module AdminHelper
|
||||||
|
def inputs_field_set(&block)
|
||||||
field_set_tag nil, class: :inputs, &block
|
field_set_tag nil, class: :inputs, &block
|
||||||
end
|
end
|
||||||
|
|
||||||
def actions_field_set &block
|
def actions_field_set(&block)
|
||||||
field_set_tag nil, class: :actions, &block
|
field_set_tag nil, class: :actions, &block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
module Admin::DashboardHelper
|
|
||||||
end
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
module Admin::DownloadsHelper
|
|
||||||
end
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
module Admin::UnlocksHelper
|
|
||||||
end
|
|
||||||
@ -3,8 +3,6 @@ class Notifier < ActionMailer::Base
|
|||||||
|
|
||||||
def contact_notification(sender)
|
def contact_notification(sender)
|
||||||
@sender = sender
|
@sender = sender
|
||||||
mail( to: 'enquiries@danbarberphoto.com',
|
mail(to: 'enquiries@danbarberphoto.com', from: sender.email, subject: sender.subject)
|
||||||
from: sender.email,
|
|
||||||
subject: sender.subject)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,11 +5,7 @@ class Heartbeat
|
|||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
if env['PATH_INFO'] == '/heartbeat'
|
if env['PATH_INFO'] == '/heartbeat'
|
||||||
[
|
[200, { 'Content-Type' => 'text/plain' }, ['OK']]
|
||||||
200,
|
|
||||||
{"Content-Type" => "text/plain"},
|
|
||||||
["OK"]
|
|
||||||
]
|
|
||||||
else
|
else
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,8 +10,8 @@ class AdminUser < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# new function to return whether a password has been set
|
# new function to return whether a password has been set
|
||||||
def has_no_password?
|
def no_password?
|
||||||
self.encrypted_password.blank?
|
encrypted_password.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
# new function to provide access to protected method unless_confirmed
|
# new function to provide access to protected method unless_confirmed
|
||||||
|
|||||||
@ -9,12 +9,12 @@ class Contact
|
|||||||
|
|
||||||
def initialize(attributes = {})
|
def initialize(attributes = {})
|
||||||
attributes.each do |key, value|
|
attributes.each do |key, value|
|
||||||
self.send("#{key}=", value)
|
send("#{key}=", value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_attribute_for_validation(key)
|
def read_attribute_for_validation(key)
|
||||||
self.send(key)
|
send(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
@ -22,7 +22,6 @@ class Contact
|
|||||||
Notifier.contact_notification(self).deliver
|
Notifier.contact_notification(self).deliver
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,32 +1,30 @@
|
|||||||
class Photo < ActiveRecord::Base
|
class Photo < ActiveRecord::Base
|
||||||
|
|
||||||
has_and_belongs_to_many :categories
|
has_and_belongs_to_many :categories
|
||||||
|
|
||||||
dragonfly_accessor :image
|
dragonfly_accessor :image
|
||||||
|
|
||||||
validates :image, presence: true
|
validates :image, presence: true
|
||||||
|
|
||||||
@@per_page = 11
|
self.per_page = 11
|
||||||
|
|
||||||
scope :enabled, lambda { where(enabled: true) }
|
scope :enabled, -> { where(enabled: true) }
|
||||||
|
|
||||||
scope :featured, lambda { enabled.where(featured: true) }
|
scope :featured, -> { enabled.where(featured: true) }
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
self.title
|
title
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
self.title
|
title
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_view
|
def log_view
|
||||||
if self.views.nil?
|
if views.nil?
|
||||||
self.views = 1
|
self.views = 1
|
||||||
else
|
else
|
||||||
self.views += 1
|
self.views += 1
|
||||||
end
|
end
|
||||||
self.save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,6 +4,6 @@ class PagePresenter < SimpleDelegator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.markdown
|
def self.markdown
|
||||||
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
|
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions: {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
# lib/email_validator.rb
|
# lib/email_validator.rb
|
||||||
class EmailValidator < ActiveModel::EachValidator
|
class EmailValidator < ActiveModel::EachValidator
|
||||||
|
|
||||||
def validate_each(object, attribute, value)
|
def validate_each(object, attribute, value)
|
||||||
unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
return if value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||||
object.errors[attribute] << (options[:message] || "is not valid")
|
object.errors[attribute] << (options[:message] || 'is not valid')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|||||||
@ -9,16 +9,16 @@ Dragonfly.app.configure do
|
|||||||
|
|
||||||
url_format "/media/:job/:name"
|
url_format "/media/:job/:name"
|
||||||
|
|
||||||
if %w[development test].include? Rails.env
|
if Rails.env.in?(%w(development production))
|
||||||
datastore :file,
|
|
||||||
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
|
|
||||||
server_root: Rails.root.join('public')
|
|
||||||
else
|
|
||||||
datastore :s3,
|
datastore :s3,
|
||||||
bucket_name: ENV['AWS_BUCKET'],
|
bucket_name: ENV['AWS_BUCKET'],
|
||||||
access_key_id: ENV['AWS_KEY'],
|
access_key_id: ENV['AWS_KEY'],
|
||||||
secret_access_key: ENV['AWS_SECRET'],
|
secret_access_key: ENV['AWS_SECRET'],
|
||||||
region: 'eu-west-1'
|
region: 'eu-west-1'
|
||||||
|
else
|
||||||
|
datastore :file,
|
||||||
|
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
|
||||||
|
server_root: Rails.root.join('public')
|
||||||
end
|
end
|
||||||
|
|
||||||
processor :preview do |content| content.process! :thumb, '600x600' end
|
processor :preview do |content| content.process! :thumb, '600x600' end
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
|
|
||||||
require 'commands/about'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/console'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/dbconsole'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/destroy'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/generate'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../../config/boot', __FILE__)
|
|
||||||
require 'commands/performance/benchmarker'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../../config/boot', __FILE__)
|
|
||||||
require 'commands/performance/profiler'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/plugin'
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
||||||
|
|
||||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'rails/commands'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/runner'
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
require File.expand_path('../../config/boot', __FILE__)
|
|
||||||
require 'commands/server'
|
|
||||||
@ -1,30 +1,30 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ContactsController, type: :controller do
|
describe ContactsController, type: :controller do
|
||||||
describe "GET new" do
|
describe 'GET new' do
|
||||||
it "renders the contact form" do
|
it 'renders the contact form' do
|
||||||
get :new
|
get :new
|
||||||
expect(response).to render_template(:new)
|
expect(response).to render_template(:new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:contact_params) do
|
let(:contact_params) do
|
||||||
{ name: "Dan Barber",
|
{ name: 'Dan Barber',
|
||||||
email: "danbee@gmail.com",
|
email: 'danbee@gmail.com',
|
||||||
message: "This is a message." }
|
message: 'This is a message.' }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "POST create" do
|
describe 'POST create' do
|
||||||
it "saves a new contact" do
|
it 'saves a new contact' do
|
||||||
expect_any_instance_of(Contact).to receive(:save).once.and_return(true)
|
expect_any_instance_of(Contact).to receive(:save).once.and_return(true)
|
||||||
post :create, contact: contact_params
|
post :create, contact: contact_params
|
||||||
expect(flash[:notice]).to eql(I18n.t("contact.thanks"))
|
expect(flash[:notice]).to eql(I18n.t('contact.thanks'))
|
||||||
expect(response).to redirect_to(:new_contact)
|
expect(response).to redirect_to(:new_contact)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "re-renders the form if params are missing" do
|
it 're-renders the form if params are missing' do
|
||||||
post :create, contact: {}
|
post :create, contact: {}
|
||||||
expect(flash[:alert]).to eql(I18n.t("contact.invalid"))
|
expect(flash[:alert]).to eql(I18n.t('contact.invalid'))
|
||||||
expect(response).to render_template(:new)
|
expect(response).to render_template(:new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe HomeController, type: :controller do
|
describe HomeController, type: :controller do
|
||||||
describe "GET index" do
|
describe 'GET index' do
|
||||||
it "renders the index template" do
|
it 'renders the index template' do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe PagesController, type: :controller do
|
describe PagesController, type: :controller do
|
||||||
describe "GET show" do
|
describe 'GET show' do
|
||||||
let(:test_page) { create(:page) }
|
let(:test_page) { create(:page) }
|
||||||
|
|
||||||
it "renders a page" do
|
it 'renders a page' do
|
||||||
get :show, name: test_page.name
|
get :show, name: test_page.name
|
||||||
expect(response).to render_template(:show)
|
expect(response).to render_template(:show)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders 404 for a non existant page" do
|
it 'renders 404 for a non existant page' do
|
||||||
get :show, name: "not-a-page"
|
get :show, name: 'not-a-page'
|
||||||
expect(response.status).to eql(404)
|
expect(response.status).to eql(404)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,23 +1,23 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe PhotosController, type: :controller do
|
describe PhotosController, type: :controller do
|
||||||
describe "GET index" do
|
describe 'GET index' do
|
||||||
it "renders the index template" do
|
it 'renders the index template' do
|
||||||
get :index
|
get :index
|
||||||
expect(response).to render_template(:index)
|
expect(response).to render_template(:index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET log_view" do
|
describe 'GET log_view' do
|
||||||
let(:photo) { create(:photo) }
|
let(:photo) { create(:photo) }
|
||||||
|
|
||||||
it "logs a photo view" do
|
it 'logs a photo view' do
|
||||||
expect_any_instance_of(Photo).to receive(:log_view).once
|
expect_any_instance_of(Photo).to receive(:log_view).once
|
||||||
get :log_view, id: photo.id
|
get :log_view, id: photo.id
|
||||||
expect(response).to be_successful
|
expect(response).to be_successful
|
||||||
end
|
end
|
||||||
|
|
||||||
it "responds with not_found if the photo isn't present" do
|
it 'responds with not_found if the photo is not present' do
|
||||||
get :log_view, id: 999
|
get :log_view, id: 999
|
||||||
expect(response.status).to eql(404)
|
expect(response.status).to eql(404)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :category do
|
factory :category do
|
||||||
name "Test Category"
|
name 'Test Category'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :contact do
|
factory :contact do
|
||||||
email "test@danbarberphoto.com"
|
email 'test@danbarberphoto.com'
|
||||||
name "Dan Barber"
|
name 'Dan Barber'
|
||||||
message "This is a message."
|
message 'This is a message.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :page do
|
factory :page do
|
||||||
name "page"
|
name 'page'
|
||||||
title "Page"
|
title 'Page'
|
||||||
content "This is a page."
|
content 'This is a page.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :photo do
|
factory :photo do
|
||||||
title "A Photo"
|
title 'A Photo'
|
||||||
description "A lovely photo of a tree"
|
description 'A lovely photo of a tree'
|
||||||
image Rails.root.join('spec/fixtures/photo.jpg')
|
image Rails.root.join('spec/fixtures/photo.jpg')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
feature 'visitor navigates site' do
|
feature 'visitor navigates site' do
|
||||||
|
|
||||||
let!(:category) { create(:category) }
|
let!(:category) { create(:category) }
|
||||||
let!(:photo) { create(:photo, featured: true, categories: [category]) }
|
let!(:photo) { create(:photo, featured: true, categories: [category]) }
|
||||||
|
|
||||||
|
|||||||
@ -7,9 +7,9 @@ describe Category do
|
|||||||
it { should validate_uniqueness_of(:name) }
|
it { should validate_uniqueness_of(:name) }
|
||||||
it { should validate_uniqueness_of(:slug) }
|
it { should validate_uniqueness_of(:slug) }
|
||||||
|
|
||||||
let(:category) { create(:category, name: "A Test Category") }
|
let(:category) { create(:category, name: 'A Test Category') }
|
||||||
|
|
||||||
it "should have a slug generated from name" do
|
it 'should have a slug generated from name' do
|
||||||
expect(category.slug).to eql("a-test-category")
|
expect(category.slug).to eql('a-test-category')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,12 +5,12 @@ describe Contact do
|
|||||||
it { should validate_presence_of(:name) }
|
it { should validate_presence_of(:name) }
|
||||||
it { should validate_presence_of(:message) }
|
it { should validate_presence_of(:message) }
|
||||||
|
|
||||||
it { should allow_value("test@test.com").for(:email) }
|
it { should allow_value('test@test.com').for(:email) }
|
||||||
it { should_not allow_value("test@test").for(:email) }
|
it { should_not allow_value('test@test').for(:email) }
|
||||||
|
|
||||||
let(:contact) { build(:contact) }
|
let(:contact) { build(:contact) }
|
||||||
|
|
||||||
it "should send an email" do
|
it 'should send an email' do
|
||||||
contact.save
|
contact.save
|
||||||
expect(ActionMailer::Base.deliveries.last.from).to eql([contact.email])
|
expect(ActionMailer::Base.deliveries.last.from).to eql([contact.email])
|
||||||
expect(ActionMailer::Base.deliveries.last.to).to eql(['enquiries@danbarberphoto.com'])
|
expect(ActionMailer::Base.deliveries.last.to).to eql(['enquiries@danbarberphoto.com'])
|
||||||
|
|||||||
@ -7,7 +7,7 @@ describe Photo do
|
|||||||
|
|
||||||
let(:photo) { create(:photo) }
|
let(:photo) { create(:photo) }
|
||||||
|
|
||||||
it "logs a view" do
|
it 'logs a view' do
|
||||||
expect { photo.log_view }.to change { photo.views }.by(1)
|
expect { photo.log_view }.to change { photo.views }.by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||||
ENV["RAILS_ENV"] ||= 'test'
|
ENV['RAILS_ENV'] ||= 'test'
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
require File.expand_path('../../config/environment', __FILE__)
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
require 'capybara/rspec'
|
require 'capybara/rspec'
|
||||||
require 'capybara/poltergeist'
|
require 'capybara/poltergeist'
|
||||||
@ -14,7 +14,7 @@ Capybara.javascript_driver = :poltergeist
|
|||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||||
# in spec/support/ and its subdirectories.
|
# in spec/support/ and its subdirectories.
|
||||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
# ## Mock Framework
|
# ## Mock Framework
|
||||||
@ -46,19 +46,19 @@ RSpec.configure do |config|
|
|||||||
# order dependency and want to debug it, you can fix the order by providing
|
# order dependency and want to debug it, you can fix the order by providing
|
||||||
# the seed, which is printed after each run.
|
# the seed, which is printed after each run.
|
||||||
# --seed 1234
|
# --seed 1234
|
||||||
config.order = "random"
|
config.order = 'random'
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
Capybara.default_wait_time = 2
|
Capybara.default_max_wait_time = 2
|
||||||
DatabaseCleaner.strategy = :transaction
|
DatabaseCleaner.strategy = :transaction
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, js: true) do
|
config.before(:each, js: true) do
|
||||||
Capybara.default_wait_time = 10
|
Capybara.default_max_wait_time = 10
|
||||||
DatabaseCleaner.strategy = :deletion
|
DatabaseCleaner.strategy = :deletion
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
module Ajax
|
module Ajax
|
||||||
def wait_for_ajax
|
def wait_for_ajax
|
||||||
Timeout.timeout(Capybara.default_wait_time) do
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
||||||
loop do
|
loop do
|
||||||
active = page.evaluate_script('jQuery.active')
|
active = page.evaluate_script('jQuery.active')
|
||||||
break if active == 0
|
break if active == 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user