From c22ad2ce072127bccfc27b5b9ee2edfee4668dc7 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Sat, 27 Dec 2014 23:23:00 -0500 Subject: [PATCH] Render issue body --- app/controllers/problems_controller.rb | 3 +-- app/views/issue_trackers/issue.txt.erb | 45 +++++++++++++++++++++++++++++++++++++++++++++ spec/controllers/problems_controller_spec.rb | 18 ++++++++++++++---- 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 app/views/issue_trackers/issue.txt.erb diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 7a11d0d..a1759a3 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -6,7 +6,6 @@ # COLLECTION => :index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search class ProblemsController < ApplicationController - include ProblemsSearcher before_filter :need_selected_problem, :only => [ @@ -62,7 +61,7 @@ class ProblemsController < ApplicationController end def create_issue - body = "" # TODO render_issue_body + body = render_to_string "issue_trackers/issue", layout: false, formats: [:txt] title = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}" issue = Issue.new(problem: problem, user: current_user, title: title, body: body) diff --git a/app/views/issue_trackers/issue.txt.erb b/app/views/issue_trackers/issue.txt.erb new file mode 100644 index 0000000..46379f0 --- /dev/null +++ b/app/views/issue_trackers/issue.txt.erb @@ -0,0 +1,45 @@ +[See this exception on Errbit](<%= app_problem_url problem.app, problem %> "See this exception on Errbit") +<% if notice = problem.notices.first %> +# <%= notice.message %> # +## Summary ## +<% if notice.request['url'].present? %> +### URL ### +[<%= notice.request['url'] %>](<%= notice.request['url'] %>)" +<% end %> +### Where ### +<%= notice.where %> + +### Occured ### +<%= notice.created_at.to_s(:micro) %> + +### Similar ### +<%= (notice.problem.notices_count - 1).to_s %> + +## Params ## +``` +<%= pretty_hash(notice.params) %> +``` + +## Session ## +``` +<%= pretty_hash(notice.session) %> +``` + +## Backtrace ## +``` +<% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>** +<% end %> +``` + +## Environment ## + + +<% for key, val in notice.env_vars %> + + + + +<% end %> +
<%= key %>:<%= val %>
+<% end %> + diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index 75565f9..f125415 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -12,9 +12,7 @@ describe ProblemsController do let(:admin) { Fabricate(:admin) } let(:problem) { Fabricate(:problem, :app => app, :environment => "production") } - describe "GET /problems" do - #render_views context 'when logged in as an admin' do before(:each) do sign_in admin @@ -287,8 +285,9 @@ describe ProblemsController do expect(line[0]).to eq(title) end - it "should save the right body" do - pending + it "should renders the issue body" do + post :create_issue, app_id: problem.app.id, id: problem.id, format: 'html' + expect(response).to render_template("issue_trackers/issue") end it "should update the problem" do @@ -296,6 +295,17 @@ describe ProblemsController do expect(problem.issue_link).to eq("http://example.com/mock-errbit") expect(problem.issue_type).to eq("mock") end + + + context "when rendering views" do + render_views + + it "should save the right body" do + post :create_issue, app_id: problem.app.id, id: problem.id, format: 'html' + line = issue_tracker.tracker.output.shift + expect(line[1]).to include(app_problem_url problem.app, problem) + end + end end context "when app has no issue tracker" do -- libgit2 0.21.2