Skip to content

Commit

Permalink
Merge pull request #4277 from sanger/4178-y24-172---make_WIP_identica…
Browse files Browse the repository at this point in the history
…l_in_SS_Limber

add wip_list method to return wip file list
  • Loading branch information
wendyyang authored Aug 28, 2024
2 parents 28863bf + 9949dec commit 1be5238
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
Bullet.bullet_logger = true
Bullet.rails_logger = true
end

# load WIP features flag
config.deploy_wip_pipelines = true
end

Rack::MiniProfiler.config.position = 'right'
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@

# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true

# load WIP features flag
config.deploy_wip_pipelines = true
end
19 changes: 19 additions & 0 deletions lib/record_loader/application_record_loader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'find'

# This file was automatically generated by `rails g record_loader`
module RecordLoader
Expand All @@ -9,5 +10,23 @@ class ApplicationRecordLoader < RecordLoader::Base
# Uses the standard RailsAdapter
# @see https://rubydoc.info/github/sanger/record_loader/RecordLoader/Adapter
adapter RecordLoader::Adapter::Rails.new

def wip_list
# return a list of WIP files name as features if deploy_wip_pipelines is set to true, or return empty list
deploy_wip_pipelines = Rails.application.config.try(:deploy_wip_pipelines) || false
return [] unless deploy_wip_pipelines

wip_files = []
# @path returns 'config/default_records' directory
# see https://github.com/sanger/record_loader/blob/master/lib/record_loader/base.rb
wip_files_path = @path
Find.find(wip_files_path) do |path|
if path.match?(/\wip\.yml$/)
file_name = File.basename(path, '.wip.yml')
wip_files << file_name
end
end
wip_files
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test record loader records
---
Test Record:
test_attribute: "A Value"
41 changes: 41 additions & 0 deletions spec/lib/record_loader/application_record_loader_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'rails_helper'
require 'record_loader/application_record_loader'

RSpec.describe RecordLoader::ApplicationRecordLoader, :loader, type: :model do
def a_new_record_loader
described_class.new(directory: test_directory)
end

subject(:record_loader) { a_new_record_loader }

let(:test_directory) { Rails.root.join('spec/data/record_loader/application_record_loader') }

context 'when deploy_wip_pipelines is false' do
before { allow(Rails.application.config).to receive(:deploy_wip_pipelines).and_return(false) }

it 'returns an empty array' do
expect(record_loader.wip_list).to eq([])
end
end

context 'when deploy_wip_pipelines is true' do
before do
allow(Rails.application.config).to receive(:deploy_wip_pipelines).and_return(true)
allow(Find).to receive(:find).with(test_directory).and_yield("#{test_directory}/example.wip.yml")
end

it 'returns a list of WIP features' do
expect(record_loader.wip_list).to eq(['example'])
end
end

context 'when deploy_wip_pipelines is not set' do
before { allow(Rails.application.config).to receive(:deploy_wip_pipelines).and_return(nil) }

it 'returns an empty array' do
expect(record_loader.wip_list).to eq([])
end
end
end

0 comments on commit 1be5238

Please sign in to comment.