Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/noid/rails/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def minter_class
# the minter will continue to cycle through ids until it finds one that
# returns false
def identifier_in_use
@identifier_in_use = lambda do |_id|
@identifier_in_use ||= lambda do |_id|
false
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/unit/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
it { is_expected.to respond_to(:statefile) }
it { is_expected.to respond_to(:namespace) }
it { is_expected.to respond_to(:minter_class) }
it { is_expected.to respond_to(:identifier_in_use) }
Copy link
Copy Markdown
Member

@jcoyne jcoyne Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bit duplicative? You are explicitly testing this method below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't normally include this, but I was following the existing pattern. Methods template and minter_class are also explicitly tested and have the respond_to test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked with @jcoyne in Slack and he gave the thumbs up to merge.


describe '#template' do
let(:default) { '.reeddeeddk' }
Expand Down Expand Up @@ -42,4 +43,30 @@
end
end
end

describe '#identifier_in_use' do
it 'defaults to always return false' do
expect(subject.identifier_in_use.call('NEW_ID')).to be false
expect(subject.identifier_in_use.call('EXISTING_ID')).to be false
end

context 'when overridden' do
let(:override_check) do
lambda do |id|
return true if id == 'EXISTING_ID'
false
end
end

before { subject.identifier_in_use = override_check }

it 'returns false if id does not exist' do
expect(subject.identifier_in_use.call('NEW_ID')).to be false
end

it 'returns true if id exists' do
expect(subject.identifier_in_use.call('EXISTING_ID')).to be true
end
end
end
end