We were already saving it as a time, but we didn't offer an interface to select the time due to lack of decent browser support for this field back when this feature was added. However, nowadays all major browsers support this field type and, at the time of writing, at least 86.5% of the browsers support it [1]. This percentage could be much higher, since support in 11.25% of the browsers is unknown. Note we still need to support the case where this field isn't supported, and so we offer a fallback and on the server side we don't assume we're always getting a time. We're doing a strange hack so we set the field type to text before changing its value; otherwise old Firefox browsers crashed. Also note that, until now, we were storing end dates in the database as a date with 00:00 as its time, but we were considering the poll to be open until 23:59 that day. So, in order to keep backwards compatibility, we're adding a task to update the dates of existing polls so we get the same behavior we had until now. This also means budget polls are now created so they end at the beginning of the day when the balloting phase ends. This is consistent with the dates we display in the budget phases table. Finally, there's one test where we're using `beginning_of_minute` when creating a poll. That's because Chrome provides an interface to enter a time in a `%H:%M` format when the "seconds" value of the provided time is zero. However, when the "seconds" value isn't zero, Chrome provides an interface to enter a time in a `%H:%M:%S` format. Since Capybara doesn't enter the seconds when using `fill_in` with a time, the test failed when Capybara tried to enter a time in the `%H:%M` format when Chrome expected a time in the `%H:%M:%S` format. To solve this last point, an alternative would be to manually provide the format when using `fill_in` so it includes the seconds. [1] https://caniuse.com/mdn-html_elements_input_type_datetime-local
50 lines
1.6 KiB
Ruby
50 lines
1.6 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Admin Budgets", :admin do
|
|
context "Index" do
|
|
scenario "Create poll if the budget does not have a poll associated" do
|
|
budget = create(:budget)
|
|
balloting_phase = budget.phases.balloting
|
|
|
|
visit admin_budget_path(budget)
|
|
|
|
accept_confirm { click_button "Create booths" }
|
|
|
|
expect(page).to have_current_path(/admin\/polls\/\d+/)
|
|
expect(page).to have_content(budget.name)
|
|
expect(page).to have_content("#{balloting_phase.starts_at.to_date} 00:00")
|
|
expect(page).to have_content("#{balloting_phase.ends_at.to_date - 1.day} 23:59")
|
|
end
|
|
|
|
scenario "Create poll in current locale if the budget does not have a poll associated" do
|
|
budget = create(:budget,
|
|
name_en: "Budget for climate change",
|
|
name_es: "Presupuesto por el cambio climático")
|
|
|
|
visit admin_budget_path(budget)
|
|
select "Español", from: "Language:"
|
|
|
|
accept_confirm { click_button "Crear urnas" }
|
|
|
|
expect(page).to have_current_path(/admin\/polls\/\d+/)
|
|
expect(page).to have_content "Presupuesto por el cambio climático"
|
|
end
|
|
end
|
|
|
|
context "Show" do
|
|
scenario "Do not show questions section if the budget have a poll associated" do
|
|
poll = create(:poll, :for_budget)
|
|
|
|
visit admin_poll_path(poll)
|
|
|
|
within "#poll-resources" do
|
|
expect(page).not_to have_content("Questions")
|
|
expect(page).to have_content("Booths")
|
|
expect(page).to have_content("Officers")
|
|
expect(page).to have_content("Recounting")
|
|
expect(page).to have_content("Results")
|
|
end
|
|
end
|
|
end
|
|
end
|