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
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem 'rails', '= 6.0.0' |
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 Posts | |
cattr_accessor :source | |
def initialize | |
@client = source.new | |
end | |
def posts(args) | |
@client.user_posts(args) | |
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
posts = Posts.new | |
posts.source = PostsSources::FakeMedium | |
posts.user_posts |
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 Medium | |
cattr_accessor :source | |
def initialize(name = nil) | |
@client = source.new(name) | |
end | |
def posts | |
@client.user_posts | |
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
module PostsSource | |
class Remote | |
def initialize(username) | |
@client = MediumAPI.new(username) | |
end | |
def user_posts | |
@client.posts | |
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
module PostsSource | |
class Fake | |
def initialize(username) | |
@client = OpenStruct.new( | |
posts: [ | |
{ | |
title: 'Signal v Noise exits Medium[Fake source]', | |
... | |
} | |
] |
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
# frozen_string_literal: true | |
require 'posts_source/remote' | |
require 'medium/testing' | |
Medium::Testing.fake! if Rails.env.test? |
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 'posts_source/fake' | |
class Medium::Testing | |
def self.fake! | |
Medium.source = PostsSource::Fake | |
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
posts = Medium.new('dhh') | |
posts.source = PostsSource::Remote | |
posts.user_posts |
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
posts = Medium.new | |
posts.source = PostsSource::Fake | |
posts.user_posts |
OlderNewer