sto 26b8064553
All checks were successful
CI / scan_ruby (push) Successful in 15s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 35s
Add login & user tests
2025-03-27 10:26:03 +01:00

64 lines
1.4 KiB
Ruby

require 'rails_helper'
RSpec.feature "Users", type: :feature do
context "when the user is a regular user" do
let!(:user) { create(:user) }
let!(:contest) { create(:contest, user: user) }
before do
login(user)
end
it "should not see a link to all users" do
visit root_path
expect(page).not_to have_content("Users")
end
it "should not be able to see the user list" do
visit users_path
expect(page).not_to have_content("All users")
end
it "should be able to create a new contest" do
visit root_path
click_link "Create a new contest"
expect(page).to have_content("New jigsaw puzzle competition")
end
it "should be able to open an existing contest" do
visit root_path
expect(page).to have_content(contest.name)
find("div.card", text: contest.name).find("a").click()
expect(page).to have_content("Edit contest")
end
end
context "when the user is an admin" do
let!(:admin) { create(:user, :admin) }
let!(:user) { create(:user) }
before do
login(admin)
end
it "should see a link to all users" do
visit root_path
expect(page).to have_content("Users")
end
it "should be able to see the user list" do
visit users_path
expect(page).to have_content("All users")
expect(page).to have_content(user.username)
end
end
end