89a126810703c666309310d0f3189e9834d70b5bTimo Sirainenrequire 'spec_helper'
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainendescribe RepositoriesController do
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen context 'deleting a repository' do
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen let(:ontology){ create :ontology }
b039dabf4c53f72454e795930e7643b6e0e625f9Timo Sirainen let(:repository){ ontology.repository }
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen let(:user){ create(:permission, role: 'owner', item: repository).subject }
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen
94e1adead9faddec88a623485b9999a87b1684faTimo Sirainen context 'signed in' do
94e1adead9faddec88a623485b9999a87b1684faTimo Sirainen before { sign_in user }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
503e5ef896c7b4a51cf73efb0d132860a8c747e6Timo Sirainen context 'successful deletion' do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen before { delete :destroy, id: repository.to_param }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it{ should respond_with :found }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it{ response.should redirect_to Repository }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen context 'unsuccessful deletion' do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen before do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen importing_repository = create :repository
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen importing = create :ontology, repository: importing_repository
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen create :import_mapping, target: importing, source: ontology
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen delete :destroy, id: repository.to_param
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen end
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen it 'sets the flash' do
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen expect(flash[:error]).to match(/is imported/)
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen end
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen it{ should respond_with :found }
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen it{ response.should redirect_to repository }
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen end
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen end
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen end
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen context 'Repository instance' do
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen render_views
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen let!(:repository) { create :repository }
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen context 'on GET to index' do
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen before { get :index }
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen it { should respond_with :success }
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen it { should render_template :index }
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen it { should render_template 'repositories/_repository' }
fc84f8af4794f4bb6caf6e5ec3fb1f8cebd0462aTimo Sirainen end
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen
91dca97b367c54a139c268b56a0c67f564bd9197Timo Sirainen context 'on GET to show' do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen context 'requesting standard representation' do
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen before { get :show, id: repository.path }
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen it { should respond_with :success }
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainen it { should render_template :show }
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen end
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainen
8a1c866a4c429f26c8746525f82024bc387f1407Timo Sirainen end
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen end
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen context 'creating a clone', :process_jobs_synchronously do
8a1c866a4c429f26c8746525f82024bc387f1407Timo Sirainen context 'signed in' do
8a1c866a4c429f26c8746525f82024bc387f1407Timo Sirainen let(:user) { create :user }
8a1c866a4c429f26c8746525f82024bc387f1407Timo Sirainen let(:git_repository) { create :git_repository }
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen before do
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen sign_in user
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen context 'mirror' do
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen before do
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen post :create, repository: { name: 'repo',
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen source_address: "file://#{git_repository.path}",
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen remote_type: 'mirror' }
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen end
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen
fd1f0e9ef52b3e157cfd1a01c464c2ac7458ab17Timo Sirainen after do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen FileUtils.rm_rf(git_repository.path)
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen it { should respond_with :found }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it { response.should redirect_to Repository.find_by_path('repo') }
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen it 'should have created a mirrored repository' do
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen expect(Repository.find_by_path('repo').mirror?).to be_truthy
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen context 'fork' do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen before do
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen post :create, repository: { name: 'repo',
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen source_address: "file://#{git_repository.path}",
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen remote_type: 'fork' }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it { should respond_with :found }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it { response.should redirect_to Repository.find_by_path('repo') }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen it 'should have created a non-mirrored repository' do
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen expect(Repository.find_by_path('repo').mirror?).to be_falsy
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen end
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen end
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen end
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainenend
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen