Files
nairobi/spec/features/admin/debates_spec.rb
Javi Martín da121ebc53 Remove redundant setting resets in after blocks
Settings are stored in the database, and so any changes to the settings
done during the tests are automatically rolled back between one test and
the next one.

There were also a few places where we weren't using an `after` block but
changing the setting at the end of the test.
2019-09-23 13:47:45 +02:00

103 lines
3.0 KiB
Ruby

require "rails_helper"
describe "Admin debates" do
scenario "Disabled with a feature flag" do
Setting["process.debates"] = nil
admin = create(:administrator)
login_as(admin.user)
expect { visit admin_hidden_debates_path }.to raise_exception(FeatureFlags::FeatureDisabled)
end
before do
admin = create(:administrator)
login_as(admin.user)
end
scenario "Show debate" do
debate = create(:debate)
visit admin_debate_path(debate)
expect(page).to have_content(debate.title)
expect(page).to have_content(debate.description)
end
scenario "Restore" do
debate = create(:debate, :hidden)
visit admin_hidden_debates_path
click_link "Restore"
expect(page).not_to have_content(debate.title)
expect(debate.reload).not_to be_hidden
expect(debate).to be_ignored_flag
end
scenario "Confirm hide" do
debate = create(:debate, :hidden)
visit admin_hidden_debates_path
click_link "Confirm moderation"
expect(page).not_to have_content(debate.title)
click_link("Confirmed")
expect(page).to have_content(debate.title)
expect(debate.reload).to be_confirmed_hide
end
scenario "Current filter is properly highlighted" do
visit admin_hidden_debates_path
expect(page).not_to have_link("Pending")
expect(page).to have_link("All")
expect(page).to have_link("Confirmed")
visit admin_hidden_debates_path(filter: "Pending")
expect(page).not_to have_link("Pending")
expect(page).to have_link("All")
expect(page).to have_link("Confirmed")
visit admin_hidden_debates_path(filter: "all")
expect(page).to have_link("Pending")
expect(page).not_to have_link("All")
expect(page).to have_link("Confirmed")
visit admin_hidden_debates_path(filter: "with_confirmed_hide")
expect(page).to have_link("All")
expect(page).to have_link("Pending")
expect(page).not_to have_link("Confirmed")
end
scenario "Filtering debates" do
create(:debate, :hidden, title: "Unconfirmed debate")
create(:debate, :hidden, :with_confirmed_hide, title: "Confirmed debate")
visit admin_hidden_debates_path(filter: "pending")
expect(page).to have_content("Unconfirmed debate")
expect(page).not_to have_content("Confirmed debate")
visit admin_hidden_debates_path(filter: "all")
expect(page).to have_content("Unconfirmed debate")
expect(page).to have_content("Confirmed debate")
visit admin_hidden_debates_path(filter: "with_confirmed_hide")
expect(page).not_to have_content("Unconfirmed debate")
expect(page).to have_content("Confirmed debate")
end
scenario "Action links remember the pagination setting and the filter" do
per_page = Kaminari.config.default_per_page
(per_page + 2).times { create(:debate, :hidden, :with_confirmed_hide) }
visit admin_hidden_debates_path(filter: "with_confirmed_hide", page: 2)
click_on("Restore", match: :first, exact: true)
expect(current_url).to include("filter=with_confirmed_hide")
expect(current_url).to include("page=2")
end
end