Skip to content

Commit

Permalink
[api][ci] Fix bug with remote projects and tests to work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Moisés Déniz Alemán committed Oct 16, 2015
1 parent 97625c3 commit 25d554a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
24 changes: 0 additions & 24 deletions src/api/app/controllers/source_controller.rb
Expand Up @@ -581,18 +581,13 @@ def check_and_remove_repositories!(repositories, full_remove, force = false)
def show_project_config
forward_from_backend(BackendFile.query_from_list(params, [:rev]))

<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 5fc651c... [webui][api] Some changes to take care about remote projects
begin
# 'project' can be a local Project in database or a String that's the name of a remote project, or even raise exceptions
project = Project.get_by_name(params[:project])
rescue Project::ReadAccessError, Project::UnknownObjectError => e
render_error status: 404, message: e.message
return
end
<<<<<<< HEAD
config = project.is_a?(String) ? ProjectConfigFile.new(project_name: project) : project.config
content = config.to_s
unless content
Expand All @@ -601,25 +596,6 @@ def show_project_config
end

send_data(content, type: config.response[:type], disposition: 'inline')
=======
project = Project.get_by_name(params[:project])
content = project.config.to_s
=======

if project.is_a?(String)
content = ProjectConfigFile.new(project_name: project).to_s
else
content = project.config.to_s
end
>>>>>>> 5fc651c... [webui][api] Some changes to take care about remote projects

unless content
render_error status: 404, message: project.config.errors.full_messages.to_sentence
return
end

send_data(content, type: project.config.response[:type], disposition: 'inline')
>>>>>>> 3809cf4... [api][webui] Implement BackendFile class
end

class PutProjectConfigNoPermission < APIException
Expand Down
14 changes: 7 additions & 7 deletions src/api/test/functional/source_controller_test.rb
Expand Up @@ -1911,17 +1911,10 @@ def test_prjconf
assert_response 404
get url_for(:controller => :source, :action => :show_project_config, :project => 'kde4')
assert_response :success
<<<<<<< HEAD
get url_for(:controller => :source, :action => :show_project_config, :project => 'RemoteInstance:BaseDistro')
assert_response :success

put url_for(:controller => :source, :action => :update_project_config, :project => 'RemoteInstance:BaseDistro'), 'Substitute: nix da'
=======
get url_for(:controller => :source, :action => :show_project_config, :project => 'RemoteInstance')
assert_response :success

put url_for(:controller => :source, :action => :update_project_config, :project => 'RemoteInstance'), 'Substitute: nix da'
>>>>>>> 5fc651c... [webui][api] Some changes to take care about remote projects
assert_response 403

prepare_request_with_user 'adrian_nobody', 'so_alone'
Expand Down Expand Up @@ -3728,6 +3721,13 @@ def test_updating_config_file
get '/source/home:Iggy/_config'
assert_response :success
assert_equal @response.body, NEW_CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT

# Leave the backend file as it was
put '/source/home:Iggy/_config?' + {
project: 'home:Iggy',
comment: 'Updated by test'
}.to_query, CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT
assert_response :success
end

end
Expand Down
7 changes: 7 additions & 0 deletions src/api/test/functional/webui/project_controller_test.rb
Expand Up @@ -606,6 +606,13 @@ def test_updating_config_file
click_link 'Project Config'
config_value = page.evaluate_script("editors[0].getValue()")
assert_equal config_value, NEW_CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT

# Leave the backend file as it was
put '/source/home:Iggy/_config?' + {
project: 'home:Iggy',
comment: 'Updated by test'
}.to_query, CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT
assert_response :success
end

end
3 changes: 3 additions & 0 deletions src/api/test/unit/project_test.rb
Expand Up @@ -937,6 +937,9 @@ def test_cycle_handling
assert @project.config.save(query_params, NEW_CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT)
assert @project.config.reload
assert_equal @project.config.to_s, NEW_CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT

# Leave the backend file as it was
assert @project.config.save(query_params, CONFIG_FILE_STRING_FOR_HOME_IGGY_PROJECT)
end

end

0 comments on commit 25d554a

Please sign in to comment.