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 initialize(gateway_service: SongGatewayService.new) | |
@gateway_service = gateway_service | |
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
RSpec.describe SongService do | |
require 'spec_helper' | |
subject { SongService.new(gateway_service: gateway_service) } | |
let(:song) { Song.new(name: 'Seek Up', artist: 'Dave Matthews Band', genre: 'Rock') } | |
context 'using spies' do | |
let(:gateway_service) do | |
spy = spy("gateway_service") |
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
RSpec.describe SongService do | |
require 'spec_helper' | |
subject { SongService.new(gateway_service: gateway_service) } | |
let(:song) { Song.new(name: 'Seek Up', artist: 'Dave Matthews Band', genre: 'Rock') } | |
context 'using doubles' do | |
let(:gateway_service) do | |
stub = double("gateway_service") |
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
RSpec.describe SongService do | |
require 'spec_helper' | |
subject { SongService.new(gateway_service: gateway_service) } | |
let(:song) { Song.new(name: 'Seek Up', artist: 'Dave Matthews Band', genre: 'Rock') } | |
context 'create_song using mocks' do | |
class MockSongGatewayService < SongGatewayService | |
def create_song(song) |
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 SongGatewayService | |
def create_song(song_json) | |
uri = URI('https://music.com/songs') | |
res = Net::HTTP.post(uri, song_json.to_json) | |
unless res.is_a?(Net::HTTPSuccess) | |
nil | |
end | |
res.body | |
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 SongService | |
attr_reader :gateway_service | |
def initialize(gateway_service: SongGatewayService.new) | |
@gateway_service = gateway_service | |
end | |
# Creates a song | |
# @param [Song] song |
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 Song | |
include ActiveModel::Model | |
include ActiveModel::Attributes | |
include ActiveModel::Serializers::JSON | |
attr_accessor :name, :artist, :genre, :id | |
validates_presence_of :name, :artist | |
def attributes=(hash) |
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
const chromium = require('chrome-aws-lambda'); | |
module.exports.handler = async (event) => { | |
let browser = null; | |
try { | |
browser = await chromium.puppeteer.launch({ | |
args: chromium.args, | |
defaultViewport: chromium.defaultViewport, | |
executablePath: await chromium.executablePath, | |
headless: chromium.headless |
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
require 'Time' | |
utc_time_str = '2020-01-02T18:16:35+0000' | |
# Outputs UTC time. | |
Time.parse(utc_time_str) | |
=> 2020-01-02 18:16:35 +0000 | |
# Outputs system timezone. Also can use to_time | |
Time.parse(utc_time_str).to_localtime | |
=> 2020-01-02 13:16:35 -0500 |
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 EventsReceivingSupervisor < Celluloid::SupervisionGroup | |
include Celluloid::Logger | |
trap_exit :work_exited | |
def start_work(queue_name, queue_uri) | |
supervise_as :event_listener, StompWorker, current_actor, queue_name, queue_uri | |
Celluloid::Actor[:event_listener].connect | |
end |
NewerOlder