mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
WIP: Rubocop compliance
This commit is contained in:
parent
37eb6f0986
commit
6dac063751
5
.rubocop.yml
Normal file
5
.rubocop.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Metrics/LineLength:
|
||||||
|
Max: 99
|
||||||
|
|
||||||
|
Documentation:
|
||||||
|
Enabled: false
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
15
Gemfile.lock
15
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
|
||||||
|
|||||||
@ -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 with_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 alls
|
||||||
|
@photos = Photo.enabled.order { taken_at.desc }
|
||||||
|
.paginate(page: params[:page], per_page: 11)
|
||||||
|
@page_title = 'All Photos'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,17 +9,11 @@ Dragonfly.app.configure do
|
|||||||
|
|
||||||
url_format "/media/:job/:name"
|
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
|
|
||||||
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'
|
||||||
end
|
|
||||||
|
|
||||||
processor :preview do |content| content.process! :thumb, '600x600' end
|
processor :preview do |content| content.process! :thumb, '600x600' end
|
||||||
|
|
||||||
|
|||||||
@ -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,7 +46,7 @@ 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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user