Skip to content
This repository was archived by the owner on May 29, 2020. It is now read-only.

Commit de061d6

Browse files
committed
GH-39: Introduce factory_bot_rails gem instead of factory_girl_rails gem
1 parent aef1fcc commit de061d6

25 files changed

+48
-48
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ gem "exception_notification"
4242
gem "haml-rails"
4343
gem "simple_form", '~> 3.5.0'
4444
gem "kaminari"
45-
gem "factory_girl_rails"
45+
gem "factory_bot_rails"
4646
gem 'faker'
4747
gem "cancan", github: "ryanb/cancan", branch: "2.0"
4848
gem 'therubyracer'

Gemfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ GEM
113113
actionmailer (>= 4.0, < 6)
114114
activesupport (>= 4.0, < 6)
115115
execjs (2.7.0)
116-
factory_girl (4.9.0)
116+
factory_bot (4.8.2)
117117
activesupport (>= 3.0.0)
118-
factory_girl_rails (4.9.0)
119-
factory_girl (~> 4.9.0)
118+
factory_bot_rails (4.8.2)
119+
factory_bot (~> 4.8.2)
120120
railties (>= 3.0.0)
121121
faker (1.8.7)
122122
i18n (>= 0.7)
@@ -311,7 +311,7 @@ DEPENDENCIES
311311
ci_reporter
312312
dalli
313313
exception_notification
314-
factory_girl_rails
314+
factory_bot_rails
315315
faker
316316
font-awesome-less (~> 4.5.0)
317317
haml-rails

spec/controllers/comments_controller_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
# This should return the minimal set of attributes required to create a valid
2424
# Comment. As you add validations to Comment, be sure to
2525
# adjust the attributes here as well.
26-
let(:valid_attributes) { FactoryGirl.attributes_for(:comment).slice(:body) }
26+
let(:valid_attributes) { FactoryBot.attributes_for(:comment).slice(:body) }
2727

2828
# This should return the minimal set of values that should be in the session
2929
# in order to pass any filters (e.g. authentication) defined in
3030
# CommentsController. Be sure to keep this updated too.
3131
let(:valid_session) { { user_id: @comment.user_id } }
3232

3333
before do
34-
@comment = FactoryGirl.create(:comment)
34+
@comment = FactoryBot.create(:comment)
3535
@post = @comment.post
3636
end
3737

@@ -135,7 +135,7 @@
135135
end
136136
end
137137
context "another's comment on another's post" do
138-
let(:session){ {user_id: FactoryGirl.create(:user).id} }
138+
let(:session){ {user_id: FactoryBot.create(:user).id} }
139139
it "fail to destroy the requested comment" do
140140
expect{subject}.to raise_error CanCan::Unauthorized
141141
end

spec/controllers/posts_controller_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
# This should return the minimal set of attributes required to create a valid
2424
# Post. As you add validations to Post, be sure to
2525
# adjust the attributes here as well.
26-
let(:valid_attributes) { FactoryGirl.attributes_for(:post) }
26+
let(:valid_attributes) { FactoryBot.attributes_for(:post) }
2727

2828
# This should return the minimal set of values that should be in the session
2929
# in order to pass any filters (e.g. authentication) defined in
3030
# PostsController. Be sure to keep this updated too.
3131
let(:valid_session) { { user_id: @post.user_id } }
3232

3333
before do
34-
@post = FactoryGirl.create(:post)
34+
@post = FactoryBot.create(:post)
3535
end
3636

3737
describe "GET index" do

spec/controllers/sessions_controller_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22

33
describe SessionsController do
4-
let(:valid_attributes){ FactoryGirl.attributes_for(:user) }
4+
let(:valid_attributes){ FactoryBot.attributes_for(:user) }
55
before do
66
@user = User.create!(valid_attributes)
77
end

spec/controllers/users_controller_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
# This should return the minimal set of attributes required to create a valid
2424
# User. As you add validations to User, be sure to
2525
# adjust the attributes here as well.
26-
let(:valid_attributes) { FactoryGirl.attributes_for(:user) }
26+
let(:valid_attributes) { FactoryBot.attributes_for(:user) }
2727

2828
# This should return the minimal set of values that should be in the session
2929
# in order to pass any filters (e.g. authentication) defined in
3030
# UsersController. Be sure to keep this updated too.
3131
let(:valid_session) { { user_id: @user.id } }
3232

3333
before do
34-
@user = FactoryGirl.create(:user)
34+
@user = FactoryBot.create(:user)
3535
end
3636

3737
describe "GET show" do

spec/factories/comments.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Read about factories at https://github.com/thoughtbot/factory_girl
22

3-
FactoryGirl.define do
3+
FactoryBot.define do
44
factory :comment do
55
user
66
post

spec/factories/posts.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Read about factories at https://github.com/thoughtbot/factory_girl
22

3-
FactoryGirl.define do
3+
FactoryBot.define do
44
factory :post do
55
user
66
text { Faker::Lorem.sentence(10) }

spec/factories/users.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Read about factories at https://github.com/thoughtbot/factory_girl
22

3-
FactoryGirl.define do
3+
FactoryBot.define do
44
factory :user do
55
sequence(:username) {|n| Faker::Internet.user_name[0..8] + n.to_s }
66
password { 'abcdefghjkmnpqrtuvwxyzABCDEFGHJKLMNPQRTUVWXY346789+-*#$_'.chars.sample(8).join }

spec/models/post_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'rails_helper'
22

33
describe Post do
4-
subject(:post){ FactoryGirl.create(:post) }
4+
subject(:post){ FactoryBot.create(:post) }
55
describe "destroy" do
66
it "also destroys comments" do
7-
comments = FactoryGirl.create_list(:comment, 2, post: post)
7+
comments = FactoryBot.create_list(:comment, 2, post: post)
88
post.destroy
99
expect{comments[0].reload}.to raise_error ActiveRecord::RecordNotFound
1010
expect{comments[1].reload}.to raise_error ActiveRecord::RecordNotFound
@@ -13,9 +13,9 @@
1313

1414
describe '#cached_comments' do
1515
before do
16-
@post = FactoryGirl.create(:post)
16+
@post = FactoryBot.create(:post)
1717
@post.flush_cache
18-
@comments = FactoryGirl.create_list(:comment, 2, post: @post).sort_by(&:id)
18+
@comments = FactoryBot.create_list(:comment, 2, post: @post).sort_by(&:id)
1919
end
2020
context 'before caching' do
2121
it 'gets comments from DB' do
@@ -47,7 +47,7 @@
4747
expect(Rails.cache.read([@post, 'comments'])).to be_present
4848
end
4949
it 'clears cache when another comment are added' do
50-
FactoryGirl.create(:comment, post: @post)
50+
FactoryBot.create(:comment, post: @post)
5151
expect(Rails.cache.read([@post, 'comments'])).to be_blank
5252
end
5353
it 'clears cache when one of the comments is destoryed' do

spec/models/user_spec.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'rails_helper'
22

33
describe User do
4-
subject(:user){ FactoryGirl.create(:user) }
4+
subject(:user){ FactoryBot.create(:user) }
55
describe "password validation" do
66
context "on create" do
77
it "fail if length is 5" do
8-
user = FactoryGirl.build(:user, password: "hogeh")
8+
user = FactoryBot.build(:user, password: "hogeh")
99
expect(user.save).to eq false
1010
expect(user.errors[:password]).not_to be_nil
1111
end
@@ -37,23 +37,23 @@
3737
end
3838
describe "destroy" do
3939
it "also destroys my posts" do
40-
posts = FactoryGirl.create_list(:post, 2, user: user)
40+
posts = FactoryBot.create_list(:post, 2, user: user)
4141
user.destroy
4242
expect{posts[0].reload}.to raise_error ActiveRecord::RecordNotFound
4343
expect{posts[1].reload}.to raise_error ActiveRecord::RecordNotFound
4444
end
4545
it "also destroys comments on destroyed posts" do
46-
post = FactoryGirl.create(:post, user: user)
47-
comments = FactoryGirl.create_list(:comment, 2, post: post)
46+
post = FactoryBot.create(:post, user: user)
47+
comments = FactoryBot.create_list(:comment, 2, post: post)
4848
user.destroy
4949
expect{comments[0].reload}.to raise_error ActiveRecord::RecordNotFound
5050
expect{comments[1].reload}.to raise_error ActiveRecord::RecordNotFound
5151
end
5252
it "also destroys my comments on other's posts" do
53-
comments = FactoryGirl.create_list(:comment, 2, user: user)
53+
comments = FactoryBot.create_list(:comment, 2, user: user)
5454
user.destroy
5555
expect{comments[0].reload}.to raise_error ActiveRecord::RecordNotFound
5656
expect{comments[1].reload}.to raise_error ActiveRecord::RecordNotFound
5757
end
5858
end
59-
end
59+
end

spec/requests/comments_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "Comments" do
44
before do
5-
@post = FactoryGirl.create(:post)
5+
@post = FactoryBot.create(:post)
66
end
77
describe "GET /posts/:post_id/comments/new" do
88
it "works! (now write some real specs)" do

spec/requests/posts_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "Posts" do
44
before do
5-
@post = FactoryGirl.create(:post)
5+
@post = FactoryBot.create(:post)
66
end
77
describe "GET /posts" do
88
it "works! (now write some real specs)" do

spec/requests/users_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "Users" do
44
before do
5-
@user = FactoryGirl.create(:user)
5+
@user = FactoryBot.create(:user)
66
end
77
describe "GET /users" do
88
it "works! (now write some real specs)" do

spec/views/comments/edit.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "comments/edit" do
44
before(:each) do
5-
@comment = assign(:comment, FactoryGirl.create(:comment))
5+
@comment = assign(:comment, FactoryBot.create(:comment))
66
end
77

88
it "renders the edit comment form" do

spec/views/comments/new.html.haml_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
describe "comments/new" do
44
before(:each) do
5-
@post = assign(:post, FactoryGirl.create(:post))
6-
assign(:comment, FactoryGirl.build(:comment))
5+
@post = assign(:post, FactoryBot.create(:post))
6+
assign(:comment, FactoryBot.build(:comment))
77
end
88

99
it "renders new comment form" do

spec/views/layouts/application.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
end
1616

1717
context "with login" do
18-
let(:user){ FactoryGirl.create(:user) }
18+
let(:user){ FactoryBot.create(:user) }
1919
it { should_not have_xpath "//a[@href='#{new_sessions_path}']" }
2020
it { should have_xpath "//a[@href='#{sessions_path}']" }
2121
it { should have_xpath "//a[@href='#{new_post_path}']" }

spec/views/posts/edit.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "posts/edit" do
44
before(:each) do
5-
@post = assign(:post, FactoryGirl.create(:post))
5+
@post = assign(:post, FactoryBot.create(:post))
66
end
77

88
it "renders the edit post form" do

spec/views/posts/index.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe "posts/index" do
44
before(:each) do
55
@q = Post.search
6-
@posts = assign(:posts, Kaminari.paginate_array(FactoryGirl.create_list(:post, 2)))
6+
@posts = assign(:posts, Kaminari.paginate_array(FactoryBot.create_list(:post, 2)))
77
end
88

99
context "without login" do

spec/views/posts/new.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "posts/new" do
44
before(:each) do
5-
assign(:post, FactoryGirl.build(:post))
5+
assign(:post, FactoryBot.build(:post))
66
end
77

88
it "renders new post form" do

spec/views/posts/show.html.haml_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
describe "posts/show" do
44
subject { render; response.body }
5-
let(:current_user){ FactoryGirl.create(:user) }
6-
let(:post){ FactoryGirl.create(:post) }
5+
let(:current_user){ FactoryBot.create(:user) }
6+
let(:post){ FactoryBot.create(:post) }
77
before do
88
Rails.cache.clear
99
allow(controller).to receive(:current_user).and_return(current_user)
@@ -16,7 +16,7 @@
1616
it { should match(post.user.username) }
1717

1818
context "owned by login user" do
19-
let(:post){ FactoryGirl.create(:post, user: current_user) }
19+
let(:post){ FactoryBot.create(:post, user: current_user) }
2020
it { should have_xpath "//a[@href='#{edit_post_path(post)}']" }
2121
end
2222

@@ -26,8 +26,8 @@
2626

2727
describe "comments" do
2828
before do
29-
FactoryGirl.create_list(:comment, 3, post: post)
30-
FactoryGirl.create_list(:comment, 2, post: post, user: current_user)
29+
FactoryBot.create_list(:comment, 3, post: post)
30+
FactoryBot.create_list(:comment, 2, post: post, user: current_user)
3131
end
3232
it { should have_xpath "//a[contains(@href,'/comments/')][contains(@href,'/edit')]", count: 2 }
3333
end

spec/views/sessions/new.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "sessions/new.html.haml" do
44
before do
5-
assign(:user, FactoryGirl.build(:user))
5+
assign(:user, FactoryBot.build(:user))
66
end
77
it do
88
render

spec/views/users/edit.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "users/edit" do
44
before(:each) do
5-
@user = assign(:user, FactoryGirl.create(:user))
5+
@user = assign(:user, FactoryBot.create(:user))
66
end
77

88
it "renders the edit user form" do

spec/views/users/new.html.haml_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "users/new" do
44
before(:each) do
5-
assign(:user, FactoryGirl.build(:user))
5+
assign(:user, FactoryBot.build(:user))
66
end
77

88
it "renders new user form" do

spec/views/users/show.html.haml_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "users/show" do
44
subject { render; response.body }
5-
let(:current_user){ FactoryGirl.create(:user) }
5+
let(:current_user){ FactoryBot.create(:user) }
66
before do
77
allow(controller).to receive(:current_user).and_return(current_user)
88
allow(view).to receive(:current_user).and_return(current_user)
@@ -18,7 +18,7 @@
1818
end
1919

2020
context "another user" do
21-
let(:user){ FactoryGirl.create(:user) }
21+
let(:user){ FactoryBot.create(:user) }
2222
it { should_not have_xpath "//a[contains(@href,'/edit')]" }
2323
end
2424
end

0 commit comments

Comments
 (0)