Commit 6523e5b903d609d72406395b5fb47b97b13ba02c
1 parent
d0894cbe
Exists in
master
and in
1 other branch
[WIP] refactor the problems_controller
Extract the filter `find_problem` in decent_exposure to get this problem
Showing
7 changed files
with
65 additions
and
50 deletions
Show diff stats
app/controllers/problems_controller.rb
| @@ -6,7 +6,6 @@ | @@ -6,7 +6,6 @@ | ||
| 6 | # COLLECTION => :index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search | 6 | # COLLECTION => :index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search |
| 7 | class ProblemsController < ApplicationController | 7 | class ProblemsController < ApplicationController |
| 8 | 8 | ||
| 9 | - before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search] | ||
| 10 | before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] | 9 | before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several] |
| 11 | before_filter :set_sorting_params, :only => [:index, :all, :search] | 10 | before_filter :set_sorting_params, :only => [:index, :all, :search] |
| 12 | before_filter :set_tracker_params, :only => [:create_issue] | 11 | before_filter :set_tracker_params, :only => [:create_issue] |
| @@ -18,6 +17,9 @@ class ProblemsController < ApplicationController | @@ -18,6 +17,9 @@ class ProblemsController < ApplicationController | ||
| 18 | current_user.apps.find(params[:app_id]) | 17 | current_user.apps.find(params[:app_id]) |
| 19 | end | 18 | end |
| 20 | } | 19 | } |
| 20 | + expose(:problem) { | ||
| 21 | + app.problems.find(params[:id]) | ||
| 22 | + } | ||
| 21 | 23 | ||
| 22 | def index | 24 | def index |
| 23 | app_scope = current_user.admin? ? App.all : current_user.apps | 25 | app_scope = current_user.admin? ? App.all : current_user.apps |
| @@ -33,28 +35,28 @@ class ProblemsController < ApplicationController | @@ -33,28 +35,28 @@ class ProblemsController < ApplicationController | ||
| 33 | end | 35 | end |
| 34 | 36 | ||
| 35 | def show | 37 | def show |
| 36 | - @notices = @problem.notices.reverse_ordered.page(params[:notice]).per(1) | 38 | + @notices = problem.notices.reverse_ordered.page(params[:notice]).per(1) |
| 37 | @notice = @notices.first | 39 | @notice = @notices.first |
| 38 | @comment = Comment.new | 40 | @comment = Comment.new |
| 39 | end | 41 | end |
| 40 | 42 | ||
| 41 | def create_issue | 43 | def create_issue |
| 42 | - issue_creation = IssueCreation.new(@problem, current_user, params[:tracker]) | 44 | + issue_creation = IssueCreation.new(problem, current_user, params[:tracker]) |
| 43 | 45 | ||
| 44 | unless issue_creation.execute | 46 | unless issue_creation.execute |
| 45 | flash[:error] = issue_creation.errors[:base].first | 47 | flash[:error] = issue_creation.errors[:base].first |
| 46 | end | 48 | end |
| 47 | 49 | ||
| 48 | - redirect_to app_problem_path(app, @problem) | 50 | + redirect_to app_problem_path(app, problem) |
| 49 | end | 51 | end |
| 50 | 52 | ||
| 51 | def unlink_issue | 53 | def unlink_issue |
| 52 | - @problem.update_attribute :issue_link, nil | ||
| 53 | - redirect_to app_problem_path(app, @problem) | 54 | + problem.update_attribute :issue_link, nil |
| 55 | + redirect_to app_problem_path(app, problem) | ||
| 54 | end | 56 | end |
| 55 | 57 | ||
| 56 | def resolve | 58 | def resolve |
| 57 | - @problem.resolve! | 59 | + problem.resolve! |
| 58 | flash[:success] = 'Great news everyone! The err has been resolved.' | 60 | flash[:success] = 'Great news everyone! The err has been resolved.' |
| 59 | redirect_to :back | 61 | redirect_to :back |
| 60 | rescue ActionController::RedirectBackError | 62 | rescue ActionController::RedirectBackError |
| @@ -109,10 +111,6 @@ class ProblemsController < ApplicationController | @@ -109,10 +111,6 @@ class ProblemsController < ApplicationController | ||
| 109 | 111 | ||
| 110 | protected | 112 | protected |
| 111 | 113 | ||
| 112 | - def find_problem | ||
| 113 | - @problem = app.problems.find(params[:id]) | ||
| 114 | - end | ||
| 115 | - | ||
| 116 | def set_tracker_params | 114 | def set_tracker_params |
| 117 | IssueTracker.default_url_options[:host] = request.host | 115 | IssueTracker.default_url_options[:host] = request.host |
| 118 | IssueTracker.default_url_options[:port] = request.port | 116 | IssueTracker.default_url_options[:port] = request.port |
app/views/problems/_issue_tracker_links.html.haml
| 1 | - if app.issue_tracker_configured? || current_user.github_account? | 1 | - if app.issue_tracker_configured? || current_user.github_account? |
| 2 | - - if @problem.issue_link.present? | ||
| 3 | - %span= link_to 'go to issue', @problem.issue_link, :class => "#{@problem.issue_type}_goto goto-issue" | ||
| 4 | - = link_to 'unlink issue', unlink_issue_app_problem_path(app, @problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue" | ||
| 5 | - - elsif @problem.issue_link == "pending" | ||
| 6 | - %span.disabled= link_to 'creating...', '#', :class => "#{@problem.issue_type}_inactive create-issue" | ||
| 7 | - = link_to 'retry', create_issue_app_problem_path(app, @problem), :method => :post | 2 | + - if problem.issue_link.present? |
| 3 | + %span= link_to 'go to issue', problem.issue_link, :class => "#{problem.issue_type}_goto goto-issue" | ||
| 4 | + = link_to 'unlink issue', unlink_issue_app_problem_path(app, problem), :method => :delete, :data => { :confirm => "Unlink err issues?" }, :class => "unlink-issue" | ||
| 5 | + - elsif problem.issue_link == "pending" | ||
| 6 | + %span.disabled= link_to 'creating...', '#', :class => "#{problem.issue_type}_inactive create-issue" | ||
| 7 | + = link_to 'retry', create_issue_app_problem_path(app, problem), :method => :post | ||
| 8 | - else | 8 | - else |
| 9 | - if app.github_repo? | 9 | - if app.github_repo? |
| 10 | - if current_user.can_create_github_issues? | 10 | - if current_user.can_create_github_issues? |
| 11 | - %span= link_to 'create issue', create_issue_app_problem_path(app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue" | 11 | + %span= link_to 'create issue', create_issue_app_problem_path(app, problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue" |
| 12 | - elsif app.issue_tracker_configured? && app.issue_tracker.label.eql?('github') | 12 | - elsif app.issue_tracker_configured? && app.issue_tracker.label.eql?('github') |
| 13 | - %span= link_to 'create issue', create_issue_app_problem_path(app, @problem), :method => :post, :class => "github_create create-issue" | 13 | + %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "github_create create-issue" |
| 14 | - if app.issue_tracker_configured? && !app.issue_tracker.label.eql?('github') | 14 | - if app.issue_tracker_configured? && !app.issue_tracker.label.eql?('github') |
| 15 | - %span= link_to 'create issue', create_issue_app_problem_path(app, @problem), :method => :post, :class => "#{app.issue_tracker.label}_create create-issue" | 15 | + %span= link_to 'create issue', create_issue_app_problem_path(app, problem), :method => :post, :class => "#{app.issue_tracker.label}_create create-issue" |
app/views/problems/show.html.haml
| 1 | -- content_for :page_title, @problem.message | 1 | +- content_for :page_title, problem.message |
| 2 | - content_for :title_css_class, 'err_show' | 2 | - content_for :title_css_class, 'err_show' |
| 3 | -- content_for :title, @problem.error_class || truncate(@problem.message, :length => 32) | 3 | +- content_for :title, problem.error_class || truncate(problem.message, :length => 32) |
| 4 | - content_for :meta do | 4 | - content_for :meta do |
| 5 | %strong App: | 5 | %strong App: |
| 6 | = link_to app.name, app | 6 | = link_to app.name, app |
| 7 | %strong Where: | 7 | %strong Where: |
| 8 | - = @problem.where | 8 | + = problem.where |
| 9 | %br | 9 | %br |
| 10 | %strong Environment: | 10 | %strong Environment: |
| 11 | - = @problem.environment | 11 | + = problem.environment |
| 12 | %strong Last Notice: | 12 | %strong Last Notice: |
| 13 | - = @problem.last_notice_at.to_s(:precise) | 13 | + = problem.last_notice_at.to_s(:precise) |
| 14 | - content_for :action_bar do | 14 | - content_for :action_bar do |
| 15 | - - if @problem.unresolved? | ||
| 16 | - %span= link_to 'resolve', [:resolve, app, @problem], :method => :put, :data => { :confirm => problem_confirm }, :class => 'resolve' | 15 | + - if problem.unresolved? |
| 16 | + %span= link_to 'resolve', [:resolve, app, problem], :method => :put, :data => { :confirm => problem_confirm }, :class => 'resolve' | ||
| 17 | - if current_user.authentication_token | 17 | - if current_user.authentication_token |
| 18 | - %span= link_to 'iCal', polymorphic_path([app, @problem], :format => "ics", :auth_token => current_user.authentication_token), :class => "calendar_link" | 18 | + %span= link_to 'iCal', polymorphic_path([app, problem], :format => "ics", :auth_token => current_user.authentication_token), :class => "calendar_link" |
| 19 | %span>= link_to 'up', (request.env['HTTP_REFERER'] ? :back : app_problems_path(app)), :class => 'up' | 19 | %span>= link_to 'up', (request.env['HTTP_REFERER'] ? :back : app_problems_path(app)), :class => 'up' |
| 20 | %br | 20 | %br |
| 21 | = render "issue_tracker_links" | 21 | = render "issue_tracker_links" |
| 22 | 22 | ||
| 23 | -- if @problem.comments_allowed? || @problem.comments.any? | 23 | +- if problem.comments_allowed? || problem.comments.any? |
| 24 | - content_for :comments do | 24 | - content_for :comments do |
| 25 | %h3 Comments | 25 | %h3 Comments |
| 26 | - - @problem.comments.each do |comment| | 26 | + - problem.comments.each do |comment| |
| 27 | .window | 27 | .window |
| 28 | %table.comment | 28 | %table.comment |
| 29 | %tr | 29 | %tr |
| @@ -37,11 +37,11 @@ | @@ -37,11 +37,11 @@ | ||
| 37 | - else | 37 | - else |
| 38 | %span.comment-info | 38 | %span.comment-info |
| 39 | = time_ago_in_words(comment.created_at, true) << " ago by [Unknown User]" | 39 | = time_ago_in_words(comment.created_at, true) << " ago by [Unknown User]" |
| 40 | - %span.delete= link_to '✘'.html_safe, [app, @problem, comment], :method => :delete, :data => { :confirm => "Are you sure you don't need this comment?" }, :class => "destroy-comment" | 40 | + %span.delete= link_to '✘'.html_safe, [app, problem, comment], :method => :delete, :data => { :confirm => "Are you sure you don't need this comment?" }, :class => "destroy-comment" |
| 41 | %tr | 41 | %tr |
| 42 | %td= simple_format comment.body | 42 | %td= simple_format comment.body |
| 43 | - - if @problem.comments_allowed? | ||
| 44 | - = form_for [app, @problem, @comment] do |comment_form| | 43 | + - if problem.comments_allowed? |
| 44 | + = form_for [app, problem, @comment] do |comment_form| | ||
| 45 | %p Add a comment | 45 | %p Add a comment |
| 46 | = comment_form.text_area :body | 46 | = comment_form.text_area :body |
| 47 | = comment_form.submit "Save Comment" | 47 | = comment_form.submit "Save Comment" |
| @@ -63,7 +63,7 @@ | @@ -63,7 +63,7 @@ | ||
| 63 | - if @notice | 63 | - if @notice |
| 64 | #summary | 64 | #summary |
| 65 | %h3 Summary | 65 | %h3 Summary |
| 66 | - = render 'notices/summary', :notice => @notice, :problem => @problem | 66 | + = render 'notices/summary', :notice => @notice |
| 67 | 67 | ||
| 68 | #backtrace | 68 | #backtrace |
| 69 | %h3 Backtrace | 69 | %h3 Backtrace |
app/views/problems/show.ics.haml
spec/controllers/problems_controller_spec.rb
| @@ -138,7 +138,7 @@ describe ProblemsController do | @@ -138,7 +138,7 @@ describe ProblemsController do | ||
| 138 | 138 | ||
| 139 | it "finds the problem" do | 139 | it "finds the problem" do |
| 140 | get :show, :app_id => app.id, :id => err.problem.id | 140 | get :show, :app_id => app.id, :id => err.problem.id |
| 141 | - assigns(:problem).should == err.problem | 141 | + controller.problem.should == err.problem |
| 142 | end | 142 | end |
| 143 | 143 | ||
| 144 | it "successfully render page" do | 144 | it "successfully render page" do |
| @@ -179,7 +179,7 @@ describe ProblemsController do | @@ -179,7 +179,7 @@ describe ProblemsController do | ||
| 179 | 179 | ||
| 180 | it 'finds the problem if the user is watching the app' do | 180 | it 'finds the problem if the user is watching the app' do |
| 181 | get :show, :app_id => @watched_app.to_param, :id => @watched_err.problem.id | 181 | get :show, :app_id => @watched_app.to_param, :id => @watched_err.problem.id |
| 182 | - assigns(:problem).should == @watched_err.problem | 182 | + controller.problem.should == @watched_err.problem |
| 183 | end | 183 | end |
| 184 | 184 | ||
| 185 | it 'raises a DocumentNotFound error if the user is not watching the app' do | 185 | it 'raises a DocumentNotFound error if the user is not watching the app' do |
| @@ -205,7 +205,7 @@ describe ProblemsController do | @@ -205,7 +205,7 @@ describe ProblemsController do | ||
| 205 | @problem.app.problems.should_receive(:find).and_return(@problem.problem) | 205 | @problem.app.problems.should_receive(:find).and_return(@problem.problem) |
| 206 | put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id | 206 | put :resolve, :app_id => @problem.app.id, :id => @problem.problem.id |
| 207 | controller.app.should == @problem.app | 207 | controller.app.should == @problem.app |
| 208 | - assigns(:problem).should == @problem.problem | 208 | + controller.problem.should == @problem.problem |
| 209 | end | 209 | end |
| 210 | 210 | ||
| 211 | it "should resolve the issue" do | 211 | it "should resolve the issue" do |
spec/views/problems/show.html.haml_spec.rb
| 1 | require 'spec_helper' | 1 | require 'spec_helper' |
| 2 | 2 | ||
| 3 | describe "problems/show.html.haml" do | 3 | describe "problems/show.html.haml" do |
| 4 | + let(:problem) { Fabricate(:problem) } | ||
| 5 | + let(:comment) { Fabricate(:comment) } | ||
| 6 | + | ||
| 4 | before do | 7 | before do |
| 5 | - problem = Fabricate(:problem) | ||
| 6 | - comment = Fabricate(:comment) | ||
| 7 | - assign :problem, problem | ||
| 8 | - assign :comment, comment | ||
| 9 | view.stub(:app).and_return(problem.app) | 8 | view.stub(:app).and_return(problem.app) |
| 9 | + view.stub(:problem).and_return(problem) | ||
| 10 | + | ||
| 11 | + assign :comment, comment | ||
| 10 | assign :notices, problem.notices.page(1).per(1) | 12 | assign :notices, problem.notices.page(1).per(1) |
| 11 | assign :notice, problem.notices.first | 13 | assign :notice, problem.notices.first |
| 14 | + | ||
| 12 | controller.stub(:current_user) { Fabricate(:user) } | 15 | controller.stub(:current_user) { Fabricate(:user) } |
| 13 | end | 16 | end |
| 14 | 17 | ||
| 15 | def with_issue_tracker(tracker, problem) | 18 | def with_issue_tracker(tracker, problem) |
| 16 | problem.app.issue_tracker = tracker.new :api_token => "token token token", :project_id => "1234" | 19 | problem.app.issue_tracker = tracker.new :api_token => "token token token", :project_id => "1234" |
| 17 | - assign :problem, problem | 20 | + view.stub(:problem).and_return(problem) |
| 18 | view.stub(:app).and_return(problem.app) | 21 | view.stub(:app).and_return(problem.app) |
| 19 | end | 22 | end |
| 20 | 23 | ||
| @@ -54,7 +57,7 @@ describe "problems/show.html.haml" do | @@ -54,7 +57,7 @@ describe "problems/show.html.haml" do | ||
| 54 | it "should link 'up' to app_problems_path if HTTP_REFERER isn't set'" do | 57 | it "should link 'up' to app_problems_path if HTTP_REFERER isn't set'" do |
| 55 | controller.request.env['HTTP_REFERER'] = nil | 58 | controller.request.env['HTTP_REFERER'] = nil |
| 56 | problem = Fabricate(:problem_with_comments) | 59 | problem = Fabricate(:problem_with_comments) |
| 57 | - assign :problem, problem | 60 | + view.stub(:problem).and_return(problem) |
| 58 | view.stub(:app).and_return(problem.app) | 61 | view.stub(:app).and_return(problem.app) |
| 59 | render | 62 | render |
| 60 | 63 | ||
| @@ -67,7 +70,7 @@ describe "problems/show.html.haml" do | @@ -67,7 +70,7 @@ describe "problems/show.html.haml" do | ||
| 67 | controller.stub(:current_user) { user } | 70 | controller.stub(:current_user) { user } |
| 68 | 71 | ||
| 69 | problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) | 72 | problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) |
| 70 | - assign :problem, problem | 73 | + view.stub(:problem).and_return(problem) |
| 71 | view.stub(:app).and_return(problem.app) | 74 | view.stub(:app).and_return(problem.app) |
| 72 | render | 75 | render |
| 73 | 76 | ||
| @@ -77,7 +80,7 @@ describe "problems/show.html.haml" do | @@ -77,7 +80,7 @@ describe "problems/show.html.haml" do | ||
| 77 | it 'should allow creating issue for github if application has a github tracker' do | 80 | it 'should allow creating issue for github if application has a github tracker' do |
| 78 | problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) | 81 | problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo")) |
| 79 | with_issue_tracker(GithubIssuesTracker, problem) | 82 | with_issue_tracker(GithubIssuesTracker, problem) |
| 80 | - assign :problem, problem | 83 | + view.stub(:problem).and_return(problem) |
| 81 | view.stub(:app).and_return(problem.app) | 84 | view.stub(:app).and_return(problem.app) |
| 82 | render | 85 | render |
| 83 | 86 | ||
| @@ -89,7 +92,7 @@ describe "problems/show.html.haml" do | @@ -89,7 +92,7 @@ describe "problems/show.html.haml" do | ||
| 89 | let(:app) { App.new(:new_record => false) } | 92 | let(:app) { App.new(:new_record => false) } |
| 90 | 93 | ||
| 91 | it 'not see link to create issue' do | 94 | it 'not see link to create issue' do |
| 92 | - assign :problem, problem | 95 | + view.stub(:problem).and_return(problem) |
| 93 | view.stub(:app).and_return(problem.app) | 96 | view.stub(:app).and_return(problem.app) |
| 94 | render | 97 | render |
| 95 | expect(view.content_for(:action_bar)).to_not match(/create issue/) | 98 | expect(view.content_for(:action_bar)).to_not match(/create issue/) |
| @@ -105,7 +108,7 @@ describe "problems/show.html.haml" do | @@ -105,7 +108,7 @@ describe "problems/show.html.haml" do | ||
| 105 | context "with problem without issue link" do | 108 | context "with problem without issue link" do |
| 106 | let(:problem){ Problem.new(:new_record => false, :app => app) } | 109 | let(:problem){ Problem.new(:new_record => false, :app => app) } |
| 107 | it 'not see link if no issue tracker' do | 110 | it 'not see link if no issue tracker' do |
| 108 | - assign :problem, problem | 111 | + view.stub(:problem).and_return(problem) |
| 109 | view.stub(:app).and_return(problem.app) | 112 | view.stub(:app).and_return(problem.app) |
| 110 | render | 113 | render |
| 111 | expect(view.content_for(:action_bar)).to match(/create issue/) | 114 | expect(view.content_for(:action_bar)).to match(/create issue/) |
| @@ -117,7 +120,7 @@ describe "problems/show.html.haml" do | @@ -117,7 +120,7 @@ describe "problems/show.html.haml" do | ||
| 117 | let(:problem){ Problem.new(:new_record => false, :app => app, :issue_link => 'http://foo') } | 120 | let(:problem){ Problem.new(:new_record => false, :app => app, :issue_link => 'http://foo') } |
| 118 | 121 | ||
| 119 | it 'not see link if no issue tracker' do | 122 | it 'not see link if no issue tracker' do |
| 120 | - assign :problem, problem | 123 | + view.stub(:problem).and_return(problem) |
| 121 | view.stub(:app).and_return(problem.app) | 124 | view.stub(:app).and_return(problem.app) |
| 122 | render | 125 | render |
| 123 | expect(view.content_for(:action_bar)).to_not match(/create issue/) | 126 | expect(view.content_for(:action_bar)).to_not match(/create issue/) |
| @@ -136,7 +139,7 @@ describe "problems/show.html.haml" do | @@ -136,7 +139,7 @@ describe "problems/show.html.haml" do | ||
| 136 | 139 | ||
| 137 | it 'should display comments and new comment form when no issue tracker' do | 140 | it 'should display comments and new comment form when no issue tracker' do |
| 138 | problem = Fabricate(:problem_with_comments) | 141 | problem = Fabricate(:problem_with_comments) |
| 139 | - assign :problem, problem | 142 | + view.stub(:problem).and_return(problem) |
| 140 | view.stub(:app).and_return(problem.app) | 143 | view.stub(:app).and_return(problem.app) |
| 141 | render | 144 | render |
| 142 | 145 |
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe "problems/show.html.ics" do | ||
| 4 | + let(:problem) { Fabricate(:problem) } | ||
| 5 | + before do | ||
| 6 | + view.stub(:problem).and_return(problem) | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + it 'should work' do | ||
| 10 | + render :template => 'problems/show.ics.haml' | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +end |