diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb index bdf7374..69bff71 100644 --- a/app/controllers/notices_controller.rb +++ b/app/controllers/notices_controller.rb @@ -4,7 +4,8 @@ class NoticesController < ApplicationController skip_before_filter :authenticate_user!, :only => :create def create - @notice = Notice.from_xml(request.raw_post) + # params[:data] if the notice came from a GET request, raw_post if it came via POST + @notice = Notice.from_xml(params[:data] || request.raw_post) respond_with @notice end diff --git a/spec/controllers/notices_controller_spec.rb b/spec/controllers/notices_controller_spec.rb index 1b9980e..44b286c 100644 --- a/spec/controllers/notices_controller_spec.rb +++ b/spec/controllers/notices_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe NoticesController do - context 'POST[XML] notices#create' do + context 'notices API' do before do @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read @app = Factory(:app_with_watcher) @@ -11,15 +11,21 @@ describe NoticesController do request.env['Content-type'] = 'text/xml' request.env['Accept'] = 'text/xml, application/xml' - request.should_receive(:raw_post).and_return(@xml) end - it "generates a notice from the xml" do + it "generates a notice from xml [POST]" do Notice.should_receive(:from_xml).with(@xml).and_return(@notice) + request.should_receive(:raw_post).and_return(@xml) post :create end + it "generates a notice from xml [GET]" do + Notice.should_receive(:from_xml).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) -- libgit2 0.21.2