add label to LicenseField

This commit is contained in:
Ben Balter 2017-11-01 11:33:47 -04:00
parent c722cd7979
commit f2802bf0fb
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 22 additions and 0 deletions

View File

@ -45,5 +45,11 @@ module Licensee
alias key name
FIELD_REGEX = /\[(#{Regexp.union(LicenseField.keys)})\]/
# The human-readable field name
def label
key.sub('fullname', 'full name').capitalize
end
alias to_s label
end
end

View File

@ -53,11 +53,27 @@ RSpec.describe Licensee::LicenseField do
it 'stores and exposes values' do
field = described_class.new('foo', 'bar')
expect(field.name).to eql('foo')
expect(field.key).to eql('foo')
expect(field.description).to eql('bar')
end
it 'returns the field label' do
field = described_class.new('foo', 'bar')
expect(field.label).to eql('Foo')
end
it "doesn't error for licenses without bodies" do
other = Licensee::License.find('other')
expect(other.fields).to be_empty
end
it 'converts fullname to two words' do
field = described_class.new('fullname', 'foo')
expect(field.label).to eql('Full name')
end
it 'returns the label for #to_s' do
field = described_class.new('foo', 'bar')
expect(field.to_s).to eql('Foo')
end
end