diff --git a/app/assets/javascripts/append_date.js.coffee b/app/assets/javascripts/append_date.js.coffee index cf54f4654..8fc31de9d 100644 --- a/app/assets/javascripts/append_date.js.coffee +++ b/app/assets/javascripts/append_date.js.coffee @@ -8,12 +8,28 @@ jQuery -> el.datepicker({'format': 'yyyy-mm-dd'}) + href = el.attr('href') + + originalText = el.text() + el.click (e) -> e.stopPropagation() e.preventDefault() + $(this).text('Confirm without date') + + $(this).bind('click.confirm', (e) -> + link = $("") + $('body').append(link) + $(link).click() + ) + + $(this).blur (e) -> + $(this).text(originalText) + $(this).unbind('click.confirm') + + el.one 'changeDate', -> - href = $(this).attr('href') date = $(this).datepicker('getDate') url = "#{href}&planting[finished_at]=#{date}" diff --git a/spec/features/shared_examples/append_date_spec.rb b/spec/features/shared_examples/append_date_spec.rb index bf4a297b1..089680ff9 100644 --- a/spec/features/shared_examples/append_date_spec.rb +++ b/spec/features/shared_examples/append_date_spec.rb @@ -1,6 +1,6 @@ shared_examples "append date" do - scenario "Displaying a datepicker" do + scenario "Selecting a date with datepicker" do this_month = Date.today.strftime("%B") this_year = Date.today.strftime("%Y") visit path @@ -12,4 +12,11 @@ shared_examples "append date" do expect(page).to have_content "Finished: #{this_month} 21, #{this_year}" end + scenario "Confirming without selecting date" do + visit path + click_link link_text + click_link "Confirm without date" + expect(page).to have_content("Finished: Yes (no date specified) ") + end + end \ No newline at end of file