Commit b0fb328f
Changed files (3)
app
services
application
handlers
config
initializers
spec
services
handlers
app/services/application/handlers/publish_cake_to_twitter.rb
@@ -1,30 +0,0 @@
-class PublishCakeToTwitter
- def initialize(twitter_publisher, cakes = Creation)
- @twitter = twitter_publisher
- @cakes = cakes
- end
-
- def handles?(event)
- :cake_published == event
- end
-
- def handle(message)
- tweet_about(@cakes.find(message[:cake_id]))
- end
-
- private
-
- def tweet_about(cake)
- @twitter.tweet(tweet_for(cake)) if cake.published?
- end
-
- def tweet_for(cake)
- "#{cake.name} By #{cake.user.name} on #{routes.cake_url(cake)}!"
- end
-
- def routes
- Cake::Application.routes.url_helpers
- end
-
- handle_asynchronously :handle, run_at: Proc.new { 10.minutes.from_now }
-end
config/initializers/container.rb
@@ -1,7 +1,6 @@
class ConfigureContainerCommand
def configure(container)
container.register(:configuration) { EnvironmentVariables.new }
- container.register(:message_handler) { |builder| builder.build(PublishCakeToTwitter) }
container.register(:message_handler) { |builder| builder.build(ProcessPhoto) }
container.register(:message_handler) { |builder| builder.build(ProcessAvatar) }
container.register(:queue) { |c| Delayed::Job }
spec/services/handlers/publish_cake_to_twitter_spec.rb
@@ -1,47 +0,0 @@
-require "rails_helper"
-
-describe PublishCakeToTwitter do
- let(:twitter) { double(tweet: '') }
- let(:cakes) { double }
-
- subject { PublishCakeToTwitter.new(twitter, cakes) }
-
- describe "#handles?" do
- it "handles cake_published" do
- expect(subject.handles?(:cake_published)).to be_truthy
- end
- end
-
- describe "#handle" do
- let(:artist) { User.new(name: 'joe') }
- let(:cake) { Creation.new(id: id, name: 'yummy') }
- let(:id) { 88 }
-
- before :each do
- allow(cake).to receive(:user).and_return(artist)
- allow(cakes).to receive(:find).with(id).and_return(cake)
- end
-
- context "when the cake is published and safe for kids" do
- before :each do
- allow(cake).to receive(:published?).and_return(true)
- end
-
- it "tweets new cakes" do
- subject.handle(cake_id: id)
- expect(twitter).to have_received(:tweet).with("yummy By joe on http://www.blah.com/cakes/88-yummy!")
- end
- end
-
- context "when the cake is not published" do
- before :each do
- allow(cake).to receive(:published?).and_return(false)
- end
-
- it "should not publish any tweets" do
- subject.handle(cake_id: id)
- expect(twitter).not_to have_received(:tweet)
- end
- end
- end
-end