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 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 | |
====== |
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
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" |
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 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) |
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
<form action="/create_tweet" method="post"> | |
<label for="content">What's your tweet?</label> | |
<input type="text" name="content"> | |
<button>Tweet</button> | |
</form> |
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 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 |
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
release: rake db:migrate | |
web: bundle exec rails server -p $PORT | |
worker: rake jobs:workoff |
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
{ | |
"name": "Dev Affirmations", | |
"description": "Affirmations for developers", | |
"repository": "https://github.com/lolaodelola/dev-affirmations", | |
"formation": { | |
"web": { | |
"quantity": 1, | |
"size": "free" | |
} | |
}, |
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
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 |
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) |
NewerOlder