64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.5 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(I18n.t("nav.users"))
 | |
|     end
 | |
| 
 | |
|     it "should not be able to see the user list" do
 | |
|       visit users_path
 | |
| 
 | |
|       expect(page).not_to have_content(I18n.t("users.index.title"))
 | |
|     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(I18n.t("contests.new.title"))
 | |
|     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(I18n.t("contests.show.title", name: contest.name))
 | |
|     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(I18n.t("nav.users"))
 | |
|     end
 | |
| 
 | |
|     it "should be able to see the user list" do
 | |
|       visit users_path
 | |
| 
 | |
|       expect(page).to have_content(I18n.t("users.index.title"))
 | |
|       expect(page).to have_content(user.username)
 | |
|     end
 | |
|   end
 | |
| end
 |