From 48def9164bba6efbe79776d1026005c365534ae1 Mon Sep 17 00:00:00 2001 From: Heitor Reis Date: Wed, 8 Jul 2015 07:46:47 -0300 Subject: [PATCH] Started implementation of a form for Repository decoupled from Project --- app/controllers/repositories_controller.rb | 10 ++++++++-- app/views/repositories/_form.html.erb | 26 ++++++++++++++++++++++++++ features/repository/create.feature | 16 ++++++++++++++++ features/step_definitions/repository_steps.rb | 6 +++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 14be6f9..3a49b06 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -30,8 +30,11 @@ class RepositoriesController < ApplicationController # POST /projects/1/repositories # POST /projects/1/repositories.json def create - @repository = Repository.new(repository_params) - @repository.project_id = params[:project_id] + r_params = repository_params + r_params.require(:project_id) + r_params[:project_id] = nil if r_params[:project_id].to_i == 0 + + @repository = Repository.new(r_params) respond_to do |format| create_and_redir(format) end @@ -104,6 +107,9 @@ private @configurations = KalibroConfiguration.public_or_owned_by_user(current_user).map { |conf| [conf.name, conf.id] } + @projects = current_user.projects.map do |proj| + [proj.name, proj.id] + end if @project_id.nil? end # Duplicated code on create and update actions extracted here diff --git a/app/views/repositories/_form.html.erb b/app/views/repositories/_form.html.erb index 97a2671..27e5eba 100644 --- a/app/views/repositories/_form.html.erb +++ b/app/views/repositories/_form.html.erb @@ -102,6 +102,23 @@ +
+
+ <%= f.label :project_id, Project.model_name.human, class: 'control-label' %> + <%= f.select( :project_id, @projects, class: 'tooltip-control' ) %> + +
+ <%= f.check_box :project_id, {id: "no_project_checkbox", class: "checkbox"}, "0", nil %> + <%= f.label "no_project" %> +
+
+
+

+ <%= t('activemodel.hints.repository.project').html_safe %> +

+
+
+
@@ -114,5 +131,14 @@ $(document).on('page:load ready', function() { _repository_branch.toggle(); + + var checkbox = $("#no_project_checkbox"); + + function toggle() { + $("#repository_project_id").prop('disabled', checkbox.prop('checked')); + }; + + checkbox.on('click', toggle); + toggle(); }); diff --git a/features/repository/create.feature b/features/repository/create.feature index d23c686..842ae41 100644 --- a/features/repository/create.feature +++ b/features/repository/create.feature @@ -75,3 +75,19 @@ Scenario: Repository name with whitespaces And I set the select field "Configuration" as "Java" When I press the Save button Then I should see "Name should be unique within project" + +@kalibro_configuration_restart @kalibro_processor_restart @javascript +Scenario: Create repository without project + Given I am a regular user + And I am signed in + And I have a sample configuration with native metrics + And I am at the New Repository page + And I fill the Name field with "Kalibro Client" + And I set the select field "License" as "ISC License (ISC)" + And I fill the Address field with "https://github.com/mezuro/kalibro_client.git" + And I set the select field "Type" as "GIT" + And I set the select field "Process Period" as "1 day" + And I set the select field "Configuration" as "Java" + And I set the select field "Project" as "No Project" + When I press the Save button + Then I should see the saved repository's content diff --git a/features/step_definitions/repository_steps.rb b/features/step_definitions/repository_steps.rb index 647a9c7..4695291 100644 --- a/features/step_definitions/repository_steps.rb +++ b/features/step_definitions/repository_steps.rb @@ -66,7 +66,11 @@ Given(/^I wait up for a error processing$/) do end Given(/^I am at the New Repository page$/) do - visit new_project_repository_path(project_id: @project.id) + if @project + visit new_project_repository_path(project_id: @project.id) + else + visit new_repository_path + end end Given(/^I am at repository edit page$/) do -- libgit2 0.21.2