FactoryGirl => FactoryBot (opf/openproject#6304)

pull/6827/head
Oliver Günther 7 years ago
parent 7a4254879a
commit 3ac4374866
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 4
      features/step_definitions/global_role_steps.rb
  2. 6
      spec/controllers/principal_roles_controller_spec.rb
  3. 2
      spec/factories/global_role_factory.rb
  4. 4
      spec/factories/principal_role_factory.rb
  5. 4
      spec/models/global_role_spec.rb
  6. 2
      spec/models/principal_role_spec.rb
  7. 6
      spec/models/principal_spec.rb
  8. 18
      spec/models/users/allowed_to_spec.rb
  9. 4
      spec/views/users/_available_global_roles.html.erb_spec.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

@ -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])

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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) }

@ -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',

Loading…
Cancel
Save