add basic receive controller
- remove dummy-test - mount engine on / in dummy-app
This commit is contained in:
parent
b7dc0709f8
commit
c497200d03
5 changed files with 59 additions and 8 deletions
25
app/controllers/diaspora_federation/receive_controller.rb
Normal file
25
app/controllers/diaspora_federation/receive_controller.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require_dependency "diaspora_federation/application_controller"
|
||||
|
||||
module DiasporaFederation
|
||||
class ReceiveController < ApplicationController
|
||||
before_action :check_for_xml, only: %i(public private)
|
||||
|
||||
def public
|
||||
Rails.logger.info "received a public message"
|
||||
Rails.logger.info CGI.unescape(params[:xml])
|
||||
render nothing: true, status: :ok
|
||||
end
|
||||
|
||||
def private
|
||||
Rails.logger.info "received a private message for #{params[:guid]}"
|
||||
Rails.logger.info CGI.unescape(params[:xml])
|
||||
render nothing: true, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_for_xml
|
||||
render nothing: true, status: 422 if params[:xml].nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,2 +1,6 @@
|
|||
DiasporaFederation::Engine.routes.draw do
|
||||
controller :receive do
|
||||
post "receive/public" => :public, :as => "receive_public"
|
||||
post "receive/users/:guid" => :private, :as => "receive_private"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
module DiasporaFederation
|
||||
describe ReceiveController, type: :controller do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "#public" do
|
||||
it "succeeds" do
|
||||
post :public, xml: "<diaspora/>"
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "returns a 422 if no xml is passed" do
|
||||
post :public
|
||||
expect(response.code).to eq("422")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#private" do
|
||||
it "succeeds" do
|
||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||
expect(response).to be_success
|
||||
end
|
||||
|
||||
it "returns a 422 if no xml is passed" do
|
||||
post :private, guid: "any-guid"
|
||||
expect(response.code).to eq("422")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
describe "Dummy" do
|
||||
# dummy test
|
||||
it "should be true" do
|
||||
expect(true).to be_truthy
|
||||
end
|
||||
end
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
Rails.application.routes.draw do
|
||||
|
||||
mount DiasporaFederation::Engine => "/diaspora_federation"
|
||||
mount DiasporaFederation::Engine => "/"
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue