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

Refactor plantings to html5 date control #3897

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/planting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def nearby_same_crop
def finished_must_be_after_planted
return unless planted_at && finished_at # only check if we have both

errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
errors.add(:finished_at, "must be after the planting date (#{finished_at}) < #{planted_at}") unless planted_at < finished_at
end

def owner_must_match_garden_owner
Expand Down
10 changes: 4 additions & 6 deletions app/views/plantings/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
label: 'Where did you plant it?')
= link_to "Add a garden.", new_garden_path
.col-md-4
= f.text_field :planted_at,
= f.date_field :planted_at,
value: @planting.planted_at ? @planting.planted_at.to_fs(:ymd) : '',
class: 'add-datepicker', label: 'When?'
label: 'When?'
%span.help-inline
Tip: Plan our your future plantings by forward dating, and subscribe to your iCalendar feed for reminders to plant

Expand All @@ -52,11 +52,9 @@
= f.check_box :finished, label: 'Mark as finished'
%span.help-block= t('.finish_helper')
.col-md-6
= f.text_field :finished_at,
= f.date_field :finished_at,
value: @planting.finished_at ? @planting.finished_at.to_fs(:ymd) : '',
class: 'add-datepicker',
label: 'Finished date',
placeholder: 'optional'
label: 'Finished date'

.card-footer
.text-right= f.submit 'Save'
10 changes: 5 additions & 5 deletions spec/features/plantings/planting_a_crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
select "semi-shade", from: "Sun or shade?"
fill_in "Tell us more about it", with: "It's rad."
choose 'Garden'
fill_in "When", with: "2014-06-15"
fill_in "When", with: Date.parse("2014-06-15")
click_button "Save"
end
end
Expand Down Expand Up @@ -185,7 +185,7 @@
click_link 'Actions'
click_link "Edit"
check "finished"
fill_in "Finished date", with: "2015-06-25"
fill_in "Finished date", with: Date.parse("2015-06-25")
click_button "Save"
expect(page).to have_content "planting was successfully updated"
expect(page).to have_content "Finished"
Expand All @@ -196,9 +196,9 @@
select_from_autocomplete "maize"
choose(member.gardens.first.name)
within "form#new_planting" do
fill_in "When?", with: "2014-07-01"
fill_in "When?", with: Date.parse("2014-07-01")
check "Mark as finished"
fill_in "Finished date", with: "2014-08-30"
fill_in "Finished date", with: Date.parse("2014-08-30")
uncheck 'Mark as finished'
end

Expand Down Expand Up @@ -253,7 +253,7 @@
fill_autocomplete "crop", with: "mai"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When", with: "2015-10-15"
fill_in "When", with: Date.parse("2015-10-15")
fill_in "How many?", with: 42
select "cutting", from: "Planted from"
select "sun", from: "Sun or shade?"
Expand Down
2 changes: 1 addition & 1 deletion spec/views/plantings/_form.html.haml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
end

it "has a free-form text field containing the planting date in ISO format" do
assert_select "input#planting_planted_at[type='text'][value='2013-03-01']"
assert_select "input#planting_planted_at[type='date'][value='2013-03-01']"
end
end
Loading