Having a class named `Poll::Question::Answer` and another class named `Poll::Answer` was so confusing that no developer working on the project has ever been capable of remembering which is which for more than a few seconds. Furthermore, we're planning to add open answers to polls, and we might add a reference from the `poll_answers` table to the `poll_question_answers` table to property differentiate between open answers and closed answers. Having yet another thing named answer would be more than what our brains can handle (we know it because we did this once in a prototype). So we're renaming `Poll::Question::Answer` to `Poll::Question::Option`. Hopefully that'll make it easier to remember. The name is also (more or less) consistent with the `Legislation::QuestionOption` class, which is similar. We aren't changing the table or columns names for now in order to avoid possible issues when upgrading (old code running with the new database tables/columns after running the migrations but before deployment has finished, for instance). We might do it in the future. I've tried not to change the internationalization keys either so existing translations would still be valid. However, since we have to change the keys in `activerecord.yml` so methods like `human_attribute_name` keep working, I'm also changing them in places where similar keys were used (like `poll_question_answer` or `poll/question/answer`). Note that it isn't clear whether we should use `option` or `question_option` in some cases. In order to keep things simple, we're using `option` where we were using `answer` and `question_option` where we were using `question_answer`. Also note we're adding tests for the admin menu component, since at first I forgot to change the `answers` reference there and all tests passed.
58 lines
1.9 KiB
Ruby
58 lines
1.9 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Polls::Questions::ReadMoreComponent do
|
|
include Rails.application.routes.url_helpers
|
|
let(:poll) { create(:poll) }
|
|
let(:question) { create(:poll_question, poll: poll, title: "Question title?") }
|
|
let(:option) { create(:poll_question_option, question: question) }
|
|
|
|
it "renders question title" do
|
|
create(:poll_question_option, question: question, description: "Question option description")
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect(page).to have_content "Question title?"
|
|
end
|
|
|
|
it "renders options in the given order" do
|
|
create(:poll_question_option, title: "Answer A", question: question, given_order: 2)
|
|
create(:poll_question_option, title: "Answer B", question: question, given_order: 1)
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect("Answer B").to appear_before("Answer A")
|
|
end
|
|
|
|
it "does not render when options does not have more information" do
|
|
option.update!(description: nil)
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect(page).not_to be_rendered
|
|
end
|
|
|
|
it "renders options with videos" do
|
|
create(:poll_option_video, option: option, title: "Awesome video", url: "youtube.com/watch?v=123")
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123")
|
|
end
|
|
|
|
it "renders options with images" do
|
|
create(:image, imageable: option, title: "The yes movement")
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect(page).to have_css "img[alt='The yes movement']"
|
|
end
|
|
|
|
it "renders options with documents" do
|
|
create(:document, documentable: option, title: "The yes movement")
|
|
|
|
render_inline Polls::Questions::ReadMoreComponent.new(question: question)
|
|
|
|
expect(page).to have_link text: "The yes movement"
|
|
end
|
|
end
|