diff --git a/lib/arclight/repository.rb b/lib/arclight/repository.rb index 84cabbc0b..a1fddf3d2 100644 --- a/lib/arclight/repository.rb +++ b/lib/arclight/repository.rb @@ -1,22 +1,18 @@ # frozen_string_literal: true +require 'ostruct' + module Arclight # # Static information about a given repository identified by a unique `slug` - # - class Repository + # rubocop:disable Style/OpenStructUse + class Repository < OpenStruct include ActiveModel::Conversion # for to_partial_path - attr_accessor :name, :slug, :collection_count - # @param [String] `slug` the unique identifier for the repository # @param [Hash] `data` def initialize(slug, data = {}) - @slug = slug - data.each do |field, value| - self.class.attr_accessor field.to_sym - send("#{field}=", value) if value.present? - end + super(**data, slug: slug) end # @return [String] handles the formatting of "city, state zip, country" @@ -124,4 +120,5 @@ def self.find_by!(**kwargs) repository end end + # rubocop:enable Style/OpenStructUse end diff --git a/spec/helpers/arclight_helper_spec.rb b/spec/helpers/arclight_helper_spec.rb index 09287aa0b..e109858bd 100644 --- a/spec/helpers/arclight_helper_spec.rb +++ b/spec/helpers/arclight_helper_spec.rb @@ -305,7 +305,7 @@ context 'when searching within a repository' do before do expect(helper).to receive_messages( - repository_faceted_on: instance_double(Arclight::Repository, name: 'Repository Name') + repository_faceted_on: Arclight::Repository.new(nil, name: 'Repository Name') ) end diff --git a/spec/models/arclight/document_downloads_spec.rb b/spec/models/arclight/document_downloads_spec.rb index 11cf6defe..e52351466 100644 --- a/spec/models/arclight/document_downloads_spec.rb +++ b/spec/models/arclight/document_downloads_spec.rb @@ -72,7 +72,7 @@ context 'when a template is provided for the href' do before do allow(document).to receive(:repository_config).and_return( - instance_double(Arclight::Repository, slug: 'the-repo-id') + Arclight::Repository.new('the-repo-id') ) end diff --git a/spec/views/repositories/index.html.erb_spec.rb b/spec/views/repositories/index.html.erb_spec.rb index 78d3f5b6b..01ae14c9f 100644 --- a/spec/views/repositories/index.html.erb_spec.rb +++ b/spec/views/repositories/index.html.erb_spec.rb @@ -84,7 +84,7 @@ end it 'does not show on repositories detail page' do - assign(:repository, instance_double(Arclight::Repository, name: 'My Repository')) + assign(:repository, Arclight::Repository.new(nil, name: 'My Repository')) allow(view).to receive(:on_repositories_index?).and_return(false) allow(view).to receive(:on_repositories_show?).and_return(true) render