Skip to content

Commit 23c38f1

Browse files
committed
Add coda_reference to the Supplier model
This reference will be used to match the supplier against their record in current finance system, called Coda.
1 parent d29c876 commit 23c38f1

4 files changed

Lines changed: 26 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: 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)