From 3ac43748666fc5821d91be1ddf7fba308e9c344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 7 May 2018 15:18:59 +0200 Subject: [PATCH] FactoryGirl => FactoryBot (opf/openproject#6304) --- features/step_definitions/global_role_steps.rb | 4 ++-- .../principal_roles_controller_spec.rb | 6 +++--- spec/factories/global_role_factory.rb | 2 +- spec/factories/principal_role_factory.rb | 4 ++-- spec/models/global_role_spec.rb | 4 ++-- spec/models/principal_role_spec.rb | 2 +- spec/models/principal_spec.rb | 6 +++--- spec/models/users/allowed_to_spec.rb | 18 +++++++++--------- .../_available_global_roles.html.erb_spec.rb | 4 ++-- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/features/step_definitions/global_role_steps.rb b/features/step_definitions/global_role_steps.rb index ac3094c4de..da5cb9bea9 100644 --- a/features/step_definitions/global_role_steps.rb +++ b/features/step_definitions/global_role_steps.rb @@ -33,7 +33,7 @@ Given /^the global permission "(.+)?" of the module "(.+)?" is defined$/ do |per 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| @@ -62,7 +62,7 @@ Given /^the [Uu]ser (.+) has the global role (.+)$/ do |user, role| 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 diff --git a/spec/controllers/principal_roles_controller_spec.rb b/spec/controllers/principal_roles_controller_spec.rb index 4aa18286d7..f8831ff771 100644 --- a/spec/controllers/principal_roles_controller_spec.rb +++ b/spec/controllers/principal_roles_controller_spec.rb @@ -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) @@ -51,12 +51,12 @@ describe PrincipalRolesController, type: :controller do # 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]) diff --git a/spec/factories/global_role_factory.rb b/spec/factories/global_role_factory.rb index 518e2898f0..3b94b16ca6 100644 --- a/spec/factories/global_role_factory.rb +++ b/spec/factories/global_role_factory.rb @@ -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 diff --git a/spec/factories/principal_role_factory.rb b/spec/factories/principal_role_factory.rb index df25d803f9..f787fd58db 100644 --- a/spec/factories/principal_role_factory.rb +++ b/spec/factories/principal_role_factory.rb @@ -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 diff --git a/spec/models/global_role_spec.rb b/spec/models/global_role_spec.rb index 0d47ea249e..02a7a9d37e 100644 --- a/spec/models/global_role_spec.rb +++ b/spec/models/global_role_spec.rb @@ -143,8 +143,8 @@ describe GlobalRole, type: :model do 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 diff --git a/spec/models/principal_role_spec.rb b/spec/models/principal_role_spec.rb index 2bddd49ce1..ed6e6d3a5d 100644 --- a/spec/models/principal_role_spec.rb +++ b/spec/models/principal_role_spec.rb @@ -30,7 +30,7 @@ describe PrincipalRole, type: :model do 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 diff --git a/spec/models/principal_spec.rb b/spec/models/principal_spec.rb index 58d0d7818a..6249d0ab1f 100644 --- a/spec/models/principal_spec.rb +++ b/spec/models/principal_spec.rb @@ -29,11 +29,11 @@ describe Principal, type: :model do 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 diff --git a/spec/models/users/allowed_to_spec.rb b/spec/models/users/allowed_to_spec.rb index a1f9f02b9e..09844774d4 100644 --- a/spec/models/users/allowed_to_spec.rb +++ b/spec/models/users/allowed_to_spec.rb @@ -13,21 +13,21 @@ require 'spec_helper' 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) } diff --git a/spec/views/users/_available_global_roles.html.erb_spec.rb b/spec/views/users/_available_global_roles.html.erb_spec.rb index 0cd6f06e04..b17894bf01 100644 --- a/spec/views/users/_available_global_roles.html.erb_spec.rb +++ b/spec/views/users/_available_global_roles.html.erb_spec.rb @@ -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',