diff --git a/.rubocop.yml b/.rubocop.yml index e08b000..9c2b597 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,4 @@ -require: rubocop-rails \ No newline at end of file +require: rubocop-rails + +Rails/FilePath: + Enabled: false \ No newline at end of file diff --git a/app/services/guide_card_loading_service.rb b/app/services/guide_card_loading_service.rb index 62028c6..649f562 100644 --- a/app/services/guide_card_loading_service.rb +++ b/app/services/guide_card_loading_service.rb @@ -1,21 +1,22 @@ # frozen_string_literal: true -require 'csv' +require 'csv' +# service for loading GuideCard data class GuideCardLoadingService # location of source data for GuideCards def csv_location Rails.root.join('data', 'dbo-guides', 'dbo.Guides.31756.csv') end + def import - guide_card_data=CSV.parse(File.read(csv_location), headers: true) + guide_card_data = CSV.parse(File.read(csv_location), headers: true) guide_card_data.each do |card| - gc=GuideCard.new - gc.id=card[0] - gc.heading=card[1] - gc.sortid=card[2] - gc.path=card[3] + gc = GuideCard.new + gc.id = card[0] + gc.heading = card[1] + gc.sortid = card[2] + gc.path = card[3] gc.save end end end - diff --git a/spec/services/guide_card_loading_service_spec.rb b/spec/services/guide_card_loading_service_spec.rb index 554788c..a478db1 100644 --- a/spec/services/guide_card_loading_service_spec.rb +++ b/spec/services/guide_card_loading_service_spec.rb @@ -1,19 +1,20 @@ # frozen_string_literal: true -require "rails_helper" + +require 'rails_helper' describe GuideCardLoadingService do - let(:gcls) {described_class.new} - it "can instantiate" do + let(:gcls) { described_class.new } + it 'can instantiate' do expect(gcls).to be_instance_of described_class end - it "has a CSV file" do + it 'has a CSV file' do expect(gcls.csv_location).to eq Rails.root.join('data', 'dbo-guides', 'dbo.Guides.31756.csv') end - it "imports all data from the CSV file" do + it 'imports all data from the CSV file' do expect(GuideCard.count).to eq 0 gcls.import - expect(GuideCard.count).to eq 31756 + expect(GuideCard.count).to eq 31_756 end -end \ No newline at end of file +end