Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failing spec for pluralizing model collection with 1 item #1359

Merged
merged 2 commits into from Oct 31, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/views/rails_admin/main/index.html.haml
Expand Up @@ -135,6 +135,6 @@
- total_count = @objects.total_count.to_i
= paginate(@objects, :theme => 'twitter-bootstrap', :remote => true)
= link_to(t("admin.misc.show_all"), index_path(params.merge(:all => true)), :class => "show-all btn clearfix pjax") unless total_count > 100 || total_count <= @objects.to_a.size
.clearfix.total-count= "#{total_count} #{@model_config.label_plural.downcase}"
.clearfix.total-count= "#{total_count} #{@model_config.pluralize(total_count).downcase}"
- else
.clearfix.total-count= "#{@objects.size} #{@model_config.label_plural.downcase}"
.clearfix.total-count= "#{@objects.size} #{@model_config.pluralize(@objects.size).downcase}"
4 changes: 4 additions & 0 deletions lib/rails_admin/config/model.rb
Expand Up @@ -63,6 +63,10 @@ def object_label
(@label_plural ||= {})[::I18n.locale] ||= abstract_model.model.model_name.human(:count => 2, :default => label.pluralize)
end

def pluralize(count)
count == 1 ? label : label_plural
end

register_instance_option :weight do
0
end
Expand Down
9 changes: 8 additions & 1 deletion spec/integration/basic/list/rails_admin_basic_list_spec.rb
Expand Up @@ -307,7 +307,14 @@
end

describe "GET /admin/player show all" do
it "responds successfully" do
it "responds successfully with a single model" do
FactoryGirl.create :player
visit index_path(:model_name => "player", :all => true)
expect(find('div.total-count')).to have_content("1 player")
expect(find('div.total-count')).not_to have_content("1 players")
end

it "responds successfully with multiple models" do
2.times.map { FactoryGirl.create :player }
visit index_path(:model_name => "player", :all => true)
expect(find('div.total-count')).to have_content("2 players")
Expand Down