Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit d4e60e5

Browse files
authored
Merge pull request #735 from alphagov/change_factory_girl_to_bot
Swap factory girl to factory bot
2 parents 35fb297 + 524156c commit d4e60e5

21 files changed

+60
-60
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ group :development, :test do
3636
gem 'brakeman', '~> 4.2'
3737
gem 'byebug', '~> 9'
3838
gem 'dotenv-rails', '~> 2.2'
39-
gem 'factory_girl_rails', '~> 4.0'
39+
gem 'factory_bot_rails', '~> 4.0'
4040
gem 'govuk-lint', '~> 3.8.0'
4141
gem 'pry', '~> 0.10'
4242
gem 'pry-byebug', '~> 3.4'

Gemfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ GEM
9393
et-orbi (1.1.2)
9494
tzinfo
9595
execjs (2.7.0)
96-
factory_girl (4.8.0)
96+
factory_bot (4.11.1)
9797
activesupport (>= 3.0.0)
98-
factory_girl_rails (4.8.0)
99-
factory_girl (~> 4.8.0)
98+
factory_bot_rails (4.11.1)
99+
factory_bot (~> 4.11.1)
100100
railties (>= 3.0.0)
101101
faraday (0.12.1)
102102
multipart-post (>= 1.2, < 3)
@@ -434,7 +434,7 @@ DEPENDENCIES
434434
elasticsearch (~> 5.0.4)
435435
elasticsearch-model (~> 5.0.1)
436436
elasticsearch-rails (~> 5.0.1)
437-
factory_girl_rails (~> 4.0)
437+
factory_bot_rails (~> 4.0)
438438
gds-sso
439439
govuk-lint (~> 3.8.0)
440440
govuk_elements_rails
@@ -476,4 +476,4 @@ RUBY VERSION
476476
ruby 2.5.0p0
477477

478478
BUNDLED WITH
479-
1.16.3
479+
1.16.6

spec/controllers/datasets_controller_spec.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
require 'rails_helper'
22

33
describe DatasetsController, type: :controller do
4-
let(:organisation) { FactoryGirl.create(:organisation) }
5-
let(:user) { FactoryGirl.create(:user, primary_organisation: organisation) }
4+
let(:organisation) { FactoryBot.create(:organisation) }
5+
let(:user) { FactoryBot.create(:user, primary_organisation: organisation) }
66

77
before do
88
sign_in_as(user)
99
end
1010

1111
it "redirects to slugged URL" do
12-
dataset = FactoryGirl.create(:dataset,
12+
dataset = FactoryBot.create(:dataset,
1313
name: "legit-name",
1414
organisation: organisation,
15-
datafiles: [FactoryGirl.create(:datafile)])
15+
datafiles: [FactoryBot.create(:datafile)])
1616

1717
get :show, params: { uuid: dataset.uuid, name: "absolute-nonsense-name" }
1818

1919
expect(response).to redirect_to(dataset_url(dataset.uuid, dataset.name))
2020
end
2121

2222
it "returns '503 forbidden' error if a user is not allowed to view the requested dataset" do
23-
another_organisation = FactoryGirl.create(:organisation)
23+
another_organisation = FactoryBot.create(:organisation)
2424

25-
_allowed_dataset = FactoryGirl.create(:dataset,
25+
_allowed_dataset = FactoryBot.create(:dataset,
2626
organisation: organisation,
27-
datafiles: [FactoryGirl.create(:datafile)])
27+
datafiles: [FactoryBot.create(:datafile)])
2828

29-
forbidden_dataset = FactoryGirl.create(:dataset,
29+
forbidden_dataset = FactoryBot.create(:dataset,
3030
organisation: another_organisation,
31-
datafiles: [FactoryGirl.create(:datafile)])
31+
datafiles: [FactoryBot.create(:datafile)])
3232

3333
get :show, params: { uuid: forbidden_dataset.uuid, name: forbidden_dataset.name }
3434

3535
expect(response).to have_http_status(403)
3636
end
3737

3838
it "returns '503 forbidden' error if a user is not allowed to update the requested dataset" do
39-
another_organisation = FactoryGirl.create(:organisation)
39+
another_organisation = FactoryBot.create(:organisation)
4040

41-
_allowed_dataset = FactoryGirl.create(:dataset,
41+
_allowed_dataset = FactoryBot.create(:dataset,
4242
organisation: organisation,
43-
datafiles: [FactoryGirl.create(:datafile)])
43+
datafiles: [FactoryBot.create(:datafile)])
4444

45-
forbidden_dataset = FactoryGirl.create(:dataset,
45+
forbidden_dataset = FactoryBot.create(:dataset,
4646
organisation: another_organisation,
47-
datafiles: [FactoryGirl.create(:datafile)])
47+
datafiles: [FactoryBot.create(:datafile)])
4848

4949
get :edit, params: { uuid: forbidden_dataset.uuid, name: forbidden_dataset.name }
5050

spec/factories/ckan_v26_ckan_org.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :ckan_v26_ckan_org, class: CKAN::V26::CKANOrg do
33
id SecureRandom.uuid
44
name "Name"

spec/factories/ckan_v26_package.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :ckan_v26_package, class: CKAN::V26::Package do
33
name "Name"
44
title "Title"

spec/factories/ckan_v26_resource.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :ckan_v26_resource, class: CKAN::V26::Resource do
33
url "http://environment.data.gov.uk/ds/wms?SERVICE=WMS&INTERFACE=ENVIRONMENT--86ec354f-d465-11e4-b09e-f0def148f590&request=GetCapabilities"
44
format "WMS"

spec/factories/datafile.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :datafile do
33
dataset
44
url 'http://google.com'

spec/factories/dataset.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :dataset do
33
organisation
44
title "Price paid for dragon glass"

spec/factories/doc.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :doc do
33
dataset
44
url 'http://google.com'

spec/factories/inspire_dataset.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :inspire_dataset do
33
dataset_reference_date do
44
"[{\"type\": \"publication\", \"value\": \"2015-12-03\"}, {\"type\": \"revision\", \"value\": \"2015-12-03\"}, {\"type\": \"creation\", \"value\": \"2006-01-01\"}]"

spec/factories/link.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :link do
33
dataset
44
url 'http://google.com'

spec/factories/organisation.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :organisation do
33
name "land-registry"
44
title "Land Registry"

spec/factories/topic.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :topic do
33
name "business-and-economy"
44
title "Business and Economy"

spec/factories/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FactoryGirl.define do
1+
FactoryBot.define do
22
factory :user do
33
44
name 'Test User'

spec/features/dataset_create_spec.rb

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require "rails_helper"
22

33
describe "creating datasets" do
4-
let(:land) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
5-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land) }
6-
let!(:dataset) { FactoryGirl.create(:dataset, organisation: land, creator: user) }
7-
let!(:topic) { FactoryGirl.create(:topic) }
4+
let(:land) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
5+
let!(:user) { FactoryBot.create(:user, primary_organisation: land) }
6+
let!(:dataset) { FactoryBot.create(:dataset, organisation: land, creator: user) }
7+
let!(:topic) { FactoryBot.create(:topic) }
88

99
context "when the user goes through entire flow" do
1010
before(:each) do
@@ -135,9 +135,9 @@
135135
end
136136

137137
describe "starting a new draft with invalid inputs" do
138-
let(:land) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
139-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land) }
140-
let!(:topic) { FactoryGirl.create(:topic) }
138+
let(:land) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
139+
let!(:user) { FactoryBot.create(:user, primary_organisation: land) }
140+
let!(:topic) { FactoryBot.create(:topic) }
141141

142142
before(:each) do
143143
url = "https://test.data.gov.uk/api/3/action/package_patch"
@@ -192,9 +192,9 @@
192192
end
193193

194194
describe "valid options for topic, licence and area" do
195-
let(:land_registry) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
196-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land_registry) }
197-
let!(:topic) { FactoryGirl.create(:topic) }
195+
let(:land_registry) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
196+
let!(:user) { FactoryBot.create(:user, primary_organisation: land_registry) }
197+
let!(:topic) { FactoryBot.create(:topic) }
198198

199199
before(:each) do
200200
url = "https://test.data.gov.uk/api/3/action/package_patch"
@@ -257,9 +257,9 @@
257257
end
258258

259259
describe "dataset frequency options" do
260-
let(:land) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
261-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land) }
262-
let!(:dataset) { FactoryGirl.create(:dataset, organisation: land) }
260+
let(:land) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
261+
let!(:user) { FactoryBot.create(:user, primary_organisation: land) }
262+
let!(:dataset) { FactoryBot.create(:dataset, organisation: land) }
263263

264264
before(:each) do
265265
url = "https://test.data.gov.uk/api/3/action/package_patch"
@@ -410,9 +410,9 @@ def pick_year(year_type)
410410
end
411411

412412
describe "passing the frequency page" do
413-
let(:land) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
414-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land) }
415-
let!(:dataset) { FactoryGirl.create(:dataset, organisation: land, frequency: nil) }
413+
let(:land) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
414+
let!(:user) { FactoryBot.create(:user, primary_organisation: land) }
415+
let!(:dataset) { FactoryBot.create(:dataset, organisation: land, frequency: nil) }
416416

417417
before(:each) do
418418
url = "https://test.data.gov.uk/api/3/action/package_patch"

spec/features/dataset_index_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require 'rails_helper'
22

33
describe "managing datasets" do
4-
let(:organisation) { FactoryGirl.create(:organisation) }
5-
let!(:user) { FactoryGirl.create(:user, primary_organisation: organisation) }
6-
let!(:dataset_1) { FactoryGirl.create(:dataset, title: "Cats per square mile", organisation: organisation) }
7-
let!(:dataset_2) { FactoryGirl.create(:dataset, title: "Dogs per square mile", organisation: organisation) }
4+
let(:organisation) { FactoryBot.create(:organisation) }
5+
let!(:user) { FactoryBot.create(:user, primary_organisation: organisation) }
6+
let!(:dataset_1) { FactoryBot.create(:dataset, title: "Cats per square mile", organisation: organisation) }
7+
let!(:dataset_2) { FactoryBot.create(:dataset, title: "Dogs per square mile", organisation: organisation) }
88

99
before(:each) do
1010
sign_in_as(user)
@@ -48,7 +48,7 @@
4848
end
4949

5050
it "paginates datasets" do
51-
FactoryGirl.create(:dataset, organisation: organisation) # create a third dataset
51+
FactoryBot.create(:dataset, organisation: organisation) # create a third dataset
5252
datasets_per_page = 2
5353

5454
visit manage_organisation_path(per: datasets_per_page)

spec/features/log_in_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require 'rails_helper'
22

33
describe "logging in" do
4-
let(:land_registry) { FactoryGirl.create(:organisation, name: 'land-registry', title: 'Land Registry') }
5-
let!(:user) { FactoryGirl.create(:user, primary_organisation: land_registry) }
4+
let(:land_registry) { FactoryBot.create(:organisation, name: 'land-registry', title: 'Land Registry') }
5+
let!(:user) { FactoryBot.create(:user, primary_organisation: land_registry) }
66

77
it "redirects logged in users to the manage page" do
88
sign_in_as(user)

spec/models/datafile_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ANNUALLY = 'annually'.freeze
77

88
before do
9-
@datafile = FactoryGirl.create(:datafile)
9+
@datafile = FactoryBot.create(:datafile)
1010
end
1111

1212
describe 'creation' do

spec/models/dataset_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
end
2121

2222
it "generates a unique slug and stores it on the name column" do
23-
dataset = FactoryGirl.create(:dataset,
23+
dataset = FactoryBot.create(:dataset,
2424
title: "My awesome dataset")
2525

2626
expect(dataset.name).to eq(dataset.title.parameterize)
2727
end
2828

2929
it "generates a new slug when the title has changed" do
30-
dataset = FactoryGirl.create(:dataset,
30+
dataset = FactoryBot.create(:dataset,
3131
uuid: 1234,
3232
title: "My awesome dataset")
3333

spec/models/link_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe Link, type: :model do
44
before do
5-
@link = FactoryGirl.create(:link)
5+
@link = FactoryBot.create(:link)
66
end
77

88
describe 'creation' do

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ENV["RAILS_ENV"] = 'test'
22

33
require "simplecov"
4-
require "factory_girl_rails"
4+
require "factory_bot_rails"
55
require "database_cleaner"
66
require "govuk_sidekiq/testing"
77
require 'webmock/rspec'
@@ -14,7 +14,7 @@
1414
SimpleCov.start unless ENV["NO_RCOV"]
1515

1616
RSpec.configure do |config|
17-
config.include FactoryGirl::Syntax::Methods
17+
config.include FactoryBot::Syntax::Methods
1818
config.include WebMock::API
1919

2020
config.order = :random

0 commit comments

Comments
 (0)