Skip to content

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 7962aa8 commit f3b8db6
Show file tree
Hide file tree
Showing 26 changed files with 77 additions and 77 deletions.
Expand Up @@ -5,7 +5,7 @@
let(:valid_credentials) do
{ username: 'foobar', password: 'AAA1111!!!!' }
end
let(:user) { FactoryGirl.create(:user, login: 'foobar', password: 'AAA1111!!!!', password_confirmation: 'AAA1111!!!!') }
let(:user) { FactoryBot.create(:user, login: 'foobar', password: 'AAA1111!!!!', password_confirmation: 'AAA1111!!!!') }

before do
# Assume the user has any memberships
Expand Down Expand Up @@ -59,7 +59,7 @@
end

context 'with a non-default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, default: false, channel: :sms }
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, default: false, channel: :sms }

before do
session[:authenticated_user_id] = user.id
Expand All @@ -71,24 +71,24 @@
end

context 'with an invalid device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, channel: :totp }
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, channel: :totp }
it_behaves_like '2FA login request failure', I18n.t('two_factor_authentication.error_no_matching_strategy')
end

context 'with an active device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, channel: :sms }
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, channel: :sms }
it_behaves_like '2FA SMS request success'
end
end

describe 'with two active strategy', with_config: { '2fa' => { active_strategies: [:developer, :totp] } } do
context 'with a totp device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, channel: :totp }
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, channel: :totp }
it_behaves_like '2FA TOTP request success'
end

context 'with an sms device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, channel: :sms }
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, channel: :sms }
it_behaves_like '2FA SMS request success'
end
end
Expand Down
Expand Up @@ -2,7 +2,7 @@
require_relative './../authentication_controller_shared_examples'

describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesController, with_2fa_ee: true do
let(:user) { FactoryGirl.create(:user, login: 'foobar') }
let(:user) { FactoryBot.create(:user, login: 'foobar') }
let(:logged_in_user) { User.anonymous }
let(:active_strategies) { [] }
let(:config) { {} }
Expand Down Expand Up @@ -134,7 +134,7 @@

describe 'and registered totp device' do
let(:active_strategies) { [:totp] }
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false}

it 'renders the confirmation page' do
get :confirm, params: { device_id: device.id }
Expand All @@ -145,7 +145,7 @@
end

describe 'with registered device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false}

it 'renders the confirmation page' do
get :confirm, params: { device_id: device.id }
Expand Down Expand Up @@ -173,7 +173,7 @@

describe 'and registered totp device' do
let(:active_strategies) { [:totp] }
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false}

it 'renders a 400 on missing token' do
post :confirm, params: { device_id: device.id }
Expand Down
Expand Up @@ -2,7 +2,7 @@
require_relative './../authentication_controller_shared_examples'

describe ::TwoFactorAuthentication::My::RememberCookieController do
let(:user) { FactoryGirl.create(:user, login: 'foobar') }
let(:user) { FactoryBot.create(:user, login: 'foobar') }
let(:logged_in_user) { user }

before do
Expand Down
Expand Up @@ -2,8 +2,8 @@
require_relative './../authentication_controller_shared_examples'

describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: true do
let(:user) { FactoryGirl.create(:user, login: 'foobar') }
let(:other_user) { FactoryGirl.create(:user) }
let(:user) { FactoryBot.create(:user, login: 'foobar') }
let(:other_user) { FactoryBot.create(:user) }
let(:logged_in_user) { user }
let(:active_strategies) { [] }
let(:config) { {} }
Expand Down Expand Up @@ -115,7 +115,7 @@

describe 'and registered totp device' do
let(:active_strategies) { [:totp] }
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false}

it 'renders the confirmation page' do
get :confirm, params: { device_id: device.id }
Expand All @@ -126,7 +126,7 @@
end

describe 'with registered device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false}

it 'renders the confirmation page' do
get :confirm, params: { device_id: device.id }
Expand Down Expand Up @@ -154,7 +154,7 @@

describe 'and registered totp device' do
let(:active_strategies) { [:totp] }
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, active: false, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false}

it 'renders a 400 on missing token' do
post :confirm, params: { device_id: device.id }
Expand Down Expand Up @@ -187,7 +187,7 @@
end

context 'with another default device present' do
let!(:default_device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: true}
let!(:default_device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true}

it 'activates the device when entered correctly' do
allow_any_instance_of(::TwoFactorAuthentication::TokenService)
Expand Down Expand Up @@ -220,7 +220,7 @@
end

context 'with existing non-default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false}

it 'deletes it' do
delete :destroy, params: { device_id: device.id }
Expand All @@ -230,7 +230,7 @@
end

context 'with existing default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true}

it 'deletes it' do
delete :destroy, params: { device_id: device.id }
Expand All @@ -240,7 +240,7 @@
end

context 'with existing default device AND enforced' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true}
let(:config) { { enforced: true } }

it 'cannot be deleted' do
Expand Down
Expand Up @@ -2,9 +2,9 @@
require_relative './../authentication_controller_shared_examples'

describe ::TwoFactorAuthentication::Users::TwoFactorDevicesController, with_2fa_ee: true do
let(:admin) { FactoryGirl.create :admin }
let(:user) { FactoryGirl.create(:user, login: 'foobar') }
let(:other_user) { FactoryGirl.create(:user) }
let(:admin) { FactoryBot.create :admin }
let(:user) { FactoryBot.create(:user, login: 'foobar') }
let(:other_user) { FactoryBot.create(:user) }
let(:logged_in_user) { admin }
let(:active_strategies) { [:developer] }
let(:config) { {} }
Expand Down Expand Up @@ -123,7 +123,7 @@
end

context 'with existing non-default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false}

it 'deletes it' do
delete :destroy, params: { id: user.id, device_id: device.id }
Expand All @@ -133,7 +133,7 @@
end

context 'with existing default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true}

it 'deletes it' do
delete :destroy, params: { id: user.id, device_id: device.id }
Expand All @@ -143,7 +143,7 @@
end

context 'with existing default device AND enforced' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true}
let(:config) { { enforced: true } }

it 'cannot be deleted' do
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/two_factor_authentication_device_factory.rb
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :two_factor_authentication_device_sms, class: ::TwoFactorAuthentication::Device::Sms do
user
channel :sms
Expand All @@ -17,7 +17,7 @@
end
end

FactoryGirl.define do
FactoryBot.define do
factory :two_factor_authentication_device_totp, class: ::TwoFactorAuthentication::Device::Totp do
user
channel :totp
Expand Down
4 changes: 2 additions & 2 deletions spec/features/account_activation_spec.rb
Expand Up @@ -7,7 +7,7 @@
js: true,
with_config: {:'2fa' => {active_strategies: [:developer]}} do
let(:user) {
user = FactoryGirl.build :user, first_login: true
user = FactoryBot.build :user, first_login: true
UserInvitation.invite_user! user

user
Expand Down Expand Up @@ -38,7 +38,7 @@ def activate!
end

context 'when not enforced, but device present' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, default: true}

it 'requests a OTP' do
sms_token = nil
Expand Down
8 changes: 4 additions & 4 deletions spec/features/admin_edit_two_factor_devices_spec.rb
Expand Up @@ -5,9 +5,9 @@
js: true do
let(:dialog) { ::Components::PasswordConfirmationDialog.new }
let(:user_password) {'admin!' * 4}
let(:other_user) { FactoryGirl.create :user, login: 'bob' }
let(:other_user) { FactoryBot.create :user, login: 'bob' }
let(:admin) do
FactoryGirl.create(:admin,
FactoryBot.create(:admin,
password: user_password,
password_confirmation: user_password,
)
Expand Down Expand Up @@ -62,8 +62,8 @@
end

context 'with multiple devices registered' do
let!(:device1) { FactoryGirl.create :two_factor_authentication_device_sms, user: other_user }
let!(:device2) { FactoryGirl.create :two_factor_authentication_device_totp, user: other_user, default: false }
let!(:device1) { FactoryBot.create :two_factor_authentication_device_sms, user: other_user }
let!(:device2) { FactoryBot.create :two_factor_authentication_device_totp, user: other_user, default: false }

it 'allows to delete all' do
visit edit_user_path(other_user, tab: :two_factor_authentication)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/backup_codes/generate_backup_codes.rb
Expand Up @@ -6,7 +6,7 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
Expand Down
4 changes: 2 additions & 2 deletions spec/features/backup_codes/login_with_backup_code_spec.rb
Expand Up @@ -6,13 +6,13 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
)
end
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: true, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true}

context 'user has no backup code' do
it 'does not show the backup code link' do
Expand Down
4 changes: 2 additions & 2 deletions spec/features/login/login_enforced_2fa_spec.rb
Expand Up @@ -6,15 +6,15 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
)
end

context 'with a default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: true, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true}

it 'requests a 2FA' do
sms_token = nil
Expand Down
4 changes: 2 additions & 2 deletions spec/features/login/login_with_2fa_spec.rb
Expand Up @@ -6,15 +6,15 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
)
end

context 'with a default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: true, default: true}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true}

it 'requests a 2FA' do
sms_token = nil
Expand Down
4 changes: 2 additions & 2 deletions spec/features/login/login_without_2fa_spec.rb
Expand Up @@ -6,15 +6,15 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
)
end

context 'non-default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: true, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: false}

it_behaves_like 'login without 2FA'
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/login/switch_available_devices_spec.rb
Expand Up @@ -6,16 +6,16 @@
js: true do
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
)
end

context 'with two default device' do
let!(:device) { FactoryGirl.create :two_factor_authentication_device_sms, user: user, active: true, default: true}
let!(:device2) { FactoryGirl.create :two_factor_authentication_device_totp, user: user, active: true, default: false}
let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true}
let!(:device2) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: true, default: false}

it 'requests a 2FA and allows switching' do
first_login_step
Expand Down
2 changes: 1 addition & 1 deletion spec/features/my_two_factor_devices_spec.rb
Expand Up @@ -6,7 +6,7 @@
let(:dialog) { ::Components::PasswordConfirmationDialog.new }
let(:user_password) {'bob!' * 4}
let(:user) do
FactoryGirl.create(:user,
FactoryBot.create(:user,
login: 'bob',
password: user_password,
password_confirmation: user_password,
Expand Down

0 comments on commit f3b8db6

Please sign in to comment.