This file contains hidden or 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
sudo apt-get install htop build-essential zlib1g-dev openssl libreadline6-dev git-core zlib1g libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf automake libtool bison libgecode-dev -y | |
sudo apt-get install libpq-dev | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc | |
echo 'eval "$(rbenv init -)"' >> ~/.bashrc | |
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv | |
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build | |
source ~/.bashrc | |
rbenv install 2.6.5 | |
rbenv global 2.6.5 |
This file contains hidden or 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
# navigate to the home directory | |
cd ~ | |
wget http://download.redis.io/redis-stable.tar.gz | |
tar xzf redis* | |
cd redis-stable | |
sudo make | |
make test | |
sudo make install PREFIX=/usr | |
sudo mkdir /etc/redis | |
sudo cp redis.conf /etc/redis/ |
This file contains hidden or 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 User < ApplicationRecord | |
has_secure_password | |
validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ | |
def generate_email_confirmation_link | |
path = ENV["CLIENT_APPLICATION_ROOT"] | |
token = CoreModules::JsonWebToken.encode({user_id: self.id}, 30.minutes.from_now) | |
return "#{path}/users/confirmations/#{token}?type=#{'email'}" | |
end | |
This file contains hidden or 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
require 'rails_helper' | |
RSpec.describe User, type: :model do | |
it 'can generate an expirable email confirmation link' do | |
user = create(:user) | |
link = user.generate_email_confirmation_link | |
token = link.split('/')[5].split('?')[0] | |
expect(CoreModules::JsonWebToken.decode(token)[:user_id]).to eql user.id | |
expiration_time = Time.now + 31.minutes | |
Timecop.travel(expiration_time) do |
This file contains hidden or 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 Api::Core::V1::UsersController < ApplicationController | |
before_action except: [:create] do | |
authenticate_token | |
end | |
def create | |
first_name = params["first_name"] | |
last_name = params["last_name"] | |
email = params["email"] | |
phone = params["phone"] | |
password = params["password"] |
This file contains hidden or 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
require 'rails_helper' | |
RSpec.describe Api::Core::V1::UsersController, type: :controller do | |
it 'must be able to create a user when first_name, last_name, email and password are specified' do | |
post :create, params: {first_name: 'Cletus', last_name: 'Mccletus', email: '[email protected]', password: 'cletus12345', password_confirmation: 'cletus12345'} | |
response_body = JSON.parse(response.body) | |
expect(response_body.keys).to eql ["status", "code"] | |
expect(response_body["code"]).to eql 200 | |
end |
This file contains hidden or 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 EmailConfirmationJob < ApplicationJob | |
queue_as :default | |
def perform(user_id) | |
user = User.find(user_id) | |
user.set_email_verification_sent | |
UserMailer.welcome_email_confirmation(user).deliver_now | |
end | |
end |
This file contains hidden or 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
require 'rails_helper' | |
require 'sidekiq/testing' | |
RSpec.describe EmailConfirmationJob, type: :job do | |
before(:each) do | |
@user = create_new_user | |
Sidekiq::Testing.inline! | |
end | |
it 'enqueues and changes the email_sent status to true' do |
This file contains hidden or 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 UserMailer < ApplicationMailer | |
default from: '[email protected]' | |
def welcome_email_confirmation(user) | |
@user = user | |
@email_confirmation_url = user.generate_email_confirmation_link | |
mail(to: user.email, subject: "Welcome to this generic SaaS product #{user.first_name.capitalize}! Please confirm your email" ) | |
end | |
end |
This file contains hidden or 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
require "rails_helper" | |
RSpec.describe UserMailer, type: :mailer do | |
it 'sends a welcome email to user with password confirmation link' do | |
user = create_new_user | |
subject_line = "Welcome to this generic SaaS product #{user.first_name.capitalize}! Please confirm your email" | |
generated_email = UserMailer.welcome_email_confirmation(user) | |
expect(generated_email.subject).to eql subject_line | |
expect(generated_email.to[0]).to eql user.email | |
expect(generated_email.from[0]).to eql '[email protected]' |