Skip to content

Commit

Permalink
Merge pull request #6304 from opf/housekeeping/bump-factory-girl
Browse files Browse the repository at this point in the history
FactoryGirl => FactoryBot
  • Loading branch information
ulferts committed May 8, 2018
2 parents 85144b3 + 059770f commit 189fd8a
Show file tree
Hide file tree
Showing 676 changed files with 4,097 additions and 4,097 deletions.
10 changes: 5 additions & 5 deletions Gemfile
Expand Up @@ -178,12 +178,12 @@ group :test do
gem 'shoulda-context', '~> 1.2'
gem 'launchy', '~> 2.4.3'

# Require factory_girl for usage with openproject plugins testing
# FactoryGirl needs to be available when loading app otherwise factory
# Require factory_bot for usage with openproject plugins testing
# FactoryBot needs to be available when loading app otherwise factory
# definitions from core are not available in the plugin thus specs break
gem 'factory_girl', '~> 4.5'
# require factory_girl_rails for convenience in core development
gem 'factory_girl_rails', '~> 4.7', require: false
gem 'factory_bot', '~> 4.8'
# require factory_bot_rails for convenience in core development
gem 'factory_bot_rails', '~> 4.8', require: false

# Test prof provides factories from code
# and other niceties
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Expand Up @@ -263,10 +263,10 @@ GEM
eventmachine (1.2.5)
excon (0.52.0)
execjs (2.7.0)
factory_girl (4.9.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
Expand Down Expand Up @@ -654,8 +654,8 @@ DEPENDENCIES
date_validator (~> 0.9.0)
delayed_job_active_record (~> 4.1.1)
equivalent-xml (~> 0.6)
factory_girl (~> 4.5)
factory_girl_rails (~> 4.7)
factory_bot (~> 4.8)
factory_bot_rails (~> 4.8)
faker
fog-aws
friendly_id (~> 5.2.1)
Expand Down
4 changes: 2 additions & 2 deletions app/seeders/development_data/custom_fields_seeder.rb
Expand Up @@ -46,14 +46,14 @@ def all_cfs
def create_types!(cfs)
# Create ALL CFs types
non_req_cfs = cfs.reject(&:is_required).map { |cf| "custom_field_#{cf.id}" }
type = FactoryGirl.build :type_with_workflow, name: 'All CFS'
type = FactoryBot.build :type_with_workflow, name: 'All CFS'
extend_group(type, ['Custom fields', non_req_cfs])
type.save!
print '.'

# Create type
req_cfs = cfs.select(&:is_required).map { |cf| "custom_field_#{cf.id}" }
type_req = FactoryGirl.build :type_with_workflow, name: 'Required CF'
type_req = FactoryBot.build :type_with_workflow, name: 'Required CF'
extend_group(type_req, ['Custom fields', req_cfs])
type_req.save!
print '.'
Expand Down
6 changes: 3 additions & 3 deletions app/seeders/root_seeder.rb
Expand Up @@ -63,9 +63,9 @@ def do_seed!

if Rails.env.development?
puts '*** Seeding development data'
require 'factory_girl'
# Load FactoryGirl factories
::FactoryGirl.find_definitions
require 'factory_bot'
# Load FactoryBot factories
::FactoryBot.find_definitions

DevelopmentDataSeeder.new.seed!
end
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/board_steps.rb
Expand Up @@ -28,7 +28,7 @@
#++

Given(/^there is a board "(.*?)" for project "(.*?)"$/) do |board_name, project_identifier|
FactoryGirl.create :board, project: get_project(project_identifier), name: board_name
FactoryBot.create :board, project: get_project(project_identifier), name: board_name
end

Given(/^the board "(.*?)" has the following messages:$/) do |board_name, table|
Expand All @@ -47,7 +47,7 @@

def create_messages(names, board, parent = nil)
names.each do |name|
FactoryGirl.create :message,
FactoryBot.create :message,
board: board,
subject: name,
parent: parent
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/common_steps.rb
Expand Up @@ -44,7 +44,7 @@
name = line.first
type = ::Type.find_by(name: name)

type = FactoryGirl.create(:type, name: name) if type.blank?
type = FactoryBot.create(:type, name: name) if type.blank?
type
}

Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/custom_field_steps.rb
Expand Up @@ -48,7 +48,7 @@
attr_hash[:default_value] = r[:default_value] ? r[:default_value] : nil
attr_hash[:is_for_all] = r[:is_for_all] || true

FactoryGirl.create type, attr_hash
FactoryBot.create type, attr_hash
end
end
end
Expand Down
26 changes: 13 additions & 13 deletions features/step_definitions/general_steps.rb
Expand Up @@ -32,14 +32,14 @@

Before do |scenario|
unless ScenarioDisabler.empty_if_disabled(scenario)
FactoryGirl.create(:admin) unless User.find_by_login('admin')
FactoryGirl.create(:anonymous) unless AnonymousUser.count > 0
FactoryBot.create(:admin) unless User.find_by_login('admin')
FactoryBot.create(:anonymous) unless AnonymousUser.count > 0
Setting.notified_events = [] # can not test mailer
end
end

Given /^I am logged in$/ do
@user = FactoryGirl.create :user
@user = FactoryBot.create :user
page.set_rack_session(user_id: @user.id, updated_at: Time.now)
end

Expand Down Expand Up @@ -86,7 +86,7 @@
end

Given /^there is 1 [pP]roject with(?: the following)?:$/ do |table|
p = FactoryGirl.build(:project)
p = FactoryBot.build(:project)
send_table_to_object(p, table)
end

Expand Down Expand Up @@ -121,8 +121,8 @@
u = User.find_by login: user
p = u.projects.last
raise 'This user must be member of a project to have issues' unless p
i = FactoryGirl.create(:work_package, project: p)
t = FactoryGirl.build(:time_entry)
i = FactoryBot.create(:work_package, project: p)
t = FactoryBot.build(:time_entry)
t.user = u
t.issue = i
t.project = p
Expand All @@ -134,8 +134,8 @@
Given /^the [Uu]ser "([^\"]*)" has 1 time entry with (\d+\.?\d*) hours? at the project "([^\"]*)"$/ do |user, hours, project|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin do
t = FactoryGirl.build(:time_entry)
i = FactoryGirl.create(:work_package, project: p)
t = FactoryBot.build(:time_entry)
i = FactoryBot.create(:work_package, project: p)
t.project = p
t.issue = i
t.hours = hours.to_f
Expand All @@ -149,8 +149,8 @@
Given /^the [Pp]roject "([^\"]*)" has (\d+) [tT]ime(?: )?[eE]ntr(?:ies|y) with the following:$/ do |project, count, table|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin count do
t = FactoryGirl.build(:time_entry)
i = FactoryGirl.create(:work_package, project: p)
t = FactoryBot.build(:time_entry)
i = FactoryBot.create(:work_package, project: p)
t.project = p
t.work_package = i
t.activity.project = p
Expand All @@ -173,14 +173,14 @@

Given /^the [pP]roject "([^\"]*)" has 1 [sS]ubproject$/ do |project|
parent = Project.find_by(name: project)
p = FactoryGirl.create(:project)
p = FactoryBot.create(:project)
p.set_parent!(parent)
p.save!
end

Given /^the [pP]roject "([^\"]*)" has 1 [sS]ubproject with the following:$/ do |project, table|
parent = Project.find_by(name: project)
p = FactoryGirl.build(:project)
p = FactoryBot.build(:project)
as_admin do
send_table_to_object(p, table)
end
Expand Down Expand Up @@ -231,7 +231,7 @@
i = WorkPackage.where(["subject = '#{issue}'"]).last
raise "No such issue: #{issue}" unless i
as_admin count do
t = FactoryGirl.build(:time_entry)
t = FactoryBot.build(:time_entry)
t.project = i.project
t.spent_on = DateTime.now
t.work_package = i
Expand Down
6 changes: 3 additions & 3 deletions features/step_definitions/group_steps.rb
Expand Up @@ -28,7 +28,7 @@
#++

Given /^there is 1 group with the following:$/ do |table|
group = FactoryGirl.build(:group)
group = FactoryBot.build(:group)

send_table_to_object group, table, name: Proc.new { |group, name| group.lastname = name }
end
Expand Down Expand Up @@ -63,11 +63,11 @@
end

Given /^We have the group "(.*?)"/ do |name|
group = FactoryGirl.create(:group, lastname: name)
group = FactoryBot.create(:group, lastname: name)
end

Given /^there is a group named "(.*?)" with the following members:$/ do |name, table|
group = FactoryGirl.create(:group, lastname: name)
group = FactoryBot.create(:group, lastname: name)

table.raw.flatten.each do |login|
group.users << User.find_by!(login: login)
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/issue_category_steps.rb
Expand Up @@ -33,7 +33,7 @@
p = Project.find_by(name: project) || Project.find_by(identifier: project)
table.rows_hash['assigned_to'] = Principal.like(table.rows_hash['assigned_to']).first if table.rows_hash['assigned_to']
as_admin count do
ic = FactoryGirl.build(:category, project: p)
ic = FactoryBot.build(:category, project: p)
send_table_to_object(ic, table)
ic.save
end
Expand All @@ -42,7 +42,7 @@
Given /^the [Pp]roject "([^\"]*)" has (\d+) [cC]ategor(?:ies|y)?$/ do |project, count|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin count do
ic = FactoryGirl.build(:category, project: p)
ic = FactoryBot.build(:category, project: p)
ic.save
end
end
10 changes: 5 additions & 5 deletions features/step_definitions/issue_steps.rb
Expand Up @@ -46,7 +46,7 @@
issue = WorkPackage.where(subject: issue_subject).order(:created_at).last
file = OpenProject::Files.create_temp_file name: file_name,
content: 'random content which is not actually a gif'
attachment = FactoryGirl.create :attachment,
attachment = FactoryBot.create :attachment,
author: issue.author,
content_type: content_type,
file: file,
Expand All @@ -60,11 +60,11 @@
u = User.find_by login: user
raise 'This user must be member of a project to have issues' unless u.projects.last
as_admin count do
i = FactoryGirl.create(:work_package,
i = FactoryBot.create(:work_package,
project: u.projects.last,
author: u,
assigned_to: u,
status: Status.default || FactoryGirl.create(:status))
status: Status.default || FactoryBot.create(:status))

i.type = ::Type.find_by(name: table.rows_hash.delete('type')) if table.rows_hash['type']

Expand All @@ -76,7 +76,7 @@
Given /^the [Pp]roject "([^\"]*)" has (\d+) [iI]ssue(?:s)? with(?: the following)?:$/ do |project, count, table|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin count do
i = FactoryGirl.build(:work_package, project: p,
i = FactoryBot.build(:work_package, project: p,
type: p.types.first)
send_table_to_object(i, table, {}, method(:add_custom_value_to_issue))
end
Expand Down Expand Up @@ -121,7 +121,7 @@
category = Category.find_by(name: attributes.delete('category'))
attributes.merge! category_id: category.id if category

issue = FactoryGirl.create(:work_package, attributes)
issue = FactoryBot.create(:work_package, attributes)

if watchers
watchers.split(',').each do |w| issue.add_watcher User.find_by_login(w) end
Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/priority_steps.rb
Expand Up @@ -32,7 +32,7 @@
Given /^there is a(?:n)? (default )?issuepriority with:$/ do |default, table|
name = table.raw.find { |ary| ary.include? 'name' }[table.raw.first.index('name') + 1].to_s
project = get_project
FactoryGirl.build(:priority).tap do |prio|
FactoryBot.build(:priority).tap do |prio|
prio.name = name
prio.is_default = !!default
prio.project = project
Expand All @@ -43,7 +43,7 @@
table.hashes.each do |row|
project = get_project

FactoryGirl.build(:priority).tap do |prio|
FactoryBot.build(:priority).tap do |prio|
prio.name = row[:name]
prio.is_default = row[:default] == 'true'
prio.project = project
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/project_steps.rb
Expand Up @@ -35,5 +35,5 @@
attributes.merge!(project_type: ProjectType.find_by!(name: project_type_name))
end

FactoryGirl.create(:project, attributes)
FactoryBot.create(:project, attributes)
end
4 changes: 2 additions & 2 deletions features/step_definitions/query_steps.rb
Expand Up @@ -30,7 +30,7 @@
Given /^the [Pp]roject "([^\"]*)" has (\d+) [wW]ork [pP]ackage [qQ]uer(?:ies|y)? with(?: the following)?:$/ do |project, count, table|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin count do
i = FactoryGirl.build(:query, project: p)
i = FactoryBot.build(:query, project: p)
send_table_to_object(i, table)
i.save
end
Expand All @@ -39,7 +39,7 @@
Given /^the [Pp]roject "([^\"]*)" has (\d+) [wW]ork [pP]ackage [qQ]uer(?:ies|y)?$/ do |project, count|
p = Project.find_by(name: project) || Project.find_by(identifier: project)
as_admin count do
i = FactoryGirl.build(:query, project: p)
i = FactoryBot.build(:query, project: p)
i.save
end
end
2 changes: 1 addition & 1 deletion features/step_definitions/repository_steps.rb
Expand Up @@ -30,7 +30,7 @@
Given(/^the project "(.*?)" has a repository$/) do |project_name|
project = Project.find(project_name)

repo = FactoryGirl.build(:repository_subversion,
repo = FactoryBot.build(:repository_subversion,
project: project)

Setting.enabled_scm = Setting.enabled_scm << repo.vendor
Expand Down
6 changes: 3 additions & 3 deletions features/step_definitions/role_steps.rb
Expand Up @@ -41,16 +41,16 @@
end

Given /^there is a [rR]ole "([^\"]*)"$/ do |name, _table = nil|
FactoryGirl.create(:role, name: name) unless Role.find_by(name: name)
FactoryBot.create(:role, name: name) unless Role.find_by(name: name)
end

Given /^there is a [rR]ole "([^\"]*)" with the following permissions:?$/ do |name, table|
FactoryGirl.create(:role, name: name, permissions: table.raw.flatten) unless Role.find_by(name: name)
FactoryBot.create(:role, name: name, permissions: table.raw.flatten) unless Role.find_by(name: name)
end

Given /^there are the following roles:$/ do |table|
table.raw.flatten.each do |name|
FactoryGirl.create(:role, name: name) unless Role.find_by(name: name)
FactoryBot.create(:role, name: name) unless Role.find_by(name: name)
end
end

Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/search_steps.rb
Expand Up @@ -28,7 +28,7 @@
#++

Given(/^there are (\d+) work packages with "(.*?)" in their description$/) do |num, desc|
work_packages = FactoryGirl.create_list :work_package, num.to_i, description: desc
work_packages = FactoryBot.create_list :work_package, num.to_i, description: desc
time = Time.now
# ensure temporal order:
work_packages.reverse.each_with_index do |wp, i|
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/status_steps.rb
Expand Up @@ -37,7 +37,7 @@
attributes = row.inject({}) { |mem, (k, v)| mem[k.to_sym] = v if v.present?; mem }
attributes[:is_default] = attributes.delete(:default) == 'true'

FactoryGirl.create(:status, attributes)
FactoryBot.create(:status, attributes)
end
end

Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/time_entry_steps.rb
Expand Up @@ -29,11 +29,11 @@

Given(/^there is a time entry for "(.*?)" with (\d+) hours$/) do |subject, hours|
work_package = WorkPackage.find_by(subject: subject)
time_entry = FactoryGirl.create(:time_entry, work_package: work_package, hours: hours, project: work_package.project)
time_entry = FactoryBot.create(:time_entry, work_package: work_package, hours: hours, project: work_package.project)
end

Given(/^there is an activity "(.*?)"$/) do |name|
FactoryGirl.create(:time_entry_activity, name: name)
FactoryBot.create(:time_entry_activity, name: name)
end

When(/^I log (\d+) hours with the comment "(.*?)"$/) do |hours, comment|
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/type_steps.rb
Expand Up @@ -35,7 +35,7 @@

Given /^the following types are enabled for the project called "(.*?)":$/ do |project_name, type_name_table|
types = type_name_table.raw.flatten.map { |type_name|
::Type.find_by(name: type_name) || FactoryGirl.create(:type, name: type_name)
::Type.find_by(name: type_name) || FactoryBot.create(:type, name: type_name)
}

project = Project.find_by(identifier: project_name)
Expand Down

0 comments on commit 189fd8a

Please sign in to comment.