Merge pull request #3768 from consul/errors_count
Don't count errors for the same field twice
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
</button>
|
||||
|
||||
<strong>
|
||||
<%= pluralize resource.errors.count, t("form.error"), t("form.errors") %>
|
||||
<% errors_count = resource.errors.messages.reject { |attribute| attribute == :base }.count %>
|
||||
|
||||
<%= pluralize errors_count, t("form.error"), t("form.errors") %>
|
||||
|
||||
<% if local_assigns[:message].present? %>
|
||||
<%= message %>
|
||||
|
||||
@@ -63,7 +63,8 @@ describe "Admin dashboard actions" do
|
||||
|
||||
scenario "Renders create form in case data is invalid" do
|
||||
click_button "Save"
|
||||
expect(page).to have_content("errors prevented this Dashboard/Action from being saved.")
|
||||
|
||||
expect(page).to have_content("error prevented this Dashboard/Action from being saved.")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
40
spec/views/shared/errors_spec.rb
Normal file
40
spec/views/shared/errors_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "shared errors" do
|
||||
class DummyModel
|
||||
include ActiveModel::Model
|
||||
attr_accessor :title, :description, :days
|
||||
|
||||
validates :title, presence: true
|
||||
validates :description, presence: true, length: { in: 10..100 }
|
||||
validates :days, numericality: { greater_than: 10 }
|
||||
end
|
||||
|
||||
it "counts the number of fields with errors" do
|
||||
resource = DummyModel.new(title: "Present", description: "", days: 3)
|
||||
resource.valid?
|
||||
|
||||
render "shared/errors", resource: resource
|
||||
|
||||
expect(rendered).to have_content "2 errors"
|
||||
end
|
||||
|
||||
it "doesn't include `base` errors in new records" do
|
||||
resource = build(:debate, title: "", description: "")
|
||||
resource.valid?
|
||||
|
||||
render "shared/errors", resource: resource
|
||||
|
||||
expect(rendered).to have_content "2 errors"
|
||||
end
|
||||
|
||||
it "doesn't include `base` errors in existing records" do
|
||||
resource = create(:debate)
|
||||
resource.translations << Debate::Translation.new(title: "Title", description: "", locale: "es")
|
||||
resource.valid?
|
||||
|
||||
render "shared/errors", resource: resource
|
||||
|
||||
expect(rendered).to have_content "1 error"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user