notices_controller_spec.rb
3.06 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
require 'spec_helper'
describe NoticesController do
it_requires_authentication :for => { :locate => :get }
let(:notice) { Fabricate(:notice) }
let(:xml) { Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read }
let(:app) { Fabricate(:app) }
let(:error_report) { double(:valid? => true, :generate_notice! => true, :notice => notice) }
context 'notices API' do
context "with all params" do
before do
expect(ErrorReport).to receive(:new).with(xml).and_return(error_report)
end
context "with xml pass in raw_port" do
before do
expect(request).to receive(:raw_post).and_return(xml)
post :create, :format => :xml
end
it "generates a notice from raw xml [POST]" do
expect(response).to be_success
# Same RegExp from Airbrake::Sender#send_to_airbrake (https://github.com/airbrake/airbrake/blob/master/lib/airbrake/sender.rb#L53)
# Inspired by https://github.com/airbrake/airbrake/blob/master/test/sender_test.rb
expect(response.body).to match(%r{<id[^>]*>#{notice.id}</id>})
expect(response.body).to match(%r{<url[^>]*>(.+)#{locate_path(notice.id)}</url>})
end
end
it "generates a notice from xml in a data param [POST]" do
post :create, :data => xml, :format => :xml
expect(response).to be_success
# Same RegExp from Airbrake::Sender#send_to_airbrake (https://github.com/airbrake/airbrake/blob/master/lib/airbrake/sender.rb#L53)
# Inspired by https://github.com/airbrake/airbrake/blob/master/test/sender_test.rb
expect(response.body).to match(%r{<id[^>]*>#{notice.id}</id>})
expect(response.body).to match(%r{<url[^>]*>(.+)#{locate_path(notice.id)}</url>})
end
it "generates a notice from xml [GET]" do
get :create, :data => xml, :format => :xml
expect(response).to be_success
expect(response.body).to match(%r{<id[^>]*>#{notice.id}</id>})
expect(response.body).to match(%r{<url[^>]*>(.+)#{locate_path(notice.id)}</url>})
end
context "with an invalid API_KEY" do
let(:error_report) { double(:valid? => false) }
it 'return 422' do
post :create, :format => :xml, :data => xml
expect(response.status).to eq 422
end
end
end
context "without params needed" do
it 'return 400' do
post :create, :format => :xml
expect(response.status).to eq 400
expect(response.body).to eq 'Need a data params in GET or raw post data'
end
end
end
describe "GET /locate/:id" do
context 'when logged in as an admin' do
before(:each) do
@user = Fabricate(:admin)
sign_in @user
end
it "should locate notice and redirect to problem" do
problem = Fabricate(:problem, :app => app, :environment => "production")
notice = Fabricate(:notice, :err => Fabricate(:err, :problem => problem))
get :locate, :id => notice.id
expect(response).to redirect_to(app_problem_path(problem.app, problem))
end
end
end
end