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
def call(user, count: 20) | |
tweets = fetch_user_timeline(user, count: count) | |
Result.new(:ok, tweets) | |
rescue Twitter::Error::NotFound | |
Result.new(:not_found, []) | |
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
context 'when the timeline is forbidden' do | |
it 'returns a result with no tweets and forbidden status' do | |
twitter_client = double('twitter_client') | |
allow(twitter_client).to receive(:user_timeline) | |
.with('screen_name', count: 5) | |
.once { fail Twitter::Error::Unauthorized } | |
twitter_timeline_hub = TwitterTimelineHub.new(twitter_client) | |
result = twitter_timeline_hub.call('screen_name', count: 5) |
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
def call(user, count: 20) | |
tweets = fetch_user_timeline(user, count: count) | |
Result.new(:ok, tweets) | |
rescue Twitter::Error::NotFound | |
Result.new(:not_found, []) | |
rescue Twitter::Error::Unauthorized | |
Result.new(:forbidden, []) | |
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 TwitterTimelineHub | |
Result = Struct.new(:status, :tweets) | |
def initialize(twitter_client = TwitterClientFactory.new.call) | |
@twitter_client = twitter_client | |
end | |
def call(user, count: 20) | |
tweets = fetch_user_timeline(user, count: count) | |
Result.new(:ok, tweets) |
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
# app/controllers/home_controller.rb | |
class HomeController < ApplicationController | |
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
# app/controllers/twitter_timeline_controller.rb | |
class TwitterTimelineController < ApplicationController | |
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
import { expect } from 'chai'; | |
import createFixture from '../support/createFixture'; | |
describe('renderCartTotal', () => { | |
// Declare shared environment variables | |
let fixture; | |
beforeEach(() => { | |
// Setup the environment | |
fixture = createFixture({ html: '<div data-js-cart-total></div>' }); |
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
import { expect } from 'chai'; | |
import createFixture from '../support/createFixture'; | |
function renderCartTotal({ domNode, itemPrices }) { | |
const sum = itemPrices.reduce((total, price) => total + price, 0); | |
const formattedPrice = `$${sum}`; | |
domNode.innerHTML = formattedPrice; | |
} |
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/javascripts/support/createFixture.js | |
function createFixtureNode() { | |
const fixture = document.createElement('div'); | |
fixture.id = 'fixture'; | |
fixture.destroy = function destroy() { | |
this.parentNode.removeChild(fixture); | |
}; |