[refs #2249] Add projects controller specs
This commit is contained in:
parent
796ff75857
commit
c2202e8113
1
Gemfile
1
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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue