This file contains hidden or 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
{ | |
"HttpStatusCode":200, | |
"Accounts":[ | |
{ | |
"Transactions":[ | |
{ | |
"Date":"2018-11-20", | |
"Code":null, | |
"Description":"ABC", | |
"Debit":50.00, |
This file contains hidden or 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
# Base | |
class Base | |
attr_reader :message | |
def initialize(message) | |
@message = message | |
end | |
def valid? | |
!message.nil? |
This file contains hidden or 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 AliceBot < Visitor | |
def respond_to_question | |
"Yeah, I'm listening." | |
end | |
def respond_to_yell | |
'🤐' | |
end | |
def respond_to_silence |
This file contains hidden or 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 BobBot < Visitor | |
def respond_to_question | |
'Sure.' | |
end | |
def respond_to_yell | |
'Woah, chill out!' | |
end | |
def respond_to_silence |
This file contains hidden or 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 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 | |
This file contains hidden or 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 BobBot | |
def respond(message) | |
[Question, Yell, Silence, Anything].each do |type| | |
return type.respond if type.valid?(message) | |
end | |
end | |
end |
This file contains hidden or 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
# config/initializers/redis.rb | |
url = URI.parse(ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" }) | |
REDIS = Redis.new(url: url) |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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 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 |