From ac033ffabde18318cc49655751b80b3d3906b61c Mon Sep 17 00:00:00 2001 From: Robert Richter Date: Sun, 16 Mar 2014 20:34:30 -0500 Subject: [PATCH] Use factory_girl for test fixtures --- Gemfile | 4 ++ Gemfile.lock | 52 +++++++++++-------- test/factories/character.rb | 6 +++ test/factories/session.rb | 6 +++ test/factories/user.rb | 7 +++ test/fixtures/.gitkeep | 0 test/fixtures/characters.yml | 9 ---- test/fixtures/sessions.yml | 9 ---- test/fixtures/users.yml | 11 ---- test/functional/characters_controller_test.rb | 2 +- test/functional/sessions_controller_test.rb | 2 +- test/test_helper.rb | 3 +- test/unit/character_test.rb | 3 +- test/unit/session_test.rb | 3 +- test/unit/user_test.rb | 3 +- 15 files changed, 61 insertions(+), 59 deletions(-) create mode 100644 test/factories/character.rb create mode 100644 test/factories/session.rb create mode 100644 test/factories/user.rb delete mode 100644 test/fixtures/.gitkeep delete mode 100644 test/fixtures/characters.yml delete mode 100644 test/fixtures/sessions.yml delete mode 100644 test/fixtures/users.yml diff --git a/Gemfile b/Gemfile index 5a922609..9e8ad8d0 100644 --- a/Gemfile +++ b/Gemfile @@ -30,6 +30,10 @@ group :assets do gem 'uglifier', '>= 1.0.3' end +group :test do + gem 'factory_girl' +end + gem 'jquery-rails' # To use ActiveModel has_secure_password diff --git a/Gemfile.lock b/Gemfile.lock index a1648ac4..8d67bbad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,18 +49,19 @@ GEM coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.4.0) + coffee-script-source (1.7.0) commonjs (0.2.7) erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) + execjs (2.0.2) + factory_girl (4.4.0) + activesupport (>= 3.0.0) hike (1.2.3) - httparty (0.12.0) + httparty (0.13.0) json (~> 1.8) multi_xml (>= 0.5.2) i18n (0.6.1) journey (1.0.4) - jquery-rails (2.1.4) + jquery-rails (3.1.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) @@ -71,7 +72,7 @@ GEM less (~> 2.4.0) less-rails-fontawesome (0.8.0) less-rails (~> 2.4.2) - libv8 (3.3.10.4) + libv8 (3.16.14.3) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -79,22 +80,27 @@ GEM mini_portile (0.5.2) mongo (1.6.0) bson (= 1.6.0) - mongoid (2.4.6) - activemodel (~> 3.1) - mongo (~> 1.3) - tzinfo (~> 0.3.22) - mongoid-paperclip (0.0.8) + mongoid (3.1.6) + activemodel (~> 3.2) + moped (~> 1.4) + origin (~> 1.0) + tzinfo (~> 0.3.29) + mongoid-paperclip (0.0.9) paperclip (>= 2.3.6) - multi_json (1.8.2) + moped (1.5.2) + multi_json (1.9.0) multi_xml (0.5.5) nokogiri (1.6.1) mini_portile (~> 0.5.0) - paperclip (3.5.2) + nokogiri (1.6.1-x86-mingw32) + mini_portile (~> 0.5.0) + origin (1.1.0) + paperclip (4.1.1) activemodel (>= 3.0.0) activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types - polyglot (0.3.3) + polyglot (0.3.4) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -117,11 +123,12 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.1.0) + rake (10.1.1) rdoc (3.12.2) json (~> 1.4) + ref (1.0.5) rmagick (2.13.2) - sass (3.2.12) + sass (3.3.3) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) @@ -131,27 +138,30 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - therubyracer (0.10.1) - libv8 (~> 3.3.10) + therubyracer (0.12.1) + libv8 (~> 3.16.14.0) + ref thor (0.18.1) tilt (1.4.1) treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.38) - uglifier (1.3.0) + tzinfo (0.3.39) + uglifier (2.5.0) execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) + json (>= 1.8.0) uuidtools (2.1.4) PLATFORMS ruby + x86-mingw32 DEPENDENCIES aws-sdk (~> 1.3.4) bootplus-rails bson_ext (= 1.6.0) coffee-rails (~> 3.2.1) + factory_girl jquery-rails less-rails less-rails-fontawesome diff --git a/test/factories/character.rb b/test/factories/character.rb new file mode 100644 index 00000000..3b745e06 --- /dev/null +++ b/test/factories/character.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :character do + name "MyString" + age "MyString" + end +end \ No newline at end of file diff --git a/test/factories/session.rb b/test/factories/session.rb new file mode 100644 index 00000000..ff1c80c0 --- /dev/null +++ b/test/factories/session.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :session do + username "MyString" + password "MyString" + end +end \ No newline at end of file diff --git a/test/factories/user.rb b/test/factories/user.rb new file mode 100644 index 00000000..a8335b52 --- /dev/null +++ b/test/factories/user.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :user do + name "MyString" + email "MyString" + password "MyString" + end +end \ No newline at end of file diff --git a/test/fixtures/.gitkeep b/test/fixtures/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/test/fixtures/characters.yml b/test/fixtures/characters.yml deleted file mode 100644 index 7a664fae..00000000 --- a/test/fixtures/characters.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - name: MyString - age: MyString - -two: - name: MyString - age: MyString diff --git a/test/fixtures/sessions.yml b/test/fixtures/sessions.yml deleted file mode 100644 index 063d3107..00000000 --- a/test/fixtures/sessions.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - username: MyString - password: MyString - -two: - username: MyString - password: MyString diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml deleted file mode 100644 index 735483f4..00000000 --- a/test/fixtures/users.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - name: MyString - email: MyString - password: MyString - -two: - name: MyString - email: MyString - password: MyString diff --git a/test/functional/characters_controller_test.rb b/test/functional/characters_controller_test.rb index 3a945ffe..393c8553 100644 --- a/test/functional/characters_controller_test.rb +++ b/test/functional/characters_controller_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class CharactersControllerTest < ActionController::TestCase setup do - @character = characters(:one) + @character = build(:character) end test "should get index" do diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb index 75dd9230..96110a13 100644 --- a/test/functional/sessions_controller_test.rb +++ b/test/functional/sessions_controller_test.rb @@ -2,7 +2,7 @@ require 'test_helper' class SessionsControllerTest < ActionController::TestCase setup do - @session = sessions(:one) + @session = build(:session) end test "should get index" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 6c01e890..9265dbf9 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,4 +3,5 @@ require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase -end + include FactoryGirl::Syntax::Methods +end \ No newline at end of file diff --git a/test/unit/character_test.rb b/test/unit/character_test.rb index 47cb44d0..bb4ff173 100644 --- a/test/unit/character_test.rb +++ b/test/unit/character_test.rb @@ -2,7 +2,6 @@ require 'test_helper' class CharacterTest < ActiveSupport::TestCase test "character exists" do - assert_not_nil characters(:one), "Characters test fixture is inaccessible" - assert_not_nil characters(:two), "Characters test fixture is inaccessible" + assert_not_nil build(:character), "Characters factory is returning nil" end end diff --git a/test/unit/session_test.rb b/test/unit/session_test.rb index 31eae9a1..843028c8 100644 --- a/test/unit/session_test.rb +++ b/test/unit/session_test.rb @@ -2,7 +2,6 @@ require 'test_helper' class SessionTest < ActiveSupport::TestCase test "session exists" do - assert_not_nil sessions(:one), "Sessions test fixture is inaccessible" - assert_not_nil sessions(:two), "Sessions test fixture is inaccessible" + assert_not_nil build(:session), "Sessions factory is returning nil" end end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 9119e92e..ff561469 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -2,7 +2,6 @@ require 'test_helper' class UserTest < ActiveSupport::TestCase test "user exists" do - assert_not_nil user(:one), "Users test fixture is inaccessible" - assert_not_nil user(:two), "Users test fixture is inaccessible" + assert_not_nil build(:user), "Users factory is returning nil" end end