Permalink
Browse files

Implementing notifications

  • Loading branch information...
1 parent e498490 commit 85032f266718662be9156cc1b3ce54344efc6b01 @matflores committed Sep 21, 2009
View
57 integrity-tumblr.gemspec
@@ -0,0 +1,57 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{integrity-tumblr}
+ s.version = "0.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Mat\303\255as Flores"]
+ s.date = %q{2009-09-21}
+ s.description = %q{Let Integrity post notifications to a Tumblr weblog after each build}
+ s.email = %q{mflores@atlanware.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.markdown",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/integrity-tumblr.rb",
+ "test/integrity-tumblr_test.rb",
+ "test/test_helper.rb"
+ ]
+ s.homepage = %q{http://github.com/matflores/integrity-tumblr}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{integrity}
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{Tumblr notifier for the Integrity continuous integration server}
+ s.test_files = [
+ "test/test_helper.rb",
+ "test/integrity-tumblr_test.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<integrity>, [">= 0"])
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ else
+ s.add_dependency(%q<integrity>, [">= 0"])
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<integrity>, [">= 0"])
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
+ end
+end
View
0 lib/integrity-tumblr.rb
No changes.
View
7 lib/integrity/notifier/config.haml
@@ -0,0 +1,7 @@
+%p.normal
+ %label{ :for => "tumblr_notifier_email" } Tumblr account's email address
+ %input.text#tumblr_notifier_email{ :name => "notifiers[Tumblr][email]", :value => config['email'], :type => 'text' }
+
+%p.normal
+ %label{ :for => "tumblr_notifier_password" } Password
+ %input.text#tumblr_notifier_password{ :name => "notifiers[Tumblr][password]", :value => config['password'], :type => 'text' }
View
24 lib/integrity/notifier/tumblr.rb
@@ -0,0 +1,24 @@
+require 'integrity'
+require File.dirname(__FILE__) + '/tumblr_client.rb'
+
+module Integrity
+ class Notifier
+ class Tumblr < Notifier::Base
+ attr_reader :config
+
+ def self.to_haml
+ File.read(File.dirname(__FILE__) + "/config.haml")
+ end
+
+ def deliver!
+ TumblrClient.post(config['email'], config['password'], short_message, full_message)
+ end
+
+ def to_s
+ 'Tumblr'
+ end
+ end
+
+ register Tumblr
+ end
+end
View
16 lib/integrity/notifier/tumblr_client.rb
@@ -0,0 +1,16 @@
+require 'httparty'
+
+module Integrity
+ class Notifier
+ class TumblrClient
+ def post(email, password, title, body)
+ HTTParty.post 'http://www.tumblr.com/api/write', :body => { :email => email,
+ :password => password,
+ :type => 'regular',
+ :title => title,
+ :body => body,
+ :generator => 'integrity-tumblr notifier' }
+ end
+ end
+ end
+end
View
39 test/integrity-tumblr_test.rb
@@ -1,7 +1,42 @@
require 'test_helper'
+require 'integrity/notifier/test'
+require 'integrity/notifier/tumblr'
+
+begin
+ require "redgreen"
+rescue LoadError
+end
class IntegrityTumblrTest < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
+ include Integrity::Notifier::Test
+
+ def notifier
+ "Tumblr"
+ end
+
+ context "A tumblr-based notifier" do
+ setup { setup_database }
+
+ should "register itself" do
+ assert_equal Integrity::Notifier::Tumblr,
+ Integrity::Notifier.available["Tumblr"]
+ end
+
+ should "have a configuration form" do
+ assert_form_have_option "email", "foo@example.org"
+ assert_form_have_option "password", "secret"
+ end
+
+ [:successful, :failed, :pending].each do |status|
+ should "post a notification to the tumblelog after completing a #{status} build" do
+ commit = Integrity::Commit.gen(status)
+ config = { :email => "foo@example.org", :password => "secret" }
+ notifier = Integrity::Notifier::Tumblr.new(commit, config)
+
+ mock(Integrity::Notifier::TumblrClient).post(config['email'], config['password'], notifier.short_message, notifier.full_message)
+
+ notifier.deliver!
+ end
+ end
end
end
View
3 test/test_helper.rb
@@ -1,10 +1,11 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'rr'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'integrity-tumblr'
class Test::Unit::TestCase
+ include RR::Adapters::TestUnit
end

0 comments on commit 85032f2

Please sign in to comment.