Skip to content

Instantly share code, notes, and snippets.

{
"HttpStatusCode":200,
"Accounts":[
{
"Transactions":[
{
"Date":"2018-11-20",
"Code":null,
"Description":"ABC",
"Debit":50.00,
# Base
class Base
attr_reader :message
def initialize(message)
@message = message
end
def valid?
!message.nil?
@lchanmann
lchanmann / alice_bot.rb
Last active June 1, 2018 21:50
bob_bot_4
class AliceBot < Visitor
def respond_to_question
"Yeah, I'm listening."
end
def respond_to_yell
'🤐'
end
def respond_to_silence
@lchanmann
lchanmann / bob_bot.rb
Last active June 1, 2018 21:20
bob_bot_3
class BobBot < Visitor
def respond_to_question
'Sure.'
end
def respond_to_yell
'Woah, chill out!'
end
def respond_to_silence
@lchanmann
lchanmann / visitor.rb
Last active June 1, 2018 21:39
bob_bot_2
class Visitor
METHODS_TOBE_IMPLEMENTED = %i(
respond_to_question respond_to_yell respond_to_silence respond_to_anything)
attr_reader :message_types
def initialize(*message_types)
@message_types = message_types
end
@lchanmann
lchanmann / bob_bot.rb
Last active June 1, 2018 21:13
bobbot_1
class BobBot
def respond(message)
[Question, Yell, Silence, Anything].each do |type|
return type.respond if type.valid?(message)
end
end
end
@lchanmann
lchanmann / redis.rb
Last active May 29, 2018 21:09
blogging
# config/initializers/redis.rb
url = URI.parse(ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" })
REDIS = Redis.new(url: url)
# spec/system/chat_stories_spec.rb
require 'rails_helper'
RSpec.describe 'Chat stories' do
before do
allow(REDIS).to receive(:incr).with('user_count').and_return(1, 2, 3)
end
it "displays chat app" do
visit root_url
# spec/controllers/home_controller_spec.rb
require 'rails_helper'
RSpec.describe HomeController, type: :controller do
before do
allow(REDIS).to receive(:incr).with('user_count').and_return(1)
end
describe 'GET #index' do
it "assigns username" do
class ChatChannel < ApplicationCable::Channel
def subscribed
stream_from "my_channel"
end
def send_message(data)
message_params = { sent_by: current_user }.merge(data['message'])
ActionCable.server.broadcast("my_channel", message_params)
end
end