Skip to content

Commit

Permalink
update FactoryGirl to FactoryBot
Browse files Browse the repository at this point in the history
  • Loading branch information
nwoodward committed Oct 9, 2018
1 parent 7db4497 commit aeb9904
Show file tree
Hide file tree
Showing 57 changed files with 146 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ group :test do
gem 'capybara'
gem 'chromedriver-helper'
gem 'database_cleaner'
gem 'factory_girl_rails'
gem 'factory_bot_rails'
# rack-test >= 0.71 does not work with older Capybara versions (< 2.17). See #214 for more details
gem 'rack-test', '0.7.0'
gem 'rails-controller-testing'
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ GEM
erubi (1.7.1)
erubis (2.7.0)
execjs (2.7.0)
factory_girl (4.8.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
Expand Down Expand Up @@ -917,7 +917,7 @@ DEPENDENCIES
devise-guests (~> 0.3)
devise-i18n
devise_invitable (~> 1.6)
factory_girl_rails
factory_bot_rails
fcrepo_wrapper (~> 0.4)
flipflop (~> 2.3)
honeybadger (~> 3.0)
Expand Down Expand Up @@ -966,4 +966,4 @@ DEPENDENCIES
zk

BUNDLED WITH
1.16.3
1.16.6
2 changes: 1 addition & 1 deletion spec/controllers/account_sign_up_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
end

context 'as admin with restricted access' do
let(:user) { FactoryGirl.create(:admin) }
let(:user) { FactoryBot.create(:admin) }

before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(true)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
end

context 'as an admin of a site' do
let(:user) { FactoryGirl.create(:user).tap { |u| u.add_role(:admin, Site.instance) } }
let(:account) { FactoryGirl.create(:account) }
let(:user) { FactoryBot.create(:user).tap { |u| u.add_role(:admin, Site.instance) } }
let(:account) { FactoryBot.create(:account) }

before do
Site.update(account: account)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/group_users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.describe Admin::GroupUsersController, faketenant: true do
let(:group) { FactoryGirl.create(:group) }
let(:group) { FactoryBot.create(:group) }

context 'as an anonymous user' do
describe 'GET #index' do
Expand All @@ -20,7 +20,7 @@
end

context 'modifying group membership' do
let(:user) { FactoryGirl.create(:user) }
let(:user) { FactoryBot.create(:user) }

describe 'POST #add' do
it 'adds a user to a group when it recieves a group ID' do
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/admin/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
describe 'POST #create' do
it 'creates a group when it recieves valid attribtes' do
expect do
post :create, params: { hyku_group: FactoryGirl.attributes_for(:group) }
post :create, params: { hyku_group: FactoryBot.attributes_for(:group) }
end.to change(Hyku::Group, :count).by(1)
end
end

context 'with an existing group' do
let(:group) { FactoryGirl.create(:group) }
let(:new_attributes) { FactoryGirl.attributes_for(:group) }
let(:group) { FactoryBot.create(:group) }
let(:new_attributes) { FactoryBot.attributes_for(:group) }

describe 'GET #edit' do
subject { get :edit, params: { id: group.id } }
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe Admin::UsersController, type: :controller do
context 'as an anonymous user' do
let(:user) { FactoryGirl.create(:user) }
let(:user) { FactoryBot.create(:user) }

describe 'DELETE #destroy' do
subject { User.find_by(id: user.id) }
Expand All @@ -14,7 +14,7 @@
end

context 'as an admin user' do
let(:user) { FactoryGirl.create(:user) }
let(:user) { FactoryBot.create(:user) }

before { sign_in create(:admin) }

Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/hyrax/generic_works_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSpec.describe Hyrax::GenericWorksController do
let(:user) { FactoryGirl.create(:user) }
let(:work) { FactoryGirl.create(:work_with_one_file, user: user) }
let(:user) { FactoryBot.create(:user) }
let(:work) { FactoryBot.create(:work_with_one_file, user: user) }
let(:file_set) { work.ordered_members.to_a.first }

before do
Expand All @@ -25,7 +25,7 @@
end

describe "#presenter" do
let(:solr_document) { SolrDocument.new(FactoryGirl.create(:generic_work).to_solr) }
let(:solr_document) { SolrDocument.new(FactoryBot.create(:generic_work).to_solr) }

before do
allow(controller).to receive(:curation_concern_from_search_results).and_return(solr_document)
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/labels_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end

context 'with an unprivileged user' do
let(:user) { FactoryGirl.create(:user) }
let(:user) { FactoryBot.create(:user) }

describe "GET #edit" do
it "denies the request" do
Expand All @@ -52,7 +52,7 @@
end

context 'with an administrator' do
let(:user) { FactoryGirl.create(:admin) }
let(:user) { FactoryBot.create(:admin) }

describe "GET #edit" do
it "assigns the requested site as @site" do
Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/proprietor/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
end

context 'as an admin of a site' do
let(:user) { FactoryGirl.create(:user).tap { |u| u.add_role(:admin, Site.instance) } }
let(:account) { FactoryGirl.create(:account) }
let(:user) { FactoryBot.create(:user).tap { |u| u.add_role(:admin, Site.instance) } }
let(:account) { FactoryBot.create(:account) }

before do
Site.update(account: account)
Expand Down Expand Up @@ -117,7 +117,7 @@
end

context 'editing another tenants account' do
let(:another_account) { FactoryGirl.create(:account) }
let(:another_account) { FactoryBot.create(:account) }

describe "GET #show" do
it "denies the request" do
Expand All @@ -143,8 +143,8 @@
end

context 'as a superadmin' do
let(:user) { FactoryGirl.create(:superadmin) }
let!(:account) { FactoryGirl.create(:account) }
let(:user) { FactoryBot.create(:superadmin) }
let!(:account) { FactoryBot.create(:account) }

describe "GET #index" do
it "assigns all accounts as @accounts" do
Expand Down Expand Up @@ -177,7 +177,7 @@
end

describe 'account dependency switching' do
let(:account) { FactoryGirl.create(:account) }
let(:account) { FactoryBot.create(:account) }

before do
Site.update(account: account)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/roles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

context 'with an administrator' do
let(:user) { FactoryGirl.create(:admin) }
let(:user) { FactoryBot.create(:admin) }

describe "GET #index" do
before do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/accounts.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :solr_endpoint do
options { Hash.new(url: 'http://fakesolr.localhost:9876/solr/', collection: 'fakecore') }
end
Expand Down
58 changes: 29 additions & 29 deletions spec/factories/collection_types.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
FactoryGirl.define do
FactoryBot.define do
factory :collection_type, class: Hyrax::CollectionType do
sequence(:title) { |n| "Collection Type #{n}" }
sequence(:machine_id) { |n| "title_#{n}" }

description 'Collection type with all options'
nestable true
discoverable true
sharable true
brandable true
share_applies_to_new_works true
allow_multiple_membership true
require_membership false
assigns_workflow false
assigns_visibility false
description { 'Collection type with all options' }
nestable { true }
discoverable { true }
sharable { true }
brandable { true }
share_applies_to_new_works { true }
allow_multiple_membership { true }
require_membership { false }
assigns_workflow { false }
assigns_visibility { false }

transient do
creator_user nil
creator_group nil
manager_user nil
manager_group nil
creator_user { nil }
creator_group { nil }
manager_user { nil }
manager_group { nil }
end

after(:create) do |collection_type, evaluator|
Expand Down Expand Up @@ -56,50 +56,50 @@
end

trait :nestable do
nestable true
nestable { true }
end

trait :not_nestable do
nestable false
nestable { false }
end

trait :discoverable do
discoverable true
discoverable { true }
end

trait :not_discoverable do
discoverable false
discoverable { false }
end

trait :brandable do
brandable true
brandable { true }
end

trait :not_brandable do
brandable false
brandable { false }
end

trait :sharable do
sharable true
share_applies_to_new_works true
sharable { true }
share_applies_to_new_works { true }
end

trait :sharable_no_work_permissions do
sharable true
share_applies_to_new_works false
sharable { true }
share_applies_to_new_works { false }
end

trait :not_sharable do
sharable false
share_applies_to_new_works false
sharable { false }
share_applies_to_new_works { false }
end

trait :allow_multiple_membership do
allow_multiple_membership true
allow_multiple_membership { true }
end

trait :not_allow_multiple_membership do
allow_multiple_membership false
allow_multiple_membership { false }
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/factories/collections.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FactoryGirl.define do
FactoryBot.define do
# TODO: swap this out for hyrax's collection_lw
factory :collection do
transient do
user { create(:user) }
# allow defaulting to default user collection
collection_type_settings nil
with_permission_template false
create_access false
with_nesting_attributes nil
collection_type_settings { nil }
with_permission_template { false }
create_access { false }
with_nesting_attributes { nil }
end
sequence(:title) { |n| ["Collection Title #{n}"] }

Expand Down
4 changes: 2 additions & 2 deletions spec/factories/file_sets.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
FactoryBot.define do
factory :file_set do
transient do
user { FactoryGirl.create(:user) }
user { FactoryBot.create(:user) }
end
after(:build) do |fs, evaluator|
fs.apply_depositor_metadata evaluator.user
Expand Down
12 changes: 6 additions & 6 deletions spec/factories/generic_works.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
FactoryGirl.define do
FactoryBot.define do
factory :generic_work, aliases: [:work] do
transient do
user { FactoryGirl.create(:user) }
user { FactoryBot.create(:user) }
end

title ["Test title"]
title { ["Test title"] }

identifier %w[
identifier { %w[
ISBN:978-83-7659-303-6 978-3-540-49698-4 9790879392788
doi:10.1038/nphys1170 3-921099-34-X 3-540-49698-x 0-19-852663-6
]
] }

factory :work_with_one_file do
before(:create) do |work, evaluator|
work.ordered_members << FactoryGirl.create(:file_set,
work.ordered_members << FactoryBot.create(:file_set,
user: evaluator.user,
title: ['A Contained Generic File'])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :group, class: Hyku::Group do
sequence(:name) { |_n| "group-#{srand}" }
sequence(:description) { |_n| "Somthing about group-#{srand}" }
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/roles.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :role do
end
end
6 changes: 3 additions & 3 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryGirl.define do
FactoryBot.define do
factory :base_user, class: User do
sequence(:email) { |_n| "email-#{srand}@test.com" }
password 'a password'
password_confirmation 'a password'
password { 'a password' }
password_confirmation { 'a password' }

factory :user do
after(:create) { |user| user.remove_role(:admin) }
Expand Down
4 changes: 2 additions & 2 deletions spec/features/accounts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
RSpec.describe 'Accounts administration', multitenant: true do
context 'as an superadmin' do
let(:user) { FactoryGirl.create(:superadmin) }
let(:user) { FactoryBot.create(:superadmin) }
let(:account) do
FactoryGirl.create(:account, solr_endpoint_attributes: { url: 'http://localhost:8080/solr' },
FactoryBot.create(:account, solr_endpoint_attributes: { url: 'http://localhost:8080/solr' },
fcrepo_endpoint_attributes: { url: 'http://localhost:8080/fcrepo' })
end

Expand Down
Loading

0 comments on commit aeb9904

Please sign in to comment.