notices_controller_spec.rb
1.17 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
require 'spec_helper'
describe NoticesController do
context 'notices API' do
before do
@xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read
@app = Fabricate(:app_with_watcher)
App.stub(:find_by_api_key!).and_return(@app)
@notice = App.report_error!(@xml)
request.env['Content-type'] = 'text/xml'
request.env['Accept'] = 'text/xml, application/xml'
end
it "generates a notice from xml [POST]" do
App.should_receive(:report_error!).with(@xml).and_return(@notice)
request.should_receive(:raw_post).and_return(@xml)
post :create
end
it "generates a notice from xml [GET]" do
App.should_receive(:report_error!).with(@xml).and_return(@notice)
get :create, {:data => @xml}
end
it "sends a notification email" do
request.should_receive(:raw_post).and_return(@xml)
post :create
email = ActionMailer::Base.deliveries.last
email.to.should include(@app.watchers.first.email)
email.subject.should include(@notice.message)
email.subject.should include("[#{@app.name}]")
email.subject.should include("[#{@notice.environment_name}]")
end
end
end