Created
December 5, 2010 03:50
-
-
Save zenom/728751 to your computer and use it in GitHub Desktop.
campfire 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 'spec_helper' | |
describe Notifier::Campfire do | |
it { should have_field(:ssl).of_type(Boolean) } | |
before(:each) do | |
@build = Fabricate(:build, :state => :building) | |
end | |
it 'should send a failed message' do | |
Tinder::Campfire.stub!(:new).and_return(true) | |
a = Notifier::Campfire.new | |
a.send_failed(@build) | |
#a = Notifier::Campfire.new | |
#a.send_failed(@build) | |
#Notifier::Campfire.should_receive(:send_failed) | |
#Tinder::Campfire.should_receive(:new) | |
#@build.build_failed! | |
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
class Notifier::Campfire | |
include Mongoid::Document | |
include Rails.application.routes.url_helpers | |
field :ssl, :type => Boolean, :default => true | |
field :token, :type => String | |
field :room, :type => String | |
field :subdomain, :type => String | |
embedded_in :project, :inverse_of => :campfire | |
def send_failed(build) | |
link = build_url(build, :host => APP_CONFIG[:domain]) | |
send_message("[#{build.project.name}] Build #{build.id} failed. #{link}") | |
end | |
def send_success(build) | |
link = build_url(build, :host => APP_CONFIG[:domain]) | |
send_message("[#{build.project.name}] Build #{build.id} successful. #{link}") | |
end | |
def post_message? | |
!token.empty? && !room.empty? && !subdomain.empty? | |
end | |
def send_message(message) | |
campfire = Tinder::Campfire.new(self.subdomain, :token => self.token, :ssl => self.ssl) | |
room = campfire.find_room_by_name(self.room) | |
room.speak(message) | |
room.leave | |
end | |
private :send_message | |
def self.icon | |
"notifications/campfire.png" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment