From c2202e8113fb0899636591af34d0549b31f31194 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 25 Nov 2011 20:23:10 +0400 Subject: [PATCH] [refs #2249] Add projects controller specs --- Gemfile | 1 + Gemfile.lock | 2 + spec/controllers/projects_controller_spec.rb | 65 ++++++++++++++++---- spec/spec_helper.rb | 4 +- 4 files changed, 59 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index a8cf5ee33..a0e106ded 100644 --- a/Gemfile +++ b/Gemfile @@ -69,6 +69,7 @@ end group :test do gem 'rspec-rails', '~> 2.7.0' gem 'factory_girl_rails', '~> 1.3.0' + gem 'rr' # gem 'spork', '>= 0.9.0.rc9' # gem 'guard-spork', '~> 0.3.1' # gem 'guard-rspec', '~> 0.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index cbdcecde9..d16d9069a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -217,6 +217,7 @@ GEM json (~> 1.4) rest-client (1.6.7) mime-types (>= 1.16) + rr (1.0.4) rspec (2.7.0) rspec-core (~> 2.7.0) rspec-expectations (~> 2.7.0) @@ -296,6 +297,7 @@ DEPENDENCIES rails (= 3.0.10) rails-xmlrpc! rails3-generators + rr rspec-rails (~> 2.7.0) ruby-debug ruby_parser diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 02bfcb7ba..85a5bf2be 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -6,6 +6,16 @@ describe ProjectsController do @another_user = Factory(:user) @create_params = {:project => {:name => 'pro', :unixname => 'pro2'}} @update_params = {:project => {:name => 'pro2', :unixname => 'pro2'}} + + platform = Factory(:platform) + any_instance_of(Project, :collected_project_versions => ['v1.0', 'v2.0']) + @process_build_params = {:build => { + :arches => {Factory(:arch).id => '1'}, + :project_version => 'v1.0', + :bpl => {platform.id => '1'}, + :pl => platform.id, + :update_type => 'security' + }} end context 'for guest' do @@ -50,6 +60,11 @@ describe ProjectsController do post :create, @create_params flash[:notice].should_not be_blank end + + it 'should be able to fork project' do + post :fork, :id => @project.id + response.should redirect_to(project_path(Project.last)) + end end context 'for owner user' do @@ -70,13 +85,32 @@ describe ProjectsController do put :update, {:id => @project.id}.merge(@update_params) flash[:notice].should_not be_blank end + + it 'should be able to perform build action' do + get :build, :id => @project.id + response.should render_template(:build) + end + + it 'should be able to perform process_build action' do + post :process_build, {:id => @project.id}.merge(@process_build_params) + response.should redirect_to(project_path(@project)) + end + + it 'should be able to perform destroy action' do + delete :destroy, {:id => @project.id} + response.should redirect_to(@project.owner) + end + + it 'should not be able to fork project' do + post :fork, :id => @project.id + response.should redirect_to(forbidden_path) + end end context 'for reader user' do before(:each) do @user = Factory(:user) set_session_for(@user) - #@project.update_attribute(:owner, @user) r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'reader') r.save! end @@ -91,22 +125,16 @@ describe ProjectsController do response.should render_template(:show) end - #it 'should not be able to perform update action' do - # get :update, {:id => @project.id}.merge(@update_params) - # response.should redirect_to(forbidden_path) - #end -# - #it 'should set flash notice on update success' do - # put :update, {:id => @project.id}.merge(@update_params) - # flash[:notice].should_not be_blank - #end + it 'should be able to fork project' do + post :fork, :id => @project.id + response.should redirect_to(project_path(Project.last)) + end end context 'for writer user' do before(:each) do @user = Factory(:user) set_session_for(@user) - #@project.update_attribute(:owner, @user) r = @project.relations.build(:object_type => 'User', :object_id => @user.id, :role => 'writer') r.save! end @@ -120,5 +148,20 @@ describe ProjectsController do put :update, {:id => @project.id}.merge(@update_params) flash[:notice].should_not be_blank end + + it 'shoud be able to perform build action' do + get :build, :id => @project.id + response.should render_template(:build) + end + + it 'shoud be able to perform process_build action' do + post :process_build, {:id => @project.id}.merge(@process_build_params) + response.should redirect_to(project_path(@project)) + end + + it 'should be able to fork project' do + post :fork, :id => @project.id + response.should redirect_to(project_path(Project.last)) + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d01766f68..46af550f5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,8 +14,8 @@ RSpec.configure do |config| # # config.mock_with :mocha # config.mock_with :flexmock - # config.mock_with :rr - config.mock_with :rspec + config.mock_with :rr + #config.mock_with :rspec # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures"