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

WIP: Rubocop compliance

This commit is contained in:
Dan Barber 2015-09-16 16:20:11 +01:00 committed by Dan Barber
parent 37eb6f0986
commit 6dac063751
21 changed files with 89 additions and 65 deletions

5
.rubocop.yml Normal file
View File

@ -0,0 +1,5 @@
Metrics/LineLength:
Max: 99
Documentation:
Enabled: false

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

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

View File

@ -9,17 +9,11 @@ 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
datastore :s3,
bucket_name: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_KEY'],
secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-1'
end
datastore :s3,
bucket_name: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_KEY'],
secret_access_key: ENV['AWS_SECRET'],
region: 'eu-west-1'
processor :preview do |content| content.process! :thumb, '600x600' end

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,7 +46,7 @@ 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)