Skip to content

Commit

Permalink
Singularize field name in HasMany index partial (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbroadley authored and nickcharlton committed Jan 16, 2018
1 parent 7c0dbdc commit f2dce70
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/fields/has_many/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ as a count of how many objects are associated through the relationship.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/HasMany
%>

<%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase) %>
<%= pluralize(field.data.size, field.attribute.to_s.humanize.downcase.singularize) %>
57 changes: 57 additions & 0 deletions spec/administrate/views/fields/has_many/_index_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require "rails_helper"

describe "fields/has_many/_index", type: :view do
context "without any associated records" do
it "displays the pluralized attribute name" do
has_many = double(
data: double(
size: 0,
),
attribute: :teams,
)

render(
partial: "fields/has_many/index.html.erb",
locals: { field: has_many },
)

expect(rendered.strip).to eq("0 teams")
end
end

context "with one associated record" do
it "displays the singularized attribute name" do
has_many = double(
data: double(
size: 1,
),
attribute: :teams,
)

render(
partial: "fields/has_many/index.html.erb",
locals: { field: has_many },
)

expect(rendered.strip).to eq("1 team")
end
end

context "with two associated records" do
it "displays the pluralized attribute name" do
has_many = double(
data: double(
size: 2,
),
attribute: :teams,
)

render(
partial: "fields/has_many/index.html.erb",
locals: { field: has_many },
)

expect(rendered.strip).to eq("2 teams")
end
end
end

0 comments on commit f2dce70

Please sign in to comment.