access_spec.rb revision 68ff70f830e958de6693000b9652c9aa8cff97e7
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksarequire 'spec_helper'
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksadescribe 'Repository Access' do
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa context 'fetching repositories' do
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let(:user) { create :user }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:repository_pub_r) { create :repository, user: user,
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa access: 'public_r' }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:repository_pub_rw) { create :repository, user: user,
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa access: 'public_rw' }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:repository_priv_r) { create :repository, user: user,
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa access: 'private_r' }
7c7a19761235efff584ee65a1c6dc4aa1735ff64Eugen Kuksa let!(:repository_priv_rw) { create :repository, user: user,
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa access: 'private_rw' }
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa %w(_r _rw).each do |access_modifier|
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa it "should fetch the public#{access_modifier} repository" do
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa expect(Repository.pub.map(&:access).
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa include?("public#{access_modifier}")).to be_truthy
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa end
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa it "should not fetch the private#{access_modifier} repository" do
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa expect(Repository.pub.map(&:access).
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa include?("private#{access_modifier}")).to be_falsy
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa end
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa end
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'private repository' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa let(:repository) { create :repository, access: 'private_rw' }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'without access token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should not have a token yet' do
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa expect(repository.access_token).to be_empty
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa context 'after generate_access_token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa before do
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa @access_token = repository.generate_access_token
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should generate a token' do
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa expect(repository.access_token).not_to be_empty
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should associate with the generated token' do
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa expect(repository.access_token.first).to eq(@access_token)
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should save the token' do
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa expect(repository.access_token.first.persisted?).to be_truthy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksaend