Skip to content

Commit

Permalink
Merge pull request #1550 from TexasDigitalLibrary/1530-update-factory…
Browse files Browse the repository at this point in the history
…girl-to-factorybot

update FactoryGirl to FactoryBot
  • Loading branch information
orangewolf authored Oct 25, 2018
2 parents 9dbe3c4 + 7bd2637 commit 59a15d7
Show file tree
Hide file tree
Showing 75 changed files with 262 additions and 179 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 @@ -912,7 +912,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 @@ -961,4 +961,4 @@ DEPENDENCIES
zk

BUNDLED WITH
1.16.3
1.16.6
8 changes: 7 additions & 1 deletion spec/controllers/account_sign_up_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(false)
end

describe "GET #new" do
it "assigns a new account as @account" do
get :new
Expand Down Expand Up @@ -68,12 +69,14 @@
before do
allow(Settings.multitenancy).to receive(:admin_only_tenant_creation).and_return(true)
end

describe "GET #new" do
it "redirects to sign in" do
get :new
expect(response).to redirect_to new_user_session_path
end
end

describe "POST #create" do
it "redirects to sign in" do
post :create, params: { account: valid_attributes }
Expand All @@ -83,22 +86,25 @@
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)
end

describe "GET #new" do
it "assigns a new account as @account" do
get :new
expect(response).to render_template("layouts/proprietor")
expect(assigns(:account)).to be_a_new(Account)
end
end

describe "POST #create" do
before do
allow_any_instance_of(CreateAccount).to receive(:create_external_resources)
end

it "creates a new Account" do
expect do
post :create, params: { account: valid_attributes }
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
7 changes: 4 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 Expand Up @@ -62,6 +62,7 @@
subject { Hyku::Group.find_by(id: group.id) }

before { delete :destroy, params: { id: group.id } }

it { is_expected.to be_nil }
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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) }

before { delete :destroy, params: { id: user.id } }

it "doesn't delete the user and redirects to login" do
expect(subject).not_to be_nil
expect(response).to redirect_to root_path
Expand All @@ -14,14 +15,15 @@
end

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

before { sign_in create(:admin) }

describe 'DELETE #destroy' do
subject { User.find_by(id: user.id) }

before { delete :destroy, params: { id: user.to_param } }

it "deletes the user and displays success message" do
expect(subject).to be_nil
expect(flash[:notice]).to eq "User \"#{user.email}\" has been successfully deleted."
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sign_in create(:user)
allow(controller).to receive(:can?).and_return(true)
end

it "is successful" do
get :show, params: { id: file_set }
expect(response).to be_successful
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/hyku/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
expect(response).to render_template('devise/registrations/new')
end
end

describe '#create' do
it 'processes the form' do
post :create, params: {
Expand All @@ -28,6 +29,7 @@
end
end
end

context 'with account signup disabled' do
let(:account_signup_enabled) { false }

Expand All @@ -38,6 +40,7 @@
expect(flash[:alert]).to eq 'Account registration is disabled'
end
end

describe '#create' do
it 'redirects with a flash message' do
post :create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe Hyrax::Admin::AppearancesController, type: :controller, singletenant: true do
before { sign_in user }

routes { Hyrax::Engine.routes }

context 'with an unprivileged user' do
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/hyrax/generic_works_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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
Hydra::Works::AddFileToFileSet.call(file_set,
fixture_file('images/world.png'),
:original_file)
end

describe '#manifest' do
let(:manifest_factory) { double(to_h: { test: 'manifest' }) }

Expand All @@ -25,11 +26,12 @@
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)
end

subject { controller.send :presenter }

it "initializes a presenter" do
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
Loading

0 comments on commit 59a15d7

Please sign in to comment.