diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index 84bdb9961..a7eb4a1b5 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -38,6 +38,10 @@ FactoryBot.define do after(:create) { |poll| create(:image, imageable: poll) } end + trait :with_author do + author factory: :user + end + transient { officers { [] } } after(:create) do |poll, evaluator| @@ -45,6 +49,8 @@ FactoryBot.define do create(:poll_officer_assignment, poll: poll, officer: officer) end end + + factory :poll_with_author, traits: [:with_author] end factory :poll_question, class: "Poll::Question" do diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 06a735d6a..c166fba2e 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -6,22 +6,6 @@ describe "Commenting Budget::Investments" do it_behaves_like "flaggable", :budget_investment_comment - scenario "Create" do - login_as(user) - visit budget_investment_path(investment.budget, investment) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#tab-comments-label" do - expect(page).to have_content "Comments (1)" - end - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - end - end - scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 6193dedf5..10f586992 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -25,19 +25,6 @@ describe "Commenting debates" do end end - scenario "Create" do - login_as(user) - visit debate_path(debate) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - expect(page).to have_content "(1)" - end - end - describe "Hide" do scenario "Without replies" do create(:comment, commentable: debate, user: user, body: "This was a mistake") diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index d128e085b..301d8feeb 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -6,19 +6,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_annotation_comment - scenario "Create" do - login_as(user) - visit polymorphic_path(annotation) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - expect(page).to have_content "(2)" - end - end - scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 2c225b283..c30706eae 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -10,19 +10,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_question_comment end - scenario "Create" do - login_as(user) - visit legislation_process_question_path(question.process, question) - - fill_in "Leave your answer", with: "Have you thought about...?" - click_button "Publish answer" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - expect(page).to have_content "(1)" - end - end - scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, :level_two, username: "Manuela") diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index 380ea0564..7e8c1e7aa 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -4,22 +4,6 @@ describe "Commenting polls" do let(:user) { create(:user) } let(:poll) { create(:poll, author: create(:user)) } - scenario "Create" do - login_as(user) - visit poll_path(poll) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - end - - within "#tab-comments-label" do - expect(page).to have_content "Comments (1)" - end - end - scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 702d295dc..47038f17b 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -6,22 +6,6 @@ describe "Commenting proposals" do it_behaves_like "flaggable", :proposal_comment - scenario "Create" do - login_as(user) - visit proposal_path(proposal) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - end - - within "#tab-comments-label" do - expect(page).to have_content "Comments (1)" - end - end - scenario "Reply" do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index 1d4ba2412..2e9900cdd 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -6,25 +6,6 @@ describe "Commenting topics from proposals" do it_behaves_like "flaggable", :topic_with_community_comment - scenario "Create" do - community = proposal.community - topic = create(:topic, community: community) - - login_as(user) - visit community_topic_path(community, topic) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - end - - within "#tab-comments-label" do - expect(page).to have_content "Comments (1)" - end - end - scenario "Reply" do community = proposal.community topic = create(:topic, community: community) @@ -353,25 +334,6 @@ describe "Commenting topics from budget investments" do let(:user) { create(:user) } let(:investment) { create(:budget_investment) } - scenario "Create" do - community = investment.community - topic = create(:topic, community: community) - - login_as(user) - visit community_topic_path(community, topic) - - fill_in "Leave your comment", with: "Have you thought about...?" - click_button "Publish comment" - - within "#comments" do - expect(page).to have_content "Have you thought about...?" - end - - within "#tab-comments-label" do - expect(page).to have_content "Comments (1)" - end - end - scenario "Reply" do community = investment.community topic = create(:topic, community: community) diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index 6097d4a81..27313cb75 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -7,7 +7,7 @@ describe "Comments" do :debate, :legislation_annotation, :legislation_question, - :poll, + :poll_with_author, :proposal, :topic_with_community, :topic_with_investment_community @@ -280,6 +280,32 @@ describe "Comments" do expect(page).to have_current_path(/#comments/, url: true) end + scenario "Create" do + login_as(user) + visit polymorphic_path(resource) + + fill_in fill_text, with: "Have you thought about...?" + click_button button_text + + if [:debate, :legislation_question].include?(factory) + within "#comments" do + expect(page).to have_content "(1)" + end + elsif factory == :legislation_annotation + within "#comments" do + expect(page).to have_content "Comments (2)" + end + else + within "#tab-comments-label" do + expect(page).to have_content "Comments (1)" + end + end + + within "#comments" do + expect(page).to have_content "Have you thought about...?" + end + end + scenario "Errors on create" do login_as(user) visit polymorphic_path(resource)