Skip to content

Commit

Permalink
Replace factory girl with bot
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Jul 15, 2018
1 parent edeaf06 commit 1c62942
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem 'rake', '~> 12.0'

group :development, :test do
gem 'capybara', '~> 2.7'
gem 'factory_girl', '~> 4.5'
gem 'factory_bot', '~> 4.8.0'
gem 'i18n-tasks', '~> 0.9.1', require: false
gem 'rspec-rails', '~> 3.4'
gem 'simplecov', '~> 0.16.1', require: false
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ GEM
erubi (1.7.1)
excon (0.62.0)
execjs (2.7.0)
factory_girl (4.9.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
faraday (0.15.2)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -417,7 +417,7 @@ DEPENDENCIES
binding_of_caller (~> 0.8.0)
byebug (~> 10.0)
capybara (~> 2.7)
factory_girl (~> 4.5)
factory_bot (~> 4.8.0)
flickraw (~> 0.9.8)
i18n-tasks (~> 0.9.1)
launchy (~> 2.4)
Expand Down
2 changes: 1 addition & 1 deletion publify_core/lib/publify_core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module PublifyCore
class Engine < ::Rails::Engine
config.generators do |generators|
generators.test_framework :rspec, fixture: false
generators.fixture_replacement :factory_girl, dir: 'spec/factories'
generators.fixture_replacement :factory_bot, dir: 'spec/factories'
end

config.to_prepare do
Expand Down
2 changes: 1 addition & 1 deletion publify_core/publify_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Gem::Specification.new do |s|
s.add_dependency 'uuidtools', '~> 2.1.1'

s.add_development_dependency 'capybara', '~> 2.7'
s.add_development_dependency 'factory_girl_rails', '~> 4.8.0'
s.add_development_dependency 'factory_bot', '~> 4.8'
s.add_development_dependency 'i18n-tasks', '~> 0.9.1'
s.add_development_dependency 'rails-controller-testing', '~> 1.0.1'
s.add_development_dependency 'rspec-rails', '~> 3.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
describe 'test publisher profile' do
before do
@blog ||= create(:blog)
@rene = FactoryGirl.create(:user, :as_publisher)
@rene = FactoryBot.create(:user, :as_publisher)
sign_in @rene
get :index
end
Expand Down
50 changes: 25 additions & 25 deletions publify_core/spec/controllers/admin/feedback_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def base_comment(options = {})
end

it 'should not create comment' do
article = FactoryGirl.create(:article)
article = FactoryBot.create(:article)
expect do
get 'create', params: { article_id: article.id, comment: base_comment }
expect(response).to redirect_to(action: 'article', id: article.id)
Expand All @@ -163,15 +163,15 @@ def base_comment(options = {})
end

it 'should create comment' do
article = FactoryGirl.create(:article)
article = FactoryBot.create(:article)
expect do
post 'create', params: { article_id: article.id, comment: base_comment }
expect(response).to redirect_to(action: 'article', id: article.id)
end.to change(Comment, :count)
end

it 'should create comment mark as ham' do
article = FactoryGirl.create(:article)
article = FactoryBot.create(:article)
expect do
post 'create', params: { article_id: article.id, comment: base_comment }
expect(response).to redirect_to(action: 'article', id: article.id)
Expand All @@ -182,8 +182,8 @@ def base_comment(options = {})

describe 'edit action' do
it 'should render edit form' do
article = FactoryGirl.create(:article)
comment = FactoryGirl.create(:comment, article: article)
article = FactoryBot.create(:article)
comment = FactoryBot.create(:comment, article: article)
get 'edit', params: { id: comment.id }
expect(assigns(:comment)).to eq(comment)
expect(assigns(:article)).to eq(article)
Expand All @@ -194,8 +194,8 @@ def base_comment(options = {})

describe 'update action' do
it 'should update comment if post request' do
article = FactoryGirl.create(:article)
comment = FactoryGirl.create(:comment, article: article)
article = FactoryBot.create(:article)
comment = FactoryBot.create(:comment, article: article)
post 'update', params: { id: comment.id,
comment: { author: 'Bob Foo2',
url: 'http://fakeurl.com',
Expand All @@ -206,7 +206,7 @@ def base_comment(options = {})
end

it 'should not update comment if get request' do
comment = FactoryGirl.create(:comment)
comment = FactoryBot.create(:comment)
get 'update', params: { id: comment.id,
comment: { author: 'Bob Foo2',
url: 'http://fakeurl.com',
Expand Down Expand Up @@ -285,89 +285,89 @@ def base_comment(options = {})

it 'delete all spam' do
Feedback.delete_all
FactoryGirl.create(:comment, state: :spam)
FactoryBot.create(:comment, state: :spam)
post :bulkops, params: { bulkop_top: 'Delete all spam' }
expect(Feedback.count).to eq(0)
end

it 'delete all spam and only confirmed spam' do
Feedback.delete_all
FactoryGirl.create(:comment, state: :presumed_spam)
FactoryGirl.create(:comment, state: :spam)
FactoryGirl.create(:comment, state: :presumed_ham)
FactoryGirl.create(:comment, state: :ham)
FactoryBot.create(:comment, state: :presumed_spam)
FactoryBot.create(:comment, state: :spam)
FactoryBot.create(:comment, state: :presumed_ham)
FactoryBot.create(:comment, state: :ham)
post :bulkops, params: { bulkop_top: 'Delete all spam' }
expect(Feedback.count).to eq(3)
end

it 'mark presumed spam comments as spam' do
comment = FactoryGirl.create(:comment, state: :presumed_spam)
comment = FactoryBot.create(:comment, state: :presumed_spam)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Spam', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'mark confirmed spam comments as spam' do
comment = FactoryGirl.create(:comment, state: :spam)
comment = FactoryBot.create(:comment, state: :spam)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Spam', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'mark presumed ham comments as spam' do
comment = FactoryGirl.create(:comment, state: :presumed_ham)
comment = FactoryBot.create(:comment, state: :presumed_ham)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Spam', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'mark ham comments as spam' do
comment = FactoryGirl.create(:comment, state: :ham)
comment = FactoryBot.create(:comment, state: :ham)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Spam', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'mark presumed spam comments as ham' do
comment = FactoryGirl.create(:comment, state: :presumed_spam)
comment = FactoryBot.create(:comment, state: :presumed_spam)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Ham', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end

it 'mark confirmed spam comments as ham' do
comment = FactoryGirl.create(:comment, state: :spam)
comment = FactoryBot.create(:comment, state: :spam)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Ham', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end

it 'mark presumed ham comments as ham' do
comment = FactoryGirl.create(:comment, state: :presumed_ham)
comment = FactoryBot.create(:comment, state: :presumed_ham)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Ham', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end

it 'mark ham comments as ham' do
comment = FactoryGirl.create(:comment, state: :ham)
comment = FactoryBot.create(:comment, state: :ham)
post :bulkops, params: { bulkop_top: 'Mark Checked Items as Ham', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end

it 'confirms presumed spam comments as spam' do
comment = FactoryGirl.create(:comment, state: :presumed_spam)
comment = FactoryBot.create(:comment, state: :presumed_spam)
post :bulkops, params: { bulkop_top: 'Confirm Classification of Checked Items', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'confirms confirmed spam comments as spam' do
comment = FactoryGirl.create(:comment, state: :spam)
comment = FactoryBot.create(:comment, state: :spam)
post :bulkops, params: { bulkop_top: 'Confirm Classification of Checked Items', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_spam
end

it 'confirms presumed ham comments as ham' do
comment = FactoryGirl.create(:comment, state: :presumed_ham)
comment = FactoryBot.create(:comment, state: :presumed_ham)
post :bulkops, params: { bulkop_top: 'Confirm Classification of Checked Items', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end

it 'confirms ham comments as ham' do
comment = FactoryGirl.create(:comment, state: :ham)
comment = FactoryBot.create(:comment, state: :ham)
post :bulkops, params: { bulkop_top: 'Confirm Classification of Checked Items', feedback_check: { comment.id.to_s => 'on' } }
expect(Feedback.find(comment.id)).to be_ham
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

describe 'GET #edit' do
before(:each) do
get :edit, params: { id: FactoryGirl.create(:post_type).id }
get :edit, params: { id: FactoryBot.create(:post_type).id }
end

it 'renders the edit template with an HTTP 200 status code' do
Expand All @@ -47,7 +47,7 @@

describe '#update an existing post_type' do
it 'should update a post_type and redirect to #index' do
@test_id = FactoryGirl.create(:post_type).id
@test_id = FactoryBot.create(:post_type).id
post :update, params: { id: @test_id, post_type: { name: 'another name' } }
assert_response :redirect, action: 'index'
expect(PostType.count).to eq(1)
Expand All @@ -57,7 +57,7 @@

describe 'destroy a post_type' do
it 'should destroy the post_type and redirect to #index' do
@test_id = FactoryGirl.create(:post_type).id
@test_id = FactoryBot.create(:post_type).id
post :destroy, params: { id: @test_id }
expect(response).to redirect_to(action: 'index')
expect(PostType.count).to eq(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

describe 'GET #edit' do
before(:each) do
get :edit, params: { id: FactoryGirl.create(:redirect).id }
get :edit, params: { id: FactoryBot.create(:redirect).id }
end

it 'renders the edit template with an HTTP 200 status code' do
Expand All @@ -72,7 +72,7 @@

describe '#update an existing redirect' do
it 'should update and redirect to #index' do
@test_id = FactoryGirl.create(:redirect).id
@test_id = FactoryBot.create(:redirect).id
post :update, params: { id: @test_id, redirect: { from_path: 'somewhere/over', to_path: 'the/rainbow' } }
assert_response :redirect, action: 'index'
expect(Redirect.count).to eq(1)
Expand All @@ -83,7 +83,7 @@

describe '#destroy a redirect' do
before(:each) do
@test_id = FactoryGirl.create(:redirect).id
@test_id = FactoryBot.create(:redirect).id
expect(Redirect.find(@test_id)).not_to be_nil
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

describe '#update' do
it 'updates content' do
sidebar = FactoryGirl.create(:sidebar)
sidebar = FactoryBot.create(:sidebar)

post :update, params: { id: sidebar.to_param, configure: { sidebar.id.to_s => { 'title' => 'Links', 'body' => 'another html' } } }
sidebar.reload
Expand Down
6 changes: 3 additions & 3 deletions publify_core/spec/controllers/admin/tags_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

describe 'GET #edit' do
before(:each) do
get :edit, params: { id: FactoryGirl.create(:tag).id }
get :edit, params: { id: FactoryBot.create(:tag).id }
end

it 'renders the edit template with an HTTP 200 status code' do
Expand All @@ -53,7 +53,7 @@

describe '#update an existing tag' do
it 'should update a tag and redirect to #index' do
@test_id = FactoryGirl.create(:tag).id
@test_id = FactoryBot.create(:tag).id
post :update, params: { id: @test_id, tag: { display_name: 'another_name' } }
assert_response :redirect, action: 'index'
expect(Tag.count).to eq(1)
Expand All @@ -63,7 +63,7 @@

describe 'destroy a tag' do
it 'should destroy the tag and redirect to #index' do
@test_id = FactoryGirl.create(:tag).id
@test_id = FactoryBot.create(:tag).id
post :destroy, params: { id: @test_id }
expect(response).to redirect_to(action: 'index')
expect(Tag.count).to eq(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Factory definitions
FactoryGirl.define do
FactoryBot.define do
sequence(:name) { |n| "name_#{n}" }
sequence(:body) { |n| "body #{n}" * (n + 3 % 5) }
sequence(:user) { |n| "user#{n}" }
Expand All @@ -10,7 +10,7 @@
sequence(:time) { |n| DateTime.new(2012, 3, 26, 19, 56).in_time_zone - n }

factory :user do
login { FactoryGirl.generate(:user) }
login { FactoryBot.generate(:user) }
email { generate(:email) }
name 'Bond'
nickname 'James Bond'
Expand Down Expand Up @@ -170,7 +170,7 @@
end

factory :tag do |tag|
tag.name { FactoryGirl.generate(:name) }
tag.name { FactoryBot.generate(:name) }
tag.display_name { |a| a.name } # rubocop:disable Style/SymbolProc
blog { Blog.first || create(:blog) }
end
Expand Down Expand Up @@ -233,9 +233,9 @@
end

factory :page do
name { FactoryGirl.generate(:name) }
name { FactoryBot.generate(:name) }
title 'Page One Title'
body { FactoryGirl.generate(:body) }
body { FactoryBot.generate(:body) }
published_at { Time.zone.now }
user
blog { Blog.first || create(:blog) }
Expand Down
2 changes: 1 addition & 1 deletion publify_core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def parse_request(_contents, _request_params)

describe '#nofollowify_links' do
before(:each) do
@blog = FactoryGirl.create :blog
@blog = FactoryBot.create :blog
end

it 'with dofollowify disabled, links should be nofollowed' do
Expand Down
4 changes: 2 additions & 2 deletions publify_core/spec/lib/publify_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
before do
Time.zone = 'UTC'

@a = FactoryGirl.build(:article)
@a = FactoryBot.build(:article)
@a.published_at = '1 Jan 2013 01:00 UTC'
@a.save!

Expand Down Expand Up @@ -128,7 +128,7 @@
before do
Time.zone = 'Tokyo'

@a = FactoryGirl.build(:article)
@a = FactoryBot.build(:article)
@a.published_at = '1 Jan 2013 01:00 +0900'
@a.save!

Expand Down
Loading

0 comments on commit 1c62942

Please sign in to comment.