diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb new file mode 100644 index 0000000..f905b73 --- /dev/null +++ b/app/controllers/notices_controller.rb @@ -0,0 +1,9 @@ +class NoticesController < ApplicationController + respond_to :xml + + def create + @notice = Notice.from_xml(request.raw_post) + respond_with @notice + end + +end diff --git a/config/routes.rb b/config/routes.rb index 4a55eda..9717614 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,58 +1,9 @@ Hypnotoad::Application.routes.draw do - # The priority is based upon order of creation: - # first created -> highest priority. - - # Sample of regular route: - # match 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Sample resource route with options: - # resources :products do - # member do - # get :short - # post :toggle - # end - # - # collection do - # get :sold - # end - # end - - # Sample resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Sample resource route with more complex sub-resources - # resources :products do - # resources :comments - # resources :sales do - # get :recent, :on => :collection - # end - # end - - # Sample resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - - # You can have the root of your site routed with "root" - # just remember to delete public/index.html. - # root :to => "welcome#index" - - # See how all your routes lay out with "rake routes" - - # This is a legacy wild controller route that's not recommended for RESTful applications. - # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id(.:format)))' + + # Hoptoad Notifier Routes + match '/notifier_api/v2/notices' => 'notices#create' + # match '/deploys.txt' => 'deploys#create' + + resources :notices + end diff --git a/spec/controllers/notices_controller_spec.rb b/spec/controllers/notices_controller_spec.rb new file mode 100644 index 0000000..f93669d --- /dev/null +++ b/spec/controllers/notices_controller_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe NoticesController do + + context 'POST[XML] notices#create' do + before do + @xml = Rails.root.join('spec','fixtures','hoptoad_test_notice.xml').read + @notice = Notice.from_xml(@xml) + + 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 + Notice.should_receive(:from_xml).with(@xml).and_return(@notice) + post :create + end + end + +end -- libgit2 0.21.2