Permalink
Browse files

Mirroring the pluralization exceptions of Inflector to Inflecto (#233)

  • Loading branch information...
mereghost authored and jodosha committed Oct 2, 2017
1 parent 19dba1c commit b244c65dac37341bdf9ae80616d1bfb47795c52d
@@ -10,6 +10,10 @@ group :multi_json do
gem 'multi_json', '~> 1.0', require: false
end

group :inflecto do
gem 'inflecto', '~> 0.0.2', require: false
end

gem 'gson', '>= 0.6', require: false, platforms: :jruby
gem 'rubocop', '0.48.0', require: false
gem 'coveralls', require: false
@@ -313,10 +313,19 @@ def self.inflections(&blk)
# exception 'alga', 'algae'
# end
def self.exception(singular, plural)
add_to_inflecto(singular, plural)
singulars.add(plural, singular)
plurals.add(singular, plural)
end

# Since ROM uses Inflecto for it inferences, we need to add an exception to it
# when one is registered against our Inflector.
# @api private
def self.add_to_inflecto(singular, plural)
return unless defined? Inflecto
Inflecto.inflections.irregular(singular, plural)
end

# Add an uncountable word
#
# @param [Array<String>] words
@@ -0,0 +1,20 @@
require_relative __dir__ + '../../../../../support/isolation_spec_helper'
Bundler.require(:default, :development, :inflecto)
require 'hanami/utils/inflector'
require 'inflecto'

RSpec.describe Hanami::Utils::Inflector do
describe ".exception" do
context "with inflecto" do
it "registers Inflecto exception" do
# just some weird Portuguese pluralization rules
described_class.exception('poção', 'poções')

expect(Inflecto.pluralize('poção')).to eq('poções')
expect(Inflecto.singularize('poções')).to eq('poção')
end
end
end
end

RSpec::Support::Runner.run
@@ -0,0 +1,18 @@
require_relative __dir__ + '../../../../../support/isolation_spec_helper'
Bundler.require(:default, :development)
require 'hanami/utils/inflector'

RSpec.describe Hanami::Utils::Inflector do
describe ".exception" do
context "without inflecto" do
it "registers exception" do
expect { described_class.exception('receita', 'receitas') }.to_not raise_error

expect(described_class.pluralize('receita')).to eq('receitas')
expect(described_class.singularize('receitas')).to eq('receita')
end
end
end
end

RSpec::Support::Runner.run

0 comments on commit b244c65

Please sign in to comment.