Commit 28cb43135ce7691a7b0022cb8fcb719d0e46c810

Authored by Dmitriy Zaporozhets
1 parent 7b7547aa

Hooks UI improved, Request tests added

Gemfile
1 1 source "http://rubygems.org"
2 2  
3   -gem "rails", "3.2.1"
  3 +gem "rails", "3.2.3"
4 4  
5 5 gem "sqlite3"
6 6 gem "mysql2"
... ... @@ -39,7 +39,7 @@ gem 'modularity'
39 39  
40 40 group :assets do
41 41 gem "sass-rails", "3.2.3"
42   - gem "coffee-rails", "3.2.1"
  42 + gem "coffee-rails", "3.2.2"
43 43 gem "uglifier", "1.0.3"
44 44 end
45 45  
... ...
Gemfile.lock
... ... @@ -41,31 +41,31 @@ GEM
41 41 remote: http://rubygems.org/
42 42 specs:
43 43 ZenTest (4.5.0)
44   - actionmailer (3.2.1)
45   - actionpack (= 3.2.1)
46   - mail (~> 2.4.0)
47   - actionpack (3.2.1)
48   - activemodel (= 3.2.1)
49   - activesupport (= 3.2.1)
  44 + actionmailer (3.2.3)
  45 + actionpack (= 3.2.3)
  46 + mail (~> 2.4.4)
  47 + actionpack (3.2.3)
  48 + activemodel (= 3.2.3)
  49 + activesupport (= 3.2.3)
50 50 builder (~> 3.0.0)
51 51 erubis (~> 2.7.0)
52 52 journey (~> 1.0.1)
53 53 rack (~> 1.4.0)
54   - rack-cache (~> 1.1)
  54 + rack-cache (~> 1.2)
55 55 rack-test (~> 0.6.1)
56 56 sprockets (~> 2.1.2)
57   - activemodel (3.2.1)
58   - activesupport (= 3.2.1)
  57 + activemodel (3.2.3)
  58 + activesupport (= 3.2.3)
59 59 builder (~> 3.0.0)
60   - activerecord (3.2.1)
61   - activemodel (= 3.2.1)
62   - activesupport (= 3.2.1)
63   - arel (~> 3.0.0)
  60 + activerecord (3.2.3)
  61 + activemodel (= 3.2.3)
  62 + activesupport (= 3.2.3)
  63 + arel (~> 3.0.2)
64 64 tzinfo (~> 0.3.29)
65   - activeresource (3.2.1)
66   - activemodel (= 3.2.1)
67   - activesupport (= 3.2.1)
68   - activesupport (3.2.1)
  65 + activeresource (3.2.3)
  66 + activemodel (= 3.2.3)
  67 + activesupport (= 3.2.3)
  68 + activesupport (3.2.3)
69 69 i18n (~> 0.6)
70 70 multi_json (~> 1.0)
71 71 acts-as-taggable-on (2.1.1)
... ... @@ -73,7 +73,7 @@ GEM
73 73 acts_as_list (0.1.4)
74 74 addressable (2.2.6)
75 75 ansi (1.4.2)
76   - arel (3.0.0)
  76 + arel (3.0.2)
77 77 autotest (4.4.6)
78 78 ZenTest (>= 4.4.1)
79 79 autotest-rails (4.1.1)
... ... @@ -96,13 +96,13 @@ GEM
96 96 childprocess (0.3.1)
97 97 ffi (~> 1.0.6)
98 98 coderay (1.0.5)
99   - coffee-rails (3.2.1)
  99 + coffee-rails (3.2.2)
100 100 coffee-script (>= 2.2.0)
101   - railties (~> 3.2.0.beta)
  101 + railties (~> 3.2.0)
102 102 coffee-script (2.2.0)
103 103 coffee-script-source
104 104 execjs
105   - coffee-script-source (1.2.0)
  105 + coffee-script-source (1.3.1)
106 106 colored (1.2)
107 107 crack (0.3.1)
108 108 daemons (1.1.8)
... ... @@ -138,11 +138,11 @@ GEM
138 138 multi_json
139 139 multi_xml
140 140 i18n (0.6.0)
141   - journey (1.0.1)
  141 + journey (1.0.3)
142 142 jquery-rails (2.0.0)
143 143 railties (>= 3.2.0.beta, < 5.0)
144 144 thor (~> 0.14)
145   - json (1.6.5)
  145 + json (1.6.6)
146 146 kaminari (0.13.0)
147 147 actionpack (>= 3.0.0)
148 148 activesupport (>= 3.0.0)
... ... @@ -153,7 +153,7 @@ GEM
153 153 letter_opener (0.0.2)
154 154 launchy
155 155 libv8 (3.3.10.4)
156   - mail (2.4.1)
  156 + mail (2.4.4)
157 157 i18n (>= 0.4.0)
158 158 mime-types (~> 1.16)
159 159 treetop (~> 1.4.8)
... ... @@ -184,7 +184,7 @@ GEM
184 184 rubypython (~> 0.5.3)
185 185 pyu-ruby-sasl (0.0.3.3)
186 186 rack (1.4.1)
187   - rack-cache (1.1)
  187 + rack-cache (1.2)
188 188 rack (>= 0.4)
189 189 rack-protection (1.2.0)
190 190 rack
... ... @@ -192,19 +192,19 @@ GEM
192 192 rack
193 193 rack-test (0.6.1)
194 194 rack (>= 1.0)
195   - rails (3.2.1)
196   - actionmailer (= 3.2.1)
197   - actionpack (= 3.2.1)
198   - activerecord (= 3.2.1)
199   - activeresource (= 3.2.1)
200   - activesupport (= 3.2.1)
  195 + rails (3.2.3)
  196 + actionmailer (= 3.2.3)
  197 + actionpack (= 3.2.3)
  198 + activerecord (= 3.2.3)
  199 + activeresource (= 3.2.3)
  200 + activesupport (= 3.2.3)
201 201 bundler (~> 1.0)
202   - railties (= 3.2.1)
  202 + railties (= 3.2.3)
203 203 rails-footnotes (3.7.5)
204 204 rails (>= 3.0.0)
205   - railties (3.2.1)
206   - actionpack (= 3.2.1)
207   - activesupport (= 3.2.1)
  205 + railties (3.2.3)
  206 + actionpack (= 3.2.3)
  207 + activesupport (= 3.2.3)
208 208 rack-ssl (~> 1.3.2)
209 209 rake (>= 0.8.7)
210 210 rdoc (~> 3.4)
... ... @@ -288,7 +288,7 @@ GEM
288 288 polyglot (>= 0.3.1)
289 289 turn (0.9.2)
290 290 ansi
291   - tzinfo (0.3.31)
  291 + tzinfo (0.3.33)
292 292 uglifier (1.0.3)
293 293 execjs (>= 0.3.0)
294 294 multi_json (>= 1.0.2)
... ... @@ -320,7 +320,7 @@ DEPENDENCIES
320 320 capybara
321 321 carrierwave
322 322 charlock_holmes
323   - coffee-rails (= 3.2.1)
  323 + coffee-rails (= 3.2.2)
324 324 colored
325 325 database_cleaner
326 326 devise
... ... @@ -343,7 +343,7 @@ DEPENDENCIES
343 343 omniauth-ldap
344 344 pry
345 345 pygments.rb (= 0.2.11)
346   - rails (= 3.2.1)
  346 + rails (= 3.2.3)
347 347 rails-footnotes
348 348 rake
349 349 redcarpet (~> 2.1.1)
... ...
app/assets/stylesheets/gitlab_bootstrap.scss
... ... @@ -465,3 +465,8 @@ table.admin-table {
465 465 background-image: -o-linear-gradient(#eee 6.6%, #dfdfdf);
466 466 }
467 467 }
  468 +
  469 +.field_with_errors {
  470 + display:inline;
  471 +}
  472 +
... ...
app/assets/stylesheets/sections/projects.scss
... ... @@ -32,9 +32,3 @@
32 32 }
33 33 }
34 34 }
35   -
36   -.new_project {
37   - .field_with_errors {
38   - display:inline;
39   - }
40   -}
... ...
app/controllers/hooks_controller.rb
... ... @@ -11,11 +11,8 @@ class HooksController &lt; ApplicationController
11 11 respond_to :html
12 12  
13 13 def index
14   - @hooks = @project.web_hooks
15   - end
16   -
17   - def new
18   - @hook = @project.web_hooks.new
  14 + @hooks = @project.web_hooks.all
  15 + @hook = WebHook.new
19 16 end
20 17  
21 18 def create
... ... @@ -23,25 +20,22 @@ class HooksController &lt; ApplicationController
23 20 @hook.save
24 21  
25 22 if @hook.valid?
26   - redirect_to project_hook_path(@project, @hook)
  23 + redirect_to project_hooks_path(@project)
27 24 else
28   - render :new
  25 + @hooks = @project.web_hooks.all
  26 + render :index
29 27 end
30 28 end
31 29  
32 30 def test
33 31 @hook = @project.web_hooks.find(params[:id])
34 32 commits = @project.commits(@project.default_branch, nil, 3)
35   - data = @project.web_hook_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user.keys.first.identifier)
  33 + data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
36 34 @hook.execute(data)
37 35  
38 36 redirect_to :back
39 37 end
40 38  
41   - def show
42   - @hook = @project.web_hooks.find(params[:id])
43   - end
44   -
45 39 def destroy
46 40 @hook = @project.web_hooks.find(params[:id])
47 41 @hook.destroy
... ...
app/views/hooks/index.html.haml
1 1 = render "projects/project_head"
2 2  
3 3 - if can? current_user, :admin_project, @project
4   - .alert-message.block-message
5   - Post receive hooks for binding events when someone push to repository.
6   - = link_to new_project_hook_path(@project), :class => "btn small", :title => "New Web Hook" do
7   - Add Post Receive Hook
  4 + .alert.alert-info
  5 + %span
  6 + Post receive hooks for binding events when someone push to repository.
  7 + %br
  8 + Read more about web hooks
  9 + %strong #{link_to "here", help_web_hooks_path, :class => "vlink"}
8 10  
9   - %p Read more about web hooks #{link_to "here", help_web_hooks_path, :class => "vlink"}
  11 += form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f|
  12 + -if @hook.errors.any?
  13 + .alert-message.block-message.error
  14 + - @hook.errors.full_messages.each do |msg|
  15 + %p= msg
  16 + .clearfix
  17 + = f.label :url, "URL:"
  18 + .input
  19 + = f.text_field :url, :class => "text_field xxlarge"
  20 + &nbsp;
  21 + = f.submit "Add Web Hook", :class => "btn primary"
  22 +%hr
10 23  
11 24 -if @hooks.any?
12   - %table
  25 + %h3
  26 + Hooks
  27 + %small (#{@hooks.count})
  28 + %br
  29 + %table.admin-table
  30 + %tr
  31 + %th URL
  32 + %th Method
  33 + %th
13 34 - @hooks.each do |hook|
14 35 %tr
15 36 %td
16 37 = link_to project_hook_path(@project, hook) do
17   - = hook.url
  38 + %strong= hook.url
  39 + = link_to 'Test Hook', test_project_hook_path(@project, hook), :class => "btn small right"
  40 + %td POST
18 41 %td
19 42 = link_to 'Remove', project_hook_path(@project, hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn small right"
  43 +
... ...
app/views/hooks/new.html.haml
... ... @@ -1,12 +0,0 @@
1   -= render "repositories/head"
2   -= form_for [@project, @hook], :as => :hook, :url => project_hooks_path(@project) do |f|
3   - -if @hook.errors.any?
4   - %ul
5   - - @hook.errors.full_messages.each do |msg|
6   - %li= msg
7   - .clearfix
8   - = f.label :url, "URL:"
9   - .input= f.text_field :url, :class => "text_field"
10   - .actions
11   - = f.submit "Save", :class => "btn"
12   -
app/views/hooks/show.html.haml
... ... @@ -1,7 +0,0 @@
1   -= render "repositories/head"
2   -%pre= @hook.url
3   -
4   -- if can? current_user, :admin_project, @project
5   - .actions
6   - = link_to 'Test Hook', test_project_hook_path(@project, @hook), :class => "btn"
7   - = link_to 'Remove', project_hook_path(@project, @hook), :confirm => 'Are you sure?', :method => :delete, :class => "danger btn"
config/routes.rb
... ... @@ -111,7 +111,7 @@ Gitlab::Application.routes.draw do
111 111 end
112 112  
113 113 resources :snippets
114   - resources :hooks, :only => [:index, :new, :create, :destroy, :show] do
  114 + resources :hooks, :only => [:index, :create, :destroy] do
115 115 member do
116 116 get :test
117 117 end
... ...
spec/requests/hooks_spec.rb 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "Hooks" do
  4 + before do
  5 + login_as :user
  6 + @project = Factory :project
  7 + @project.add_access(@user, :read, :admin)
  8 + end
  9 +
  10 + describe "GET index" do
  11 + it "should be available" do
  12 + @hook = Factory :web_hook, :project => @project
  13 + visit project_hooks_path(@project)
  14 + page.should have_content "Hooks"
  15 + page.should have_content @hook.url
  16 + end
  17 + end
  18 +
  19 + describe "New Hook" do
  20 + before do
  21 + @url = Faker::Internet.url
  22 + visit project_hooks_path(@project)
  23 + fill_in "hook_url", :with => @url
  24 + expect { click_button "Add Web Hook" }.to change(WebHook, :count).by(1)
  25 + end
  26 +
  27 + it "should open new team member popup" do
  28 + page.current_path.should == project_hooks_path(@project)
  29 + page.should have_content(@url)
  30 + end
  31 + end
  32 +
  33 + describe "Test" do
  34 + before do
  35 + @hook = Factory :web_hook, :project => @project
  36 + visit project_hooks_path(@project)
  37 + click_link "Test Hook"
  38 + end
  39 +
  40 + it { page.current_path.should == project_hooks_path(@project) }
  41 + end
  42 +end
... ...