From 5cf14ad536a5a9b9ec8b6f2e0906b7dac2560e82 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 13 Oct 2024 13:36:15 +0000 Subject: [PATCH 01/15] Refactor planted at --- app/views/plantings/_form.html.haml | 10 ++++------ spec/features/plantings/planting_a_crop_spec.rb | 16 ++++++++-------- spec/views/plantings/_form.html.haml_spec.rb | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/views/plantings/_form.html.haml b/app/views/plantings/_form.html.haml index fbc94c54db..f2476e629d 100644 --- a/app/views/plantings/_form.html.haml +++ b/app/views/plantings/_form.html.haml @@ -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 @@ -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' diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 68032bb438..69a0b06b05 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -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) click_button "Save" end end @@ -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 + @right_now = Time.zone.today + @a_future_date = 1.year.from_now end it "shows that it is not planted yet" do @@ -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) click_button "Save" expect(page).to have_content "planting was successfully updated" expect(page).to have_content "Finished" @@ -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) check "Mark as finished" - fill_in "Finished date", with: "2014-08-30" + fill_in "Finished date", with: Time.new(2014, 8, 30) uncheck 'Mark as finished' end @@ -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) fill_in "How many?", with: 42 select "cutting", from: "Planted from" select "sun", from: "Sun or shade?" diff --git a/spec/views/plantings/_form.html.haml_spec.rb b/spec/views/plantings/_form.html.haml_spec.rb index 0dc7a5a1a8..8634b19e19 100644 --- a/spec/views/plantings/_form.html.haml_spec.rb +++ b/spec/views/plantings/_form.html.haml_spec.rb @@ -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 From a04cbf3b2a4426df732e7c96c5e854c0be9e7c7a Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:23:13 +1030 Subject: [PATCH 02/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 69a0b06b05..a3a7aecb00 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -62,7 +62,7 @@ before do visit new_planting_path - @a_past_date = 15.days.ago + @a_past_date = 15.days.ago.to_time @right_now = Time.zone.today @a_future_date = 1.year.from_now end From bce1407859e196a64da421e1bf30b37b8b73330d Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:23:34 +1030 Subject: [PATCH 03/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index a3a7aecb00..444f05b232 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -64,7 +64,7 @@ @a_past_date = 15.days.ago.to_time @right_now = Time.zone.today - @a_future_date = 1.year.from_now + @a_future_date = 1.year.from_now.to_time end it "shows that it is not planted yet" do From a689b04bfc387f7bba7831169dc78d13718589ea Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:27:34 +1030 Subject: [PATCH 04/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 444f05b232..f1c4bcd82f 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -62,7 +62,7 @@ before do visit new_planting_path - @a_past_date = 15.days.ago.to_time + @a_past_date = 15.days.ago.to_date @right_now = Time.zone.today @a_future_date = 1.year.from_now.to_time end From 64d51ec4bd63d5ea269700da98df74be5a8221ab Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:27:50 +1030 Subject: [PATCH 05/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index f1c4bcd82f..0274d94da6 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -63,7 +63,7 @@ visit new_planting_path @a_past_date = 15.days.ago.to_date - @right_now = Time.zone.today + @right_now = Time.zone.today.to_date @a_future_date = 1.year.from_now.to_time end From e4efa0bfab40aab0a4edf2de43eb94bb75c9f7b0 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:28:04 +1030 Subject: [PATCH 06/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 0274d94da6..e9b079bff2 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -64,7 +64,7 @@ @a_past_date = 15.days.ago.to_date @right_now = Time.zone.today.to_date - @a_future_date = 1.year.from_now.to_time + @a_future_date = 1.year.from_now.to_date end it "shows that it is not planted yet" do From 724d55147b5659e8019ff115d17c6aaf798155f2 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:33:58 +1030 Subject: [PATCH 07/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index e9b079bff2..0b16b7f29e 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -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: Time.new(2014, 6, 15) + fill_in "When", with: "2014-06-15" click_button "Save" end end From 0eacdf8fb883aa6de04980c619cadab9967d317e Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:35:08 +1030 Subject: [PATCH 08/15] Apply suggestions from code review --- spec/features/plantings/planting_a_crop_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 0b16b7f29e..2ac5cb7a5c 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -62,9 +62,9 @@ before do visit new_planting_path - @a_past_date = 15.days.ago.to_date - @right_now = Time.zone.today.to_date - @a_future_date = 1.year.from_now.to_date + @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") end it "shows that it is not planted yet" do From d1e6ce6c42e6ef893c76c607571fd94d576ac6bd Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:35:16 +1030 Subject: [PATCH 09/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 2ac5cb7a5c..df0598fd66 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -185,7 +185,7 @@ click_link 'Actions' click_link "Edit" check "finished" - fill_in "Finished date", with: Time.new(2015, 6, 25) + fill_in "Finished date", with: "2015-06-25" click_button "Save" expect(page).to have_content "planting was successfully updated" expect(page).to have_content "Finished" From 30ac140eb7fd41be92463241492696746b4c1930 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:36:07 +1030 Subject: [PATCH 10/15] Apply suggestions from code review --- spec/features/plantings/planting_a_crop_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index df0598fd66..b01094ee26 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -196,9 +196,9 @@ select_from_autocomplete "maize" choose(member.gardens.first.name) within "form#new_planting" do - fill_in "When?", with: Time.new(2014, 7, 1) + fill_in "When?", with: "2014-07-01" check "Mark as finished" - fill_in "Finished date", with: Time.new(2014, 8, 30) + fill_in "Finished date", with: "2014-08-30" uncheck 'Mark as finished' end From d5ad194ded71847ef5d9d70c1c49ed26f196d4f2 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 00:36:32 +1030 Subject: [PATCH 11/15] Update spec/features/plantings/planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index b01094ee26..68032bb438 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -253,7 +253,7 @@ fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do - fill_in "When", with: Time.new(2015, 10, 15) + fill_in "When", with: "2015-10-15" fill_in "How many?", with: 42 select "cutting", from: "Planted from" select "sun", from: "Sun or shade?" From 6ec5226f0b54a9df6b42bc91929bd4968fb72f85 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 08:43:45 +1030 Subject: [PATCH 12/15] Update planting.rb --- app/models/planting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index a1c469d697..35882632dc 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -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 From 37441120c279c049ac0690f485d012cb3eebfcf9 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 09:04:57 +1030 Subject: [PATCH 13/15] Update planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 68032bb438..561d48c344 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -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) click_button "Save" end end From 6c1f1a85423e9c939ab021b85e3d4fe1ef776935 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 09:05:54 +1030 Subject: [PATCH 14/15] Update planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 561d48c344..69e67fd525 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -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: Time.new(2014, 6, 15) + fill_in "When", with: Date.parse("2014-06-15") click_button "Save" end end From 4f548a8f8ecd23dcd106147a9dc61b291b3648d2 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Mon, 14 Oct 2024 09:09:40 +1030 Subject: [PATCH 15/15] Update planting_a_crop_spec.rb --- spec/features/plantings/planting_a_crop_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 69e67fd525..6dd73e2633 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -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" @@ -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 @@ -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?"