problems_controller_spec.rb
3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require 'spec_helper'
describe Api::V1::ProblemsController do
context "when logged in" do
before do
@user = Fabricate(:user)
end
describe "GET /api/v1/problems/:id" do
before do
notice = Fabricate(:notice)
err = Fabricate(:err, :notices => [notice])
@problem = Fabricate(:problem, :errs => [err])
end
it "should return JSON if JSON is requested" do
get :show, :auth_token => @user.authentication_token, :format => "json", :id => Problem.first.id
expect { JSON.load(response.body) }.not_to raise_error() #JSON::ParserError
end
it "should return XML if XML is requested" do
get :index, :auth_token => @user.authentication_token, :format => "xml", :id => @problem.id
expect(Nokogiri::XML(response.body).errors).to be_empty
end
it "should return JSON by default" do
get :show, :auth_token => @user.authentication_token, :id => @problem.id
expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError)
end
it "should return the correct problem" do
get :show, :auth_token => @user.authentication_token, :format => "json", :id => @problem.id
returned_problem = JSON.parse(response.body)
expect( returned_problem["_id"] ).to eq(@problem.id.to_s)
end
it "should return only the correct fields" do
get :show, :auth_token => @user.authentication_token, :format => "json", :id => @problem.id
returned_problem = JSON.parse(response.body)
expect( returned_problem.keys ).to match_array([
"app_name",
"first_notice_at",
"error_class",
"messages",
"hosts",
"created_at",
"app_id",
"last_notice_at",
"_id",
"issue_link",
"resolved",
"updated_at",
"resolved_at",
"last_deploy_at",
"where",
"issue_type",
"notices_count",
"user_agents",
"comments_count",
"message",
"environment"
])
end
it "returns a 404 if the problem cannot be found" do
get :show, :auth_token => @user.authentication_token, :format => "json", :id => 'IdontExist'
expect( response.status ).to eq(404)
end
end
describe "GET /api/v1/problems" do
before do
Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 01), :resolved_at => Date.new(2012, 8, 02))
Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 01), :resolved_at => Date.new(2012, 8, 21))
Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 21))
Fabricate(:problem, :first_notice_at => Date.new(2012, 8, 30))
end
it "should return JSON if JSON is requested" do
get :index, :auth_token => @user.authentication_token, :format => "json"
expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError)
end
it "should return XML if XML is requested" do
get :index, :auth_token => @user.authentication_token, :format => "xml"
expect(Nokogiri::XML(response.body).errors).to be_empty
end
it "should return JSON by default" do
get :index, :auth_token => @user.authentication_token
expect { JSON.load(response.body) }.not_to raise_error()#JSON::ParserError)
end
describe "given a date range" do
it "should return only the problems open during the date range" do
get :index, {:auth_token => @user.authentication_token, :start_date => "2012-08-20", :end_date => "2012-08-27"}
expect(response).to be_success
problems = JSON.load response.body
expect(problems.length).to eq 2
end
end
it "should return all problems" do
get :index, {:auth_token => @user.authentication_token}
expect(response).to be_success
problems = JSON.load response.body
expect(problems.length).to eq 4
end
end
end
end