Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from projecthydra/mixin
Add a module mixin to make integration easier
- Loading branch information
Showing
4 changed files
with
46 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveFedora | ||
module Noid | ||
# Mix this class into an ActiveFedora:Base model in order to have you new objects | ||
# created with a noid id. | ||
module Model | ||
## This overrides the default behavior, which is to ask Fedora for an id | ||
# @see ActiveFedora::Persistence.assign_id | ||
def assign_id | ||
service.mint | ||
end | ||
|
||
private | ||
|
||
def service | ||
@service ||= ActiveFedora::Noid::Service.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
RSpec.describe ActiveFedora::Noid::Model do | ||
let(:sample_class) do | ||
Class.new(ActiveFedora::Base) do | ||
include ActiveFedora::Noid::Model | ||
end | ||
end | ||
let(:instance) { sample_class.new } | ||
let(:service) { instance_double(ActiveFedora::Noid::Service, mint: '1234') } | ||
|
||
before do | ||
allow(ActiveFedora::Noid::Service).to receive(:new).and_return(service) | ||
end | ||
|
||
describe '#assign_id' do | ||
it 'returns the id from the noid service' do | ||
expect(instance.assign_id).to eq '1234' | ||
end | ||
end | ||
end |