Commit 6aec6f2e2186ab83af8ee832ea3d5c70f110a48b
1 parent
25a79373
Exists in
master
and in
1 other branch
Add a flag that will cause deploys to resolve all errs for the given project
Showing
5 changed files
with
33 additions
and
0 deletions
Show diff stats
app/models/deploy.rb
| @@ -10,6 +10,7 @@ class Deploy | @@ -10,6 +10,7 @@ class Deploy | ||
| 10 | embedded_in :project, :inverse_of => :deploys | 10 | embedded_in :project, :inverse_of => :deploys |
| 11 | 11 | ||
| 12 | after_create :deliver_notification, :if => :should_notify? | 12 | after_create :deliver_notification, :if => :should_notify? |
| 13 | + after_create :resolve_project_errs, :if => :should_resolve_project_errs? | ||
| 13 | 14 | ||
| 14 | validates_presence_of :username, :environment | 15 | validates_presence_of :username, :environment |
| 15 | 16 | ||
| @@ -17,10 +18,18 @@ class Deploy | @@ -17,10 +18,18 @@ class Deploy | ||
| 17 | Mailer.deploy_notification(self).deliver | 18 | Mailer.deploy_notification(self).deliver |
| 18 | end | 19 | end |
| 19 | 20 | ||
| 21 | + def resolve_project_errs | ||
| 22 | + project.errs.unresolved.each {|err| err.resolve!} | ||
| 23 | + end | ||
| 24 | + | ||
| 20 | protected | 25 | protected |
| 21 | 26 | ||
| 22 | def should_notify? | 27 | def should_notify? |
| 23 | project.watchers.any? | 28 | project.watchers.any? |
| 24 | end | 29 | end |
| 30 | + | ||
| 31 | + def should_resolve_project_errs? | ||
| 32 | + project.resolve_errs_on_deploy? | ||
| 33 | + end | ||
| 25 | 34 | ||
| 26 | end | 35 | end |
app/models/project.rb
| @@ -4,6 +4,7 @@ class Project | @@ -4,6 +4,7 @@ class Project | ||
| 4 | 4 | ||
| 5 | field :name, :type => String | 5 | field :name, :type => String |
| 6 | field :api_key | 6 | field :api_key |
| 7 | + field :resolve_errs_on_deploy, :type => Boolean, :default => false | ||
| 7 | key :name | 8 | key :name |
| 8 | 9 | ||
| 9 | embeds_many :watchers | 10 | embeds_many :watchers |
app/views/projects/_fields.html.haml
| @@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
| 2 | = f.label :name | 2 | = f.label :name |
| 3 | = f.text_field :name | 3 | = f.text_field :name |
| 4 | 4 | ||
| 5 | +%div.checkbox | ||
| 6 | + = f.check_box :resolve_errs_on_deploy | ||
| 7 | + = f.label :resolve_errs_on_deploy, 'Resolve errors on deploy' | ||
| 8 | + | ||
| 5 | %fieldset.nested-wrapper | 9 | %fieldset.nested-wrapper |
| 6 | %legend Watchers | 10 | %legend Watchers |
| 7 | - f.fields_for :watchers do |w| | 11 | - f.fields_for :watchers do |w| |
public/stylesheets/application.css
| @@ -122,6 +122,7 @@ form label { | @@ -122,6 +122,7 @@ form label { | ||
| 122 | display: block; | 122 | display: block; |
| 123 | } | 123 | } |
| 124 | form label.inline { display: inline; } | 124 | form label.inline { display: inline; } |
| 125 | +form .checkbox label { display: inline; } | ||
| 125 | form .required label { color: #BF3838;} | 126 | form .required label { color: #BF3838;} |
| 126 | form input[type=text], form input[type=password] { | 127 | form input[type=text], form input[type=password] { |
| 127 | width: 96%; padding: 0.8em; | 128 | width: 96%; padding: 0.8em; |
spec/models/deploy_spec.rb
| @@ -22,6 +22,24 @@ describe Deploy do | @@ -22,6 +22,24 @@ describe Deploy do | ||
| 22 | and_return(mock('email', :deliver => true)) | 22 | and_return(mock('email', :deliver => true)) |
| 23 | Factory(:deploy, :project => Factory(:project_with_watcher)) | 23 | Factory(:deploy, :project => Factory(:project_with_watcher)) |
| 24 | end | 24 | end |
| 25 | + | ||
| 26 | + context 'when the project has resolve_errs_on_deploy set to false' do | ||
| 27 | + it 'should not resolve the projects errs' do | ||
| 28 | + project = Factory(:project, :resolve_errs_on_deploy => false) | ||
| 29 | + @errs = 3.times.inject([]) {|errs,_| errs << Factory(:err, :resolved => false, :project => project)} | ||
| 30 | + Factory(:deploy, :project => project) | ||
| 31 | + project.reload.errs.none?{|err| err.resolved?}.should == true | ||
| 32 | + end | ||
| 33 | + end | ||
| 34 | + | ||
| 35 | + context 'when the project has resolve_errs_on_deploy set to true' do | ||
| 36 | + it 'should not resolve the projects errs' do | ||
| 37 | + project = Factory(:project, :resolve_errs_on_deploy => true) | ||
| 38 | + @errs = 3.times.inject([]) {|errs,_| errs << Factory(:err, :resolved => false, :project => project)} | ||
| 39 | + Factory(:deploy, :project => project) | ||
| 40 | + project.reload.errs.all?{|err| err.resolved?}.should == true | ||
| 41 | + end | ||
| 42 | + end | ||
| 25 | end | 43 | end |
| 26 | 44 | ||
| 27 | end | 45 | end |