1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00

Merge pull request #1 from danbee/rubocop

Rubocop
This commit is contained in:
Daniel Barber 2015-10-14 12:41:31 +01:00
commit 18b08964f4
56 changed files with 386 additions and 385 deletions

16
.rubocop.yml Normal file
View 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$/

View File

@ -47,6 +47,7 @@ end
group :test, :development do
gem 'rspec-rails'
gem 'rubocop'
gem 'pry'
end

View File

@ -35,6 +35,9 @@ GEM
tzinfo (~> 1.1)
addressable (2.3.8)
arel (5.0.1.20140414130214)
ast (2.1.0)
astrolabe (1.3.1)
parser (~> 2.2)
aws-sdk (2.1.29)
aws-sdk-resources (= 2.1.29)
aws-sdk-core (2.1.29)
@ -149,6 +152,8 @@ GEM
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
pg (0.18.3)
poltergeist (1.7.0)
capybara (~> 2.1)
@ -159,6 +164,7 @@ GEM
activerecord (>= 3.0)
powder (0.3.0)
thor (>= 0.11.5)
powerpack (0.1.1)
pry (0.10.2)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -187,6 +193,7 @@ GEM
activesupport (= 4.1.13)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2)
redcarpet (3.3.3)
responders (1.1.2)
@ -208,6 +215,13 @@ GEM
rspec-mocks (~> 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)
sexp_processor (~> 4.1)
sass (3.4.19)
@ -300,6 +314,7 @@ DEPENDENCIES
rails_12factor
redcarpet
rspec-rails
rubocop
ruby_parser
sass-rails (~> 5.0.0)
shoulda
@ -314,6 +329,3 @@ DEPENDENCIES
uglifier
unf
will_paginate
BUNDLED WITH
1.10.6

View File

@ -1,15 +1,17 @@
class Admin::AdminController < ApplicationController
layout 'admin/layouts/admin'
before_filter :authenticate_admin_user!
before_filter :admin_menu
module Admin
class AdminController < ApplicationController
layout 'admin/layouts/admin'
before_filter :authenticate_admin_user!
before_filter :admin_menu
force_ssl host: APP_CONFIG[:ssl_hostname]
force_ssl host: APP_CONFIG[:ssl_hostname]
def admin_menu
@admin_menu = { dashboard: '',
admin_users: '',
categories: '',
photos: '',
pages: '' }
def admin_menu
@admin_menu = { dashboard: '',
admin_users: '',
categories: '',
photos: '',
pages: '' }
end
end
end

View File

@ -1,66 +1,64 @@
class Admin::AdminUsersController < Admin::AdminController
def index
@admin_users = AdminUser.all
end
def new
@admin_user = AdminUser.new
end
def edit
@admin_user = AdminUser.find(params[:id])
end
def update
@admin_user = AdminUser.find(params[:id])
if @admin_user.update_attributes(permitted_params)
redirect_to admin_admin_users_path, notice: 'Admin User was successfully updated.'
else
render :edit
module Admin
class AdminUsersController < Admin::AdminController
def index
@admin_users = AdminUser.all
end
end
def create
@admin_user = AdminUser.new(permitted_params)
def new
@admin_user = AdminUser.new
end
def edit
@admin_user = AdminUser.find(params[:id])
end
def update
@admin_user = AdminUser.find(params[:id])
if @admin_user.update_attributes(permitted_params)
redirect_to admin_admin_users_path, notice: 'Admin User was successfully updated.'
else
render :edit
end
end
def create
@admin_user = AdminUser.new(permitted_params)
respond_to do |format|
if @admin_user.save
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
else
render :edit
end
end
end
def destroy
@admin_user = AdminUser.find(params[:id])
@admin_user.destroy
def destroy
@admin_user = AdminUser.find(params[:id])
@admin_user.destroy
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
end
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
end
# Allow the current logged in user to change their password
def edit_password
@admin_user = current_admin_user
end
# Allow the current logged in user to change their password
def edit_password
@admin_user = current_admin_user
end
def update_password
@admin_user = current_admin_user
def update_password
@admin_user = current_admin_user
if @admin_user.update_with_password(permitted_params)
sign_in @admin_user, bypass: true
redirect_to admin_dashboard_path, notice: "Password updated!"
else
render :edit_password
if @admin_user.update_with_password(permitted_params)
sign_in @admin_user, bypass: true
redirect_to admin_dashboard_path, notice: 'Password updated!'
else
render :edit_password
end
end
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end
end
private
def permitted_params
params.require(:admin_user).permit(:email, :password, :password_confirmable, :remember_me)
end
end

View File

@ -1,48 +1,48 @@
class Admin::CategoriesController < Admin::AdminController
def index
@categories = Category.all
end
def new
@category = Category.new
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
if @category.update_attributes(permitted_params)
redirect_to admin_categories_path, notice: 'Category was successfully updated.'
else
render :edit
module Admin
class CategoriesController < Admin::AdminController
def index
@categories = Category.all
end
end
def create
@category = Category.new(permitted_params)
def new
@category = Category.new
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
if @category.update_attributes(permitted_params)
redirect_to admin_categories_path, notice: 'Category was successfully updated.'
else
render :edit
end
end
def create
@category = Category.new(permitted_params)
if @category.save
redirect_to admin_categories_path, notice: 'Category was successfully added.'
else
render :edit
end
end
def destroy
@category = Category.find(params[:id])
@category.destroy
redirect_to admin_categories_path, notice: 'Category was deleted.'
end
private
def permitted_params
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
end
end
def destroy
@category = Category.find(params[:id])
@category.destroy
redirect_to admin_categories_path, notice: 'Category was deleted.'
end
private
def permitted_params
params.require(:category).permit(:name, :slug, :description, :base_colour, :sort)
end
end

View File

@ -1,60 +1,64 @@
class Admin::ConfirmationsController < ::Devise::PasswordsController
layout "admin/layouts/login"
module Admin
class ConfirmationsController < ::Devise::PasswordsController
layout 'admin/layouts/login'
skip_before_filter(:authenticate_user!)
skip_before_filter(:authenticate_user!)
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
@confirmable.attempt_set_password(params[:admin_user])
if @confirmable.valid?
do_confirm
def update
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
update_password
else
do_show
@confirmable.errors.clear #so that we wont render :new
self.class.add_error_on(self, :email, :password_already_set)
end
else
self.class.add_error_on(self, :email, :password_allready_set)
end
render_with_scope :new unless confirmable.errors.empty?
end
if !@confirmable.errors.empty?
render_with_scope :new
end
end
def show
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
do_show
else
do_confirm
end
end
def show
with_unconfirmed_confirmable do
if @confirmable.has_no_password?
do_show
else
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
if !@confirmable.errors.empty?
render_with_scope :new
protected
def with_unconfirmed_confirmable
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
@confirmable.only_if_unconfirmed { yield } unless @confirmable.new_record?
end
end
protected
def with_unconfirmed_confirmable
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
if !@confirmable.new_record?
@confirmable.only_if_unconfirmed {yield}
def do_show
@confirmation_token = params[:confirmation_token]
@requires_password = true
self.resource = @confirmable
render_with_scope :show
end
end
def do_show
@confirmation_token = params[:confirmation_token]
@requires_password = true
self.resource = @confirmable
render_with_scope :show
end
def do_confirm
@confirmable.confirm!
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable)
def do_confirm
@confirmable.confirm!
set_flash_message :notice, :confirmed
sign_in_and_redirect(resource_name, @confirmable)
end
end
end

View File

@ -1,2 +1,4 @@
class Admin::DashboardController < Admin::AdminController
module Admin
class DashboardController < Admin::AdminController
end
end

View File

@ -1,53 +1,53 @@
class Admin::PagesController < Admin::AdminController
module Admin
class PagesController < Admin::AdminController
def index
@pages = Page.all
end
def index
@pages = Page.all
end
def new
@page = Page.new
end
def new
@page = Page.new
end
def edit
@page = Page.find(params[:id])
end
def edit
@page = Page.find(params[:id])
end
def show
page = Page.find(params[:id])
@page = PagePresenter.new(page)
end
def show
page = Page.find(params[:id])
@page = PagePresenter.new(page)
end
def update
@page = Page.find(params[:id])
def update
@page = Page.find(params[:id])
if @page.update_attributes(permitted_params)
redirect_to admin_pages_path, notice: 'Page was successfully updated.'
else
render :edit
end
end
if @page.update_attributes(permitted_params)
redirect_to admin_pages_path, notice: 'Page was successfully updated.'
else
render :edit
def create
@page = Page.new(permitted_params)
if @page.save
redirect_to admin_pages_path, notice: 'Page was successfully added.'
else
render :edit
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
redirect_to admin_pages_path, notice: 'Page was deleted.'
end
private
def permitted_params
params.require(:page).permit(:name, :title, :content)
end
end
def create
@page = Page.new(permitted_params)
if @page.save
redirect_to admin_pages_path, notice: 'Page was successfully added.'
else
render :edit
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
redirect_to admin_pages_path, notice: 'Page was deleted.'
end
private
def permitted_params
params.require(:page).permit(:name, :title, :content)
end
end

View File

@ -1,3 +1,5 @@
class Admin::PasswordsController < ::Devise::PasswordsController
layout "admin/layouts/login"
module Admin
class PasswordsController < ::Devise::PasswordsController
layout 'admin/layouts/login'
end
end

View File

@ -1,53 +1,55 @@
class Admin::PhotosController < Admin::AdminController
before_filter :get_categories
module Admin
class PhotosController < Admin::AdminController
before_filter :categories
def index
@photos = Photo.paginate(page: params[:page], per_page: 16)
end
def new
@photo = Photo.new
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(permitted_params)
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
else
render :edit
def index
@photos = Photo.paginate(page: params[:page], per_page: 16)
end
end
def create
@photo = Photo.new(permitted_params)
def new
@photo = Photo.new
end
def edit
@photo = Photo.find(params[:id])
end
def update
@photo = Photo.find(params[:id])
if @photo.update_attributes(permitted_params)
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
else
render :edit
end
end
def create
@photo = Photo.new(permitted_params)
if @photo.save
redirect_to admin_photos_path, notice: 'Photo was successfully added.'
else
render :edit
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to :back, notice: 'Photo was deleted.'
end
private
def categories
@categories = Category.all
end
def permitted_params
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured,
:enabled, :taken_at, category_ids: [])
end
end
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to :back, notice: 'Photo was deleted.'
end
private
def get_categories
@categories = Category.all
end
def permitted_params
params.require(:photo).permit(:image, :title, :description, :flickr_url, :featured, :enabled, :taken_at, category_ids: [])
end
end

View File

@ -1,3 +1,5 @@
class Admin::RegistrationsController < ::Devise::RegistrationsController
layout "admin/layouts/login"
module Admin
class RegistrationsController < ::Devise::RegistrationsController
layout 'admin/layouts/login'
end
end

View File

@ -1,12 +1,14 @@
class Admin::SessionsController < ::Devise::SessionsController
layout "admin/layouts/login"
module Admin
class SessionsController < ::Devise::SessionsController
layout 'admin/layouts/login'
before_filter :check_https
before_filter :check_https
private
private
def check_https
secure_link = url_for(protocol: 'https')
flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https'
def check_https
secure_link = url_for(protocol: 'https')
flash[:alert] = I18n.t('insecure_alert', secure_link: secure_link).html_safe unless request.scheme == 'https'
end
end
end

View File

@ -1,3 +1,5 @@
class Admin::UnlocksController < ::Devise::UnlocksController
layout "admin/layouts/login"
module Admin
class UnlocksController < ::Devise::UnlocksController
layout 'admin/layouts/login'
end
end

View File

@ -3,16 +3,15 @@ class ApplicationController < ActionController::Base
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
end
def after_sign_out_path_for(resource_or_scope)
def after_sign_out_path_for(*)
new_admin_user_session_path
end
def render_404
render 'errors/not_found', status: :not_found
end
end

View File

@ -26,5 +26,4 @@ class CategoriesController < ApplicationController
format.xml { render xml: @category }
end
end
end

View File

@ -7,9 +7,9 @@ class ContactsController < ApplicationController
def create
@contact = Contact.new(params[:contact])
if @contact.save
redirect_to(:new_contact, notice: t("contact.thanks"))
redirect_to(:new_contact, notice: t('contact.thanks'))
else
flash[:alert] = t("contact.invalid")
flash[:alert] = t('contact.invalid')
render :new
end
end

View File

@ -1,12 +1,9 @@
class PhotosController < ApplicationController
def index
if params[:category_id]
@category = Category.find_by_id(params[:category_id])
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
@page_title = @category.name
for_category(params[:category_id])
else
@photos = Photo.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
@page_title = 'All Photos'
all
end
@num_blank = 11 - @photos.length
@ -25,4 +22,19 @@ class PhotosController < ApplicationController
head :not_found
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

View File

@ -1,9 +1,11 @@
module Admin::AdminHelper
def inputs_field_set &block
field_set_tag nil, class: :inputs, &block
end
module Admin
module AdminHelper
def inputs_field_set(&block)
field_set_tag nil, class: :inputs, &block
end
def actions_field_set &block
field_set_tag nil, class: :actions, &block
def actions_field_set(&block)
field_set_tag nil, class: :actions, &block
end
end
end

View File

@ -1,2 +0,0 @@
module Admin::DashboardHelper
end

View File

@ -1,2 +0,0 @@
module Admin::DownloadsHelper
end

View File

@ -1,2 +0,0 @@
module Admin::UnlocksHelper
end

View File

@ -3,8 +3,6 @@ class Notifier < ActionMailer::Base
def contact_notification(sender)
@sender = sender
mail( to: 'enquiries@danbarberphoto.com',
from: sender.email,
subject: sender.subject)
mail(to: 'enquiries@danbarberphoto.com', from: sender.email, subject: sender.subject)
end
end

View File

@ -5,11 +5,7 @@ class Heartbeat
def call(env)
if env['PATH_INFO'] == '/heartbeat'
[
200,
{"Content-Type" => "text/plain"},
["OK"]
]
[200, { 'Content-Type' => 'text/plain' }, ['OK']]
else
@app.call(env)
end

View File

@ -10,8 +10,8 @@ class AdminUser < ActiveRecord::Base
end
# new function to return whether a password has been set
def has_no_password?
self.encrypted_password.blank?
def no_password?
encrypted_password.blank?
end
# new function to provide access to protected method unless_confirmed

View File

@ -9,12 +9,12 @@ class Contact
def initialize(attributes = {})
attributes.each do |key, value|
self.send("#{key}=", value)
send("#{key}=", value)
end
end
def read_attribute_for_validation(key)
self.send(key)
send(key)
end
def save
@ -22,7 +22,6 @@ class Contact
Notifier.contact_notification(self).deliver
return true
end
return false
false
end
end

View File

@ -1,32 +1,30 @@
class Photo < ActiveRecord::Base
has_and_belongs_to_many :categories
dragonfly_accessor :image
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
self.title
title
end
def name
self.title
title
end
def log_view
if self.views.nil?
if views.nil?
self.views = 1
else
self.views += 1
end
self.save
save
end
end

View File

@ -4,6 +4,6 @@ class PagePresenter < SimpleDelegator
end
def self.markdown
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = {})
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions: {})
end
end

View File

@ -1,10 +1,7 @@
# lib/email_validator.rb
class EmailValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
unless value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
object.errors[attribute] << (options[:message] || "is not valid")
end
return if value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
object.errors[attribute] << (options[:message] || 'is not valid')
end
end

View File

@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
require ::File.expand_path('../config/environment', __FILE__)
run DanBarberPhoto::Application

View File

@ -9,16 +9,16 @@ Dragonfly.app.configure do
url_format "/media/:job/:name"
if %w[development test].include? Rails.env
datastore :file,
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
server_root: Rails.root.join('public')
else
if Rails.env.in?(%w(development production))
datastore :s3,
bucket_name: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_KEY'],
secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-1'
else
datastore :file,
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
server_root: Rails.root.join('public')
end
processor :preview do |content| content.process! :thumb, '600x600' end

View File

@ -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'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'

View File

@ -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'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'

View File

@ -1,30 +1,30 @@
require 'spec_helper'
describe ContactsController, type: :controller do
describe "GET new" do
it "renders the contact form" do
describe 'GET new' do
it 'renders the contact form' do
get :new
expect(response).to render_template(:new)
end
end
let(:contact_params) do
{ name: "Dan Barber",
email: "danbee@gmail.com",
message: "This is a message." }
{ name: 'Dan Barber',
email: 'danbee@gmail.com',
message: 'This is a message.' }
end
describe "POST create" do
it "saves a new contact" do
describe 'POST create' do
it 'saves a new contact' do
expect_any_instance_of(Contact).to receive(:save).once.and_return(true)
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)
end
it "re-renders the form if params are missing" do
it 're-renders the form if params are missing' do
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)
end
end

View File

@ -1,8 +1,8 @@
require 'spec_helper'
describe HomeController, type: :controller do
describe "GET index" do
it "renders the index template" do
describe 'GET index' do
it 'renders the index template' do
get :index
expect(response).to render_template(:index)
end

View File

@ -1,16 +1,16 @@
require 'spec_helper'
describe PagesController, type: :controller do
describe "GET show" do
describe 'GET show' do
let(:test_page) { create(:page) }
it "renders a page" do
it 'renders a page' do
get :show, name: test_page.name
expect(response).to render_template(:show)
end
it "renders 404 for a non existant page" do
get :show, name: "not-a-page"
it 'renders 404 for a non existant page' do
get :show, name: 'not-a-page'
expect(response.status).to eql(404)
end
end

View File

@ -1,23 +1,23 @@
require 'spec_helper'
describe PhotosController, type: :controller do
describe "GET index" do
it "renders the index template" do
describe 'GET index' do
it 'renders the index template' do
get :index
expect(response).to render_template(:index)
end
end
describe "GET log_view" do
describe 'GET log_view' do
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
get :log_view, id: photo.id
expect(response).to be_successful
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
expect(response.status).to eql(404)
end

View File

@ -2,6 +2,6 @@
FactoryGirl.define do
factory :category do
name "Test Category"
name 'Test Category'
end
end

View File

@ -2,8 +2,8 @@
FactoryGirl.define do
factory :contact do
email "test@danbarberphoto.com"
name "Dan Barber"
message "This is a message."
email 'test@danbarberphoto.com'
name 'Dan Barber'
message 'This is a message.'
end
end

View File

@ -2,8 +2,8 @@
FactoryGirl.define do
factory :page do
name "page"
title "Page"
content "This is a page."
name 'page'
title 'Page'
content 'This is a page.'
end
end

View File

@ -2,8 +2,8 @@
FactoryGirl.define do
factory :photo do
title "A Photo"
description "A lovely photo of a tree"
title 'A Photo'
description 'A lovely photo of a tree'
image Rails.root.join('spec/fixtures/photo.jpg')
end
end

View File

@ -1,7 +1,6 @@
require 'spec_helper'
feature 'visitor navigates site' do
let!(:category) { create(:category) }
let!(:photo) { create(:photo, featured: true, categories: [category]) }

View File

@ -7,9 +7,9 @@ describe Category do
it { should validate_uniqueness_of(:name) }
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
expect(category.slug).to eql("a-test-category")
it 'should have a slug generated from name' do
expect(category.slug).to eql('a-test-category')
end
end

View File

@ -5,12 +5,12 @@ describe Contact do
it { should validate_presence_of(:name) }
it { should validate_presence_of(:message) }
it { should allow_value("test@test.com").for(:email) }
it { should_not allow_value("test@test").for(:email) }
it { should allow_value('test@test.com').for(:email) }
it { should_not allow_value('test@test').for(:email) }
let(:contact) { build(:contact) }
it "should send an email" do
it 'should send an email' do
contact.save
expect(ActionMailer::Base.deliveries.last.from).to eql([contact.email])
expect(ActionMailer::Base.deliveries.last.to).to eql(['enquiries@danbarberphoto.com'])

View File

@ -7,7 +7,7 @@ describe Photo do
let(:photo) { create(:photo) }
it "logs a view" do
expect { photo.log_view }.to change{photo.views}.by(1)
it 'logs a view' do
expect { photo.log_view }.to change { photo.views }.by(1)
end
end

View File

@ -1,6 +1,6 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
@ -14,7 +14,7 @@ Capybara.javascript_driver = :poltergeist
# Requires supporting ruby files with custom matchers and macros, etc,
# 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|
# ## Mock Framework
@ -46,19 +46,19 @@ RSpec.configure do |config|
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.order = 'random'
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
Capybara.default_wait_time = 2
Capybara.default_max_wait_time = 2
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
Capybara.default_wait_time = 10
Capybara.default_max_wait_time = 10
DatabaseCleaner.strategy = :deletion
end

View File

@ -1,6 +1,6 @@
module Ajax
def wait_for_ajax
Timeout.timeout(Capybara.default_wait_time) do
Timeout.timeout(Capybara.default_max_wait_time) do
loop do
active = page.evaluate_script('jQuery.active')
break if active == 0