Skip to content

Instantly share code, notes, and snippets.

@SViccari
Last active December 20, 2017 21:54
Show Gist options
  • Save SViccari/7347b5eefd61d51e9ac60c9ca851974c to your computer and use it in GitHub Desktop.
Save SViccari/7347b5eefd61d51e9ac60c9ca851974c to your computer and use it in GitHub Desktop.
Account Registration
class AccountRegistration
include ActiveModel::Model
attr_accessor :email
validates :email, presence: true, format: { with: /.+@.+\..+/i }
end
require "rails_helper"
describe AccountRegistration do
context "validations" do
describe "#email" do
context "when the email is an invalid format" do
it "adds an error message" do
account_registration = AccountRegistration.new(email: "foo")
expect(account_registration).not_to be_valid
expect(account_registration.errors[:email]).
to include("is invalid")
end
end
end
end
end
class API::AccountsController < ActionController::Base
SALESFORCE_EMAIL_SUBMITTED_STATE = "Email_Submitted".freeze
def create
account_registration = AccountRegistration.new(email: email)
if account_registration.valid?
if account.paid_and_has_not_logged_in?
send_onboard_instruction_email
render status: 202, json: {}
elsif account.paid_and_has_logged_in?
render status: 202, json: { login_url: new_session_url }
else
send_account_to_salesforce_through_segment
render status: 200, json: { account_id: account.id }
end
else
render status: 400, json: { errors: account_registration.errors.full_messages }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment