Commit ca52f848411efaa5ccfb364c2169b38a8e9644b4

Authored by Dmitriy Zaporozhets
1 parent f4978bc0

Update chosen, improve ui, fix MR fork tests

Gemfile
... ... @@ -129,7 +129,7 @@ group :assets do
129 129 gem 'turbolinks'
130 130 gem 'jquery-turbolinks'
131 131  
132   - gem 'chosen-rails', "0.9.8"
  132 + gem 'chosen-rails', "1.0.0"
133 133 gem 'select2-rails'
134 134 gem 'jquery-atwho-rails', "0.3.0"
135 135 gem "jquery-rails", "2.1.3"
... ...
Gemfile.lock
... ... @@ -72,9 +72,12 @@ GEM
72 72 charlock_holmes (0.6.9.4)
73 73 childprocess (0.3.9)
74 74 ffi (~> 1.0, >= 1.0.11)
75   - chosen-rails (0.9.8)
76   - railties (~> 3.0)
77   - thor (~> 0.14)
  75 + chosen-rails (1.0.0)
  76 + coffee-rails (>= 3.2)
  77 + compass-rails (>= 1.0)
  78 + railties (>= 3.0)
  79 + sass-rails (>= 3.2)
  80 + chunky_png (1.2.8)
78 81 code_analyzer (0.3.2)
79 82 sexp_processor
80 83 coderay (1.0.9)
... ... @@ -87,6 +90,12 @@ GEM
87 90 coffee-script-source (1.6.2)
88 91 colored (1.2)
89 92 colorize (0.5.8)
  93 + compass (0.12.2)
  94 + chunky_png (~> 1.2)
  95 + fssm (>= 0.2.7)
  96 + sass (~> 3.1)
  97 + compass-rails (1.0.3)
  98 + compass (>= 0.12.2, < 0.14)
90 99 connection_pool (1.1.0)
91 100 coveralls (0.6.7)
92 101 colorize
... ... @@ -149,6 +158,7 @@ GEM
149 158 dotenv (>= 0.7)
150 159 thor (>= 0.13.6)
151 160 formatador (0.2.4)
  161 + fssm (0.2.10)
152 162 gemoji (1.2.1)
153 163 gherkin-ruby (0.3.0)
154 164 github-linguist (2.3.4)
... ... @@ -548,7 +558,7 @@ DEPENDENCIES
548 558 bootstrap-sass
549 559 capybara
550 560 carrierwave
551   - chosen-rails (= 0.9.8)
  561 + chosen-rails (= 1.0.0)
552 562 coffee-rails
553 563 colored
554 564 coveralls
... ...
app/assets/stylesheets/selects.scss
1 1 /* CHZN reset few styles */
2   -.chzn-container-single .chzn-single {
  2 +.chosen-container-single .chosen-single {
3 3 background: #FFF;
4 4 border: 1px solid #bbb;
5 5 box-shadow: none;
6 6 }
7   -.chzn-container-active .chzn-single {
  7 +.chosen-container-active .chosen-single {
8 8 background: #fff;
9 9 }
10 10  
... ... @@ -41,38 +41,38 @@
41 41 width: 120px;
42 42 }
43 43  
44   -.project-refs-form .chzn-container {
  44 +.project-refs-form .chosen-container {
45 45 position: relative;
46 46 top: 0;
47 47 left: 0;
48 48 margin-right: 10px;
49 49  
50   - .chzn-drop {
  50 + .chosen-drop {
51 51 min-width: 400px;
52   - .chzn-results {
  52 + .chosen-results {
53 53 max-height: 300px;
54 54 }
55   - .chzn-search input {
  55 + .chosen-search input {
56 56 min-width: 365px;
57 57 }
58 58 }
59 59 }
60 60  
61 61 /** Fix for Search Dropdown Border **/
62   -.chzn-container {
63   - .chzn-search {
  62 +.chosen-container {
  63 + .chosen-search {
64 64 input:focus {
65 65 @include box-shadow(none);
66 66 }
67 67 }
68 68  
69   - .chzn-drop {
  69 + .chosen-drop {
70 70 margin: 7px 0;
71 71 min-width: 200px;
72 72 border: 1px solid #bbb;
73 73 @include border-radius(0);
74 74  
75   - .chzn-results {
  75 + .chosen-results {
76 76 margin-top: 5px;
77 77 max-height: 300px;
78 78  
... ... @@ -95,7 +95,7 @@
95 95 }
96 96 }
97 97  
98   - .chzn-search {
  98 + .chosen-search {
99 99 @include bg-gray-gradient;
100 100 input {
101 101 min-width: 165px;
... ... @@ -104,7 +104,7 @@
104 104 }
105 105 }
106 106  
107   - .chzn-single {
  107 + .chosen-single {
108 108 @include bg-light-gray-gradient;
109 109  
110 110 div {
... ...
app/controllers/projects/merge_requests_controller.rb
... ... @@ -101,12 +101,12 @@ class Projects::MergeRequestsController &lt; Projects::ApplicationController
101 101 def branch_from
102 102 #This is always source
103 103 @source_project = @merge_request.nil? ? @project : @merge_request.source_project
104   - @commit = @repository.commit(params[:ref])
  104 + @commit = @repository.commit(params[:ref]) if params[:ref].present?
105 105 end
106 106  
107 107 def branch_to
108 108 @target_project = selected_target_project
109   - @commit = @target_project.repository.commit(params[:ref])
  109 + @commit = @target_project.repository.commit(params[:ref]) if params[:ref].present?
110 110 end
111 111  
112 112 def update_branches
... ...
app/views/projects/merge_requests/_form.html.haml
... ... @@ -13,8 +13,12 @@
13 13 .span5
14 14 .light-well
15 15 %h5.cgray From
16   - .padded= f.select(:source_project_id,[[@merge_request.source_project.path_with_namespace,@merge_request.source_project.id]] , {}, {class: 'source_project chosen span4'})
17   - .padded= f.select(:source_branch, @merge_request.source_project.repository.branch_names, { include_blank: "Select branch" }, {class: 'source_branch chosen span4'})
  16 + .padded
  17 + = f.select(:source_project_id,[[@merge_request.source_project.path_with_namespace,@merge_request.source_project.id]] , {}, {class: 'source_project chosen span4'})
  18 + .prepend-top-10
  19 + %i.icon-code-fork
  20 + &nbsp;
  21 + = f.select(:source_branch, @merge_request.source_project.repository.branch_names, { include_blank: "Select branch" }, {class: 'source_branch chosen span3'})
18 22 .mr_source_commit.prepend-top-10
19 23 .span2
20 24 %h1.merge-request-angle
... ... @@ -23,9 +27,13 @@
23 27 .light-well
24 28 %h5.cgray To
25 29 - projects = @project.forked_from_project.nil? ? [@project] : [ @project,@project.forked_from_project]
26   - .padded= f.select(:target_project_id, projects.map { |proj| [proj.path_with_namespace,proj.id] }, {include_blank: "Select Target Project" }, {class: 'target_project chosen span4'})
27   - .padded= f.select(:target_branch, @target_branches, { include_blank: "Select branch" }, {class: 'target_branch chosen span4'})
28   - .mr_target_commit.prepend-top-10
  30 + .padded
  31 + = f.select(:target_project_id, projects.map { |proj| [proj.path_with_namespace,proj.id] }, {include_blank: "Select Target Project" }, {class: 'target_project chosen span4'})
  32 + .prepend-top-10
  33 + %i.icon-code-fork
  34 + &nbsp;
  35 + = f.select(:target_branch, @target_branches, { include_blank: "Select branch" }, {class: 'target_branch chosen span3'})
  36 + .mr_target_commit.prepend-top-10
29 37  
30 38 %hr
31 39  
... ...
features/project/forked_merge_requests.feature
... ... @@ -21,14 +21,6 @@ Feature: Project Forked Merge Requests
21 21 Then I should see merge request "Merge Request On Forked Project"
22 22  
23 23 @javascript
24   - Scenario: I should see a push widget for forked merge requests
25   - Given project "Forked Shop" has push event
26   - And I visit dashboard page
27   - Then I should see last push widget
28   - And I click "Create Merge Request on fork" link
29   - Then I see prefilled new Merge Request page for the forked project
30   -
31   - @javascript
32 24 Scenario: I can edit a forked merge request
33 25 Given I visit project "Forked Shop" merge requests page
34 26 And I click link "New Merge Request"
... ... @@ -47,4 +39,4 @@ Feature: Project Forked Merge Requests
47 39 And I click link "New Merge Request"
48 40 And I fill out an invalid "Merge Request On Forked Project" merge request
49 41 And I submit the merge request
50   - Then I should see validation errors
51 42 \ No newline at end of file
  43 + Then I should see validation errors
... ...
features/steps/project/project_forked_merge_requests.rb
... ... @@ -3,30 +3,31 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
3 3 include SharedProject
4 4 include SharedNote
5 5 include SharedPaths
  6 + include ChosenHelper
6 7  
7   - Given 'I am a member of project "Shop"' do
  8 + step 'I am a member of project "Shop"' do
8 9 @project = Project.find_by_name "Shop"
9 10 @project ||= create(:project_with_code, name: "Shop")
10 11 @project.team << [@user, :reporter]
11 12 end
12 13  
13   - And 'I have a project forked off of "Shop" called "Forked Shop"' do
  14 + step 'I have a project forked off of "Shop" called "Forked Shop"' do
14 15 @forking_user = @user
15 16 forked_project_link = build(:forked_project_link)
16 17 @forked_project = Project.find_by_name "Forked Shop"
17 18 @forked_project ||= create(:source_project_with_code, name: "Forked Shop", forked_project_link: forked_project_link, creator_id: @forking_user.id , namespace: @forking_user.namespace)
  19 +
18 20 forked_project_link.forked_from_project = @project
19 21 forked_project_link.forked_to_project = @forked_project
20 22 @forked_project.team << [@forking_user , :master]
21 23 forked_project_link.save!
22 24 end
23 25  
24   - Given 'I click link "New Merge Request"' do
  26 + step 'I click link "New Merge Request"' do
25 27 click_link "New Merge Request"
26 28 end
27 29  
28   - Then 'I should see merge request "Merge Request On Forked Project"' do
29   - page.should have_content "Merge Request On Forked Project"
  30 + step 'I should see merge request "Merge Request On Forked Project"' do
30 31 @project.merge_requests.size.should >= 1
31 32 @merge_request = @project.merge_requests.last
32 33 current_path.should == project_merge_request_path(@project, @merge_request)
... ... @@ -40,56 +41,41 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
40 41 page.should have_content @merge_request.target_branch
41 42 end
42 43  
43   - And 'I fill out a "Merge Request On Forked Project" merge request' do
44   - #The ordering here is a bit whacky on purpose:
45   - #Select the target right away, to give update_branches time to run and clean up the target_branches
46   - find(:select, "merge_request_target_project_id", {}).value.should == @forked_project.id.to_s
47   - select @project.path_with_namespace, from: "merge_request_target_project_id"
48   -
  44 + step 'I fill out a "Merge Request On Forked Project" merge request' do
  45 + chosen @forked_project.id, from: "#merge_request_source_project_id"
  46 + chosen @project.id, from: "#merge_request_target_project_id"
49 47  
50   - fill_in "merge_request_title", with: "Merge Request On Forked Project"
51 48 find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s
52   -
53 49 find(:select, "merge_request_target_project_id", {}).value.should == @project.id.to_s
54 50  
55   - #Ensure the option exists in the select
56   - find(:select, "merge_request_source_branch", {}).should have_content "master"
57   - select "master", from: "merge_request_source_branch"
58   - #Ensure the option is selected
59   - find(:select, "merge_request_source_branch", {}).value.should have_content "master"
60   - verify_commit_link(".mr_source_commit",@forked_project)
61   -
  51 + chosen "master", from: "#merge_request_source_branch"
  52 + chosen "stable", from: "#merge_request_target_branch"
62 53  
63   - #This could fail if the javascript hasn't run yet, there is a timing issue here -- this is why we do the select at the top
64   - #Ensure the option exists in the select
65   - find(:select, "merge_request_target_branch", {}).should have_content "stable"
66   - #We must give apparently lots of time for update branches to finish
  54 + find(:select, "merge_request_source_branch", {}).value.should == 'master'
  55 + find(:select, "merge_request_target_branch", {}).value.should == 'stable'
67 56  
68   - (find(:select, "merge_request_target_branch", {}).find(:option, "stable",{}).select_option).should be_true
69   - #Ensure the option is selected
70   - find(:select, "merge_request_target_branch", {}).value.should have_content "stable"
71   - verify_commit_link(".mr_target_commit",@project)
  57 + fill_in "merge_request_title", with: "Merge Request On Forked Project"
72 58 end
73 59  
74   - And 'I submit the merge request' do
  60 + step 'I submit the merge request' do
75 61 click_button "Submit merge request"
76 62 end
77 63  
78   - And 'I follow the target commit link' do
  64 + step 'I follow the target commit link' do
79 65 commit = @project.repository.commit
80 66 click_link commit.short_id(8)
81 67 end
82 68  
83   - Then 'I should see the commit under the forked from project' do
  69 + step 'I should see the commit under the forked from project' do
84 70 commit = @project.repository.commit
85 71 page.should have_content(commit.message)
86 72 end
87 73  
88   - And 'I click "Create Merge Request on fork" link' do
  74 + step 'I click "Create Merge Request on fork" link' do
89 75 click_link "Create Merge Request on fork"
90 76 end
91 77  
92   - Then 'I see prefilled new Merge Request page for the forked project' do
  78 + step 'I see prefilled new Merge Request page for the forked project' do
93 79 current_path.should == new_project_merge_request_path(@forked_project)
94 80 find("#merge_request_source_project_id").value.should == @forked_project.id.to_s
95 81 find("#merge_request_target_project_id").value.should == @project.id.to_s
... ... @@ -100,15 +86,15 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
100 86 verify_commit_link(".mr_source_commit",@forked_project)
101 87 end
102 88  
103   - And 'I update the merge request title' do
  89 + step 'I update the merge request title' do
104 90 fill_in "merge_request_title", with: "An Edited Forked Merge Request"
105 91 end
106 92  
107   - And 'I save the merge request' do
  93 + step 'I save the merge request' do
108 94 click_button "Save changes"
109 95 end
110 96  
111   - Then 'I should see the edited merge request' do
  97 + step 'I should see the edited merge request' do
112 98 page.should have_content "An Edited Forked Merge Request"
113 99 @project.merge_requests.size.should >= 1
114 100 @merge_request = @project.merge_requests.last
... ... @@ -122,12 +108,12 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
122 108 page.should have_content @merge_request.target_branch
123 109 end
124 110  
125   - Then 'I should see last push widget' do
  111 + step 'I should see last push widget' do
126 112 page.should have_content "You pushed to new_design"
127 113 page.should have_link "Create Merge Request"
128 114 end
129 115  
130   - Given 'project "Forked Shop" has push event' do
  116 + step 'project "Forked Shop" has push event' do
131 117 @forked_project = Project.find_by_name("Forked Shop")
132 118  
133 119 data = {
... ... @@ -154,13 +140,13 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
154 140 end
155 141  
156 142  
157   - Then 'I click link edit "Merge Request On Forked Project"' do
  143 + step 'I click link edit "Merge Request On Forked Project"' do
158 144 find("#edit_merge_request").click
159 145 end
160 146  
161   - Then 'I see the edit page prefilled for "Merge Request On Forked Project"' do
  147 + step 'I see the edit page prefilled for "Merge Request On Forked Project"' do
162 148 current_path.should == edit_project_merge_request_path(@project, @merge_request)
163   - page.should have_content "Edit merge request #{@merge_request.id}"
  149 + page.should have_content "Edit merge request ##{@merge_request.id}"
164 150 find("#merge_request_title").value.should == "Merge Request On Forked Project"
165 151 find("#merge_request_source_project_id").value.should == @forked_project.id.to_s
166 152 find("#merge_request_target_project_id").value.should == @project.id.to_s
... ... @@ -170,7 +156,7 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
170 156 verify_commit_link(".mr_target_commit",@project)
171 157 end
172 158  
173   - And 'I fill out an invalid "Merge Request On Forked Project" merge request' do
  159 + step 'I fill out an invalid "Merge Request On Forked Project" merge request' do
174 160 #If this isn't filled in the rest of the validations won't be triggered
175 161 fill_in "merge_request_title", with: "Merge Request On Forked Project"
176 162 find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s
... ... @@ -179,7 +165,7 @@ class ProjectForkedMergeRequests &lt; Spinach::FeatureSteps
179 165 find(:select, "merge_request_target_branch", {}).value.should == ""
180 166 end
181 167  
182   - Then 'I should see validation errors' do
  168 + step 'I should see validation errors' do
183 169 page.should have_content "Source branch can't be blank"
184 170 page.should have_content "Target branch can't be blank"
185 171 page.should have_content "Branch conflict You can not use same project/branch for source and target"
... ...
features/support/env.rb
... ... @@ -14,7 +14,7 @@ require &#39;spinach/capybara&#39;
14 14 require 'sidekiq/testing/inline'
15 15  
16 16  
17   -%w(valid_commit select2_helper test_env).each do |f|
  17 +%w(valid_commit select2_helper chosen_helper test_env).each do |f|
18 18 require Rails.root.join('spec', 'support', f)
19 19 end
20 20  
... ...
spec/support/chosen_helper.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# Chosen programmatic helper
  2 +# It allows you to select value from chosen select
  3 +#
  4 +# Params
  5 +# value - real value of selected item
  6 +# opts - options containing css selector
  7 +#
  8 +# Usage:
  9 +#
  10 +# chosen(2, from: '#user_ids')
  11 +#
  12 +
  13 +module ChosenHelper
  14 + def chosen(value, options={})
  15 + raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from)
  16 +
  17 + selector = options[:from]
  18 +
  19 + page.execute_script("$('#{selector}').val('#{value}').trigger('chosen:updated');")
  20 + end
  21 +end
... ...
spec/support/test_env.rb
... ... @@ -88,11 +88,11 @@ module TestEnv
88 88  
89 89 def clear_repo_dir(namespace, name)
90 90 setup_stubs
91   - #Clean any .wiki.git that may have been created
  91 + # Clean any .wiki.git that may have been created
92 92 FileUtils.rm_rf File.join(testing_path(), "#{name}.wiki.git")
93 93 end
94 94  
95   - #Create a repo and it's satellite
  95 + # Create a repo and it's satellite
96 96 def create_repo(namespace, name)
97 97 setup_stubs
98 98 repo = repo(namespace, name)
... ... @@ -152,7 +152,7 @@ module TestEnv
152 152 # Recreate tmp/test-git-base-path
153 153 FileUtils.mkdir_p Gitlab.config.gitlab_shell.repos_path
154 154  
155   - #Since much more is happening in satellites
  155 + # Since much more is happening in satellites
156 156 FileUtils.mkdir_p Gitlab.config.satellites.path
157 157 end
158 158  
... ... @@ -161,8 +161,8 @@ module TestEnv
161 161 satellite_repo = satellite(namespace, satellite_name)
162 162 # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already
163 163 satellite_dir = File.dirname(satellite_repo)
164   - FileUtils.mkdir_p satellite_dir unless File.exists?(satellite_dir)
165   - system("ln -s -f #{seed_satellite_path()} #{satellite_repo}")
  164 + FileUtils.mkdir_p(satellite_dir) unless File.exists?(satellite_dir)
  165 + system("ln -s -f #{seed_satellite_path} #{satellite_repo}")
166 166 end
167 167  
168 168 def create_temp_repo(path)
... ...