mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
commit
93cd1a3585
@ -1,6 +1,3 @@
|
||||
Metrics/LineLength:
|
||||
Max: 120
|
||||
|
||||
Documentation:
|
||||
Enabled: false
|
||||
|
||||
|
||||
@ -13,6 +13,6 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def render_404
|
||||
render 'errors/not_found', status: :not_found
|
||||
render "errors/not_found", status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,11 +2,11 @@ class CategoriesController < ApplicationController
|
||||
# GET /categories
|
||||
# GET /categories.xml
|
||||
def index
|
||||
@categories = Category.order('sort ASC').page(params[:page]).per(4)
|
||||
@categories = Category.order("sort ASC").page(params[:page]).per(4)
|
||||
|
||||
@photos = Photo.featured.limit(2).order('RANDOM()')
|
||||
@photos = Photo.featured.limit(2).order("RANDOM()")
|
||||
|
||||
@page_title = 'Portfolio'
|
||||
@page_title = "Portfolio"
|
||||
|
||||
@num_blank = 4 - @categories.length
|
||||
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
class ContactsController < ApplicationController
|
||||
def new
|
||||
@contact = Contact.new(id: 1)
|
||||
@page_title = 'Contact'
|
||||
@page_title = "Contact"
|
||||
end
|
||||
|
||||
def create
|
||||
@contact = Contact.new(params[:contact])
|
||||
if @contact.valid?
|
||||
Notifier.contact_notification(@contact).deliver
|
||||
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
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class HomeController < ApplicationController
|
||||
def index
|
||||
@photos = Photo.featured.order('RANDOM()').limit(1)
|
||||
@photos = Photo.featured.order("RANDOM()").limit(1)
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,6 +25,6 @@ class PhotosController < ApplicationController
|
||||
def all
|
||||
@photos = Photo.enabled.order(taken_at: :desc)
|
||||
.page(params[:page])
|
||||
@page_title = 'All Photos'
|
||||
@page_title = "All Photos"
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
class SessionsController < ApplicationController
|
||||
layout 'admin/login'
|
||||
layout "admin/login"
|
||||
|
||||
skip_before_action :require_login, only: [:new, :create], raise: false
|
||||
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
class EmailValidator < ActiveModel::EachValidator
|
||||
def validate_each(object, attribute, value)
|
||||
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
|
||||
|
||||
@ -7,10 +7,10 @@
|
||||
<meta name="keywords" content="photography, images, landscapes" />
|
||||
<meta name="description" content="The photography portfolio of Dan Barber" />
|
||||
<meta name="language" content="English" />
|
||||
<%= stylesheet_link_tag 'application' %>
|
||||
<%= javascript_include_tag 'application' %>
|
||||
<%= stylesheet_link_tag "application" %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= render "shared/fonts" %>
|
||||
<%= favicon_link_tag 'favicon.ico' %>
|
||||
<%= favicon_link_tag "favicon.ico" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
<div class="sgParent sg-12">
|
||||
<header class="sg-11">
|
||||
<%= link_to image_tag(asset_url('title.svg'), alt: 'Dan Barber Photography', width: 236), '/' %>
|
||||
<%= link_to image_tag(asset_url("title.svg"), alt: "Dan Barber Photography", width: 236), "/" %>
|
||||
</header>
|
||||
|
||||
<%= yield :navigation %>
|
||||
@ -33,12 +33,12 @@
|
||||
<%= yield %>
|
||||
</div>
|
||||
|
||||
<%= render 'shared/footer' %>
|
||||
<%= render "shared/footer" %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<%= render 'shared/analytics' if Rails.env.production? %>
|
||||
<%= render "shared/analytics" if Rails.env.production? %>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="sg-5 about">
|
||||
</div>
|
||||
<div class="sg-5 portfolio">
|
||||
<%= link_to content_tag(:span, 'portfolio'), controller: 'categories' %>
|
||||
<%= link_to content_tag(:span, "portfolio"), controller: "categories" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sg-11" style="background: url(<%= asset_url('me.jpg') %>);">
|
||||
<div class="sg-11" style="background: url(<%= asset_url("me.jpg") %>);">
|
||||
</div>
|
||||
|
||||
<div class="sg-5" style="background: #222;">
|
||||
@ -22,5 +22,5 @@
|
||||
<div class="sg-5" style="background: #555;">
|
||||
</div>
|
||||
<div class="sg-5 contact">
|
||||
<%= link_to content_tag(:span, 'contact'), new_contact_path %>
|
||||
<%= link_to content_tag(:span, "contact"), new_contact_path %>
|
||||
</div>
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
<% if !Rails.env.test? %>
|
||||
<%= stylesheet_link_tag 'https://cloud.typography.com/7434852/6922572/css/fonts.css' %>
|
||||
<%= stylesheet_link_tag "https://cloud.typography.com/7434852/6922572/css/fonts.css" %>
|
||||
<% end %>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<div class="sg-5 about">
|
||||
<%= link_to content_tag(:span, 'about'), page_path(:about) %>
|
||||
<%= link_to content_tag(:span, "about"), page_path(:about) %>
|
||||
</div>
|
||||
<div class="sg-5 portfolio">
|
||||
<%= link_to content_tag(:span, 'portfolio'), controller: 'categories' %>
|
||||
<%= link_to content_tag(:span, "portfolio"), controller: "categories" %>
|
||||
</div>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
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
|
||||
@ -10,28 +10,28 @@ describe ContactsController, type: :controller do
|
||||
|
||||
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
|
||||
valid_contact = double(valid?: true)
|
||||
allow(Contact).to receive(:new).and_return(valid_contact)
|
||||
allow(Notifier).to receive(:contact_notification).and_return(double(deliver: true))
|
||||
post :create, params: { contact: contact_params }
|
||||
|
||||
expect(Notifier).to have_received(:contact_notification).with(valid_contact)
|
||||
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
|
||||
allow(Contact).to receive(:new).and_return(double(valid?: false))
|
||||
post :create, params: { 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
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
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
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
require 'spec_helper'
|
||||
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, params: { name: test_page.name }
|
||||
expect(response).to render_template(:show)
|
||||
end
|
||||
|
||||
it 'renders 404 for a non existant page' do
|
||||
get :show, params: { name: 'not-a-page' }
|
||||
it "renders 404 for a non existant page" do
|
||||
get :show, params: { name: "not-a-page" }
|
||||
expect(response.status).to eql(404)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
require 'spec_helper'
|
||||
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
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe ViewsController, type: :controller do
|
||||
describe 'POST create' do
|
||||
describe "POST create" 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
|
||||
post :create, params: { photo_id: photo.id }
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
it 'responds with not_found if the photo is not present' do
|
||||
it "responds with not_found if the photo is not present" do
|
||||
post :create, params: { photo_id: 999 }
|
||||
expect(response.status).to eql(404)
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :photo do
|
||||
title 'A Photo'
|
||||
description 'A lovely photo of a tree'
|
||||
image Rails.root.join('spec/fixtures/photo.jpg')
|
||||
title "A Photo"
|
||||
description "A lovely photo of a tree"
|
||||
image Rails.root.join("spec/fixtures/photo.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
feature 'visitor navigates site' do
|
||||
it 'shows the featured image on the home page' do
|
||||
feature "visitor navigates site" do
|
||||
it "shows the featured image on the home page" do
|
||||
category = create(:category)
|
||||
photo = create(:photo, featured: true, categories: [category])
|
||||
|
||||
@ -9,7 +9,7 @@ feature 'visitor navigates site' do
|
||||
expect(page).to have_selector("a[data-id='#{photo.id}']")
|
||||
end
|
||||
|
||||
it 'increments the view counter when an image is displayed', js: true do
|
||||
it "increments the view counter when an image is displayed", js: true do
|
||||
category = create(:category)
|
||||
photo = create(:photo, featured: true, categories: [category])
|
||||
|
||||
@ -19,7 +19,7 @@ feature 'visitor navigates site' do
|
||||
|
||||
page.find(selector).click
|
||||
|
||||
expect(page).to have_selector('img.fancybox-image')
|
||||
expect(page).to have_selector("img.fancybox-image")
|
||||
|
||||
wait_for_ajax
|
||||
photo.reload
|
||||
@ -27,20 +27,20 @@ feature 'visitor navigates site' do
|
||||
expect(photo.views).to eq(1)
|
||||
end
|
||||
|
||||
it 'shows the categories' do
|
||||
it "shows the categories" do
|
||||
categories = create_list(:category, 5)
|
||||
|
||||
visit root_path
|
||||
click_link 'portfolio'
|
||||
click_link "portfolio"
|
||||
|
||||
expect(page).to have_link(categories.first.name.downcase)
|
||||
|
||||
click_link '→'
|
||||
click_link "→"
|
||||
|
||||
expect(page).to have_link(categories.last.name.downcase)
|
||||
end
|
||||
|
||||
it 'shows the photos for the category' do
|
||||
it "shows the photos for the category" do
|
||||
category = create(:category)
|
||||
photo = create(:photo, featured: true, categories: [category])
|
||||
|
||||
@ -52,13 +52,13 @@ feature 'visitor navigates site' do
|
||||
expect(page).to have_selector(selector)
|
||||
end
|
||||
|
||||
it 'shows the second page of photos' do
|
||||
it "shows the second page of photos" do
|
||||
category = create(:category)
|
||||
photos = create_list(:photo, 12, featured: true, categories: [category])
|
||||
|
||||
visit url_for([category, :photos])
|
||||
|
||||
click_link '→'
|
||||
click_link "→"
|
||||
|
||||
selector = "a[data-id='#{photos.last.id}']"
|
||||
expect(page).to have_selector(selector)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe Category do
|
||||
it { should have_and_belong_to_many(:photos) }
|
||||
@ -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
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe Contact do
|
||||
it { should validate_presence_of(:email) }
|
||||
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) }
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
describe Photo do
|
||||
it { should have_and_belong_to_many(:categories) }
|
||||
@ -7,7 +7,7 @@ describe Photo do
|
||||
|
||||
let(:photo) { create(:photo) }
|
||||
|
||||
it 'logs a view' do
|
||||
it "logs a view" do
|
||||
expect { photo.log_view }.to change { photo.views }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
require 'spec_helper'
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe User, type: :model do
|
||||
it { is_expected.to validate_presence_of(:email) }
|
||||
it { is_expected.to validate_presence_of(:password_digest) }
|
||||
|
||||
it 'validates uniqueness of email' do
|
||||
create(:user, email: 'test@example.com')
|
||||
user = User.new(email: 'test@example.com')
|
||||
it "validates uniqueness of email" do
|
||||
create(:user, email: "test@example.com")
|
||||
user = User.new(email: "test@example.com")
|
||||
|
||||
expect(user).to validate_uniqueness_of(:email)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user