Skip to content

Instantly share code, notes, and snippets.

@luxflux
Created May 14, 2013 11:15
Show Gist options
  • Save luxflux/5575214 to your computer and use it in GitHub Desktop.
Save luxflux/5575214 to your computer and use it in GitHub Desktop.
context 'role: user' do
let(:user1) { FactoryGirl.create(:user) }
let(:user2) { FactoryGirl.create(:user) }
let(:admin_user) { FactoryGirl.create(:admin) }
shared_example :ok do
it 'allows access' do
expect { visit path }.to_not raise_error(CanCan::AccessDenied)
end
end
shared_example :fail do
it 'allows access' do
expect { visit path }.to_not raise_error(CanCan::AccessDenied)
end
end
before do
login(current_user)
end
context 'time_sheet_path of user1' do
let(:path) { time_sheet_path(user.current_time_sheet) }
context 'the user itself' do
let(:current_user) { user1 }
include_examples :ok
end
context 'other user' do
let(:current_user) { user2 }
include_examples :fail
end
context 'as admin user' do
let(:current_user) { admin_user }
include_examples :ok
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment