Skip to content

Instantly share code, notes, and snippets.

View lolaodelola's full-sized avatar

Lola lolaodelola

View GitHub Profile
it 'enques the text' do
confirmed_dev = Developer.create(phone_number: "1234456", confirmed: true)
affirmations = Affirmation.create([{affirmation: "this is one"}, {affirmation: "this is two"}, {affirmation: "this is three"}])
ActiveJob::Base.queue_adapter = :test
expect { SendAffirmationJob.new.deliver(confirmed_dev, affirmations.first) }.to have_enqueued_job
end
class SendAffirmationJob < ApplicationJob
queue_as :default
def deliver(dev, affirmation)
  Rails.env != 'test' ? send_prod(dev, affirmation) : send_test(dev, affirmation)
end
handle_asynchronously :deliver
def send_prod(dev, affirmation)
class AffirmationText
def initialize()
  @client = Twilio::REST::Client.new(ENV['TWILIO_SID'], ENV['TWILIO_TOKEN'])
end
def message(dev_phone_number, affirmation)
   @client.messages.create(
     from: ENV['TWILIO_NUMBER'],
     to: dev_phone_number,
     body: affirmation
<% if flash[:notice] %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>
<h1>Submit an Affirmation</h1>
<%= form_for @affirmation  do |f| %>
  <div class="form-group">
      <%= f.label :affirmation%><br />
      <%= f.text_area :affirmation, placeholder: "Submit your affirmation", id: "affirmation" %>
  </div>
  <%= f.submit "Create" %>
def landing
render 'landing'
end
def new
@affirmation = Affirmation.new
end
def create
Affirmation.create!(affirmation_params)
def receive
req_body = params['Body'].downcase
if (req_body == 'affirm') || (req_body == 'start')
  create
elsif req_body == 'stop'
   delete
end
end
def create
# app/models/affirmation.rb
has_many :sent_affirmations
has_many :developers, through: :sent_affirmation
d = Developer.new
d.uuid = SecureRandom.uuid
d.phone_number = '0984737424'
d.save
before_create :generate_uuid
private
def generate_uuid
self.uuid = SecureRandom.uuid
end
it 'creates a uuid before create' do
d = Developer.create!(phone_number: '0984737424')
expect(d.uuid).to_not be_nil
end