Files
nairobi/spec/shared/system/flaggable.rb
Javi Martín e49c32638d Use if instead of skip to skip tests
This way the tests won't appear as "pending" when running the test
suite, and so we get rid of a lot of noise in the test results. There
doesn't seem to be a way to call `skip` without the test being marked as
"pending".

Note that in the globalizable tests we need to build a factory before
deciding whether an atribute is required or not (particularly for the
milestone factory, since milestone attributes are required depending on
the presence of other attributes). This isn't possible before we're
inside the test, so we can't add an `if:` condition to the test. So
we're adding the condition inside the test instead. A minor
inconvenience of this method is the test still runs even when the
condition is `false`.
2022-04-07 15:34:10 +02:00

112 lines
2.8 KiB
Ruby

shared_examples "flaggable" do |factory_name, admin: false|
include ActionView::RecordIdentifier
let(:flaggable) { create(factory_name) }
let(:user) do
if admin
create(:administrator).user
else
create(:user, :level_two)
end
end
let(:path) do
if flaggable.is_a?(Comment)
polymorphic_path(flaggable.commentable)
elsif admin
admin_polymorphic_path(flaggable)
else
polymorphic_path(flaggable)
end
end
scenario "Flagging as inappropriate" do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
expect(page).to have_link "Unflag", visible: :hidden
expect(page).not_to have_link "Flag as inappropriate", visible: :all
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Unflag", visible: :hidden
expect(page).not_to have_link "Flag as inappropriate", visible: :all
end
end
scenario "Unflagging" do
Flag.flag(user, flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_button "Unflag"
click_button "Unflag"
click_link "Unflag"
expect(page).not_to have_button "Unflag"
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
end
scenario "Flagging and unflagging" do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
click_button "Unflag"
click_link "Unflag"
expect(page).not_to have_button "Unflag"
end
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_link "Flag as inappropriate", visible: :hidden
expect(page).not_to have_link "Unflag", visible: :all
end
end
scenario "Flagging a comment with a child does not update its children", if: factory_name =~ /comment/ do
child_comment = create(:comment, commentable: flaggable.commentable, parent: flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} > .comment-body .flag-content" do
click_button "Flag as inappropriate"
click_link "Flag as inappropriate"
expect(page).to have_button "Unflag"
end
within "##{dom_id(child_comment)} .flag-content" do
expect(page).not_to have_button "Unflag"
end
end
end