Commit d0d658c2ea16a7b3468bac97b53ba1ebb84f350a
1 parent
2e279eb1
Exists in
master
and in
1 other branch
the notices API responds to GET requests as well (to support JavaScript notifier)
Showing
2 changed files
with
11 additions
and
4 deletions
Show diff stats
app/controllers/notices_controller.rb
| @@ -4,7 +4,8 @@ class NoticesController < ApplicationController | @@ -4,7 +4,8 @@ class NoticesController < ApplicationController | ||
| 4 | skip_before_filter :authenticate_user!, :only => :create | 4 | skip_before_filter :authenticate_user!, :only => :create |
| 5 | 5 | ||
| 6 | def create | 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 | respond_with @notice | 9 | respond_with @notice |
| 9 | end | 10 | end |
| 10 | 11 |
spec/controllers/notices_controller_spec.rb
| @@ -2,7 +2,7 @@ require 'spec_helper' | @@ -2,7 +2,7 @@ require 'spec_helper' | ||
| 2 | 2 | ||
| 3 | describe NoticesController do | 3 | describe NoticesController do |
| 4 | 4 | ||
| 5 | - context 'POST[XML] notices#create' do | 5 | + context 'notices API' do |
| 6 | before do | 6 | before do |
| 7 | @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read | 7 | @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read |
| 8 | @app = Factory(:app_with_watcher) | 8 | @app = Factory(:app_with_watcher) |
| @@ -11,15 +11,21 @@ describe NoticesController do | @@ -11,15 +11,21 @@ describe NoticesController do | ||
| 11 | 11 | ||
| 12 | request.env['Content-type'] = 'text/xml' | 12 | request.env['Content-type'] = 'text/xml' |
| 13 | request.env['Accept'] = 'text/xml, application/xml' | 13 | request.env['Accept'] = 'text/xml, application/xml' |
| 14 | - request.should_receive(:raw_post).and_return(@xml) | ||
| 15 | end | 14 | end |
| 16 | 15 | ||
| 17 | - it "generates a notice from the xml" do | 16 | + it "generates a notice from xml [POST]" do |
| 18 | Notice.should_receive(:from_xml).with(@xml).and_return(@notice) | 17 | Notice.should_receive(:from_xml).with(@xml).and_return(@notice) |
| 18 | + request.should_receive(:raw_post).and_return(@xml) | ||
| 19 | post :create | 19 | post :create |
| 20 | end | 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 | it "sends a notification email" do | 27 | it "sends a notification email" do |
| 28 | + request.should_receive(:raw_post).and_return(@xml) | ||
| 23 | post :create | 29 | post :create |
| 24 | email = ActionMailer::Base.deliveries.last | 30 | email = ActionMailer::Base.deliveries.last |
| 25 | email.to.should include(@app.watchers.first.email) | 31 | email.to.should include(@app.watchers.first.email) |