mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Add first feature spec.
This commit is contained in:
parent
cbf09ee37a
commit
9c6db30261
1
Gemfile
1
Gemfile
@ -54,6 +54,7 @@ group :test do
|
|||||||
gem 'factory_girl_rails'
|
gem 'factory_girl_rails'
|
||||||
gem 'shoulda-matchers'
|
gem 'shoulda-matchers'
|
||||||
gem 'poltergeist'
|
gem 'poltergeist'
|
||||||
|
gem 'database_cleaner'
|
||||||
gem 'fivemat'
|
gem 'fivemat'
|
||||||
gem 'capybara-screenshot'
|
gem 'capybara-screenshot'
|
||||||
end
|
end
|
||||||
|
|||||||
@ -76,6 +76,7 @@ GEM
|
|||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.7.0)
|
coffee-script-source (1.7.0)
|
||||||
daemons (1.1.9)
|
daemons (1.1.9)
|
||||||
|
database_cleaner (1.2.0)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
devise (3.2.3)
|
devise (3.2.3)
|
||||||
bcrypt-ruby (~> 3.0)
|
bcrypt-ruby (~> 3.0)
|
||||||
@ -255,6 +256,7 @@ DEPENDENCIES
|
|||||||
bourbon
|
bourbon
|
||||||
capybara-screenshot
|
capybara-screenshot
|
||||||
coffee-rails (~> 4.0.0)
|
coffee-rails (~> 4.0.0)
|
||||||
|
database_cleaner
|
||||||
devise
|
devise
|
||||||
dragonfly
|
dragonfly
|
||||||
dragonfly-s3_data_store
|
dragonfly-s3_data_store
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
$(document).ready ->
|
$(document).ready ->
|
||||||
$(".fancy").fancybox
|
$(".fancy").fancybox
|
||||||
afterLoad: () ->
|
afterLoad: () ->
|
||||||
$.post "/photos/#{this.element.attr('id')}/log_view"
|
$.post "/photos/#{this.element.data('id')}/log_view"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
module PhotosHelper
|
module PhotosHelper
|
||||||
def link_to_photo(photo)
|
def link_to_photo(photo)
|
||||||
link_to '', photo.image.url, rel: 'photos', class: 'fancy', id: photo.id
|
link_to '', photo.image.url, rel: 'photos', class: 'fancy', data: { id: photo.id }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
36
spec/features/visitor_navigates_site_spec.rb
Normal file
36
spec/features/visitor_navigates_site_spec.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'visitor navigates site' do
|
||||||
|
|
||||||
|
let!(:category) { create(:category) }
|
||||||
|
let!(:photo) { create(:photo, featured: true, categories: [category]) }
|
||||||
|
|
||||||
|
it 'shows the featured image on the home page' do
|
||||||
|
visit root_path
|
||||||
|
expect(page).to have_selector("a[data-id='#{photo.id}']")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'increments the view counter when an image is displayed', js: true do
|
||||||
|
visit root_path
|
||||||
|
|
||||||
|
selector = "a[data-id='#{photo.id}']"
|
||||||
|
expect(page).to have_selector(selector)
|
||||||
|
|
||||||
|
page.find(selector).click
|
||||||
|
|
||||||
|
expect(page).to have_selector('img.fancybox-image')
|
||||||
|
|
||||||
|
wait_for_ajax
|
||||||
|
photo.reload
|
||||||
|
|
||||||
|
expect(photo.views).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows the categories' do
|
||||||
|
visit root_path
|
||||||
|
|
||||||
|
click_link 'portfolio'
|
||||||
|
|
||||||
|
expect(page).to have_link(category.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -3,6 +3,11 @@ 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 'rspec/autorun'
|
require 'rspec/autorun'
|
||||||
|
require 'capybara/rspec'
|
||||||
|
require 'capybara/poltergeist'
|
||||||
|
|
||||||
|
# Use Poltergeist
|
||||||
|
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.
|
||||||
@ -19,6 +24,7 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
# Include FactoryGirl methods
|
# Include FactoryGirl methods
|
||||||
config.include FactoryGirl::Syntax::Methods
|
config.include FactoryGirl::Syntax::Methods
|
||||||
|
config.include Ajax, type: :feature
|
||||||
|
|
||||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||||
@ -26,7 +32,7 @@ RSpec.configure do |config|
|
|||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||||
# examples within a transaction, remove the following line or assign false
|
# examples within a transaction, remove the following line or assign false
|
||||||
# instead of true.
|
# instead of true.
|
||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = false
|
||||||
|
|
||||||
# If true, the base class of anonymous controllers will be inferred
|
# If true, the base class of anonymous controllers will be inferred
|
||||||
# automatically. This will be the default behavior in future versions of
|
# automatically. This will be the default behavior in future versions of
|
||||||
@ -38,4 +44,26 @@ RSpec.configure do |config|
|
|||||||
# 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
|
||||||
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
Capybara.default_wait_time = 2
|
||||||
|
DatabaseCleaner.strategy = :transaction
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each, js: true) do
|
||||||
|
Capybara.default_wait_time = 10
|
||||||
|
DatabaseCleaner.strategy = :deletion
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
DatabaseCleaner.start
|
||||||
|
end
|
||||||
|
|
||||||
|
config.after(:each) do
|
||||||
|
DatabaseCleaner.clean
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
10
spec/support/ajax.rb
Normal file
10
spec/support/ajax.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
module Ajax
|
||||||
|
def wait_for_ajax
|
||||||
|
Timeout.timeout(Capybara.default_wait_time) do
|
||||||
|
loop do
|
||||||
|
active = page.evaluate_script('jQuery.active')
|
||||||
|
break if active == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user