Commit d9deb24f3a507933106b2c9a00a9bc73f9eee269

Authored by Johannes Schleifenbaum
1 parent c27e49e9

Preselect the current issue tracker with selected="selected"

The previous behavior was, that the first element of the select was
preselected, thus upon saving the project, the previous selected could
be overwritten.
app/helpers/projects_helper.rb
... ... @@ -80,7 +80,7 @@ module ProjectsHelper
80 80 @project.milestones.active.order("due_date, title ASC").all
81 81 end
82 82  
83   - def project_issues_trackers
  83 + def project_issues_trackers(current_tracker = nil)
84 84 values = Project.issues_tracker.values.map do |tracker_key|
85 85 if tracker_key.to_sym == :gitlab
86 86 ['GitLab', tracker_key]
... ... @@ -89,7 +89,7 @@ module ProjectsHelper
89 89 end
90 90 end
91 91  
92   - options_for_select(values)
  92 + options_for_select(values, current_tracker)
93 93 end
94 94  
95 95 private
... ...
app/views/projects/edit.html.haml
... ... @@ -67,7 +67,7 @@
67 67 - if Project.issues_tracker.values.count > 1
68 68 .control-group
69 69 = f.label :issues_tracker, "Issues tracker", class: 'control-label'
70   - .controls= f.select(:issues_tracker, project_issues_trackers, {}, { disabled: !@project.issues_enabled })
  70 + .controls= f.select(:issues_tracker, project_issues_trackers(@project.issues_tracker), {}, { disabled: !@project.issues_enabled })
71 71  
72 72 .control-group
73 73 = f.label :issues_tracker_id, "Project name or id in issues tracker", class: 'control-label'
... ...
features/project/edit_issuetracker.feature 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +Feature: Project Issue Tracker
  2 + Background:
  3 + Given I sign in as a user
  4 + And I own project "Shop"
  5 + And project "Shop" has issues enabled
  6 + And I visit project "Shop" page
  7 +
  8 + Scenario: I set the issue tracker to "GitLab"
  9 + When I visit edit project "Shop" page
  10 + And change the issue tracker to "GitLab"
  11 + And I save project
  12 + Then I the project should have "GitLab" as issue tracker
  13 +
  14 + Scenario: I set the issue tracker to "Redmine"
  15 + When I visit edit project "Shop" page
  16 + And change the issue tracker to "Redmine"
  17 + And I save project
  18 + Then I the project should have "Redmine" as issue tracker
0 19 \ No newline at end of file
... ...
features/steps/project/project_issue_tracker.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +class ProjectIssueTracker < Spinach::FeatureSteps
  2 + include SharedAuthentication
  3 + include SharedProject
  4 + include SharedPaths
  5 +
  6 + step 'project "Shop" has issues enabled' do
  7 + @project = Project.find_by_name "Shop"
  8 + @project ||= create(:project_with_code, name: "Shop", namespace: @user.namespace)
  9 + @project.issues_enabled = true
  10 + end
  11 +
  12 + step 'change the issue tracker to "GitLab"' do
  13 + select 'GitLab', from: 'project_issues_tracker'
  14 + end
  15 +
  16 + step 'I the project should have "GitLab" as issue tracker' do
  17 + find_field('project_issues_tracker').value.should == 'gitlab'
  18 + end
  19 +
  20 + step 'change the issue tracker to "Redmine"' do
  21 + select 'Redmine', from: 'project_issues_tracker'
  22 + end
  23 +
  24 + step 'I the project should have "Redmine" as issue tracker' do
  25 + find_field('project_issues_tracker').value.should == 'redmine'
  26 + end
  27 +
  28 + And 'I save project' do
  29 + click_button 'Save changes'
  30 + end
  31 +end
... ...
spec/helpers/projects_helper_spec.rb
... ... @@ -7,5 +7,17 @@ describe ProjectsHelper do
7 7 "<option value=\"redmine\">Redmine</option>\n" \
8 8 "<option value=\"gitlab\">GitLab</option>"
9 9 end
  10 +
  11 + it "returns the correct issues trackers available with current tracker 'gitlab' selected" do
  12 + project_issues_trackers('gitlab').should ==
  13 + "<option value=\"redmine\">Redmine</option>\n" \
  14 + "<option value=\"gitlab\" selected=\"selected\">GitLab</option>"
  15 + end
  16 +
  17 + it "returns the correct issues trackers available with current tracker 'redmine' selected" do
  18 + project_issues_trackers('redmine').should ==
  19 + "<option value=\"redmine\" selected=\"selected\">Redmine</option>\n" \
  20 + "<option value=\"gitlab\">GitLab</option>"
  21 + end
10 22 end
11 23 end
... ...