Files
nairobi/spec/features/admin/moderators_spec.rb
Javi Martín 307cf24846 Use describe on feature tests
The `type: :feature` is automatically detected by RSpec because these
tests are inside the `spec/features` folder. Using `feature` re-adds a
`type: :feature` to these files, which will result in a conflict when we
upgrade to Rails 5.1's system tests.

Because of this change, we also need to change `background` to `before`
or else these tests will fail.
2019-05-28 16:36:54 +02:00

86 lines
2.4 KiB
Ruby

require "rails_helper"
describe "Admin moderators" do
before do
@admin = create(:administrator)
@user = create(:user, username: "Jose Luis Balbin")
@moderator = create(:moderator)
login_as(@admin.user)
visit admin_moderators_path
end
scenario "Index" do
expect(page).to have_content @moderator.name
expect(page).to have_content @moderator.email
expect(page).not_to have_content @user.name
end
scenario "Create Moderator", :js do
fill_in "name_or_email", with: @user.email
click_button "Search"
expect(page).to have_content @user.name
click_link "Add"
within("#moderators") do
expect(page).to have_content @user.name
end
end
scenario "Delete Moderator" do
click_link "Delete"
within("#moderators") do
expect(page).not_to have_content @moderator.name
end
end
context "Search" do
before do
user = create(:user, username: "Elizabeth Bathory", email: "elizabeth@bathory.com")
user2 = create(:user, username: "Ada Lovelace", email: "ada@lovelace.com")
@moderator1 = create(:moderator, user: user)
@moderator2 = create(:moderator, user: user2)
visit admin_moderators_path
end
scenario "returns no results if search term is empty" do
expect(page).to have_content(@moderator1.name)
expect(page).to have_content(@moderator2.name)
fill_in "name_or_email", with: " "
click_button "Search"
expect(page).to have_content("Moderators: User search")
expect(page).to have_content("No results found")
expect(page).not_to have_content(@moderator1.name)
expect(page).not_to have_content(@moderator2.name)
end
scenario "search by name" do
expect(page).to have_content(@moderator1.name)
expect(page).to have_content(@moderator2.name)
fill_in "name_or_email", with: "Eliz"
click_button "Search"
expect(page).to have_content("Moderators: User search")
expect(page).to have_content(@moderator1.name)
expect(page).not_to have_content(@moderator2.name)
end
scenario "search by email" do
expect(page).to have_content(@moderator1.email)
expect(page).to have_content(@moderator2.email)
fill_in "name_or_email", with: @moderator2.email
click_button "Search"
expect(page).to have_content("Moderators: User search")
expect(page).to have_content(@moderator2.email)
expect(page).not_to have_content(@moderator1.email)
end
end
end