Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
FactoryGirl => FactoryBot (opf/openproject#6304)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverguenther committed May 7, 2018
1 parent 7a42548 commit 3ac4374
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions features/step_definitions/global_role_steps.rb
Expand Up @@ -33,7 +33,7 @@
end

Given /^there is a global [rR]ole "([^\"]*)"$/ do |name|
FactoryGirl.create(:global_role, name: name) unless GlobalRole.find_by_name(name)
FactoryBot.create(:global_role, name: name) unless GlobalRole.find_by_name(name)
end

Given /^the global [rR]ole "([^\"]*)" may have the following [rR]ights:$/ do |role, table|
Expand Down Expand Up @@ -62,7 +62,7 @@
role = GlobalRole.find_by_name(role.delete("\""))

as_admin do
FactoryGirl.create(:principal_role, principal: user, role: role)
FactoryBot.create(:principal_role, principal: user, role: role)
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/principal_roles_controller_spec.rb
Expand Up @@ -20,7 +20,7 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe PrincipalRolesController, type: :controller do
let(:current_user) { FactoryGirl.build_stubbed(:admin) }
let(:current_user) { FactoryBot.build_stubbed(:admin) }

before(:each) do
login_as(current_user)
Expand Down Expand Up @@ -51,12 +51,12 @@
# Those stubs are marked with the comment "only necessary with impermanent-memberships".
#
# If this problem occurs again with another plugin (or the same, really) this should be fixed for good
# by using FactoryGirl to create actual model instances.
# by using FactoryBot to create actual model instances.
# I'm only patching this up right now because I don't want to spend any more time on it and
# the added methods are orthogonal to the test, also additional, unused stubs won't break things
# as opposed to missing ones.
#
# And yet: @TODO Don't use doubles but FactoryGirl.
# And yet: @TODO Don't use doubles but FactoryBot.
allow(@global_role).to receive(:id).and_return(42)
allow(@global_role).to receive(:permanent?).and_return(false) # only necessary with impermanent-memberships
allow(Role).to receive(:find).and_return([@global_role])
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/global_role_factory.rb
Expand Up @@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#++

FactoryGirl.define do
FactoryBot.define do
factory :global_role do
sequence(:name) { |n| "Global Role #{n}" }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/principal_role_factory.rb
Expand Up @@ -17,14 +17,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#++

FactoryGirl.define do
FactoryBot.define do
factory :principal_role do |pr|
pr.association :role, :factory => :global_role
pr.association :principal, :factory => :user
end
end

FactoryGirl.define do
FactoryBot.define do
factory :empty_principal_role, :class => PrincipalRole do |pr|
end
end
4 changes: 2 additions & 2 deletions spec/models/global_role_spec.rb
Expand Up @@ -143,8 +143,8 @@

describe '#assignable_to?' do
before(:each) do
@role = FactoryGirl.build(:global_role)
@user = FactoryGirl.build(:user)
@role = FactoryBot.build(:global_role)
@user = FactoryBot.build(:user)
end
it 'always true global roles for now' do
expect(@role.assignable_to?(@user)).to be_truthy
Expand Down
2 changes: 1 addition & 1 deletion spec/models/principal_role_spec.rb
Expand Up @@ -30,7 +30,7 @@

describe '#valid?' do
before(:each) do
@principal_role = FactoryGirl.build(:principal_role)
@principal_role = FactoryBot.build(:principal_role)
end

describe 'role not assignable to user' do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/principal_spec.rb
Expand Up @@ -29,11 +29,11 @@
end

describe 'WHEN deleting a principal' do
let(:principal) { FactoryGirl.build(:user) }
let(:role) { FactoryGirl.build(:global_role) }
let(:principal) { FactoryBot.build(:user) }
let(:role) { FactoryBot.build(:global_role) }

before do
FactoryGirl.create(:principal_role, role: role,
FactoryBot.create(:principal_role, role: role,
principal: principal)
principal.destroy
end
Expand Down
18 changes: 9 additions & 9 deletions spec/models/users/allowed_to_spec.rb
Expand Up @@ -13,21 +13,21 @@

describe User, 'allowed to' do
let(:user) { member.principal }
let(:anonymous) { FactoryGirl.build(:anonymous) }
let(:project) { FactoryGirl.build(:project, is_public: false) }
let(:project2) { FactoryGirl.build(:project, is_public: false) }
let(:role) { FactoryGirl.build(:role) }
let(:role2) { FactoryGirl.build(:role) }
let(:anonymous_role) { FactoryGirl.build(:anonymous_role) }
let(:member) { FactoryGirl.build(:member, project: project,
let(:anonymous) { FactoryBot.build(:anonymous) }
let(:project) { FactoryBot.build(:project, is_public: false) }
let(:project2) { FactoryBot.build(:project, is_public: false) }
let(:role) { FactoryBot.build(:role) }
let(:role2) { FactoryBot.build(:role) }
let(:anonymous_role) { FactoryBot.build(:anonymous_role) }
let(:member) { FactoryBot.build(:member, project: project,
roles: [role]) }

let(:action) { :the_one }
let(:other_action) { :another }
let(:public_action) { :view_project }
let(:global_permission) { Redmine::AccessControl.permissions.find { |p| p.global? } }
let(:global_role) { FactoryGirl.build(:global_role, :permissions => [global_permission.name]) }
let(:principal_role) { FactoryGirl.build(:empty_principal_role, principal: user,
let(:global_role) { FactoryBot.build(:global_role, :permissions => [global_permission.name]) }
let(:principal_role) { FactoryBot.build(:empty_principal_role, principal: user,
role: global_role) }


Expand Down
4 changes: 2 additions & 2 deletions spec/views/users/_available_global_roles.html.erb_spec.rb
Expand Up @@ -20,8 +20,8 @@
require 'spec_helper'

describe 'users/_available_global_roles' do
let(:user) { FactoryGirl.create :user }
let(:global_roles) { FactoryGirl.create_list :global_role, 3 }
let(:user) { FactoryBot.create :user }
let(:global_roles) { FactoryBot.create_list :global_role, 3 }

it 'links to the principal roles controller using a path, not a URL' do
render partial: 'users/available_global_roles',
Expand Down

0 comments on commit 3ac4374

Please sign in to comment.