Skip to content

Instantly share code, notes, and snippets.

@jordangraft
Created April 24, 2016 19:41
Show Gist options
  • Save jordangraft/3da3896648149e7a01639a4ff57bc72b to your computer and use it in GitHub Desktop.
Save jordangraft/3da3896648149e7a01639a4ff57bc72b to your computer and use it in GitHub Desktop.
class EmailsController < ApplicationController
##
# Receive the AWS post, validate the token and pass to our model method
def incoming
if params[:token] && (params[:token] == 'test_token')
@email = Email.process_incoming_email(params[:message_id])
if @email.valid?
render text: 'email created', status: :created
else
render text: @email.errors.full_messages, status: :unprocessable_entity
end
else
render text: 'unauthorized', status: :unauthorized
end
end
end
context 'receive a post from Lambda' do
it 'should be receive a message from email via Lambda' do
expect { post(:incoming, token: 'test_token', message_id: 'test') }.to change { Email.count }.by(1)
end
it 'should be be unauthorized without the lamda token' do
response = post :incoming, message_id: 'test'
expect(response.status).to eq(401)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment