From 245020a127b8e3b95d16d0683f79d48895c8944c Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sat, 11 Mar 2017 19:02:21 +1100 Subject: [PATCH 1/7] Fix visibility level on new project page --- app/views/projects/new.html.haml | 3 ++- changelogs/unreleased/fix_visibility_level.yml | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix_visibility_level.yml diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 2a98bba05ee..1a51f777bd9 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,5 +1,6 @@ - page_title 'New Project' - header_title "Projects", dashboard_projects_path +- visibility_level = params.try(:[], :project).try(:[], :visibility_level).to_i || default_project_visibility .project-edit-container .project-edit-errors @@ -95,7 +96,7 @@ = f.label :visibility_level, class: 'label-light' do Visibility Level = link_to icon('question-circle'), help_page_path("public_access/public_access") - = render 'shared/visibility_level', f: f, visibility_level: default_project_visibility, can_change_visibility_level: true, form_model: @project, with_label: false + = render 'shared/visibility_level', f: f, visibility_level: visibility_level, can_change_visibility_level: true, form_model: @project, with_label: false = f.submit 'Create project', class: "btn btn-create project-submit", tabindex: 4 = link_to 'Cancel', dashboard_projects_path, class: 'btn btn-cancel' diff --git a/changelogs/unreleased/fix_visibility_level.yml b/changelogs/unreleased/fix_visibility_level.yml new file mode 100644 index 00000000000..4cf649124ca --- /dev/null +++ b/changelogs/unreleased/fix_visibility_level.yml @@ -0,0 +1,4 @@ +--- +title: Fix visibility level on new project page +merge_request: 9885 +author: blackst0ne From 5c209d91c2748935c70b7906015a430d1b85b4b0 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sat, 11 Mar 2017 20:09:39 +1100 Subject: [PATCH 2/7] Added specs --- spec/features/projects/new_project_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb index 45185f2dd1f..651a46f62b1 100644 --- a/spec/features/projects/new_project_spec.rb +++ b/spec/features/projects/new_project_spec.rb @@ -53,6 +53,7 @@ feature "New project", feature: true do click_button('Create project') expect(page).to have_css '.project-edit-errors .alert.alert-danger' + expect(find("[name='project[visibility_level]'][checked].option-title").value).to eq('Internal') end it "selects the group namespace" do From 93e204ea524830baa47be8d6bbeb6f5aa39d7991 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sat, 11 Mar 2017 21:47:48 +1100 Subject: [PATCH 3/7] Update specs --- spec/features/projects/new_project_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb index 651a46f62b1..1dc1179c795 100644 --- a/spec/features/projects/new_project_spec.rb +++ b/spec/features/projects/new_project_spec.rb @@ -53,7 +53,6 @@ feature "New project", feature: true do click_button('Create project') expect(page).to have_css '.project-edit-errors .alert.alert-danger' - expect(find("[name='project[visibility_level]'][checked].option-title").value).to eq('Internal') end it "selects the group namespace" do @@ -61,6 +60,12 @@ feature "New project", feature: true do expect(namespace.text).to eq group.name end + + it 'selects the visibility level' do + level = Gitlab::VisibilityLevel.options['Internal'] + + expect(find_field("project_visibility_level_#{level}")).to be_checked + end end end end From 6625d605ec8405b1d687b13e7624b10ced832fd2 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sun, 12 Mar 2017 00:59:09 +1100 Subject: [PATCH 4/7] Refactor specs --- spec/features/projects/new_project_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb index 1dc1179c795..e153eb2bc42 100644 --- a/spec/features/projects/new_project_spec.rb +++ b/spec/features/projects/new_project_spec.rb @@ -16,6 +16,15 @@ feature "New project", feature: true do expect(find_field("project_visibility_level_#{level}")).to be_checked end + + it 'saves visibility level on validation error' do + visit new_project_path + + choose(key) + click_button('Create project') + + expect(find_field("project_visibility_level_#{level}")).to be_checked + end end end @@ -60,12 +69,6 @@ feature "New project", feature: true do expect(namespace.text).to eq group.name end - - it 'selects the visibility level' do - level = Gitlab::VisibilityLevel.options['Internal'] - - expect(find_field("project_visibility_level_#{level}")).to be_checked - end end end end From d274bbb9b93183cb74f7ba4c3de286ebd5b0cb5a Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sun, 12 Mar 2017 01:20:22 +1100 Subject: [PATCH 5/7] Fix specs --- app/views/projects/new.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 1a51f777bd9..560e3439fc2 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,6 +1,6 @@ - page_title 'New Project' - header_title "Projects", dashboard_projects_path -- visibility_level = params.try(:[], :project).try(:[], :visibility_level).to_i || default_project_visibility +- visibility_level = params.try(:[], :project).try(:[], :visibility_level) || default_project_visibility .project-edit-container .project-edit-errors @@ -96,7 +96,7 @@ = f.label :visibility_level, class: 'label-light' do Visibility Level = link_to icon('question-circle'), help_page_path("public_access/public_access") - = render 'shared/visibility_level', f: f, visibility_level: visibility_level, can_change_visibility_level: true, form_model: @project, with_label: false + = render 'shared/visibility_level', f: f, visibility_level: visibility_level.to_i, can_change_visibility_level: true, form_model: @project, with_label: false = f.submit 'Create project', class: "btn btn-create project-submit", tabindex: 4 = link_to 'Cancel', dashboard_projects_path, class: 'btn btn-cancel' From 42151a15df1b920f7092e3f7c6f31cb24136cff9 Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Sun, 12 Mar 2017 08:01:43 +1100 Subject: [PATCH 6/7] Fix rubocop offenses --- spec/features/projects/new_project_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/projects/new_project_spec.rb b/spec/features/projects/new_project_spec.rb index e153eb2bc42..52196ce49bd 100644 --- a/spec/features/projects/new_project_spec.rb +++ b/spec/features/projects/new_project_spec.rb @@ -18,12 +18,12 @@ feature "New project", feature: true do end it 'saves visibility level on validation error' do - visit new_project_path + visit new_project_path - choose(key) - click_button('Create project') + choose(key) + click_button('Create project') - expect(find_field("project_visibility_level_#{level}")).to be_checked + expect(find_field("project_visibility_level_#{level}")).to be_checked end end end From 37ce638ccd476144fe9235a4d091be4135a3e00a Mon Sep 17 00:00:00 2001 From: blackst0ne Date: Tue, 14 Mar 2017 07:24:30 +1100 Subject: [PATCH 7/7] Use dig --- app/views/projects/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 560e3439fc2..d129da943f8 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -1,6 +1,6 @@ - page_title 'New Project' - header_title "Projects", dashboard_projects_path -- visibility_level = params.try(:[], :project).try(:[], :visibility_level) || default_project_visibility +- visibility_level = params.dig(:project, :visibility_level) || default_project_visibility .project-edit-container .project-edit-errors