atig 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. data/.gitignore +24 -0
  2. data/Gemfile +3 -0
  3. data/README.mkdn +52 -0
  4. data/Rakefile +15 -0
  5. data/atig.gemspec +25 -0
  6. data/bin/atig +74 -0
  7. data/docs/OMakefile +32 -0
  8. data/docs/OMakeroot +45 -0
  9. data/docs/_static/allow.png +0 -0
  10. data/docs/_static/emacs.png +0 -0
  11. data/docs/_static/irc_setting.png +0 -0
  12. data/docs/_static/irssi.png +0 -0
  13. data/docs/_static/limechat.png +0 -0
  14. data/docs/_static/limechat_s.png +0 -0
  15. data/docs/_static/oauth_channel.png +0 -0
  16. data/docs/_static/screenshot.png +0 -0
  17. data/docs/_static/structure.png +0 -0
  18. data/docs/_static/verify.png +0 -0
  19. data/docs/changelog.rst +96 -0
  20. data/docs/commandline_options.rst +21 -0
  21. data/docs/commands.rst +84 -0
  22. data/docs/conf.py +194 -0
  23. data/docs/config.rst +159 -0
  24. data/docs/feature.rst +41 -0
  25. data/docs/graphics.graffle +1995 -0
  26. data/docs/hacking_guide.rst +43 -0
  27. data/docs/index.rst +109 -0
  28. data/docs/irc.rst +31 -0
  29. data/docs/options.rst +75 -0
  30. data/docs/quickstart.rst +89 -0
  31. data/docs/resize.sh +7 -0
  32. data/docs/tiarra.rst +2 -0
  33. data/docs/tig.rst +21 -0
  34. data/lib/atig.rb +19 -0
  35. data/lib/atig/agent.rb +8 -0
  36. data/lib/atig/agent/agent.rb +38 -0
  37. data/lib/atig/agent/clenup.rb +23 -0
  38. data/lib/atig/agent/dm.rb +35 -0
  39. data/lib/atig/agent/following.rb +45 -0
  40. data/lib/atig/agent/full_list.rb +20 -0
  41. data/lib/atig/agent/list.rb +55 -0
  42. data/lib/atig/agent/list_status.rb +46 -0
  43. data/lib/atig/agent/mention.rb +13 -0
  44. data/lib/atig/agent/other_list.rb +18 -0
  45. data/lib/atig/agent/own_list.rb +18 -0
  46. data/lib/atig/agent/stream_follow.rb +38 -0
  47. data/lib/atig/agent/timeline.rb +13 -0
  48. data/lib/atig/agent/user_stream.rb +31 -0
  49. data/lib/atig/basic_twitter.rb +116 -0
  50. data/lib/atig/bitly.rb +52 -0
  51. data/lib/atig/channel.rb +5 -0
  52. data/lib/atig/channel/channel.rb +17 -0
  53. data/lib/atig/channel/dm.rb +14 -0
  54. data/lib/atig/channel/list.rb +76 -0
  55. data/lib/atig/channel/mention.rb +20 -0
  56. data/lib/atig/channel/retweet.rb +28 -0
  57. data/lib/atig/channel/timeline.rb +74 -0
  58. data/lib/atig/command.rb +21 -0
  59. data/lib/atig/command/autofix.rb +58 -0
  60. data/lib/atig/command/command.rb +24 -0
  61. data/lib/atig/command/command_helper.rb +95 -0
  62. data/lib/atig/command/destroy.rb +44 -0
  63. data/lib/atig/command/dm.rb +31 -0
  64. data/lib/atig/command/favorite.rb +27 -0
  65. data/lib/atig/command/info.rb +50 -0
  66. data/lib/atig/command/limit.rb +15 -0
  67. data/lib/atig/command/location.rb +23 -0
  68. data/lib/atig/command/name.rb +18 -0
  69. data/lib/atig/command/option.rb +37 -0
  70. data/lib/atig/command/refresh.rb +18 -0
  71. data/lib/atig/command/reply.rb +37 -0
  72. data/lib/atig/command/retweet.rb +63 -0
  73. data/lib/atig/command/search.rb +51 -0
  74. data/lib/atig/command/spam.rb +26 -0
  75. data/lib/atig/command/status.rb +41 -0
  76. data/lib/atig/command/thread.rb +44 -0
  77. data/lib/atig/command/time.rb +32 -0
  78. data/lib/atig/command/uptime.rb +32 -0
  79. data/lib/atig/command/user.rb +42 -0
  80. data/lib/atig/command/user_info.rb +27 -0
  81. data/lib/atig/command/version.rb +49 -0
  82. data/lib/atig/command/whois.rb +39 -0
  83. data/lib/atig/db/db.rb +60 -0
  84. data/lib/atig/db/followings.rb +131 -0
  85. data/lib/atig/db/listenable.rb +22 -0
  86. data/lib/atig/db/lists.rb +76 -0
  87. data/lib/atig/db/roman.rb +30 -0
  88. data/lib/atig/db/sized_uniq_array.rb +62 -0
  89. data/lib/atig/db/sql.rb +35 -0
  90. data/lib/atig/db/statuses.rb +147 -0
  91. data/lib/atig/db/transaction.rb +47 -0
  92. data/lib/atig/exception_util.rb +26 -0
  93. data/lib/atig/gateway.rb +62 -0
  94. data/lib/atig/gateway/channel.rb +99 -0
  95. data/lib/atig/gateway/session.rb +326 -0
  96. data/lib/atig/http.rb +95 -0
  97. data/lib/atig/ifilter.rb +7 -0
  98. data/lib/atig/ifilter/expand_url.rb +74 -0
  99. data/lib/atig/ifilter/retweet.rb +14 -0
  100. data/lib/atig/ifilter/retweet_time.rb +16 -0
  101. data/lib/atig/ifilter/sanitize.rb +18 -0
  102. data/lib/atig/ifilter/strip.rb +15 -0
  103. data/lib/atig/ifilter/utf7.rb +26 -0
  104. data/lib/atig/ifilter/xid.rb +36 -0
  105. data/lib/atig/levenshtein.rb +49 -0
  106. data/lib/atig/monkey.rb +4 -0
  107. data/lib/atig/oauth-patch.rb +40 -0
  108. data/lib/atig/oauth.rb +55 -0
  109. data/lib/atig/ofilter.rb +4 -0
  110. data/lib/atig/ofilter/escape_url.rb +102 -0
  111. data/lib/atig/ofilter/footer.rb +20 -0
  112. data/lib/atig/ofilter/geo.rb +17 -0
  113. data/lib/atig/ofilter/short_url.rb +47 -0
  114. data/lib/atig/option.rb +90 -0
  115. data/lib/atig/scheduler.rb +79 -0
  116. data/lib/atig/search.rb +22 -0
  117. data/lib/atig/search_twitter.rb +21 -0
  118. data/lib/atig/sized_hash.rb +33 -0
  119. data/lib/atig/stream.rb +66 -0
  120. data/lib/atig/twitter.rb +79 -0
  121. data/lib/atig/twitter_struct.rb +63 -0
  122. data/lib/atig/unu.rb +27 -0
  123. data/lib/atig/update_checker.rb +53 -0
  124. data/lib/atig/url_escape.rb +62 -0
  125. data/lib/atig/util.rb +16 -0
  126. data/lib/atig/version.rb +3 -0
  127. data/lib/memory_profiler.rb +77 -0
  128. data/spec/command/autofix_spec.rb +35 -0
  129. data/spec/command/destroy_spec.rb +98 -0
  130. data/spec/command/dm_spec.rb +28 -0
  131. data/spec/command/favorite_spec.rb +55 -0
  132. data/spec/command/limit_spec.rb +27 -0
  133. data/spec/command/location_spec.rb +25 -0
  134. data/spec/command/name_spec.rb +19 -0
  135. data/spec/command/option_spec.rb +133 -0
  136. data/spec/command/refresh_spec.rb +22 -0
  137. data/spec/command/reply_spec.rb +79 -0
  138. data/spec/command/retweet_spec.rb +66 -0
  139. data/spec/command/spam_spec.rb +27 -0
  140. data/spec/command/status_spec.rb +44 -0
  141. data/spec/command/thread_spec.rb +91 -0
  142. data/spec/command/time_spec.rb +52 -0
  143. data/spec/command/uptime_spec.rb +55 -0
  144. data/spec/command/user_info_spec.rb +42 -0
  145. data/spec/command/user_spec.rb +50 -0
  146. data/spec/command/version_spec.rb +67 -0
  147. data/spec/command/whois_spec.rb +78 -0
  148. data/spec/db/followings_spec.rb +100 -0
  149. data/spec/db/listenable_spec.rb +32 -0
  150. data/spec/db/lists_spec.rb +104 -0
  151. data/spec/db/roman_spec.rb +17 -0
  152. data/spec/db/sized_uniq_array_spec.rb +63 -0
  153. data/spec/db/statuses_spec.rb +180 -0
  154. data/spec/ifilter/expand_url_spec.rb +44 -0
  155. data/spec/ifilter/retweet_spec.rb +28 -0
  156. data/spec/ifilter/retweet_time_spec.rb +25 -0
  157. data/spec/ifilter/sanitize_spec.rb +25 -0
  158. data/spec/ifilter/sid_spec.rb +29 -0
  159. data/spec/ifilter/strip_spec.rb +23 -0
  160. data/spec/ifilter/tid_spec.rb +29 -0
  161. data/spec/ifilter/utf7_spec.rb +30 -0
  162. data/spec/levenshtein_spec.rb +24 -0
  163. data/spec/ofilter/escape_url_spec.rb +50 -0
  164. data/spec/ofilter/footer_spec.rb +32 -0
  165. data/spec/ofilter/geo_spec.rb +33 -0
  166. data/spec/ofilter/short_url_spec.rb +127 -0
  167. data/spec/option_spec.rb +91 -0
  168. data/spec/sized_hash_spec.rb +45 -0
  169. data/spec/spec_helper.rb +35 -0
  170. data/spec/update_checker_spec.rb +55 -0
  171. metadata +326 -0
@@ -0,0 +1,79 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/reply'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Reply do
8
+ include CommandHelper
9
+ before do
10
+ @command = init Atig::Command::Reply
11
+
12
+ target = status 'blah blah', 'id'=>'1'
13
+ entry = entry user(1,'mzp'), target
14
+ @res = mock 'res'
15
+
16
+ stub_status(:find_by_tid,'a' => entry)
17
+ stub_status(:find_by_sid,'mzp:a' => entry)
18
+ stub_status(:find_by_screen_name,'mzp' => [ entry ], :default => [])
19
+ end
20
+
21
+ it "should have '/me status' name" do
22
+ @gateway.names.should == %w(mention re reply rp)
23
+ end
24
+
25
+ it "should post the status" do
26
+ @api.should_receive(:post).
27
+ with('statuses/update', {:status=>'abc @mzp', :in_reply_to_status_id=>'1'}).
28
+ and_return(@res)
29
+
30
+ call '#twitter', "reply", %w(a abc @mzp)
31
+
32
+ @gateway.updated.should == [ @res, '#twitter', 'In reply to mzp: blah blah' ]
33
+ @gateway.filtered.should == { :status => 'abc @mzp', :in_reply_to_status_id=>'1'}
34
+ end
35
+
36
+ it "should post the status by sid" do
37
+ @api.should_receive(:post).
38
+ with('statuses/update', {:status=>'abc @mzp', :in_reply_to_status_id=>'1'}).
39
+ and_return(@res)
40
+
41
+ call '#twitter', "reply", %w(mzp:a abc @mzp)
42
+
43
+ @gateway.updated.should == [ @res, '#twitter', 'In reply to mzp: blah blah' ]
44
+ @gateway.filtered.should == { :status => 'abc @mzp', :in_reply_to_status_id=>'1'}
45
+ end
46
+
47
+ it "should post the status by API" do
48
+ @api.should_receive(:post).
49
+ with('statuses/update', {:status=>'abc @mzp', :in_reply_to_status_id=>'1'}).
50
+ and_return(@res)
51
+
52
+ call '#twitter', "reply", %w(a abc @mzp)
53
+
54
+ @gateway.updated.should == [ @res, '#twitter', 'In reply to mzp: blah blah' ]
55
+ @gateway.filtered.should == { :status => 'abc @mzp', :in_reply_to_status_id=>'1'}
56
+ end
57
+
58
+ it "should post the status with screen_name" do
59
+ @api.should_receive(:post).
60
+ with('statuses/update', {:status=>'abc @mzp', :in_reply_to_status_id=>'1'}).
61
+ and_return(@res)
62
+
63
+ call '#twitter', "reply", %w(mzp abc @mzp)
64
+
65
+ @gateway.updated.should == [ @res, '#twitter', 'In reply to mzp: blah blah' ]
66
+ @gateway.filtered.should == { :status => 'abc @mzp', :in_reply_to_status_id=>'1'}
67
+ end
68
+
69
+ it "should add screen name as prefix" do
70
+ @api.should_receive(:post).
71
+ with('statuses/update', {:status=>'@mzp mzp', :in_reply_to_status_id=>'1'}).
72
+ and_return(@res)
73
+
74
+ call '#twitter', "reply", %w(a mzp)
75
+
76
+ @gateway.updated.should == [ @res, '#twitter', 'In reply to mzp: blah blah' ]
77
+ @gateway.filtered.should == { :status => '@mzp mzp', :in_reply_to_status_id=>'1'}
78
+ end
79
+ end
@@ -0,0 +1,66 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/retweet'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Retweet do
8
+ include CommandHelper
9
+ before do
10
+ bitly = mock("Bitly")
11
+ bitly.stub!(:shorten).and_return{|s|
12
+ "[#{s}]"
13
+ }
14
+ Atig::Bitly.stub!(:no_login).and_return(bitly)
15
+
16
+ @command = init Atig::Command::Retweet
17
+
18
+ target = status 'blah blah blah blah blah blah blah blah', 'id'=>'1'
19
+ entry = entry user(1,'mzp'), target
20
+ @res = mock 'res'
21
+
22
+ stub_status(:find_by_tid,'a' => entry)
23
+ stub_status(:find_by_sid,'mzp:a' => entry)
24
+ stub_status(:find_by_screen_name,'mzp' => [ entry ], :default=>[])
25
+ end
26
+
27
+ it "should have command name" do
28
+ @gateway.names.should == %w(ort rt retweet qt)
29
+ end
30
+
31
+ it "should post official retweet without comment" do
32
+ @api.should_receive(:post).with('statuses/retweet/1').and_return(@res)
33
+ call "#twitter", 'rt', %w(a)
34
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
35
+ end
36
+
37
+ it "should post official retweet without comment by screen name" do
38
+ @api.should_receive(:post).with('statuses/retweet/1').and_return(@res)
39
+ call "#twitter", 'rt', %w(mzp)
40
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
41
+ end
42
+
43
+ it "should post official retweet without comment by sid" do
44
+ @api.should_receive(:post).with('statuses/retweet/1').and_return(@res)
45
+ call "#twitter", 'rt', %w(mzp:a)
46
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
47
+ end
48
+
49
+ it "should post un-official retweet with comment" do
50
+ @api.should_receive(:post).with('statuses/update',:status=> "aaa RT @mzp: blah blah blah blah blah blah blah blah").and_return(@res)
51
+ call "#twitter", 'rt', %w(a aaa)
52
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
53
+ end
54
+
55
+ it "should post un-official retweet with comment by screen name" do
56
+ @api.should_receive(:post).with('statuses/update',:status=> "aaa RT @mzp: blah blah blah blah blah blah blah blah").and_return(@res)
57
+ call "#twitter", 'rt', %w(mzp aaa)
58
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
59
+ end
60
+
61
+ it "should post un-official retweet with long comment" do
62
+ @api.should_receive(:post).with('statuses/update',:status=> "#{'a' * 95} RT @mzp: b [http://twitter.com/mzp/status/1]").and_return(@res)
63
+ call "#twitter", 'rt', ['a', 'a' * 95 ]
64
+ @gateway.updated.should == [ @res, '#twitter', 'RT to mzp: blah blah blah blah blah blah blah blah' ]
65
+ end
66
+ end
@@ -0,0 +1,27 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/command_helper'
5
+ require 'atig/command/spam'
6
+
7
+ describe Atig::Command::Spam do
8
+ include CommandHelper
9
+ before do
10
+ @command = init Atig::Command::Spam
11
+ end
12
+
13
+ it "はspamコマンドを提供する" do
14
+ @gateway.names.should == %w(spam SPAM)
15
+ end
16
+
17
+ it "は指定されたscreen_nameを通報する" do
18
+ user = user(1,'examplespammer')
19
+ @api.
20
+ should_receive(:post).
21
+ with('report_spam',:screen_name=> 'examplespammer').
22
+ and_return(user)
23
+
24
+ @channel.should_receive(:notify).with("Report examplespammer as SPAMMER")
25
+ call "#twitter", 'spam', %w(examplespammer)
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/status'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Status do
8
+ include CommandHelper
9
+ before do
10
+ @command = init Atig::Command::Status
11
+ end
12
+
13
+ it "should have '/me status' name" do
14
+ @gateway.names.should == ['status']
15
+ end
16
+
17
+ it "should post the status by API" do
18
+ res = status('blah blah')
19
+ @statuses.should_receive(:find_by_user).with(@me,:limit=>1).and_return(nil)
20
+ @api.should_receive(:post).with('statuses/update', {:status=>'blah blah'}).and_return(res)
21
+
22
+ call '#twitter', "status", %w(blah blah)
23
+
24
+ @gateway.updated.should == [ res, '#twitter' ]
25
+ @gateway.filtered.should == { :status => 'blah blah' }
26
+ end
27
+
28
+ it "should not post same post" do
29
+ e = entry user(1,'mzp'), status('blah blah')
30
+ @statuses.should_receive(:find_by_user).with(@me,:limit=>1).and_return([ e ] )
31
+ @channel.should_receive(:notify).with("You can't submit the same status twice in a row.")
32
+
33
+ call '#twitter', "status", %w(blah blah)
34
+ @gateway.notified.should == '#twitter'
35
+ end
36
+
37
+ it "should not post over 140" do
38
+ @statuses.should_receive(:find_by_user).with(@me,:limit=>1).and_return(nil)
39
+ @channel.should_receive(:notify).with("You can't submit the status over 140 chars")
40
+
41
+ call '#twitter', "status", [ 'a' * 141 ]
42
+ @gateway.notified.should == '#twitter'
43
+ end
44
+ end
@@ -0,0 +1,91 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/thread'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Thread do
8
+ include CommandHelper
9
+ before do
10
+ u = mock 'user'
11
+ @entries = [
12
+ entry(u, status(''),'entry-0'),
13
+ entry(u, status('','in_reply_to_status_id'=>2),'entry-1'),
14
+ entry(u, status('','in_reply_to_status_id'=>3),'entry-2'),
15
+ entry(u, status(''),'entry-3'),
16
+ entry(u, status('','in_reply_to_status_id'=>5),'entry-4')
17
+ ]
18
+ @command = init Atig::Command::Thread
19
+ @messages = []
20
+ @channel.stub!(:message).and_return{|entry,_|
21
+ @messages.unshift entry
22
+ }
23
+ @statuses.stub!(:find_by_status_id).with(anything).and_return{|id|
24
+ @entries[id.to_i]
25
+ }
26
+ end
27
+
28
+ it "should provide thread command" do
29
+ @gateway.names.should == %w( thread )
30
+ end
31
+
32
+ it "should show the tweet" do
33
+ @statuses.should_receive(:find_by_tid).with('a').and_return(@entries[0])
34
+
35
+ call "#twitter","thread",%w(a)
36
+
37
+ @messages.should == [ @entries[0] ]
38
+ end
39
+
40
+ it "should chain the tweets" do
41
+ @statuses.should_receive(:find_by_tid).with('a').and_return(@entries[1])
42
+
43
+ call "#twitter","thread",%w(a)
44
+
45
+ @messages.should == @entries[1..3]
46
+ end
47
+
48
+ it "should chain the tweets by screen name" do
49
+ @statuses.should_receive(:find_by_tid).with('mzp').and_return(nil)
50
+ @statuses.should_receive(:find_by_sid).with('mzp').and_return(nil)
51
+ @statuses.should_receive(:find_by_screen_name).with('mzp',:limit=>1).and_return([ @entries[1] ])
52
+
53
+ call "#twitter","thread",%w(mzp)
54
+
55
+ @messages.should == @entries[1..3]
56
+ end
57
+
58
+ it "should chain the tweets by sid" do
59
+ @statuses.should_receive(:find_by_tid).with('mzp:a').and_return(nil)
60
+ @statuses.should_receive(:find_by_sid).with('mzp:a').and_return(@entries[1])
61
+
62
+ call "#twitter","thread",%w(mzp:a)
63
+
64
+ @messages.should == @entries[1..3]
65
+ end
66
+
67
+
68
+
69
+ it "should chain the tweets with limit" do
70
+ @statuses.should_receive(:find_by_tid).with('a').and_return(@entries[1])
71
+
72
+ call "#twitter","thread",%w(a 2)
73
+
74
+ @messages.should == @entries[1..2]
75
+ end
76
+
77
+ it "should get new tweets" do
78
+ @statuses.should_receive(:find_by_tid).with('a').and_return(@entries[4])
79
+ user = user 1, 'mzp'
80
+ status = status '','user'=>user
81
+ entry = entry user,status,'new-entry'
82
+ @statuses.should_receive(:add).with(:status => status, :user => user, :source=>:thread).and_return{
83
+ @entries << entry
84
+ }
85
+ @api.should_receive(:get).with('statuses/show/5').and_return(status)
86
+
87
+ call "#twitter","thread",%w(a)
88
+
89
+ @messages.should == [@entries[4], entry]
90
+ end
91
+ end
@@ -0,0 +1,52 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/time'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Time do
8
+ include CommandHelper
9
+
10
+ def user(offset, tz)
11
+ u = mock "user-#{offset}"
12
+ u.stub!(:utc_offset).and_return(offset)
13
+ u.stub!(:time_zone).and_return(tz)
14
+ u
15
+ end
16
+
17
+ before do
18
+ @command = init Atig::Command::Time
19
+ @user = user(61*60+1,'Tokyo')
20
+ end
21
+
22
+ it "should provide time command" do
23
+ @gateway.names.should == ['time']
24
+ end
25
+
26
+ it "should show offset time on DB" do
27
+ ::Time.should_receive(:now).and_return(Time.at(0))
28
+ @followings.should_receive(:find_by_screen_name).with('mzp').and_return(@user)
29
+ @channel.
30
+ should_receive(:message).
31
+ with(anything, Net::IRC::Constants::NOTICE).
32
+ and_return{|s,_|
33
+ s.status.text.should == "\x01TIME :1970-01-01T01:01:01+01:01 (Tokyo)\x01"
34
+ }
35
+ call '#twitter', 'time', ['mzp']
36
+ @gateway.notified.should == '#twitter'
37
+ end
38
+
39
+ it "should show offset time via API" do
40
+ ::Time.should_receive(:now).and_return(Time.at(0))
41
+ @followings.should_receive(:find_by_screen_name).with('mzp').and_return(nil)
42
+ @api.should_receive(:get).with('users/show', :screen_name=>'mzp').and_return(@user)
43
+ @channel.
44
+ should_receive(:message).
45
+ with(anything, Net::IRC::Constants::NOTICE).
46
+ and_return{|s,_|
47
+ s.status.text.should == "\x01TIME :1970-01-01T01:01:01+01:01 (Tokyo)\x01"
48
+ }
49
+ call '#twitter', 'time', ['mzp']
50
+ @gateway.notified.should == '#twitter'
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__ )
4
+ require 'atig/command/uptime'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::Uptime do
8
+ include CommandHelper
9
+
10
+ before do
11
+ ::Time.should_receive(:now).and_return(::Time.at(0))
12
+ @command = init Atig::Command::Uptime
13
+ end
14
+
15
+ it "should register uptime command" do
16
+ @gateway.names.should == ['uptime']
17
+ end
18
+
19
+ it "should return mm:ss(min)" do
20
+ ::Time.should_receive(:now).and_return(::Time.at(0))
21
+ @channel.should_receive(:notify).with("00:00")
22
+ call '#twitter', 'uptime', []
23
+
24
+ @gateway.notified.should == '#twitter'
25
+ end
26
+
27
+ it "should return mm:ss(max)" do
28
+ ::Time.should_receive(:now).and_return(::Time.at(60*60-1))
29
+ @channel.should_receive(:notify).with("59:59")
30
+ call '#twitter', 'uptime', []
31
+
32
+ @gateway.notified.should == '#twitter'
33
+ end
34
+
35
+ it "should return hh:mm:ss(min)" do
36
+ ::Time.should_receive(:now).and_return(::Time.at(60*60))
37
+ @channel.should_receive(:notify).with("01:00:00")
38
+ call '#twitter', 'uptime', []
39
+ @gateway.notified.should == '#twitter'
40
+ end
41
+
42
+ it "should return hh:mm:ss(max)" do
43
+ ::Time.should_receive(:now).and_return(::Time.at(24*60*60-1))
44
+ @channel.should_receive(:notify).with("23:59:59")
45
+ call '#twitter', 'uptime', []
46
+ @gateway.notified.should == '#twitter'
47
+ end
48
+
49
+ it "should return dd days hh:mm:ss" do
50
+ ::Time.should_receive(:now).and_return(::Time.at(24*60*60))
51
+ @channel.should_receive(:notify).with("1 days 00:00")
52
+ call '#twitter', 'uptime', []
53
+ @gateway.notified.should == '#twitter'
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ # -*- mode:ruby; coding:utf-8 -*-
2
+
3
+ require File.expand_path( '../../spec_helper', __FILE__)
4
+ require 'atig/command/user_info'
5
+ require 'atig/command/command_helper'
6
+
7
+ describe Atig::Command::UserInfo do
8
+ include CommandHelper
9
+
10
+ before do
11
+ @command = init Atig::Command::UserInfo
12
+ @status = stub "status"
13
+ @user = stub "user"
14
+ @user.stub!(:description).and_return('hogehoge')
15
+ @user.stub!(:status).and_return(@status)
16
+ end
17
+
18
+ it "should show the source via DB" do
19
+ @followings.should_receive(:find_by_screen_name).with('mzp').and_return(@user)
20
+ @channel.
21
+ should_receive(:message).
22
+ with(anything, Net::IRC::Constants::NOTICE).
23
+ and_return{|s,_|
24
+ s.status.text.should == "\x01hogehoge\x01"
25
+ }
26
+ call '#twitter','userinfo',%w(mzp)
27
+ end
28
+
29
+ it "should show the source via API" do
30
+ @followings.should_receive(:find_by_screen_name).with('mzp').and_return(nil)
31
+ @api.should_receive(:get).with('users/show',:screen_name=>'mzp').and_return(@user)
32
+
33
+ @channel.
34
+ should_receive(:message).
35
+ with(anything, Net::IRC::Constants::NOTICE).
36
+ and_return{|s,_|
37
+ s.status.text.should == "\x01hogehoge\x01"
38
+ }
39
+
40
+ call '#twitter','userinfo',%w(mzp)
41
+ end
42
+ end