Skip to content

Commit

Permalink
202 1.20 fix date range errors. Fixes #202 (#221)
Browse files Browse the repository at this point in the history
* Failing test

* Don't show duplicate errors on multiple date ranges, highlight on error

* Make the test just a little more pretty
  • Loading branch information
tom95 authored and bjrne committed Dec 16, 2016
1 parent 60a5e05 commit ebba074
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/event.rb
Expand Up @@ -167,7 +167,7 @@ def date_ranges_attributes=(*args)
event.date_ranges.each do |date_range|
next if date_range.valid?
date_range.errors.full_messages.each do |msg|
errors.add :date_ranges, msg
errors.add :date_ranges, msg unless errors[:date_ranges].include? msg
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_form.html.erb
Expand Up @@ -37,7 +37,7 @@
</div>
<div class="form-group">
<%= f.label :date_ranges, :class => 'control-label col-lg-2' %>
<div class="col-lg-10" id="event-date-pickers">
<div class="col-lg-10 <%= 'has-error' unless @event.errors.messages[:date_ranges].empty? %>" id="event-date-pickers">
<% def date_picker_template(start_date = Date.current, end_date = Date.current)
start_picker = text_field_tag "event[date_ranges_attributes][][start_date]", (I18n.l start_date),
class: 'form-control', :"data-enable-datepicker" => 'true'
Expand Down
23 changes: 23 additions & 0 deletions spec/features/event_spec.rb
Expand Up @@ -97,6 +97,29 @@

expect(page).to have_text("Bewerbungsschluss muss vor Beginn der Veranstaltung liegen")
end

it "should not display errors on date ranges twice", js: true do
visit new_event_path

fill_in "Maximale Teilnehmerzahl", :with => 25

within page.find("#event-date-pickers").all("div")[0] do
fill_in "event[date_ranges_attributes][][start_date]", with: I18n.l(Date.current.prev_day(7))
fill_in "event[date_ranges_attributes][][end_date]", with: I18n.l(Date.yesterday.prev_day(7))
end

click_link "Zeitspanne hinzufügen"

within page.find("#event-date-pickers").all("div")[1] do
fill_in "event[date_ranges_attributes][][start_date]", with: I18n.l(Date.current)
fill_in "event[date_ranges_attributes][][end_date]", with: I18n.l(Date.yesterday)
end

click_button I18n.t(".events.form.publish")

expect(page).to have_css("div.has-error")
expect(page).to have_content("kann nicht vor Start-Datum liegen", count: 1)
end
end

describe "show page" do
Expand Down

0 comments on commit ebba074

Please sign in to comment.