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 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
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'
16 changes: 8 additions & 8 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: Time.new(2014, 6, 15)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
click_button "Save"
end
end
Expand All @@ -62,9 +62,9 @@
before do
visit new_planting_path

@a_past_date = 15.days.ago.strftime("%Y-%m-%d")
@right_now = Time.zone.today.strftime("%Y-%m-%d")
@a_future_date = 1.year.from_now.strftime("%Y-%m-%d")
@a_past_date = 15.days.ago.to_date
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
@right_now = Time.zone.today.to_date
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
@a_future_date = 1.year.from_now.to_time
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
end

it "shows that it is not planted yet" do
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: Time.new(2015, 6, 25)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
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: Time.new(2014, 7, 1)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
check "Mark as finished"
fill_in "Finished date", with: "2014-08-30"
fill_in "Finished date", with: Time.new(2014, 8, 30)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
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: Time.new(2015, 10, 15)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
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