schubert-minglr 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ module Resources
5
5
  class AttachmentTest < Test::Unit::TestCase
6
6
 
7
7
  context Attachment do
8
-
8
+
9
9
  context "configure" do
10
10
 
11
11
  should "append to the site url" do
@@ -21,14 +21,64 @@ module Resources
21
21
 
22
22
  context "fetch" do
23
23
 
24
- should_eventually "download all found attachments for a given card number" do
24
+ should "download all found attachments for a given card number" do
25
+ card = Card.new
26
+ card.stubs(:number).returns(1)
27
+
28
+ attachment1 = Attachment.new
29
+ attachment1.stubs(:url).returns("http://attachment1.url")
30
+ attachment1.stubs(:file_name).returns("attachment1.txt")
31
+ attachment2 = Attachment.new
32
+ attachment2.stubs(:url).returns("http://attachment2.url")
33
+ attachment2.stubs(:file_name).returns("attachment2.txt")
34
+
35
+ Attachment.stubs(:puts)
36
+ Card.expects(:find).with(1).returns(card)
37
+ Attachment.expects(:find).with(:all, :params => { :card_number => 1 }).returns([attachment1, attachment2])
38
+ Attachment.expects(:curl).with("curl --insecure --progress-bar --output attachment1.txt --user username:password http://attachment1.url")
39
+ Attachment.expects(:curl).with("curl --insecure --progress-bar --output attachment2.txt --user username:password http://attachment2.url")
40
+
41
+ Attachment.fetch(1, "username", "password")
25
42
  end
26
43
 
27
44
  end
28
45
 
29
46
  context "attach" do
30
47
 
31
- should_eventually "upload file for a given card number" do
48
+ setup do
49
+ options = { :username => "user",
50
+ :password => "pass",
51
+ :url => "proto://somehost.com:1234/projects/my_project" }
52
+ Base.configure(options)
53
+ end
54
+
55
+ should "upload file for a given card number" do
56
+ file_name = File.join(File.dirname(__FILE__), "..", "..", "Rakefile")
57
+
58
+ card = Card.new
59
+ card.stubs(:number).returns(1)
60
+
61
+ fake_response = stub("Response", :status_code => 201)
62
+ fake_client = mock("HTTPClient")
63
+ fake_client.expects(:post).returns(fake_response)
64
+ fake_client.expects(:set_auth).with(nil, "username", "password")
65
+
66
+ Card.expects(:find).with(1).returns(card)
67
+ HTTPClient.expects(:new).returns(fake_client)
68
+ Attachment.expects(:puts).with("File '#{file_name}' attached to card 1")
69
+
70
+ Attachment.attach(1, file_name, "username", "password")
71
+ end
72
+
73
+ should "warn for invalid file" do
74
+ card = Card.new
75
+ card.stubs(:number).returns(1)
76
+
77
+ Card.expects(:find).with(1).returns(card)
78
+ File.expects(:exist?).with("myfile.txt").returns(false)
79
+ Attachment.expects(:warn).with("Unable to open file 'myfile.txt'")
80
+
81
+ Attachment.attach(1, "myfile.txt", "username", "password")
32
82
  end
33
83
 
34
84
  end
@@ -30,10 +30,23 @@ module Resources
30
30
 
31
31
  context "print_collection" do
32
32
 
33
- should_eventually "print values of attributes of objects separated by dashes and aligning columns of values" do
33
+ setup do
34
+ @object1 = stub("Object", :name => "Foo", :description => "Bar")
35
+ @object2 = stub("Object", :name => "Bar", :description => "Frobble")
36
+ @collection = [@object1, @object2]
37
+ @attributes = [:name, :description]
34
38
  end
35
39
 
36
- should_eventually "allow for right adjusted values" do
40
+ should "print values of attributes of objects separated by dashes and aligning columns of values" do
41
+ Base.expects(:puts).with("Foo - Bar ")
42
+ Base.expects(:puts).with("Bar - Frobble")
43
+ Base.print_collection(@collection, @attributes)
44
+ end
45
+
46
+ should "allow for right adjusted values" do
47
+ Base.expects(:puts).with("Foo - Bar")
48
+ Base.expects(:puts).with("Bar - Frobble")
49
+ Base.print_collection(@collection, @attributes, :right)
37
50
  end
38
51
 
39
52
  end
@@ -5,16 +5,33 @@ module Resources
5
5
  class CardTest < Test::Unit::TestCase
6
6
 
7
7
  context Card do
8
-
8
+
9
9
  context "create" do
10
10
 
11
- should_eventually "create a card with options passed in" do
11
+ should "create a card with options passed in" do
12
+ card = Card.new
13
+ card.stubs(:number).returns(1)
14
+ Card.expects(:new).with(:name => "Name").returns(card)
15
+ Card.any_instance.expects(:save).returns(true)
16
+ Card.any_instance.expects(:reload)
17
+ Card.expects(:puts).with("Card #1 created")
18
+ Card.create({:name => "Name"})
12
19
  end
13
20
 
14
- should_eventually "create a card with the status of new if status property is available" do
21
+ should "create a card with the status of new if status property is available" do
22
+ card = Card.new
23
+ card.stubs(:number).returns(1)
24
+ Card.expects(:new).with(:some_option => "value", :cp_status => "New").returns(card)
25
+ Card.any_instance.expects(:save).returns(true)
26
+ Card.any_instance.expects(:reload)
27
+ Card.expects(:puts).with("Card #1 created")
28
+ Card.create({:some_option => "value"}, "cp_status")
15
29
  end
16
30
 
17
- should_eventually "warn if it is unable to create the card" do
31
+ should "warn if it is unable to create the card" do
32
+ Card.any_instance.expects(:save).returns(false)
33
+ Card.expects(:warn).with("Unable to create card")
34
+ Card.create
18
35
  end
19
36
 
20
37
  end
@@ -22,9 +39,44 @@ module Resources
22
39
  context "move" do
23
40
 
24
41
  should "move card from one state to the next as defined" do
42
+ card = Card.new
43
+ card.stubs(:card_type_name).returns("story")
44
+ card.stubs(:status).returns("New")
45
+ config = { :story_state_1 => "New > Dev", :status_property => "status"}
46
+ response = stub("Response", :attributes => { "status" => "completed" })
47
+
48
+ Card.expects(:find).with(1).returns(card)
49
+ TransitionExecution.expects(:create).with(:transition => 'Dev', :card => 1).returns(response)
50
+ Card.expects(:puts).with("Moved card from New to Dev")
51
+ Card.move(1, {}, config)
52
+ end
53
+
54
+ should "warn if no matching card type is found" do
55
+ card = Card.new
56
+ card.stubs(:card_type_name).returns("someothertype")
57
+ card.stubs(:status).returns("New")
58
+ config = { :story_state_1 => "New > Dev", :status_property => "status"}
59
+
60
+ Card.expects(:find).with(1).returns(card)
61
+ Card.expects(:warn).with("No transitions defined for card of type someothertype")
62
+ Card.move(1, {}, config)
63
+ end
64
+
65
+ should "warn if card has no status property" do
66
+ card = Card.new
67
+ card.stubs(:card_type_name).returns("story")
68
+ card.stubs(:current_status).returns("New")
69
+ config = { :story_state_1 => "New > Dev"}
70
+
71
+ Card.expects(:find).with(1).returns(card)
72
+ Card.expects(:warn).with("No known status of card #1, cannot move!")
73
+ Card.move(1, {}, config)
25
74
  end
26
75
 
27
76
  should "warn if card cannot be found" do
77
+ Card.expects(:find).with(0).returns(nil)
78
+ Card.expects(:warn).with("No card #0 found to move")
79
+ Card.move(0)
28
80
  end
29
81
 
30
82
  end
@@ -57,27 +109,85 @@ module Resources
57
109
 
58
110
  context "print_card" do
59
111
 
60
- should_eventually "print the details for a given card" do
112
+ should "print the details for a given card" do
113
+ status_property = "cp_status"
114
+ card = Card.new
115
+ card.expects(:to_s).with(status_property)
116
+ Card.expects(:find).with(1).returns(card)
117
+ Card.stubs(:puts)
118
+ Card.print_card(1, status_property)
119
+ end
120
+
121
+ should "warn if it is not able to find the card" do
122
+ Card.expects(:find).with(0).returns(nil)
123
+ Card.expects(:warn).with("No card #0 found")
124
+ Card.print_card(0)
61
125
  end
62
126
 
63
127
  end
64
128
 
65
129
  context "update" do
66
130
 
67
- should_eventually "update a card with the options passed in" do
131
+ should "update a card with the options passed in" do
132
+ card = mock("Card")
133
+ card.stubs(:number).returns(1)
134
+ card.expects(:foo=).with("bar")
135
+ card.expects(:baz=).with("frobble")
136
+ card.expects(:save)
137
+ Card.stubs(:puts)
138
+ Card.expects(:find).with(1).returns(card)
139
+
140
+ Card.update(1, {:foo => "bar", :baz => "frobble"})
68
141
  end
69
142
 
70
- should_eventually "print out the details of the card after updating" do
143
+ should "print out the details of the card after updating" do
144
+ card = mock("Card")
145
+ card.stubs(:number).returns(1)
146
+ card.stubs(:foo=)
147
+ card.stubs(:baz=)
148
+ card.stubs(:save)
149
+ Card.stubs(:find).with(1).returns(card)
150
+
151
+ Card.expects(:puts).with("Card #1 updated\n\n")
152
+ Card.expects(:puts).with(card.to_s)
153
+ Card.update(1, {:foo => "bar", :baz => "frobble"})
71
154
  end
72
155
 
73
- should_eventually "warn if it is not able to find the card" do
156
+ should "warn if it is not able to find the card" do
157
+ Card.expects(:find).with(0).returns(nil)
158
+ Card.expects(:warn).with("Unable to update card #0")
159
+ Card.update(0)
74
160
  end
75
161
 
76
162
  end
77
163
 
78
164
  context "to_s" do
79
165
 
80
- should_eventually "format the details of a given card including attachments" do
166
+ should "format the details of a given card including attachments" do
167
+ Resources::Base.site = "http://foo.bar"
168
+
169
+ attachment = Attachment.new
170
+ attachment.stubs(:file_name).returns("My File Name")
171
+ attachment.stubs(:url).returns("http://some.url")
172
+ Attachment.expects(:find).with(:all, :params => { :card_number => 1 }).returns([attachment])
173
+
174
+ card = Card.new
175
+ card.stubs(:number).returns(1)
176
+ card.stubs(:name).returns("My Name")
177
+ card.stubs(:card_type_name).returns("My Type")
178
+ card.stubs(:description).returns("My Description")
179
+
180
+ expected_output = <<-EOS
181
+ Number: 1
182
+ Name: My Name
183
+ Type: My Type
184
+ Status:
185
+ Description: My Description
186
+
187
+ Attachments:
188
+ * My File Name: http://some.url
189
+ EOS
190
+ assert_equal expected_output, card.to_s
81
191
  end
82
192
 
83
193
  end
@@ -18,6 +18,24 @@ module Resources
18
18
  end
19
19
 
20
20
  end
21
+
22
+ context "print_all" do
23
+
24
+ should "print list of all projects" do
25
+ project1 = Project.new
26
+ project2 = Project.new
27
+ Project.expects(:find).with(:all).returns([project1, project2])
28
+ Project.expects(:print_collection).with([project1, project2], [:name, :description])
29
+ Project.print_all
30
+ end
31
+
32
+ should "print warning if no projects are found" do
33
+ Project.expects(:find).with(:all).returns([])
34
+ Project.expects(:warn).with("No projects found")
35
+ Project.print_all
36
+ end
37
+
38
+ end
21
39
 
22
40
  end
23
41
 
@@ -24,13 +24,6 @@ module Resources
24
24
  end
25
25
 
26
26
  end
27
-
28
- context "find_user_id_for_user" do
29
-
30
- should_eventually "return the owner_id of the user matching the username" do
31
- end
32
-
33
- end
34
27
 
35
28
  end
36
29
 
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ MINGLR_ENV = "test"
2
+
1
3
  require "rubygems"
2
4
  require "test/unit"
3
5
  begin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schubert-minglr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Schubert
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-07-26 00:00:00 -07:00
14
+ date: 2009-07-27 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -35,12 +35,17 @@ files:
35
35
  - VERSION.yml
36
36
  - bin/minglr
37
37
  - bin/mtx
38
+ - cucumber.yml
39
+ - features/cards.feature
40
+ - features/step_definitions/minglr_steps.rb
41
+ - features/step_definitions/shared_steps.rb
42
+ - features/users.feature
38
43
  - lib/minglr.rb
39
44
  - lib/minglr/action.rb
40
45
  - lib/minglr/config_parser.rb
41
46
  - lib/minglr/extensions/array.rb
42
- - lib/minglr/input_cache.rb
43
- - lib/minglr/mtx_options_parser.rb
47
+ - lib/minglr/mtx/input_cache.rb
48
+ - lib/minglr/mtx/options_parser.rb
44
49
  - lib/minglr/options_parser.rb
45
50
  - lib/minglr/resources/attachment.rb
46
51
  - lib/minglr/resources/base.rb
@@ -53,7 +58,11 @@ files:
53
58
  - minglrconfig.sample
54
59
  - tasks/commit.sample.rake
55
60
  - tasks/svn.sample.rake
61
+ - test/action_test.rb
62
+ - test/commands_test.rb
63
+ - test/config_parser_test.rb
56
64
  - test/extensions/array_test.rb
65
+ - test/options_parser_test.rb
57
66
  - test/resources/attachment_test.rb
58
67
  - test/resources/base_test.rb
59
68
  - test/resources/card_test.rb
@@ -61,8 +70,9 @@ files:
61
70
  - test/resources/property_definition_test.rb
62
71
  - test/resources/user_test.rb
63
72
  - test/test_helper.rb
64
- has_rdoc: true
73
+ has_rdoc: false
65
74
  homepage: http://github.com/schubert/minglr
75
+ licenses:
66
76
  post_install_message: PostInstall.txt
67
77
  rdoc_options:
68
78
  - --charset=UTF-8
@@ -83,12 +93,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
93
  requirements: []
84
94
 
85
95
  rubyforge_project:
86
- rubygems_version: 1.2.0
96
+ rubygems_version: 1.3.5
87
97
  signing_key:
88
- specification_version: 2
98
+ specification_version: 3
89
99
  summary: command line user tool for Mingle (http://mingle.thoughtworks.com/mingle-agile-project-management)
90
100
  test_files:
101
+ - test/action_test.rb
102
+ - test/commands_test.rb
103
+ - test/config_parser_test.rb
91
104
  - test/extensions/array_test.rb
105
+ - test/options_parser_test.rb
92
106
  - test/resources/attachment_test.rb
93
107
  - test/resources/base_test.rb
94
108
  - test/resources/card_test.rb
@@ -1,22 +0,0 @@
1
- class InputCache
2
- class << self
3
- def put(key, content)
4
- File.open(file_pathname(key), File::CREAT | File::WRONLY | File::TRUNC) { |file| file.write content }
5
- end
6
-
7
- def get(key)
8
- if content = File.read(file_pathname(key))
9
- return nil if content.blank?
10
- content
11
- end
12
- rescue
13
- nil
14
- end
15
-
16
- protected
17
-
18
- def file_pathname(key)
19
- File.join(Dir::tmpdir, "#{key.to_s.gsub(/[^\w]/, '')}.entry")
20
- end
21
- end
22
- end
@@ -1,53 +0,0 @@
1
- class MtxOptionsParser
2
- def self.parse(args, *required_by_command)
3
- uri_options = {}
4
- command_options = {}
5
-
6
- parser = OptionParser.new do |opts|
7
- opts.banner = "Usage: mtx [options]"
8
- opts.on("--transition TRANSITION", "Transition name.") do |transition|
9
- command_options[:transition] = transition
10
- end
11
-
12
- opts.on("--card CARD", "Card number.") do |card|
13
- command_options[:card] = card
14
- end
15
-
16
- opts.on("--properties ARGS", Array, "User-entered properties and values for the transition in array format. Must be an even number of comma-delimited values, like \"A,B,'C with spaces','D with spaces'\".") do |args|
17
- command_options[:properties] = args.in_groups_of(2).map { |key, value| {'name' => key, 'value' => value} }
18
- end
19
-
20
- opts.on("--comment COMMENT", "Transition comment. This may be required depending on your transition settings.") do |comment|
21
- command_options[:comment] = comment
22
- end
23
-
24
- opts.on("--username USERNAME", "Mingle username.") do |username|
25
- uri_options[:username] = username
26
- end
27
-
28
- opts.on("--password PASSWORD", "Mingle password.") do |password|
29
- uri_options[:password] = password
30
- end
31
-
32
- opts.on("--host_port HOST_PORT", "Host and port.") do |host_and_port|
33
- uri_options[:host_and_port] = host_and_port
34
- end
35
-
36
- opts.on("--project PROJECT", "Project name.") do |project|
37
- uri_options[:project] = project
38
- end
39
- end
40
-
41
- parser.parse! args
42
-
43
- ([:project, :host_and_port] | required_by_command).each do |arg|
44
- unless command_options[arg] || uri_options[arg]
45
- # TODO: let commands handle their own errors
46
- $stderr.puts "Missing command-line argument --#{arg.to_s}, use --help for command-line options."
47
- exit 1
48
- end
49
- end
50
-
51
- [uri_options, command_options]
52
- end
53
- end