Skip to content

Commit

Permalink
Merge pull request #1713 from simonc/1713-model-plural-label-with-num…
Browse files Browse the repository at this point in the history
…eric

Model plural label should be called with a Numeric, not a String
  • Loading branch information
mshibuya committed Aug 22, 2013
2 parents 50ad6bd + 3cddf38 commit 0be9e22
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def object_label
end

register_instance_option :label_plural do
(@label_plural ||= {})[::I18n.locale] ||= abstract_model.model.model_name.human(:count => 'other', :default => label.pluralize)
(@label_plural ||= {})[::I18n.locale] ||= abstract_model.model.model_name.human(:count => Float::INFINITY, :default => label.pluralize)
end

def pluralize(count)
Expand Down
46 changes: 46 additions & 0 deletions spec/rails_admin/config/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,52 @@
it "is pretty" do
expect(RailsAdmin.config(Comment).label_plural).to eq('Comments')
end

context "when using i18n as label source", skip_mongoid: true do
around do |example|
I18n.backend.class.send(:include, I18n::Backend::Pluralization)
I18n.backend.store_translations :xx, {
activerecord: {
models: {
comment: {
one: 'one', two: 'two', other: 'other'
}
}
}
}
I18n.locale = :xx

example.run

I18n.locale = :en
end

context "and the locale uses a specific pluralization rule" do
before do
I18n.backend.store_translations :xx, {
i18n: {
plural: {
rule: ->(count) {
if count == 0
:zero
elsif count == 1
:one
elsif count == 2
:two
else
:other
end
}
}
},
}
end

it "always uses :other as pluralization key" do
expect(RailsAdmin.config(Comment).label_plural).to eq('other')
end
end
end
end

describe "#weight" do
Expand Down

0 comments on commit 0be9e22

Please sign in to comment.