Commit b2964a64415173b3c089fe3bfd8edbb09e1a20b0
1 parent
949ae68a
Exists in
master
and in
1 other branch
Limit the show action to just the problem
This commit backs out the nesting of the error and notices as this would be better placed in an error or notices route.
Showing
2 changed files
with
47 additions
and
8 deletions
Show diff stats
app/controllers/api/v1/problems_controller.rb
@@ -5,8 +5,7 @@ class Api::V1::ProblemsController < ApplicationController | @@ -5,8 +5,7 @@ class Api::V1::ProblemsController < ApplicationController | ||
5 | def show | 5 | def show |
6 | result = benchmark("[api/v1/problems_controller/show] query time") do | 6 | result = benchmark("[api/v1/problems_controller/show] query time") do |
7 | begin | 7 | begin |
8 | - problem = Problem.only(FIELDS).find(params[:id]) | ||
9 | - problem.as_json(include: {errs: { include: :notices}}) | 8 | + Problem.only(FIELDS).find(params[:id]) |
10 | rescue Mongoid::Errors::DocumentNotFound | 9 | rescue Mongoid::Errors::DocumentNotFound |
11 | head :not_found | 10 | head :not_found |
12 | return false | 11 | return false |
spec/controllers/api/v1/problems_controller_spec.rb
@@ -11,18 +11,58 @@ describe Api::V1::ProblemsController do | @@ -11,18 +11,58 @@ describe Api::V1::ProblemsController do | ||
11 | before do | 11 | before do |
12 | notice = Fabricate(:notice) | 12 | notice = Fabricate(:notice) |
13 | err = Fabricate(:err, :notices => [notice]) | 13 | err = Fabricate(:err, :notices => [notice]) |
14 | - problem = Fabricate(:problem, :errs => [err]) | 14 | + @problem = Fabricate(:problem, :errs => [err]) |
15 | end | 15 | end |
16 | 16 | ||
17 | - it "returns JSON if JSON is requested" do | 17 | + it "should return JSON if JSON is requested" do |
18 | get :show, :auth_token => @user.authentication_token, :format => "json", :id => Problem.first.id | 18 | get :show, :auth_token => @user.authentication_token, :format => "json", :id => Problem.first.id |
19 | + expect { JSON.load(response.body) }.not_to raise_error() #JSON::ParserError | ||
20 | + end | ||
21 | + | ||
22 | + it "should return XML if XML is requested" do | ||
23 | + get :index, :auth_token => @user.authentication_token, :format => "xml", :id => @problem.id | ||
24 | + expect(Nokogiri::XML(response.body).errors).to be_empty | ||
25 | + end | ||
26 | + | ||
27 | + it "should return JSON by default" do | ||
28 | + get :show, :auth_token => @user.authentication_token, :id => @problem.id | ||
19 | expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) | 29 | expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError) |
20 | end | 30 | end |
21 | 31 | ||
22 | - it "returns the correct problem" do | ||
23 | - requested_problem = Problem.first | ||
24 | - get :show, :auth_token => @user.authentication_token, :format => "json", :id => requested_problem.id | ||
25 | - expect( response.body ).to eq(requested_problem.to_json(include: {errs: { include: :notices}})) | 32 | + it "should return the correct problem" do |
33 | + get :show, :auth_token => @user.authentication_token, :format => "json", :id => @problem.id | ||
34 | + | ||
35 | + returned_problem = JSON.parse(response.body) | ||
36 | + expect( returned_problem["_id"] ).to eq(@problem.id.to_s) | ||
37 | + end | ||
38 | + | ||
39 | + it "should return only the correct fields" do | ||
40 | + get :show, :auth_token => @user.authentication_token, :format => "json", :id => @problem.id | ||
41 | + returned_problem = JSON.parse(response.body) | ||
42 | + | ||
43 | + expect( returned_problem.keys ).to match_array([ | ||
44 | + "app_name", | ||
45 | + "first_notice_at", | ||
46 | + "error_class", | ||
47 | + "messages", | ||
48 | + "hosts", | ||
49 | + "created_at", | ||
50 | + "app_id", | ||
51 | + "last_notice_at", | ||
52 | + "_id", | ||
53 | + "issue_link", | ||
54 | + "resolved", | ||
55 | + "updated_at", | ||
56 | + "resolved_at", | ||
57 | + "last_deploy_at", | ||
58 | + "where", | ||
59 | + "issue_type", | ||
60 | + "notices_count", | ||
61 | + "user_agents", | ||
62 | + "comments_count", | ||
63 | + "message", | ||
64 | + "environment" | ||
65 | + ]) | ||
26 | end | 66 | end |
27 | 67 | ||
28 | it "returns a 404 if the problem cannot be found" do | 68 | it "returns a 404 if the problem cannot be found" do |