notices_controller_spec.rb
1.72 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
describe "Notices management", type: 'request' do
let(:errbit_app) { Fabricate(:app, api_key: 'APIKEY') }
describe "create a new notice" do
context "with valide notice" do
let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
it 'save a new notice' do
expect do
post '/notifier_api/v2/notices', data: xml
expect(response).to be_success
end.to change {
errbit_app.problems.count
}.by(1)
end
end
context "with notice with empty backtrace" do
let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice_without_line_of_backtrace.xml').read }
it 'save a new notice' do
expect do
post '/notifier_api/v2/notices', data: xml
expect(response).to be_success
end.to change {
errbit_app.problems.count
}.by(1)
end
end
context "with notice with bad api_key" do
let(:errbit_app) { Fabricate(:app) }
let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
it 'not save a new notice and return 422' do
expect do
post '/notifier_api/v2/notices', data: xml
expect(response.status).to eq 422
expect(response.body).to eq "Your API key is unknown"
end.to_not change(errbit_app.problems, :count)
end
end
context "with GET request" do
let(:xml) { Rails.root.join('spec', 'fixtures', 'hoptoad_test_notice.xml').read }
it 'save a new notice' do
expect do
get '/notifier_api/v2/notices', data: xml
expect(response).to be_success
end.to change {
errbit_app.problems.count
}.by(1)
end
end
end
end