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_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
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa let(:ontology_version) { create :ontology_version }
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa let(:repository) { ontology_version.repository }
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa before do
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa repository.access = 'private_rw'
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa repository.save
745541d1ed9a97715ee21919e3dc495a1add55c0Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa context 'without access token' do
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should not have a token yet' do
4de867f5bf046eb83029341a4b6520c7cac42274Eugen Kuksa expect(repository.access_tokens).to be_empty
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
68ff70f830e958de6693000b9652c9aa8cff97e7Eugen Kuksa context 'after generate_access_token' do
fff4fdff482b9349911ce6365e9ac85b86a1fd5fEugen Kuksa let!(:access_token) { repository.generate_access_token }
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should generate a token' do
4de867f5bf046eb83029341a4b6520c7cac42274Eugen Kuksa expect(repository.access_tokens).not_to be_empty
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should associate with the generated token' do
4de867f5bf046eb83029341a4b6520c7cac42274Eugen Kuksa expect(repository.access_tokens.first).to eq(access_token)
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa it 'should save the token' do
4de867f5bf046eb83029341a4b6520c7cac42274Eugen Kuksa expect(repository.access_tokens.first.persisted?).to be_truthy
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
9dd500e3acdc343dbefcaf88b7663db25be0ef46Eugen Kuksa end
6f74297c639ecd2696280eb0db456ffad65515deEugen Kuksaend