Skip to content

Instantly share code, notes, and snippets.

View lolaodelola's full-sized avatar

Lola lolaodelola

View GitHub Profile
class Customer < ApplicationRecord
validates_presence_of :first_name, :last_name, :phone
validates_uniqueness_of :phone
# Implicit validations on presence being done
has_secure_password
has_secure_password :password_confirmation
has_secure_password :recovery_password, validations: false
end
======
create_table "hotels", force: :cascade do |t|
t.string "name"
t.string "location"
t.string "h_type"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "review_details", force: :cascade do |t|
t.integer "review_id"
class TweetController
require 'tweet'
get '/new_tweet' do
# display html page with form
end
post '/create_tweet' do
content_string = request[:params[:content]]
if Tweet.create(content_string)
<form action="/create_tweet" method="post">
<label for="content">What's your tweet?</label>
<input type="text" name="content">
<button>Tweet</button>
</form>
class Tweet
require 'my_database'
def create(content_string)
begin
my_database.connect("connection string")
my_database.execute("INSERT INTO Tweets(content) VALUES (?)", content_string)
my_database.commit
my_database.disconnect
rescue => e
release: rake db:migrate
web: bundle exec rails server -p $PORT
worker: rake jobs:workoff
{
"name": "Dev Affirmations",
"description": "Affirmations for developers",
"repository": "https://github.com/lolaodelola/dev-affirmations",
"formation": {
"web": {
"quantity": 1,
"size": "free"
}
},
namespace :affirmation do
task :send_text => :environment do |task, args|
  count = Affirmation.count
random_offset = rand(count)
affirmation = Affirmation.offset(random_offset).first
   Developer.confirmed.each do |dev|
     SendAffirmationJob.new.deliver(dev, affirmation)
     SentAffirmation.create!(developer_id: dev.id, affirmation_id: affirmation.id, sent_at: DateTime.now)
  end
end
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)