Skip to content

Commit a87c2fe

Browse files
authored
Merge pull request #25 from dxw/289-code-reference-against-suppliers
Add coda_reference to the Supplier model
2 parents d29c876 + badf382 commit a87c2fe

5 files changed

Lines changed: 59 additions & 1 deletion

File tree

app/models/supplier.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ class Supplier < ApplicationRecord
55
has_many :memberships, dependent: :destroy
66

77
validates :name, presence: true
8+
validates :coda_reference, allow_nil: true, format: {
9+
with: /\AC0\d{5}\z/,
10+
message: 'must start with “C0” and have five additional numbers, for example: “C012345”'
11+
}
812
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
NAME_TO_CODA_REFERENCE_MAPPING = {
3+
'Addleshaw Goddard LLP' => 'C000976',
4+
'Ashurst LLP' => 'C005187',
5+
'DLA Piper LLP' => 'C002107',
6+
'Eversheds Sutherland (International) LLP' => 'C000941',
7+
'Linklaters LLP' => 'C002112',
8+
'Norton Rose Fulbright LLP' => 'C002119',
9+
'Osborne Clarke LLP' => 'C009841',
10+
'Stephenson Harwood' => 'C005196',
11+
'Bond Dickinson LLP' => 'C000940',
12+
'Burges Salmon LLP' => 'C000977',
13+
'DAC Beachcroft LLP' => 'C009492',
14+
'Dentons UK MEA LLP' => 'C000851',
15+
'Gowling WLG (UK) LLP' => 'C000855',
16+
'Mills & Reeve LLP' => 'C002031',
17+
'Pinsent Mason' => 'C000853',
18+
'PricewaterhouseCoopers LLP' => 'C000568',
19+
'TLT LLP' => 'C009493',
20+
'Bevan Brittan LLP' => 'C000850',
21+
'Browne Jacobson LLP' => 'C005191',
22+
'Field Fisher Waterhouse' => 'C000911',
23+
'Hogan Lovells International LLP' => 'C002113',
24+
'Simmons & Simmons LLP' => 'C000917',
25+
'Slaughter & May' => 'C002123',
26+
'BRYAN CAVE LEIGHTON PAISNER LLP' => 'C002101',
27+
'Clifford Chance LLP' => 'C009889',
28+
'Freshfields Bruckhaus Deringer' => 'C002108',
29+
}.freeze
30+
31+
NAME_TO_CODA_REFERENCE_MAPPING.each_pair do |name, coda_reference|
32+
Supplier.find_by!(name: name).update!(coda_reference: coda_reference)
33+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCodaReferenceToSuppliers < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :suppliers, :coda_reference, :string, limit: 7
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2018_07_27_170406) do
13+
ActiveRecord::Schema.define(version: 2018_08_06_154052) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "pgcrypto"
@@ -102,6 +102,7 @@
102102

103103
create_table "suppliers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
104104
t.string "name", null: false
105+
t.string "coda_reference", limit: 7
105106
end
106107

107108
create_table "tasks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|

spec/models/supplier_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,19 @@
77
it { is_expected.to have_many(:agreements) }
88
it { is_expected.to have_many(:frameworks).through(:agreements) }
99
it { is_expected.to have_many(:memberships) }
10+
11+
it 'validates coda_reference begins with C0 and ends with 5 more digits' do
12+
valid_coda_references = %w[C012345 C002928 C099999]
13+
invalid_coda_references = %w[C012 D012345 C0AB123]
14+
15+
valid_coda_references.each do |coda_reference|
16+
expect(FactoryBot.create(:supplier, coda_reference: coda_reference)).to be_valid
17+
end
18+
19+
invalid_coda_references.each do |coda_reference|
20+
supplier = FactoryBot.build(:supplier, coda_reference: coda_reference)
21+
expect(supplier).not_to be_valid
22+
expect(supplier.errors[:coda_reference]).to be_present
23+
end
24+
end
1025
end

0 commit comments

Comments
 (0)