Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use bundler, update for changes in Command

  • Loading branch information...
commit 41b649774ea7cd16a8a35ad0f3a7a22385b07442 1 parent e368afc
@svenfuchs authored
View
2  .bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_WITHOUT: ""
View
14 Gemfile
@@ -0,0 +1,14 @@
+source 'http://gemcutter.org'
+
+gem 'sinatra'
+gem 'rack-respond_to'
+gem 'httparty'
+gem 'mbbx6spp-twitter4r'
+gem 'twibot'
+gem 'simply_stored'
+gem 'command', :path => '/Volumes/Users/sven/Development/lab/command'
+
+group :test do
+ gem 'mocha'
+ gem 'rack-test'
+end
View
8 lib/identity.rb
@@ -69,7 +69,9 @@ def to_json(*args)
{ :handles => handles, :profiles => profiles, :groups => groups, :created_at => created_at }.to_json
end
end
+#
+# class Command
+# include Identity::Command
+# end
+require 'identity/command'
-class Command
- include Identity::Command
-end
View
25 lib/identity/command.rb
@@ -1,27 +1,30 @@
-module Identity::Command
- def initialize(command, message)
+class Identity::Command < Command
+ def initialize(command, args, message)
super
@command = :create if command = :update && sender.created_at.nil?
end
+ desc 'create [sources]', 'create your identity'
def create
- arguments << "#{message.source}:#{message.sender}" # i.e. on create we always pull the source's profile (e.g. twitter)
- arguments.uniq!
+ args << "#{message.source}:#{message.sender}" # i.e. on create we always pull the source's profile (e.g. twitter)
+ args.uniq!
update
end
- def join
- sender.groups ||= []
- sender.groups << receiver
- sender.save
- end
-
+ desc 'update [sources]', 'update from all or given sources'
def update
- Identity::Sources.update_all(sender, arguments)
+ Identity::Sources.update_all(sender, args)
sender.claim
sender.save
end
+ desc 'join', 'join this group'
+ def join
+ sender.groups ||= []
+ sender.groups << message.receiver
+ sender.save
+ end
+
protected
def sender
View
2  test/app_test.rb
@@ -34,7 +34,7 @@ def setup
test '/ responding to :html' do
setup_stubs
- command('create', 'rugb', 'svenfuchs', 'twitter:svenfuchs github:svenphoox').dispatch
+ command('rugb', 'svenfuchs', '!create twitter:svenfuchs github:svenphoox').run
get '/'
assert_equal 'text/html', last_response['Content-Type']
View
28 test/command_test.rb
@@ -6,15 +6,15 @@ def setup
end
test '#arguments' do
- cmd = command('create', 'rugb', 'svenfuchs', 'github:foo json:http://tinyurl.com/yc7t8bv')
- assert_equal(['github:foo', 'json:http://tinyurl.com/yc7t8bv'], cmd.arguments)
+ cmd = command('rugb', 'svenfuchs', '!create github:foo json:http://tinyurl.com/yc7t8bv')
+ assert_equal(['github:foo', 'json:http://tinyurl.com/yc7t8bv'], cmd.args)
- cmd = command('create', 'rugb', 'svenfuchs', 'me foo')
- assert_equal([], cmd.arguments)
+ cmd = command('rugb', 'svenfuchs', '!create me foo')
+ assert_equal([], cmd.args)
end
test 'creating w/ a twitter handle' do
- command('create', 'rugb', 'svenfuchs', 'twitter:svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create twitter:svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal 'svenfuchs', identity.twitter['handle']
@@ -22,14 +22,14 @@ def setup
end
test 'creating w/ a github handle' do
- command('create', 'rugb', 'svenfuchs', 'github:svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create github:svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal 'svenfuchs', identity.github['handle']
end
test 'creating w/ a json url' do
- command('create', 'rugb', 'svenfuchs', 'json:http://tinyurl.com/yc7t8bv').dispatch
+ command('rugb', 'svenfuchs', '!create json:http://tinyurl.com/yc7t8bv').run
identity = Identity.find_by_handle('svenphoox')
assert_equal 'svenphoox', identity.github['handle']
@@ -37,21 +37,21 @@ def setup
end
test 'creating w/ a github url' do
- command('create', 'rugb', 'svenfuchs', 'http://github.com/svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create http://github.com/svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal 'svenfuchs', identity.github['handle']
end
test 'creating w/ a twitter url' do
- command('create', 'rugb', 'svenfuchs', 'http://twitter.com/svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create http://twitter.com/svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal 'svenfuchs', identity.twitter['handle']
end
test 'creating w/ a url returning json' do
- command('create', 'rugb', 'svenfuchs', 'http://tinyurl.com/yc7t8bv').dispatch
+ command('rugb', 'svenfuchs', '!create http://tinyurl.com/yc7t8bv').run
identity = Identity.find_by_handle('svenphoox')
assert_equal 'svenphoox', identity.github['handle']
@@ -63,20 +63,20 @@ def setup
github_at = Time.local(2010, 1, 2, 12, 0, 0)
Time.stubs(:now).returns(twitter_at)
- command('create', 'rugb', 'svenfuchs', 'twitter:svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create twitter:svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal twitter_at, Time.parse(identity.twitter['claimed_at'])
Time.stubs(:now).returns(Time.local(2010, 1, 2, 12, 0, 0))
- command('update', 'rugb', 'svenfuchs', 'github:svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create github:svenfuchs').run
identity = Identity.find_by_handle('svenfuchs')
assert_equal twitter_at, Time.parse(identity.twitter['claimed_at'])
assert_equal github_at, Time.parse(identity.github['claimed_at'])
end
test 'joining a group' do
- command('create', 'rugb', 'svenfuchs').dispatch
- command('join', 'rugb', 'svenfuchs', 'twitter:svenfuchs').dispatch
+ command('rugb', 'svenfuchs', '!create').run
+ command('rugb', 'svenfuchs', '!join').run # twitter:svenfuchs
identity = Identity.find_by_handle('svenfuchs')
assert identity.groups.include?('rugb')
View
73 test/poller_test.rb
@@ -0,0 +1,73 @@
+# require File.expand_path('../test_helper', __FILE__)
+# require 'stringio'
+#
+# class PollerTest < Test::Unit::TestCase
+# def setup
+# setup_stubs
+# end
+#
+# def process!(from, message, id = '12345')
+# status = twitter_status(from, message, id)
+# bot = Command::Poller::Twitter.new(:reply, 'rugb_test', 'password')
+# bot.handler('rugb_test').dispatch(status)
+# end
+#
+# test "polls from twitter once and handles new replies by queueing commands" do
+# Command::Message.stubs(:max_message_id).returns(12345)
+# poller = Command::Poller::Twitter.new(:reply, 'rugb_test', 'password')
+#
+# replies = [twitter_status('svenfuchs', '@rugb_test !update')]
+# poller.twitter.expects(:status).with(:replies, { :since_id => 12345 }).returns(replies)
+#
+# message = { :message_id => '12345', :receiver => 'rugb_test', :sender => 'svenfuchs', :text => '@rugb_test !update', :source => 'twitter' }
+# Command.expects(:queue).with('rugb_test', message)
+# log = capture_stdout { poller.run! }
+#
+# assert_match /imposing as @rugb_test/, log
+# assert_match /Received 1 reply/, log
+# end
+#
+# test 'updating w/ a me url and a github handle' do
+# process!('svenfuchs', '!update json:http://tinyurl.com/yc7t8bv github:svenphoox')
+# identity = Identity.find_by_handle('svenphoox')
+#
+# assert_equal 'svenphoox', identity.github['handle']
+# assert_equal 'Sven', identity.github['name']
+# end
+#
+# test 'updating an existing profile' do
+# process!('svenfuchs', '!create', '12345')
+# assert Identity.find_by_handle('svenfuchs')
+#
+# process!('svenfuchs', '!update json:http://tinyurl.com/yc7t8bv', '12346')
+# identity = Identity.find_by_handle('svenfuchs')
+#
+# assert_equal 'svenfuchs', identity.twitter['handle']
+# assert_equal 'Sven Fuchs', identity.twitter['name']
+# assert_equal 'svenfuchs', identity.json['irc']
+# end
+#
+# test 'logs processed messages' do
+# now = Time.now
+# Time.stubs(:now).returns(now)
+#
+# process!('svenfuchs', '!update')
+# Identity.find_by_handle('svenfuchs')
+# message = Command::Message.find_by_message_id('12345')
+#
+# assert_equal 'rugb_test', message.receiver
+# assert_equal 'svenfuchs', message.sender
+# assert_equal '!update', message.text
+# assert_equal '12345', message.message_id
+# assert_equal now.to_s, Time.parse(message.received_at).to_s
+# end
+#
+# test 'does not process an already processed message' do
+# process!('svenfuchs', '!update')
+# Identity.find_by_handle('svenfuchs')
+#
+# Command.expects(:new).never # TODO
+# Identity.find_by_handle('svenfuchs')
+# end
+#
+# end
View
10 test/test_helper.rb
@@ -1,3 +1,7 @@
+require 'rubygems'
+require 'bundler'
+Bundler.setup
+
$: << File.expand_path('../..', __FILE__)
$: << File.expand_path('../../lib', __FILE__)
@@ -32,8 +36,10 @@ def response(filename)
File.read(File.expand_path("../stubs/#{filename}", __FILE__))
end
- def command(type, receiver, sender, text = '', source = 'twitter')
- Command.new(type, msg(12345, text, sender, receiver, source))
+ def command(receiver, sender, text = '', source = 'twitter')
+ message = msg(12345, text, sender, receiver, source)
+ command, args = *message.parse.first
+ Identity::Command.new(command, args, message)
end
def msg(id = 12345, text = 'text', sender = 'sender', receiver = 'receiver', source = 'twitter')
Please sign in to comment.
Something went wrong with that request. Please try again.