Commit 00300501 by Clinton Blackburn

Added factory_girl

Factories will replace spec helper methods created for generating test data. Factories are more flexible than the helpers.
parent 331772c4
...@@ -14,7 +14,7 @@ gem 'sinatra' ...@@ -14,7 +14,7 @@ gem 'sinatra'
gem 'yajl-ruby' gem 'yajl-ruby'
gem 'mongoid', "~>5.0" gem 'mongoid', '~> 5.0.0'
gem 'bson', '~>3.1' gem 'bson', '~>3.1'
gem 'bson_ext' gem 'bson_ext'
gem 'protected_attributes' gem 'protected_attributes'
...@@ -27,7 +27,6 @@ gem 'mongoid-tree', :git => 'https://github.com/macdiesel/mongoid-tree' ...@@ -27,7 +27,6 @@ gem 'mongoid-tree', :git => 'https://github.com/macdiesel/mongoid-tree'
gem 'rs_voteable_mongo', :git => 'https://github.com/navneet35371/voteable_mongo.git' gem 'rs_voteable_mongo', :git => 'https://github.com/navneet35371/voteable_mongo.git'
gem 'mongoid_magic_counter_cache' gem 'mongoid_magic_counter_cache'
gem 'faker'
gem 'will_paginate_mongoid', "~>2.0" gem 'will_paginate_mongoid', "~>2.0"
gem 'rdiscount' gem 'rdiscount'
gem 'nokogiri', "~>1.6.7.1" gem 'nokogiri', "~>1.6.7.1"
...@@ -40,12 +39,14 @@ gem 'dalli' ...@@ -40,12 +39,14 @@ gem 'dalli'
gem 'rest-client' gem 'rest-client'
group :test do group :test do
gem 'rspec' gem 'codecov', :require => false
gem 'rack-test', :require => "rack/test" gem 'database_cleaner', '~> 1.5.1'
gem 'factory_girl', '~> 4.0'
gem 'faker', '~> 1.6'
gem 'guard' gem 'guard'
gem 'guard-unicorn' gem 'guard-unicorn'
gem 'codecov', :require => false gem 'rack-test', :require => 'rack/test'
gem 'database_cleaner', "~>1.5.1" gem 'rspec', '~> 2.11.0'
end end
gem 'newrelic_rpm' gem 'newrelic_rpm'
......
...@@ -55,8 +55,10 @@ GEM ...@@ -55,8 +55,10 @@ GEM
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
enumerize (0.11.0) enumerize (0.11.0)
activesupport (>= 3.2) activesupport (>= 3.2)
faker (1.0.1) factory_girl (4.5.0)
i18n (~> 0.4) activesupport (>= 3.0.0)
faker (1.6.1)
i18n (~> 0.5)
guard (1.3.2) guard (1.3.2)
listen (>= 0.4.2) listen (>= 0.4.2)
thor (>= 0.14.6) thor (>= 0.14.6)
...@@ -173,11 +175,12 @@ DEPENDENCIES ...@@ -173,11 +175,12 @@ DEPENDENCIES
delayed_job delayed_job
delayed_job_mongoid delayed_job_mongoid
enumerize enumerize
faker factory_girl (~> 4.0)
faker (~> 1.6)
guard guard
guard-unicorn guard-unicorn
i18n i18n
mongoid (~> 5.0) mongoid (~> 5.0.0)
mongoid-tree! mongoid-tree!
mongoid_magic_counter_cache mongoid_magic_counter_cache
newrelic_rpm newrelic_rpm
...@@ -192,10 +195,13 @@ DEPENDENCIES ...@@ -192,10 +195,13 @@ DEPENDENCIES
rdiscount rdiscount
rest-client rest-client
rs_voteable_mongo! rs_voteable_mongo!
rspec rspec (~> 2.11.0)
sinatra sinatra
tire (= 0.6.2) tire (= 0.6.2)
tire-contrib tire-contrib
unicorn unicorn
will_paginate_mongoid (~> 2.0) will_paginate_mongoid (~> 2.0)
yajl-ruby yajl-ruby
BUNDLED WITH
1.11.2
require 'faker'
# Reload i18n data for faker
I18n.reload!
FactoryGirl.define do
factory :user do
# Initialize the model with all attributes since we are using a custom _id field.
# See https://github.com/thoughtbot/factory_girl/issues/544.
initialize_with { new(attributes) }
sequence(:username) { |n| "#{Faker::Internet.user_name}_#{n}" }
sequence(:external_id) { username }
end
factory :comment_thread do
title { Faker::Lorem.sentence }
body { Faker::Lorem.paragraph }
course_id { Faker::Lorem.word }
thread_type :discussion
commentable_id { Faker::Lorem.word }
association :author, factory: :user
group_id nil
pinned false
trait :subscribe_author do
after(:create) do |thread|
thread.author.subscribe(thread)
end
end
trait :with_group_id do
group_id { Faker::Number.number(4) }
end
end
factory :comment do
association :author, factory: :user
comment_thread { parent ? parent.comment_thread : create(:comment_thread) }
body { Faker::Lorem.paragraph }
course_id { comment_thread.course_id }
commentable_id { comment_thread.commentable_id }
end
end
...@@ -9,13 +9,13 @@ end ...@@ -9,13 +9,13 @@ end
require File.join(File.dirname(__FILE__), '..', 'app') require File.join(File.dirname(__FILE__), '..', 'app')
require 'sinatra'
require 'rack/test' require 'rack/test'
require 'sinatra'
require 'yajl' require 'yajl'
require 'database_cleaner'
require 'support/database_cleaner' require 'support/database_cleaner'
require 'support/elasticsearch' require 'support/elasticsearch'
require 'support/factory_girl'
# setup test environment # setup test environment
set :environment, :test set :environment, :test
......
require 'factory_girl'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
FactoryGirl.find_definitions
config.before(:suite) do
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment