Use shared specs to flag comments

This commit is contained in:
Javi Martín
2020-03-20 19:03:57 +01:00
parent 3c27df592e
commit 014ccd8374
8 changed files with 51 additions and 376 deletions

View File

@@ -1,13 +1,22 @@
shared_examples "flaggable" do |factory_name|
let(:user) { create(:user) }
include ActionView::RecordIdentifier
let(:user) { create(:user, :level_two) }
let(:flaggable) { create(factory_name) }
let(:path) { polymorphic_path(flaggable) }
let(:path) do
if flaggable.is_a?(Comment)
polymorphic_path(flaggable.commentable)
else
polymorphic_path(flaggable)
end
end
scenario "Flagging as inappropriate", :js do
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
@@ -24,7 +33,7 @@ shared_examples "flaggable" do |factory_name|
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_css ".flag-active"
find(".icon-flag").click
@@ -41,7 +50,7 @@ shared_examples "flaggable" do |factory_name|
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
@@ -56,4 +65,24 @@ shared_examples "flaggable" do |factory_name|
expect(Flag.flagged?(user, flaggable)).not_to be
end
scenario "Flagging a comment with a child does not update its children", :js do
skip "Only for comments" unless flaggable.is_a?(Comment)
child_comment = create(:comment, commentable: flaggable.commentable, parent: flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} > .comment-body .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
expect(page).to have_css ".flag-active"
end
within "##{dom_id(child_comment)} .flag-content" do
expect(page).not_to have_css ".flag-active"
end
end
end