This method is ambiguous. Sometimes we use it to set invalid data in tests (which can usually be done with `update_column`), and other times we use it instead of `update!`. I'm removing it because, even if sometimes it could make sense to use it, it's too similar to `update_attributes` (which is an alias for `update` and runs validations), making it confusing. However, there's one case where we're still using it: in the ActsAsParanoidAliases module, we need to invoke the callbacks, which `update_column` skips, but tests related to translations fail if we use `update!`. The reason for this is the tests check what happens if we restore a record without restoring its translations. But that will make the record invalid, since there's a validation rule checking it has at least one translation. I'm not blacklisting any other method which skips validations because we know they skip validations and use them anyway (hopefully with care).
116 lines
3.9 KiB
Ruby
116 lines
3.9 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Legislation" do
|
|
context "process debate page" do
|
|
let(:process) do
|
|
create(:legislation_process,
|
|
debate_start_date: Date.current - 3.days,
|
|
debate_end_date: Date.current + 2.days)
|
|
end
|
|
|
|
before do
|
|
create(:legislation_question, process: process, title: "Question 1")
|
|
create(:legislation_question, process: process, title: "Question 2")
|
|
create(:legislation_question, process: process, title: "Question 3")
|
|
end
|
|
|
|
scenario "shows question list" do
|
|
visit legislation_process_path(process)
|
|
|
|
expect(page).to have_content("Participate in the debate")
|
|
|
|
expect(page).to have_content("Question 1")
|
|
expect(page).to have_content("Question 2")
|
|
expect(page).to have_content("Question 3")
|
|
|
|
click_link "Question 1"
|
|
|
|
expect(page).to have_content("Question 1")
|
|
expect(page).to have_content("Next question")
|
|
|
|
click_link "Next question"
|
|
|
|
expect(page).to have_content("Question 2")
|
|
expect(page).to have_content("Next question")
|
|
|
|
click_link "Next question"
|
|
|
|
expect(page).to have_content("Question 3")
|
|
expect(page).not_to have_content("Next question")
|
|
end
|
|
|
|
scenario "shows question page" do
|
|
visit legislation_process_question_path(process, process.questions.first)
|
|
|
|
expect(page).to have_content("Question 1")
|
|
expect(page).to have_content("Open answers (0)")
|
|
end
|
|
|
|
scenario "shows next question link in question page" do
|
|
visit legislation_process_question_path(process, process.questions.first)
|
|
|
|
expect(page).to have_content("Question 1")
|
|
expect(page).to have_content("Next question")
|
|
|
|
click_link "Next question"
|
|
|
|
expect(page).to have_content("Question 2")
|
|
expect(page).to have_content("Next question")
|
|
|
|
click_link "Next question"
|
|
|
|
expect(page).to have_content("Question 3")
|
|
expect(page).not_to have_content("Next question")
|
|
end
|
|
|
|
scenario "answer question" do
|
|
question = process.questions.first
|
|
create(:legislation_question_option, question: question, value: "Yes")
|
|
create(:legislation_question_option, question: question, value: "No")
|
|
option = create(:legislation_question_option, question: question, value: "I don't know")
|
|
user = create(:user, :level_two)
|
|
|
|
login_as(user)
|
|
|
|
visit legislation_process_question_path(process, question)
|
|
|
|
expect(page).to have_selector(:radio_button, "Yes")
|
|
expect(page).to have_selector(:radio_button, "No")
|
|
expect(page).to have_selector(:radio_button, "I don't know")
|
|
expect(page).to have_selector(:link_or_button, "Submit answer")
|
|
|
|
choose("I don't know")
|
|
click_button "Submit answer"
|
|
|
|
within(:css, "label.is-active") do
|
|
expect(page).to have_content("I don't know")
|
|
expect(page).not_to have_content("Yes")
|
|
expect(page).not_to have_content("No")
|
|
end
|
|
expect(page).not_to have_selector(:link_or_button, "Submit answer")
|
|
|
|
expect(question.reload.answers_count).to eq(1)
|
|
expect(option.reload.answers_count).to eq(1)
|
|
end
|
|
|
|
scenario "cannot answer question when phase not open" do
|
|
process.update!(debate_end_date: Date.current - 1.day)
|
|
question = process.questions.first
|
|
create(:legislation_question_option, question: question, value: "Yes")
|
|
create(:legislation_question_option, question: question, value: "No")
|
|
create(:legislation_question_option, question: question, value: "I don't know")
|
|
user = create(:user, :level_two)
|
|
|
|
login_as(user)
|
|
|
|
visit legislation_process_question_path(process, question)
|
|
|
|
expect(page).to have_selector(:radio_button, "Yes", disabled: true)
|
|
expect(page).to have_selector(:radio_button, "No", disabled: true)
|
|
expect(page).to have_selector(:radio_button, "I don't know", disabled: true)
|
|
|
|
expect(page).not_to have_selector(:link_or_button, "Submit answer")
|
|
end
|
|
end
|
|
end
|