1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksarequire 'spec_helper'
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksadescribe RepositoryDirectoriesController do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:user) { create :user }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:repository) { create :repository, user: user }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa context 'not signed in: create' do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa before do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa post :create, repository_directory: attributes_for(:repository_directory), repository_id: repository.to_param
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa it{ should respond_with :redirect }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa context 'signed in' do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa before do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa sign_in user
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa context 'POST to create' do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:target) { generate :name }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:name) { generate :name }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa before do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa post :create, repository_directory: {
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa target_directory: target,
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa name: name
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa }, repository_id: repository.to_param
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
9f39fe20bc7fd95b95937327aa31165d7bd08104Eugen Kuksa it { should respond_with(201) }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa context 'POST to create when it already exists' do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:target) { generate :name }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:name) { generate :name }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa let(:repo_dir) do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa create :repository_directory, repository: repository, user: user,
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa name: name, target_directory: target
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa before do
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa post :create, repository_directory: {
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa target_directory: repo_dir.target_directory,
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa name: repo_dir.name
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa }, repository_id: repository.to_param
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
9f39fe20bc7fd95b95937327aa31165d7bd08104Eugen Kuksa it { should respond_with(422) }
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa end
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksa
1dc4b347882e22db6d12af621d7db12e219655f5Eugen Kuksaend