Commit 25a79373f6e08a1e259e78db3075870e3f9c4398
1 parent
6b24a989
Exists in
master
and in
1 other branch
Add errs#resolve
Showing
6 changed files
with
72 additions
and
3 deletions
Show diff stats
app/controllers/errs_controller.rb
| ... | ... | @@ -11,4 +11,17 @@ class ErrsController < ApplicationController |
| 11 | 11 | @notice = @notices.first |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | + def resolve | |
| 15 | + @project = Project.find(params[:project_id]) | |
| 16 | + @err = @project.errs.unresolved.find(params[:id]) | |
| 17 | + | |
| 18 | + # Deal with bug in mogoid where find is returning an Enumberable obj | |
| 19 | + @err = @err.first if @err.respond_to?(:first) | |
| 20 | + | |
| 21 | + @err.resolve! | |
| 22 | + | |
| 23 | + flash[:success] = 'Great news everyone! The error has been resolved.' | |
| 24 | + redirect_to errs_path | |
| 25 | + end | |
| 26 | + | |
| 14 | 27 | end | ... | ... |
app/models/err.rb
app/views/errs/show.html.haml
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | .float-left viewing occurrence #{@notices.current_page} of #{@notices.total_pages} |
| 14 | 14 | = link_to "back to '#{@project.name}'", project_path(@project) |
| 15 | 15 | | |
| 16 | - = link_to 'resolve', '#' if @err.unresolved? | |
| 16 | + = link_to 'resolve', resolve_project_err_path(@project, @err), :method => :put, :confirm => 'Seriously?' if @err.unresolved? | |
| 17 | 17 | |
| 18 | 18 | %h3#summary Summary |
| 19 | 19 | = render 'notices/summary', :notice => @notice | ... | ... |
config/routes.rb
spec/controllers/errs_controller_spec.rb
| ... | ... | @@ -17,7 +17,7 @@ describe ErrsController do |
| 17 | 17 | end |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | - describe "GET /errs/:id" do | |
| 20 | + describe "GET /projects/:project_id/errs/:id" do | |
| 21 | 21 | before do |
| 22 | 22 | 3.times { Factory(:notice, :err => err)} |
| 23 | 23 | end |
| ... | ... | @@ -42,4 +42,38 @@ describe ErrsController do |
| 42 | 42 | end |
| 43 | 43 | end |
| 44 | 44 | |
| 45 | + describe "PUT /projects/:project_id/errs/:id/resolve" do | |
| 46 | + before do | |
| 47 | + @err = Factory(:err) | |
| 48 | + Project.stub(:find).with(@err.project.id).and_return(@err.project) | |
| 49 | + @err.project.errs.stub(:unresolved). | |
| 50 | + and_return(stub('proxy', :find => @err)) | |
| 51 | + @err.stub(:resolve!) | |
| 52 | + end | |
| 53 | + | |
| 54 | + it 'finds the project and the err' do | |
| 55 | + Project.should_receive(:find).with(@err.project.id).and_return(@err.project) | |
| 56 | + @err.project.errs.should_receive(:unresolved). | |
| 57 | + and_return(mock('proxy', :find => @err)) | |
| 58 | + put :resolve, :project_id => @err.project.id, :id => @err.id | |
| 59 | + assigns(:project).should == @err.project | |
| 60 | + assigns(:err).should == @err | |
| 61 | + end | |
| 62 | + | |
| 63 | + it "should resolve the issue" do | |
| 64 | + @err.should_receive(:resolve!).and_return(true) | |
| 65 | + put :resolve, :project_id => @err.project.id, :id => @err.id | |
| 66 | + end | |
| 67 | + | |
| 68 | + it "should display a message" do | |
| 69 | + put :resolve, :project_id => @err.project.id, :id => @err.id | |
| 70 | + request.flash[:success].should match(/Great news/) | |
| 71 | + end | |
| 72 | + | |
| 73 | + it "should redirect do the errs page" do | |
| 74 | + put :resolve, :project_id => @err.project.id, :id => @err.id | |
| 75 | + response.should redirect_to(errs_path) | |
| 76 | + end | |
| 77 | + end | |
| 78 | + | |
| 45 | 79 | end | ... | ... |
spec/models/err_spec.rb
| ... | ... | @@ -82,6 +82,25 @@ describe Err do |
| 82 | 82 | end |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | + context "resolve!" do | |
| 86 | + it "marks the error as resolved" do | |
| 87 | + err = Factory(:err) | |
| 88 | + err.should_not be_resolved | |
| 89 | + err.resolve! | |
| 90 | + err.should be_resolved | |
| 91 | + end | |
| 92 | + | |
| 93 | + it "should throw an error if it's not successful" do | |
| 94 | + err = Factory(:err) | |
| 95 | + err.should_not be_resolved | |
| 96 | + err.klass = nil | |
| 97 | + err.should_not be_valid | |
| 98 | + lambda { | |
| 99 | + err.resolve! | |
| 100 | + }.should raise_error(Mongoid::Errors::Validations) | |
| 101 | + end | |
| 102 | + end | |
| 103 | + | |
| 85 | 104 | context "Scopes" do |
| 86 | 105 | context "resolved" do |
| 87 | 106 | it 'only finds resolved Errors' do | ... | ... |