Skip to content

Commit

Permalink
added high level capybara tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grammaticof committed May 17, 2013
1 parent e4f351b commit 11b7034
Show file tree
Hide file tree
Showing 41 changed files with 224 additions and 144 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color
13 changes: 3 additions & 10 deletions Gemfile
Expand Up @@ -13,25 +13,18 @@ gem "jquery-rails"
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

gem 'rspec-rails', group: [:test, :development]
gem 'factory_girl_rails', group: [:test, :development]
# gem 'rspec-rails', group: [:test, :development]
# gem 'factory_girl_rails', group: [:test, :development]

gem 'jazz_hands', group: [:test, :development]

group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'quiet_assets'
gem 'guard-livereload'
gem 'pry-rails'
gem 'thin'
end

group :test do
gem 'capybara'
gem 'launchy'
gem 'guard-rspec'
gem 'rb-fsevent'
end

# To use debugger
# gem 'debugger'
18 changes: 5 additions & 13 deletions Gemfile.lock
Expand Up @@ -34,7 +34,6 @@ GEM
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
addressable (2.3.4)
arel (3.0.2)
awesome_print (1.1.0)
better_errors (0.8.0)
Expand Down Expand Up @@ -62,9 +61,6 @@ GEM
debugger-ruby_core_source (1.2.0)
diff-lcs (1.2.4)
diffy (2.1.4)
em-websocket (0.5.0)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.5.3)
erubis (2.7.0)
eventmachine (1.0.3)
factory_girl (4.2.0)
Expand All @@ -78,22 +74,18 @@ GEM
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
growl (1.0.3)
guard (1.8.0)
formatador (>= 0.2.4)
listen (>= 1.0.0)
lumberjack (>= 1.0.2)
pry (>= 0.9.10)
thor (>= 0.14.6)
guard-livereload (1.4.0)
em-websocket (>= 0.5.0)
guard (>= 1.8.0)
multi_json (~> 1.7)
guard-rspec (2.5.4)
guard (>= 1.1)
rspec (~> 2.11)
hike (1.2.2)
hirb (0.7.1)
http_parser.rb (0.5.3)
i18n (0.6.1)
jazz_hands (0.5.0)
awesome_print (~> 1.1.0)
Expand All @@ -113,8 +105,6 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.7.7)
launchy (2.3.0)
addressable (~> 2.3)
listen (1.0.3)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
Expand Down Expand Up @@ -224,19 +214,21 @@ PLATFORMS
ruby

DEPENDENCIES
awesome_print
better_errors
binding_of_caller
capybara
factory_girl_rails
guard-livereload
growl
guard-rspec
jazz_hands
jquery-rails
launchy
pry
pry-rails
quiet_assets
rails-agegate!
rb-fsevent
rspec
rspec-rails
sqlite3
thin
23 changes: 23 additions & 0 deletions Guardfile
@@ -0,0 +1,23 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
3 changes: 0 additions & 3 deletions README.rdoc
Expand Up @@ -30,6 +30,3 @@ Add the following to your configuration, if you need to override one of the defa

config.agegate.skip = false
config.agegate.min_age = 18

TODO:
tests!
13 changes: 1 addition & 12 deletions Rakefile
Expand Up @@ -23,18 +23,7 @@ end
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'



Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

task :default => 'app:spec'

task :default => :test
14 changes: 13 additions & 1 deletion agegate.gemspec
Expand Up @@ -19,5 +19,17 @@ Gem::Specification.new do |s|
s.add_dependency "rails", "~> 3.2.12"
# s.add_dependency "jquery-rails"

s.add_development_dependency "sqlite3"
s.add_development_dependency 'pry'
s.add_development_dependency 'awesome_print'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'capybara'
s.add_development_dependency 'factory_girl_rails'
s.add_development_dependency 'rspec'
s.add_development_dependency 'guard-rspec'
s.add_development_dependency 'rb-fsevent'
s.add_development_dependency 'growl'

s.add_development_dependency 'sqlite3'

s.test_files = Dir["spec/**/*"]
end
File renamed without changes.
@@ -1,5 +1,5 @@
module Agegate
module GatesHelper
module GatesCheck

def check_agegate
return if Rails.application.config.agegate.skip
Expand All @@ -21,4 +21,4 @@ def redirect_back_or_default(default)
session[:return_to] = nil
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/agegate/gates_controller.rb
Expand Up @@ -2,6 +2,7 @@

module Agegate
class GatesController < ApplicationController
layout 'agegate/gates/application'

def show
unless cookies[:gate].blank?
Expand Down
8 changes: 2 additions & 6 deletions app/models/agegate/gate.rb
Expand Up @@ -28,14 +28,10 @@ def gate_pass?

def convert_date(hash, date_symbol_or_string)
attribute = date_symbol_or_string.to_s
if hash.has_value?('')
if hash.nil? || hash.empty? || hash.has_value?('')
nil
else
begin
Date.new(hash[attribute + '(1i)'].to_i, hash[attribute + '(2i)'].to_i, hash[attribute + '(3i)'].to_i)
rescue
nil
end
Date.new(hash[attribute + '(1i)'].to_i, hash[attribute + '(2i)'].to_i, hash[attribute + '(3i)'].to_i)
end
end

Expand Down
15 changes: 8 additions & 7 deletions app/views/agegate/gates/_form.html.erb
@@ -1,11 +1,12 @@
<%= form_tag(:controller => "gate", :action => "check", :method => "post") do %>
<%= label_tag :birthday, "Please insert you date of birth" %>
<%= date_select(
"user", "birthday",
<%= form_for @gate do |f| %>
<%= f.label :birthday, "Please insert your date of birth" %>
<%= f.date_select(
:birthday,
:order => [:day, :month, :year],
:start_year => Time.now.year - 100,
:end_year => Time.now.year - 10,
:start_year => Time.now.year - 4,
:end_year => Time.now.year - 100,
:prompt => { :day => 'day', :month => 'month', :year => 'year' })
%>
<%= submit_tag("Check") %>
<%= hidden_field_tag :referrer, request.referer %>
<%= f.submit "Check" %>
<% end %>
3 changes: 1 addition & 2 deletions app/views/agegate/gates/denied.html.erb
@@ -1,2 +1 @@
<h1>Gate#denied</h1>
<p>Find me in app/views/agegate/gate/denied.html.erb</p>
<h1>Access denied</h1>
14 changes: 1 addition & 13 deletions app/views/agegate/gates/show.html.erb
@@ -1,16 +1,4 @@
<h1>Age gate</h1>
<div class="gate">
<%= form_for @gate do |f| %>
<%= f.label :birthday, "Please insert your date of birth" %>
<%= f.date_select(
:birthday,
:order => [:day, :month, :year],
:start_year => Time.now.year - 100,
:end_year => Time.now.year - 10,
:prompt => { :day => 'day', :month => 'month', :year => 'year' })
%>
<%= hidden_field_tag :referrer, request.referer %>
<%= f.submit "Check" %>
<% end %>

<%= render 'form' %>
</div>
8 changes: 6 additions & 2 deletions lib/agegate/engine.rb
Expand Up @@ -5,7 +5,11 @@ class Engine < ::Rails::Engine
isolate_namespace Agegate

# default test framework
config.app_generators.test_framework :rspec
config.generators do |g|
g.test_framework :rspec
g.integration_tool :rspec
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end

# default options, we can override it in the initializer
config.agegate = ActiveSupport::OrderedOptions.new
Expand All @@ -20,7 +24,7 @@ class Engine < ::Rails::Engine
end

initializer "agegate.load_helpers" do |app|
ActionController::Base.send :include, Agegate::GatesHelper
ActionController::Base.send :include, GatesCheck
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/agegate/version.rb
@@ -1,3 +1,3 @@
module Agegate
VERSION = "0.0.2"
VERSION = "0.0.3"
end
4 changes: 2 additions & 2 deletions lib/generators/agegate/install_generator.rb
Expand Up @@ -3,18 +3,18 @@ class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../../templates', __FILE__)

def install

# run 'bundle install'
route "use_agegate"

# copy views
copy_file "views/show.html.erb", "app/views/agegate/gates/show.html.erb"
copy_file "views/denied.html.erb", "app/views/agegate/gates/denied.html.erb"
copy_file "views/_form.html.erb", "app/views/agegate/gates/_form.html.erb"
copy_file "views/application.html.erb", "app/views/layouts/agegate/gates/application.html.erb"

# copy assets
copy_file "assets/application.css", "app/assets/stylesheets/agegate/application.css"
copy_file "assets/gate.css", "app/assets/stylesheets/agegate/gate.css"

end
end
end
12 changes: 12 additions & 0 deletions lib/generators/templates/views/_form.html.erb
@@ -0,0 +1,12 @@
<%= form_for @gate do |f| %>
<%= f.label :birthday, "Please insert your date of birth" %>
<%= f.date_select(
:birthday,
:order => [:day, :month, :year],
:start_year => Time.now.year - 4,
:end_year => Time.now.year - 100,
:prompt => { :day => 'day', :month => 'month', :year => 'year' })
%>
<%= hidden_field_tag :referrer, request.referer %>
<%= f.submit "Check" %>
<% end %>
1 change: 1 addition & 0 deletions lib/generators/templates/views/denied.html.erb
@@ -0,0 +1 @@
<h1>Access denied</h1>
14 changes: 1 addition & 13 deletions lib/generators/templates/views/show.html.erb
@@ -1,16 +1,4 @@
<h1>Age gate</h1>
<div class="gate">
<%= form_for @gate do |f| %>
<%= f.label :birthday, "Please insert your date of birth" %>
<%= f.date_select(
:birthday,
:order => [:day, :month, :year],
:start_year => Time.now.year - 100,
:end_year => Time.now.year - 10,
:prompt => { :day => 'day', :month => 'month', :year => 'year' })
%>
<%= hidden_field_tag :referrer, request.referer %>
<%= f.submit "Check" %>
<% end %>

<%= render 'form' %>
</div>
13 changes: 13 additions & 0 deletions spec/controllers/agegate/gates_controller_spec.rb
@@ -0,0 +1,13 @@
# require 'spec_helper'

# module Agegate
# describe GatesController do

# describe "GET 'show'" do
# it "returns http success" do
# get('show', use_route: 'agegate')
# response.should be_success
# end
# end
# end
# end
23 changes: 23 additions & 0 deletions spec/features/visitors_can_pass_agegate_spec.rb
@@ -0,0 +1,23 @@
# spec/acceptance/visitors_can_pass_agegate_spec.rb
require 'spec_helper'

describe 'agegate' do
it 'block < 18 visitors' do
visit '/'

select_birthday 1, 'April', (Time.now.year - 10)
click_button 'Check'

page.should have_content('Access denied')
end

it 'allow > 18 visitors' do
visit '/'

select_birthday 1, 'April', (Time.now.year - 30)
click_button 'Check'

page.should have_content('Access granted')
end

end

0 comments on commit 11b7034

Please sign in to comment.