Skip to content

Commit

Permalink
Merge branch 'hotfix/0.6.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
thornomad committed Aug 4, 2020
2 parents 023cdd6 + ea1a7d1 commit 1b81de3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
enumbler (0.6.4)
enumbler (0.6.5)
activerecord (>= 5.2.3, < 6.1)
activesupport (>= 5.2.3, < 6.1)

Expand Down
11 changes: 10 additions & 1 deletion lib/enumbler/enabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ module Enabler
# The Enumble definition that this record defined.
# @return [Enumbler::Enumble]
def enumble
@enumble = self.class.enumbles.find { |enumble| enumble.id == id }
@enumble = self.class.find_enumble(id)

raise Error, 'An enumble is not defined for this record!' if @enumble.nil?

@enumble
end

# The enumble label if it exists.
# @return [String]
def to_s
enumble = self.class.find_enumble(id)
return enumble.label if enumble.present?

super
end

# These ClassMethods can be included in any model that you wish to
# _Enumble_!
#
Expand Down
2 changes: 1 addition & 1 deletion lib/enumbler/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Enumbler
VERSION = '0.6.4'
VERSION = '0.6.5'
end
4 changes: 4 additions & 0 deletions spec/enumbler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class ModelWithoutTable < ApplicationRecord
expect { Color.infinity(:oh_my) }.to raise_error(Enumbler::Error, /not supported/)
end

it 'uses the label for #to_s', :seed do
expect(Color.black.to_s).to eq 'black'
end

context 'when the table for the model does not yet exist' do
it 'does not raise any errors' do
expect(ModelWithoutTable).to receive(:warn).with(/pending migration/)
Expand Down

0 comments on commit 1b81de3

Please sign in to comment.