We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
62 lines
1.6 KiB
Ruby
62 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)
|
|
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
|