• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.66
/app/services/location_data_service.rb
1
class LocationDataService
1✔
2
  # Delete existing locations data repopulate tables with data from Alma
3
  def self.delete_existing_and_repopulate
1✔
UNCOV
4
    new.delete_existing_and_repopulate
×
5
  end
6

7
  def delete_existing_and_repopulate
1✔
UNCOV
8
    DeliveryLocation.delete_all
×
UNCOV
9
    HoldingLocation.delete_all
×
UNCOV
10
    Library.delete_all
×
UNCOV
11
    populate_libraries
×
UNCOV
12
    populate_delivery_locations
×
UNCOV
13
    populate_holding_locations
×
14
  end
15

16
  def populate_libraries
1✔
17
    # Populate Library model using the libraries.json file
UNCOV
18
    libraries_array.each do |library|
×
UNCOV
19
      Library.create(
×
20
        label: library['label'],
21
        code: library['code'],
22
        order: library['order']
23
      )
24
    end
25
  end
26

27
  def populate_holding_locations
1✔
UNCOV
28
    holding_locations_array.each do |holding_location|
×
UNCOV
29
      holding_location_record = HoldingLocation.create(
×
30
        label: holding_location['label'],
31
        code: holding_location['code'],
32
        aeon_location: holding_location['aeon_location'],
33
        recap_electronic_delivery_location: holding_location['recap_electronic_delivery_location'],
34
        open: holding_location['open'],
35
        requestable: holding_location['requestable'],
36
        always_requestable: holding_location['always_requestable'],
37
        circulates: holding_location['circulates'],
38
        remote_storage: holding_location['remote_storage'],
39
        fulfillment_unit: holding_location['fulfillment_unit'],
UNCOV
40
        locations_library_id: holding_location['library'] ? library_id(holding_location['library']['code']) : {},
×
UNCOV
41
        holding_library_id: holding_location['holding_library'] ? library_id(holding_location['holding_library']['code']) : {} # Library.where(label: holding_location["holding_library"]).first.id
×
42
      )
UNCOV
43
      holding_location_record.delivery_location_ids = delivery_library_ids(holding_location['delivery_locations'])
×
44
    end
45
  end
46

47
  # Populate delivery locations based on the delivery_locations.json
48
  # @note Do NOT remove values from here without updating Figgy appropriately.
49
  # The URIs are referenced in Figgy and removing them will break manifests.
50
  # These values will not change when we move to alma.
51
  def populate_delivery_locations
1✔
UNCOV
52
    highest_id = delivery_locations_array.sort_by { |x| x['id'] }.last['id']
×
53
    # Reset the auto-increment column so it starts above the highest count.
UNCOV
54
    DeliveryLocation.connection.execute("ALTER SEQUENCE locations_delivery_locations_id_seq RESTART WITH #{highest_id + 1}")
×
UNCOV
55
    delivery_locations_array.each do |delivery_location|
×
UNCOV
56
      library_record_id = find_library_by_code(delivery_location['library']['code']).id
×
UNCOV
57
      DeliveryLocation.create(
×
58
        id: delivery_location['id'],
59
        label: delivery_location['label'],
60
        address: delivery_location['address'],
61
        phone_number: delivery_location['phone_number'],
62
        contact_email: delivery_location['contact_email'],
63
        staff_only: delivery_location['staff_only'],
64
        locations_library_id: library_record_id,
65
        gfa_pickup: delivery_location['gfa_pickup'],
66
        pickup_location: delivery_location['pickup_location'],
67
        digital_location: delivery_location['digital_location']
68
      )
69
    end
70
  end
71

72
  private
1✔
73

74
    def library_id(holding_library_code)
1✔
UNCOV
75
      return {} unless holding_library_code
×
76

UNCOV
77
      library = find_library_by_code(holding_library_code)
×
UNCOV
78
      library.id if library.present?
×
79
    end
80

81
    # Find the delivery library using the gfa_pickup value
82
    # example: gfa_pickup = ["QT", "QA", "PA", "QC"] for anxbnc
83
    def delivery_library_ids(gfa_pickup)
1✔
UNCOV
84
      ids = []
×
UNCOV
85
      gfa_pickup.each do |d|
×
UNCOV
86
        delivery_location = DeliveryLocation.all.find { |m| m['gfa_pickup'] == d }
×
UNCOV
87
        ids << delivery_location.id if delivery_location.present?
×
88
      end
UNCOV
89
      ids
×
90
    end
91

92
    # Find the library using the library code
93
    def find_library_by_code(code)
1✔
UNCOV
94
      Library.find_by(code:)
×
95
    end
96

97
    # Parses holding_locations.json file
98
    # Creates an array of holding_location hashes
99
    def holding_locations_array
1✔
UNCOV
100
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'holding_locations.json'))
×
UNCOV
101
      JSON.parse(file)
×
102
    end
103

104
    # Parses delivery_locations.json file
105
    # Creates an array of delivery_locations hashes
106
    def delivery_locations_array
1✔
UNCOV
107
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'delivery_locations.json'))
×
UNCOV
108
      JSON.parse(file)
×
109
    end
110

111
    # Parses libraries.json file
112
    # Creates an array of libraries hashes
113
    def libraries_array
1✔
UNCOV
114
      file = File.read(File.join(MARC_LIBERATION_CONFIG['location_files_dir'], 'libraries.json'))
×
UNCOV
115
      JSON.parse(file)
×
116
    end
117
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc