Skip to content

Commit 1f3be3a

Browse files
author
Michael MacDonald
committed
Initial version of demo
0 parents  commit 1f3be3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+9026
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db/*.sqlite3
2+
log/*.log

README

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
== Pickle Example
2+
3+
This is a very basic and contrived example designed to demonstrate the benefits of using Ian White's "Pickle gem":http://github.com/ianwhite/pickle with Cucumber to improve the way you BDD.
4+
5+
== Getting Started
6+
7+
1. rake gems:install
8+
2. rake db:migrate
9+
3. rake db:test:prepare
10+
4. cucumber
11+
12+
For more information see "Pickle my Cucumber!":http://rubyflare.com/2009/10/28/pickle-my-cucumber

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3+
4+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5+
6+
require 'rake'
7+
require 'rake/testtask'
8+
require 'rake/rdoctask'
9+
10+
require 'tasks/rails'
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Filters added to this controller apply to all controllers in the application.
2+
# Likewise, all the methods added will be available for all controllers.
3+
4+
class ApplicationController < ActionController::Base
5+
helper :all # include all helpers, all the time
6+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
7+
8+
# Scrub sensitive parameters from your log
9+
# filter_parameter_logging :password
10+
end
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class CompaniesController < ApplicationController
2+
3+
def index
4+
@companies = Company.all
5+
end
6+
7+
def show
8+
@company = Company.find(params[:id])
9+
end
10+
11+
end
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class EmployeesController < ApplicationController
2+
3+
def index
4+
@employees = Company.find(params[:company_id]).employees
5+
end
6+
7+
end

app/controllers/people_controller.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class PeopleController < ApplicationController
2+
3+
def index
4+
@people = Person.all
5+
end
6+
7+
def show
8+
@person = Person.find(params[:id])
9+
end
10+
11+
end

app/helpers/application_helper.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Methods added to this helper will be available to all templates in the application.
2+
module ApplicationHelper
3+
end

app/helpers/companies_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CompaniesHelper
2+
end

app/helpers/people_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module PeopleHelper
2+
end

app/models/company.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Company < ActiveRecord::Base
2+
has_many :employees, :class_name => "Person", :foreign_key => "company_id"
3+
end

app/models/notifier.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Notifier < ActionMailer::Base
2+
3+
def activation_notification(recipient)
4+
recipients recipient.email
5+
subject "Account activated"
6+
body :account => recipient
7+
end
8+
9+
end

app/models/person.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Person < ActiveRecord::Base
2+
3+
belongs_to :company
4+
5+
validates_presence_of :name
6+
validates_presence_of :age
7+
8+
def child?
9+
age < 18
10+
end
11+
12+
def adult?
13+
age >= 18
14+
end
15+
16+
def activate
17+
Notifier.deliver_activation_notification(self)
18+
end
19+
20+
end

app/views/companies/index.html.erb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<h1>Listing companies</h1>
2+
3+
<table>
4+
<tr>
5+
<th>Name</th>
6+
</tr>
7+
8+
<% @companies.each do |company| %>
9+
<tr>
10+
<td><%=h company.name %></td>
11+
<td><%= link_to 'Show', company %></td>
12+
</tr>
13+
<% end %>
14+
</table>

app/views/companies/show.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<p>
2+
<b>Name:</b>
3+
<%=h @company.name %>
4+
</p>
5+
6+
<%= link_to 'Back', companies_path %>

app/views/employees/index.html.erb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h1>Listing employees</h1>
2+
3+
<table>
4+
<tr>
5+
</tr>
6+
7+
<% @employees.each do |person| %>
8+
<tr>
9+
<td><%= link_to 'Show', person %></td>
10+
</tr>
11+
<% end %>
12+
</table>

app/views/layouts/companies.html.erb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
4+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5+
<head>
6+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7+
<title>Companies: <%= controller.action_name %></title>
8+
<%= stylesheet_link_tag 'scaffold' %>
9+
</head>
10+
<body>
11+
12+
<p style="color: green"><%= flash[:notice] %></p>
13+
14+
<%= yield %>
15+
16+
</body>
17+
</html>

app/views/layouts/people.html.erb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
4+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5+
<head>
6+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7+
<title>People: <%= controller.action_name %></title>
8+
<%= stylesheet_link_tag 'scaffold' %>
9+
</head>
10+
<body>
11+
12+
<p style="color: green"><%= flash[:notice] %></p>
13+
14+
<%= yield %>
15+
16+
</body>
17+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hi!

app/views/people/index.html.erb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<h1>Listing people</h1>
2+
3+
<table>
4+
<tr>
5+
</tr>
6+
7+
<% @people.each do |person| %>
8+
<tr>
9+
<td><%= link_to 'Show', person %></td>
10+
</tr>
11+
<% end %>
12+
</table>

app/views/people/show.html.erb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>
2+
<b>Name:</b>
3+
<%=h @person.name %>
4+
</p>
5+
6+
<%= link_to 'Edit', edit_person_path(@person) %> |
7+
<%= link_to 'Back', people_path %>

config/boot.rb

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Don't change this file!
2+
# Configure your app in config/environment.rb and config/environments/*.rb
3+
4+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5+
6+
module Rails
7+
class << self
8+
def boot!
9+
unless booted?
10+
preinitialize
11+
pick_boot.run
12+
end
13+
end
14+
15+
def booted?
16+
defined? Rails::Initializer
17+
end
18+
19+
def pick_boot
20+
(vendor_rails? ? VendorBoot : GemBoot).new
21+
end
22+
23+
def vendor_rails?
24+
File.exist?("#{RAILS_ROOT}/vendor/rails")
25+
end
26+
27+
def preinitialize
28+
load(preinitializer_path) if File.exist?(preinitializer_path)
29+
end
30+
31+
def preinitializer_path
32+
"#{RAILS_ROOT}/config/preinitializer.rb"
33+
end
34+
end
35+
36+
class Boot
37+
def run
38+
load_initializer
39+
Rails::Initializer.run(:set_load_path)
40+
end
41+
end
42+
43+
class VendorBoot < Boot
44+
def load_initializer
45+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46+
Rails::Initializer.run(:install_gem_spec_stubs)
47+
Rails::GemDependency.add_frozen_gem_path
48+
end
49+
end
50+
51+
class GemBoot < Boot
52+
def load_initializer
53+
self.class.load_rubygems
54+
load_rails_gem
55+
require 'initializer'
56+
end
57+
58+
def load_rails_gem
59+
if version = self.class.gem_version
60+
gem 'rails', version
61+
else
62+
gem 'rails'
63+
end
64+
rescue Gem::LoadError => load_error
65+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66+
exit 1
67+
end
68+
69+
class << self
70+
def rubygems_version
71+
Gem::RubyGemsVersion rescue nil
72+
end
73+
74+
def gem_version
75+
if defined? RAILS_GEM_VERSION
76+
RAILS_GEM_VERSION
77+
elsif ENV.include?('RAILS_GEM_VERSION')
78+
ENV['RAILS_GEM_VERSION']
79+
else
80+
parse_gem_version(read_environment_rb)
81+
end
82+
end
83+
84+
def load_rubygems
85+
min_version = '1.3.2'
86+
require 'rubygems'
87+
unless rubygems_version >= min_version
88+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89+
exit 1
90+
end
91+
92+
rescue LoadError
93+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94+
exit 1
95+
end
96+
97+
def parse_gem_version(text)
98+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99+
end
100+
101+
private
102+
def read_environment_rb
103+
File.read("#{RAILS_ROOT}/config/environment.rb")
104+
end
105+
end
106+
end
107+
end
108+
109+
# All that for this:
110+
Rails.boot!

config/database.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SQLite version 3.x
2+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
3+
development:
4+
adapter: sqlite3
5+
database: db/development.sqlite3
6+
pool: 5
7+
timeout: 5000
8+
9+
# Warning: The database defined as "test" will be erased and
10+
# re-generated from your development database when you run "rake".
11+
# Do not set this db to the same as development or production.
12+
test: &TEST
13+
adapter: sqlite3
14+
database: db/test.sqlite3
15+
pool: 5
16+
timeout: 5000
17+
18+
production:
19+
adapter: sqlite3
20+
database: db/production.sqlite3
21+
pool: 5
22+
timeout: 5000
23+
24+
cucumber:
25+
<<: *TEST

config/environment.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Be sure to restart your server when you modify this file
2+
3+
# Specifies gem version of Rails to use when vendor/rails is not present
4+
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
5+
6+
# Bootstrap the Rails environment, frameworks, and default configuration
7+
require File.join(File.dirname(__FILE__), 'boot')
8+
9+
Rails::Initializer.run do |config|
10+
# Settings in config/environments/* take precedence over those specified here.
11+
# Application configuration should go into files in config/initializers
12+
# -- all .rb files in that directory are automatically loaded.
13+
14+
# Add additional load paths for your own custom dirs
15+
# config.load_paths += %W( #{RAILS_ROOT}/extras )
16+
17+
# Specify gems that this application depends on and have them installed with rake gems:install
18+
# config.gem "bj"
19+
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20+
# config.gem "sqlite3-ruby", :lib => "sqlite3"
21+
# config.gem "aws-s3", :lib => "aws/s3"
22+
23+
# Only load the plugins named here, in the order given (default is alphabetical).
24+
# :all can be used as a placeholder for all plugins not explicitly named
25+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26+
27+
# Skip frameworks you're not going to use. To use Rails without a database,
28+
# you must remove the Active Record framework.
29+
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30+
31+
# Activate observers that should always be running
32+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33+
34+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35+
# Run "rake -D time" for a list of tasks for finding time zone names.
36+
config.time_zone = 'UTC'
37+
38+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40+
# config.i18n.default_locale = :de
41+
end

0 commit comments

Comments
 (0)