Skip to content

Commit

Permalink
Merge pull request #1832 from mdeniz/project_controller_test_part_5
Browse files Browse the repository at this point in the history
Project controller RSpec (part 5)
  • Loading branch information
Moisés Déniz Alemán committed May 31, 2016
2 parents d49c647 + f23cb80 commit 06bf21d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
101 changes: 101 additions & 0 deletions src/api/spec/controllers/webui/project_controller_spec.rb
Expand Up @@ -11,6 +11,7 @@
let(:home_moi_project) { create(:project, name: 'home:moi') }
let(:maintenance_project) { create(:maintenance_project, name: 'maintenance_project') }
let(:project_with_package) { create(:project_with_package, name: 'NewProject', package_name: 'PackageExample') }
let(:repo_for_user_home) { create(:repository, project: user.home_project) }

describe 'CSRF protection' do
before do
Expand Down Expand Up @@ -393,4 +394,104 @@
expect(flash[:error]).to eq("Couldn't add repository: 'Name must not start with '_' or contain any of these characters ':/'")
end
end

describe 'GET #buildresult' do
it 'assigns the buildresult' do
summary = Xmlhash::XMLHash.new({'statuscount' => {'code' => 'succeeded', 'count' => 1} })
build_result = { 'result' => Xmlhash::XMLHash.new({'repository' => 'openSUSE', 'arch' => 'x86_64', 'summary' => summary }) }
Buildresult.stubs(:find_hashed).returns(Xmlhash::XMLHash.new(build_result))
xhr :get, :buildresult, project: project_with_package
expect(assigns(:buildresult)).to match_array([["openSUSE", [["x86_64", [[:succeeded, 1]]]]]])
end
end

describe 'GET #delete_dialog' do
it 'assigns only linking_projects' do
apache2_project
another_project.projects_linking_to << apache_project
xhr :get, :delete_dialog, project: apache_project
expect(assigns(:linking_projects)).to match_array([another_project.name])
end
end

describe 'DELETE #destroy' do
before do
login user
end

context 'with check_weak_dependencies enabled' do
before do
Project.any_instance.stubs(:check_weak_dependencies?).returns(true)
end

context 'having a parent project' do
before do
subproject = create(:project, name: "#{user.home_project}:subproject")
delete :destroy, project: subproject
end

it { expect(Project.count).to eq(1) }
it { is_expected.to redirect_to(project_show_path(user.home_project)) }
it { expect(flash[:notice]).to eq("Project was successfully removed.") }
end

context 'not having a parent project' do
before do
delete :destroy, project: user.home_project
end

it { expect(Project.count).to eq(0) }
it { is_expected.to redirect_to(action: :index) }
it { expect(flash[:notice]).to eq("Project was successfully removed.") }
end
end

context 'with check_weak_dependencies disabled' do
before do
Project.any_instance.stubs(:check_weak_dependencies?).returns(false)
delete :destroy, project: user.home_project
end

it { expect(Project.count).to eq(1) }
it { is_expected.to redirect_to(project_show_path(user.home_project)) }
it { expect(flash[:notice]).to start_with("Project can't be removed:") }
end
end

describe 'POST #update_target' do
before do
login user
end

context 'updating non existent repository' do
it 'will raise a NoMethodError' do
expect do
post :update_target, project: user.home_project, repo: 'standard'
end.to raise_error(NoMethodError)
end
end

context 'updating the repository without architectures' do
before do
post :update_target, project: user.home_project, repo: repo_for_user_home.name
end

it { expect(repo_for_user_home.architectures.pluck(:name)).to be_empty }
it { expect(assigns(:repository_arch_hash).to_a).to match_array([["armv7l", false], ['i586', false], ['x86_64', false]])}
it { is_expected.to redirect_to(action: :repositories) }
it { expect(flash[:notice]).to eq("Successfully updated repository") }
end

context 'updating the repository with architectures' do
before do
post :update_target, project: user.home_project, repo: repo_for_user_home.name, arch: {'i586' => true, 'x86_64' => true}
end

it { expect(repo_for_user_home.architectures.pluck(:name)).to match_array(['i586', 'x86_64']) }
it { expect(Architecture.available.pluck(:name)).to match_array(["armv7l", "i586", "x86_64"]) }
it { expect(assigns(:repository_arch_hash).to_a).to match_array([["armv7l", false], ['i586', true], ['x86_64', true]])}
it { is_expected.to redirect_to(action: :repositories) }
it { expect(flash[:notice]).to eq("Successfully updated repository") }
end
end
end
2 changes: 1 addition & 1 deletion src/api/spec/factories/repository.rb
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :repository do
project
name { Faker::Internet.domain_word }
sequence(:name) { |n| "#{Faker::Internet.domain_word}#{n}" }

transient do
architectures []
Expand Down

0 comments on commit 06bf21d

Please sign in to comment.