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
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 |
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 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) |
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 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 |
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
<% 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" %> |
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
def landing | |
render 'landing' | |
end | |
def new | |
@affirmation = Affirmation.new | |
end | |
def create | |
Affirmation.create!(affirmation_params) |
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
def receive | |
req_body = params['Body'].downcase | |
if (req_body == 'affirm') || (req_body == 'start') | |
create | |
elsif req_body == 'stop' | |
delete | |
end | |
end | |
def create |
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
# app/models/affirmation.rb | |
has_many :sent_affirmations | |
has_many :developers, through: :sent_affirmation | |
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
d = Developer.new | |
d.uuid = SecureRandom.uuid | |
d.phone_number = '0984737424' | |
d.save |
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
before_create :generate_uuid | |
private | |
def generate_uuid | |
self.uuid = SecureRandom.uuid | |
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
it 'creates a uuid before create' do | |
d = Developer.create!(phone_number: '0984737424') | |
expect(d.uuid).to_not be_nil | |
end |