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

pulibrary / allsearch_api / 8cca27ea-0ec0-4546-b1e5-0dc9f1ef05a3

31 Oct 2025 06:27PM UTC coverage: 99.903% (+0.003%) from 99.9%
8cca27ea-0ec0-4546-b1e5-0dc9f1ef05a3

Pull #389

circleci

sandbergja
Replace uses of the Banner ActiveRecord model with Rom-RB

The ActiveRecord model is still used in tests and a database migration,
maybe those could be migrated to Rom-RB in a separate PR?

A Rom Container is created that uses the same database connections as
ActiveRecord.  This allows rom to use the same database transactions
as activerecord, allowing tests (which use db transactions to stay
isolated from one another) to still pass.
Pull Request #389: Replace uses of the Banner ActiveRecord model with Rom-RB

34 of 39 new or added lines in 4 files covered. (87.18%)

57 existing lines in 13 files now uncovered.

1031 of 1032 relevant lines covered (99.9%)

112.35 hits per line

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

100.0
/app/repositories/banner_repository.rb
1
# frozen_string_literal: true
2

3
require 'rom-repository'
3✔
4

5
# This repository translates between the objects and methods in our repository and the data and queries in our database
6
# To instantiate:
7
# br = BannerRepository.new env['rom']
8
# br.banners.first
9
class BannerRepository < ROM::Repository[:banners]
3✔
10
  def modify(new_values)
3✔
NEW
11
    existing_banner = banners.first
5✔
NEW
12
    if existing_banner
5✔
NEW
13
      update existing_banner.id, new_values
3✔
14
    else
NEW
15
      create new_values
2✔
16
    end
17
  end
18

19
  def delete
3✔
20
    # There should only ever be one, banner, so it is safe to delete them all
NEW
21
    banners.changeset(:delete).commit
2✔
22
  end
23

24
  commands :create,
3✔
25
           use: :timestamps,
26
           plugins_options: { timestamps: { timestamps: [:created_at, :updated_at] } }
27

28
  commands update: :by_pk,
3✔
29
           use: :timestamps,
30
           plugins_options: { timestamps: { timestamps: [:updated_at] } }
31

32
  module Structs
3✔
33
    # This struct represents a row from the banners database table
34
    class Banner < ROM::Struct
3✔
35
      # :reek:UtilityFunction
36
      def display?
3✔
37
        Flipper.enabled?(:banner)
7✔
38
      end
39

40
      def status_code
3✔
41
        ALERT_STATUS_CODES[alert_status]
7✔
42
      end
43

44
      def as_json
3✔
45
        {
46
          text:,
7✔
47
          display_banner: display?,
48
          alert_status: status_code,
49
          dismissible:,
50
          autoclear:
51
        }.to_json
52
      end
53
    end
54
  end
55
  auto_struct true
3✔
56
  struct_namespace Structs
3✔
57
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