File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class SupplierImport
2+ end
Original file line number Diff line number Diff line change 1+ class SupplierImportRow
2+ def initialize ( row )
3+ @row = row
4+ end
5+
6+ def import!
7+ supplier = Supplier . create! ( name : @row [ :suppliername ] )
8+ framework = Framework . find_by! ( short_name : @row [ :frameworkreference ] )
9+
10+ supplier . agreements . create! ( framework : framework )
11+ end
12+ end
Original file line number Diff line number Diff line change 1+ require 'rails_helper'
2+ require './lib/supplier_import_row'
3+
4+ RSpec . describe SupplierImportRow do
5+ describe '#import!' do
6+ it 'creates a new supplier and adds it to the framework' do
7+ framework = FactoryBot . create ( :framework , short_name : 'RM3756' )
8+
9+ data = {
10+ frameworkreference : 'RM3756' ,
11+ supplierid : 1234 ,
12+ suppliername : 'Bob and Bucket LLP' ,
13+ lotid : 5678 ,
14+ lotnumber : 1 ,
15+ username : 'francis.brown' ,
16+ personname : 'Francis Brown' ,
17+ jobtitle : 'Big Cheese' ,
18+ contacttel : '02088118055' ,
19+ contactmobile : '07900111222' ,
20+ email : 'francis.brown@example.com' ,
21+ usercreationdate : '1/1/1970 18:00' ,
22+ lastlogindate : '1/7/2018 12:40'
23+ }
24+
25+ row = SupplierImportRow . new ( data )
26+
27+ expect { row . import! } . to change { Supplier . count } . by ( 1 )
28+
29+ supplier = Supplier . first
30+ expect ( supplier . name ) . to eql 'Bob and Bucket LLP'
31+ expect ( supplier . frameworks ) . to contain_exactly ( framework )
32+ end
33+ end
34+ end
Original file line number Diff line number Diff line change 1+ require 'rails_helper'
2+ require 'supplier_import'
3+
4+ RSpec . describe SupplierImport do
5+ describe '#initialize' do
6+ it 'accepts CSV data as a string input' do
7+ end
8+ end
9+ end
You can’t perform that action at this time.
0 commit comments