Commit d0d658c2ea16a7b3468bac97b53ba1ebb84f350a

Authored by Bob Lail
1 parent 2e279eb1
Exists in master and in 1 other branch production

the notices API responds to GET requests as well (to support JavaScript notifier)

app/controllers/notices_controller.rb
... ... @@ -4,7 +4,8 @@ class NoticesController < ApplicationController
4 4 skip_before_filter :authenticate_user!, :only => :create
5 5  
6 6 def create
7   - @notice = Notice.from_xml(request.raw_post)
  7 + # params[:data] if the notice came from a GET request, raw_post if it came via POST
  8 + @notice = Notice.from_xml(params[:data] || request.raw_post)
8 9 respond_with @notice
9 10 end
10 11  
... ...
spec/controllers/notices_controller_spec.rb
... ... @@ -2,7 +2,7 @@ require 'spec_helper'
2 2  
3 3 describe NoticesController do
4 4  
5   - context 'POST[XML] notices#create' do
  5 + context 'notices API' do
6 6 before do
7 7 @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read
8 8 @app = Factory(:app_with_watcher)
... ... @@ -11,15 +11,21 @@ describe NoticesController do
11 11  
12 12 request.env['Content-type'] = 'text/xml'
13 13 request.env['Accept'] = 'text/xml, application/xml'
14   - request.should_receive(:raw_post).and_return(@xml)
15 14 end
16 15  
17   - it "generates a notice from the xml" do
  16 + it "generates a notice from xml [POST]" do
18 17 Notice.should_receive(:from_xml).with(@xml).and_return(@notice)
  18 + request.should_receive(:raw_post).and_return(@xml)
19 19 post :create
20 20 end
21 21  
  22 + it "generates a notice from xml [GET]" do
  23 + Notice.should_receive(:from_xml).with(@xml).and_return(@notice)
  24 + get :create, {:data => @xml}
  25 + end
  26 +
22 27 it "sends a notification email" do
  28 + request.should_receive(:raw_post).and_return(@xml)
23 29 post :create
24 30 email = ActionMailer::Base.deliveries.last
25 31 email.to.should include(@app.watchers.first.email)
... ...