geera 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/ChangeLog +43 -0
- data/Manifest.txt +30 -0
- data/README.rdoc +189 -0
- data/Rakefile +15 -0
- data/bin/geera +118 -0
- data/lib/geera.rb +23 -0
- data/lib/geera/client.rb +63 -0
- data/lib/geera/commands/assign.rb +13 -0
- data/lib/geera/commands/command.rb +19 -0
- data/lib/geera/commands/estimate.rb +13 -0
- data/lib/geera/commands/filters.rb +16 -0
- data/lib/geera/commands/fix.rb +15 -0
- data/lib/geera/commands/list.rb +29 -0
- data/lib/geera/commands/show.rb +13 -0
- data/lib/geera/commands/start.rb +17 -0
- data/lib/geera/commands/take.rb +13 -0
- data/lib/geera/executable.rb +10 -0
- data/lib/geera/ticket.rb +116 -0
- data/lib/template.txt +12 -0
- data/test/commands/test_assign.rb +27 -0
- data/test/commands/test_estimate.rb +27 -0
- data/test/commands/test_filters.rb +34 -0
- data/test/commands/test_fix.rb +74 -0
- data/test/commands/test_list.rb +90 -0
- data/test/commands/test_show.rb +34 -0
- data/test/commands/test_start.rb +28 -0
- data/test/commands/test_take.rb +31 -0
- data/test/test_client.rb +214 -0
- data/test/test_ticket.rb +19 -0
- metadata +170 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
module Geera
|
6
|
+
module Commands
|
7
|
+
class TestFix < Test::Unit::TestCase
|
8
|
+
def test_handle?
|
9
|
+
assert Fix.handle?('fix')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_execute_startable
|
13
|
+
recorder = Object.new
|
14
|
+
flexmock(recorder) do |thing|
|
15
|
+
thing.should_receive(:startable?).once.and_return(true)
|
16
|
+
thing.should_receive(:start!).once
|
17
|
+
thing.should_receive(:fixable?).once.and_return(true)
|
18
|
+
thing.should_receive(:fix!).once
|
19
|
+
thing.should_receive(:assign_to).once.with('foo')
|
20
|
+
end
|
21
|
+
|
22
|
+
fake_command.new(recorder, {'qa' => 'foo'}).execute!
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_execute_not_startable
|
26
|
+
recorder = Object.new
|
27
|
+
flexmock(recorder) do |thing|
|
28
|
+
thing.should_receive(:startable?).once.and_return(false)
|
29
|
+
thing.should_receive(:start!).never
|
30
|
+
thing.should_receive(:fixable?).once.and_return(true)
|
31
|
+
thing.should_receive(:fix!).once
|
32
|
+
thing.should_receive(:assign_to).once.with('foo')
|
33
|
+
end
|
34
|
+
|
35
|
+
fake_command.new(recorder, {'qa' => 'foo'}).execute!
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_execute_not_fixable
|
39
|
+
recorder = Object.new
|
40
|
+
flexmock(recorder) do |thing|
|
41
|
+
thing.should_receive(:startable?).once.and_return(false)
|
42
|
+
thing.should_receive(:start!).never
|
43
|
+
thing.should_receive(:fixable?).once.and_return(false)
|
44
|
+
thing.should_receive(:fix!).never
|
45
|
+
thing.should_receive(:assign_to).once.with('foo')
|
46
|
+
end
|
47
|
+
|
48
|
+
fake_command.new(recorder, {'qa' => 'foo'}).execute!
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_execute_no_qa
|
52
|
+
recorder = Object.new
|
53
|
+
flexmock(recorder) do |thing|
|
54
|
+
thing.should_receive(:startable?).once.and_return(false)
|
55
|
+
thing.should_receive(:start!).never
|
56
|
+
thing.should_receive(:fixable?).once.and_return(false)
|
57
|
+
thing.should_receive(:fix!).never
|
58
|
+
thing.should_receive(:assign_to).never
|
59
|
+
end
|
60
|
+
|
61
|
+
fake_command.new(recorder, {'qa' => nil}).execute!
|
62
|
+
end
|
63
|
+
|
64
|
+
def fake_command
|
65
|
+
Class.new(Geera::Commands::Fix) {
|
66
|
+
def initialize ticket, config
|
67
|
+
super(config, nil, nil, nil)
|
68
|
+
@ticket = ticket
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
module Geera
|
6
|
+
module Commands
|
7
|
+
class TestList < Test::Unit::TestCase
|
8
|
+
FakeTicket = Struct.new(:key, :summary)
|
9
|
+
|
10
|
+
def test_handle?
|
11
|
+
assert List.handle?('list')
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_number_with_name
|
15
|
+
recorder = Object.new
|
16
|
+
flexmock(recorder) do |thing|
|
17
|
+
thing.should_receive(:filters).once.and_return(
|
18
|
+
[Struct.new(:name, :id).new('foo', 10)]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
cmd = List.new(nil, 'foo', recorder, [])
|
23
|
+
assert_equal 10, cmd.number
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_number
|
27
|
+
recorder = Object.new
|
28
|
+
flexmock(recorder) do |thing|
|
29
|
+
thing.should_receive(:filters).never
|
30
|
+
end
|
31
|
+
|
32
|
+
cmd = List.new(nil, 10, recorder, [])
|
33
|
+
assert_equal 10, cmd.number
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_execute!
|
37
|
+
number = 10
|
38
|
+
|
39
|
+
recorder = Object.new
|
40
|
+
flexmock(recorder) do |thing|
|
41
|
+
thing.should_receive(:list).with(number).once.and_return([
|
42
|
+
FakeTicket.new('BZ-123', 'hello'),
|
43
|
+
FakeTicket.new('BZ-124', 'world'),
|
44
|
+
])
|
45
|
+
end
|
46
|
+
|
47
|
+
cmd = Class.new(List) {
|
48
|
+
attr_reader :putses
|
49
|
+
def initialize *args
|
50
|
+
super
|
51
|
+
@putses = []
|
52
|
+
end
|
53
|
+
|
54
|
+
def puts string
|
55
|
+
@putses << string
|
56
|
+
end
|
57
|
+
}.new(nil, number, recorder, [])
|
58
|
+
|
59
|
+
cmd.execute!
|
60
|
+
assert_match(/BZ-123/, cmd.putses.first)
|
61
|
+
assert_match(/hello/, cmd.putses.first)
|
62
|
+
assert_match(/BZ-124/, cmd.putses[1])
|
63
|
+
assert_match(/world/, cmd.putses[1])
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_empty_execute
|
67
|
+
recorder = Object.new
|
68
|
+
flexmock(recorder) do |thing|
|
69
|
+
thing.should_receive(:list).with(10).once.and_return([])
|
70
|
+
end
|
71
|
+
|
72
|
+
cmd = Class.new(List) {
|
73
|
+
attr_reader :putses
|
74
|
+
def initialize *args
|
75
|
+
super
|
76
|
+
@putses = []
|
77
|
+
end
|
78
|
+
|
79
|
+
def puts string
|
80
|
+
@putses << string
|
81
|
+
end
|
82
|
+
}.new(nil, 10, recorder, [])
|
83
|
+
cmd.execute!
|
84
|
+
|
85
|
+
assert_equal ["No Tickets found"], cmd.putses
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
module Geera
|
6
|
+
module Commands
|
7
|
+
class TestShow < Test::Unit::TestCase
|
8
|
+
def test_handle?
|
9
|
+
assert Show.handle?('show')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_execute!
|
13
|
+
recorder = Object.new
|
14
|
+
flexmock(recorder) do |thing|
|
15
|
+
thing.should_receive(:inspect).once.and_return('foo')
|
16
|
+
end
|
17
|
+
|
18
|
+
cmd = fake_command.new recorder
|
19
|
+
|
20
|
+
flexmock(cmd).should_receive(:puts).with('foo')
|
21
|
+
cmd.execute!
|
22
|
+
end
|
23
|
+
|
24
|
+
def fake_command
|
25
|
+
Class.new(Geera::Commands::Show) {
|
26
|
+
def initialize ticket
|
27
|
+
super(nil, nil, nil, nil)
|
28
|
+
@ticket = ticket
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
module Geera
|
6
|
+
module Commands
|
7
|
+
class TestStart < Test::Unit::TestCase
|
8
|
+
def test_handle?
|
9
|
+
assert Start.handle?('start')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_execute!
|
13
|
+
recorder = Object.new
|
14
|
+
flexmock(recorder) do |thing|
|
15
|
+
thing.should_receive(:startable?).once.and_return(true)
|
16
|
+
thing.should_receive(:start!).once
|
17
|
+
end
|
18
|
+
|
19
|
+
Class.new(Geera::Commands::Start) {
|
20
|
+
def initialize ticket
|
21
|
+
super(nil, nil, nil, nil)
|
22
|
+
@ticket = ticket
|
23
|
+
end
|
24
|
+
}.new(recorder).execute!
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
module Geera
|
6
|
+
module Commands
|
7
|
+
class TestTake < Test::Unit::TestCase
|
8
|
+
def test_handle?
|
9
|
+
assert Take.handle?('take')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_execute!
|
13
|
+
recorder = Object.new
|
14
|
+
flexmock(recorder) do |thing|
|
15
|
+
thing.should_receive(:assign_to).with('foo').once
|
16
|
+
end
|
17
|
+
|
18
|
+
fake_command.new(recorder, 'username' => 'foo').execute!
|
19
|
+
end
|
20
|
+
|
21
|
+
def fake_command
|
22
|
+
Class.new(Geera::Commands::Take) {
|
23
|
+
def initialize ticket, config
|
24
|
+
super(config, nil, nil, nil)
|
25
|
+
@ticket = ticket
|
26
|
+
end
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "geera"
|
3
|
+
require 'flexmock/test_unit'
|
4
|
+
|
5
|
+
###
|
6
|
+
# This is our fake jira object
|
7
|
+
class FakeJiraTool
|
8
|
+
attr_accessor :call_stack, :returns
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@call_stack = []
|
12
|
+
@returns = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing *args
|
16
|
+
@call_stack << args
|
17
|
+
@returns.delete(args.first) if @returns.key?(args.first)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestClient < Test::Unit::TestCase
|
22
|
+
FakeIssue = Struct.new(:description, :key, :priority)
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@url = 'some_url'
|
26
|
+
@fj = FakeJiraTool.new
|
27
|
+
flexmock(Jira4R::JiraTool).should_receive(:new).with(2, @url).
|
28
|
+
and_return(@fj)
|
29
|
+
|
30
|
+
@number = 'BZ-123'
|
31
|
+
@client = Geera::Client.new(@url)
|
32
|
+
@username = 'foo'
|
33
|
+
@client.login(@username, 'bar')
|
34
|
+
@ticket = @client.ticket @number
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_login
|
38
|
+
client = Geera::Client.new(@url)
|
39
|
+
client.login('foo', 'bar')
|
40
|
+
|
41
|
+
assert_equal([:login, "foo", "bar"], @fj.call_stack.pop)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_comment
|
45
|
+
number = 'BZ-123'
|
46
|
+
comment = 'hello world'
|
47
|
+
|
48
|
+
client = Geera::Client.new(@url)
|
49
|
+
client.login('foo', 'bar')
|
50
|
+
|
51
|
+
ticket = client.ticket number
|
52
|
+
ticket.comment comment
|
53
|
+
|
54
|
+
last_call = @fj.call_stack.pop
|
55
|
+
assert_equal :addComment, last_call.first
|
56
|
+
assert_equal number, last_call[1]
|
57
|
+
assert_instance_of(Jira4R::V2::RemoteComment, last_call.last)
|
58
|
+
assert_equal(comment, last_call.last.body)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_available_actions
|
62
|
+
actions = [
|
63
|
+
Jira4R::V2::RemoteNamedObject.new("1", "Fix"),
|
64
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
65
|
+
]
|
66
|
+
|
67
|
+
@fj.returns[:getAvailableActions] = actions
|
68
|
+
|
69
|
+
assert_equal(actions, @ticket.available_actions)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_startable?
|
73
|
+
actions = [
|
74
|
+
Jira4R::V2::RemoteNamedObject.new("1", "Fix"),
|
75
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
76
|
+
]
|
77
|
+
@fj.returns[:getAvailableActions] = actions
|
78
|
+
|
79
|
+
assert !@ticket.startable?
|
80
|
+
|
81
|
+
actions = [
|
82
|
+
Jira4R::V2::RemoteNamedObject.new("1", "Fix"),
|
83
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Start"),
|
84
|
+
]
|
85
|
+
|
86
|
+
@fj.returns[:getAvailableActions] = actions
|
87
|
+
assert @ticket.startable?
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_start!
|
91
|
+
startid = '1'
|
92
|
+
|
93
|
+
actions = [
|
94
|
+
Jira4R::V2::RemoteNamedObject.new(startid, "Start"),
|
95
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
96
|
+
]
|
97
|
+
|
98
|
+
@fj.returns[:getAvailableActions] = actions
|
99
|
+
@fj.returns[:getIssue] = FakeIssue.new('desc', nil, '5')
|
100
|
+
@ticket.start!
|
101
|
+
|
102
|
+
last_call = @fj.call_stack.pop
|
103
|
+
assert_equal :progressWorkflowAction, last_call.first
|
104
|
+
assert_equal @number, last_call[1]
|
105
|
+
assert_equal startid, last_call[2]
|
106
|
+
|
107
|
+
assert_instance_of(Array, last_call.last)
|
108
|
+
|
109
|
+
params = last_call.last
|
110
|
+
assert_equal 'assignee', params.first.id
|
111
|
+
assert_equal @username, params.first.values
|
112
|
+
|
113
|
+
assert_equal 'description', params[1].id
|
114
|
+
assert_equal 'desc', params[1].values
|
115
|
+
|
116
|
+
assert_equal 'priority', params[2].id
|
117
|
+
assert_equal '5', params[2].values
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_fixable?
|
121
|
+
actions = [
|
122
|
+
Jira4R::V2::RemoteNamedObject.new('1', "Start"),
|
123
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
124
|
+
]
|
125
|
+
|
126
|
+
@fj.returns[:getAvailableActions] = actions
|
127
|
+
assert !@ticket.fixable?
|
128
|
+
|
129
|
+
actions = [
|
130
|
+
Jira4R::V2::RemoteNamedObject.new('1', "Fix"),
|
131
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
132
|
+
]
|
133
|
+
|
134
|
+
@fj.returns[:getAvailableActions] = actions
|
135
|
+
assert @ticket.fixable?
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_fix!
|
139
|
+
startid = '1'
|
140
|
+
|
141
|
+
actions = [
|
142
|
+
Jira4R::V2::RemoteNamedObject.new(startid, "Fix"),
|
143
|
+
Jira4R::V2::RemoteNamedObject.new("2", "Update Progress"),
|
144
|
+
]
|
145
|
+
|
146
|
+
@fj.returns[:getAvailableActions] = actions
|
147
|
+
@fj.returns[:getIssue] = FakeIssue.new('desc', nil, '5')
|
148
|
+
@ticket.fix!
|
149
|
+
|
150
|
+
last_call = @fj.call_stack.pop
|
151
|
+
assert_equal :progressWorkflowAction, last_call.first
|
152
|
+
assert_equal @number, last_call[1]
|
153
|
+
assert_equal startid, last_call[2]
|
154
|
+
|
155
|
+
assert_instance_of(Array, last_call.last)
|
156
|
+
|
157
|
+
params = last_call.last
|
158
|
+
assert_equal 'assignee', params.first.id
|
159
|
+
assert_equal @username, params.first.values
|
160
|
+
|
161
|
+
assert_equal 'description', params[1].id
|
162
|
+
assert_equal 'desc', params[1].values
|
163
|
+
|
164
|
+
assert_equal 'priority', params[2].id
|
165
|
+
assert_equal '5', params[2].values
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_assign_to
|
169
|
+
@ticket.assign_to 'aaron'
|
170
|
+
last_call = @fj.call_stack.pop
|
171
|
+
assert_equal :updateIssue, last_call.first
|
172
|
+
assert_instance_of Array, last_call.last
|
173
|
+
|
174
|
+
rfv = last_call.last.first
|
175
|
+
assert_equal 'assignee', rfv.id
|
176
|
+
assert_equal 'aaron', rfv.values
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_create_ticket
|
180
|
+
params = { :project => 'BZ',
|
181
|
+
:summary => 'hello world',
|
182
|
+
:description => 'testing' }
|
183
|
+
|
184
|
+
@fj.returns[:createIssue] = FakeIssue.new(params[:description], 'foo')
|
185
|
+
|
186
|
+
@client.create_ticket params
|
187
|
+
|
188
|
+
last_call = @fj.call_stack.pop
|
189
|
+
assert_equal :createIssue, last_call.first
|
190
|
+
assert_instance_of Jira4R::V2::RemoteIssue, last_call.last
|
191
|
+
|
192
|
+
ri = last_call.last
|
193
|
+
assert_equal params[:project], ri.project
|
194
|
+
assert_equal '1', ri.type
|
195
|
+
assert_equal @username, ri.assignee
|
196
|
+
assert_equal params[:summary], ri.summary
|
197
|
+
assert_equal params[:description], ri.description
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_create_bad_args
|
201
|
+
assert_raises(ArgumentError) do
|
202
|
+
@client.create_ticket {}
|
203
|
+
end
|
204
|
+
|
205
|
+
assert_raises(ArgumentError) do
|
206
|
+
@client.create_ticket :project => 'ab'
|
207
|
+
end
|
208
|
+
|
209
|
+
assert_raises(ArgumentError) do
|
210
|
+
@client.create_ticket :project => 'ab', :description => 'foo'
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|