Created
April 24, 2016 19:41
-
-
Save jordangraft/3da3896648149e7a01639a4ff57bc72b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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