Files
nairobi/spec/features/admin/poll/questions/answers/answers_spec.rb
Javi Martín d0d1c9972c Remove unused variables following their parent
There's a very common pattern in our test, where the setup only has two
lines:

variable = create(:something)
unused_variable = create(:something_else, something: variable)

In this case, since there's a blank line below these ones and then we'll
get to the body of the test, and the second variable is going to be
created based on the first variable, we can remove the useless
assignment and the readability is still OK.

Another option we almost unanimously discarded was:

variable = create(:something)
_unused_variable = create(:something_else, something: variable)

We don't use it anywhere else, either.

One more option we considered but found a bit too much for simple tests:

variable = create(:something) do |something|
  create(:something_else, something: variable)
end

Then of course we could move the setup to `let` and `before` blocks, but
the tests could get over-structured really quickly.
2019-09-30 15:47:13 +02:00

64 lines
1.6 KiB
Ruby

require "rails_helper"
describe "Answers" do
before do
admin = create(:administrator)
login_as admin.user
end
scenario "Create" do
question = create(:poll_question)
visit admin_question_path(question)
click_link "Add answer"
fill_in "Answer", with: "The answer is always 42"
fill_in "Description", with: "The Hitchhiker's Guide To The Universe"
click_button "Save"
expect(page).to have_content "The answer is always 42"
expect(page).to have_content "The Hitchhiker's Guide To The Universe"
end
scenario "Create second answer and place after the first one" do
question = create(:poll_question)
create(:poll_question_answer, title: "First", question: question, given_order: 1)
visit admin_question_path(question)
click_link "Add answer"
fill_in "Answer", with: "Second"
fill_in "Description", with: "Description"
click_button "Save"
expect("First").to appear_before("Second")
end
scenario "Update" do
question = create(:poll_question)
answer = create(:poll_question_answer, question: question, title: "Answer title", given_order: 2)
answer2 = create(:poll_question_answer, question: question, title: "Another title", given_order: 1)
visit admin_answer_path(answer)
click_link "Edit answer"
fill_in "Answer", with: "New title"
click_button "Save"
expect(page).to have_content "Changes saved"
expect(page).to have_content "New title"
visit admin_question_path(question)
expect(page).not_to have_content "Answer title"
expect("Another title").to appear_before("New title")
end
end