Skip to content

Commit

Permalink
Added factory_girl
Browse files Browse the repository at this point in the history
  • Loading branch information
ml committed Dec 21, 2010
1 parent acfe7bb commit d408f8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -13,4 +13,5 @@ group :development, :test do
gem 'sqlite3-ruby', '~> 1.3'
end
gem 'webrat', :git => 'http://github.com/kalv/webrat.git'
gem 'factory_girl', :git => 'http://github.com/thoughtbot/factory_girl.git'
end
28 changes: 28 additions & 0 deletions spec/factories.rb
@@ -0,0 +1,28 @@
FactoryGirl.define do
%w[team manager division league].each do |type|
sequence :"#{type}_name" do |n|
"#{type.capitalize} #{n}"
end
end


factory :team do
league_id rand(99999)
division_id rand(99999)
name Factory.next(:team_name)
manager Factory.next(:manager_name)
founded 1869 + rand(130)
wins (wins = rand(163))
losses 162 - wins
win_percentage ("%.3f" % (wins.to_f / 162).to_f)
end

factory :league do
name Factory.next(:league_name)
end

factory :division do
name Factory.next(:division_name)
association :league
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -14,6 +14,8 @@
require File.expand_path('../dummy_app/config/environment', __FILE__)
require "rails/test_help"
require "rspec/rails"
require "factory_girl"
require "factories"

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
Expand Down

0 comments on commit d408f8f

Please sign in to comment.