morale 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,7 @@ Feature: Running the tickets command
4
4
  I should be able to run tickets to view, create, update, and delete tickets
5
5
 
6
6
  @interactive
7
- Scenario: Running projects should not require authorization if the account and api key are stored
7
+ Scenario: Posting a ticket should return the ticket results
8
8
  Given a file named "credentials" with:
9
9
  """
10
10
  spartan
@@ -23,4 +23,52 @@ Feature: Running the tickets command
23
23
  And the output should contain:
24
24
  """
25
25
  Jimmy P.
26
+ """
27
+
28
+ @interactive
29
+ Scenario: Posting a ticket without a project should ask for a project
30
+ Given a file named "credentials" with:
31
+ """
32
+ spartan
33
+ 12345
34
+ """
35
+ When I run `morale ticket "task: This is a new task as: Jimmy"` interactively
36
+ Then the output should contain:
37
+ """
38
+ No project specified.
39
+ """
40
+
41
+ @interactive
42
+ Scenario: Running tickets should return a list of all active tickets
43
+ Given a file named "credentials" with:
44
+ """
45
+ spartan
46
+ 12345
47
+ 1
48
+ """
49
+ When I run `morale tickets` interactively
50
+ Then the output should contain:
51
+ """
52
+ Task
53
+ """
54
+ And the output should contain:
55
+ """
56
+ Refactor user signup code
57
+ """
58
+ And the output should contain:
59
+ """
60
+ Create icon for list view
61
+ """
62
+
63
+ @interactive
64
+ Scenario: Running tickets without a project should ask for a project
65
+ Given a file named "credentials" with:
66
+ """
67
+ spartan
68
+ 12345
69
+ """
70
+ When I run `morale tickets` interactively
71
+ Then the output should contain:
72
+ """
73
+ No project specified.
26
74
  """
@@ -30,6 +30,7 @@ module Morale
30
30
  end
31
31
 
32
32
  def project
33
+ get_credentials
33
34
  @credentials[2] if !@credentials.nil? && @credentials.length > 2
34
35
  end
35
36
 
data/lib/morale/client.rb CHANGED
@@ -57,6 +57,11 @@ module Morale
57
57
  end
58
58
 
59
59
  def tickets(options={})
60
+ authorize
61
+ response = self.class.get("/projects/#{options[:project_id]}/tickets")
62
+ raise Unauthorized if response.code == 401
63
+ raise NotFound if response.code == 404
64
+ response
60
65
  end
61
66
 
62
67
  def ticket(project_id, command)
@@ -45,13 +45,9 @@ module Morale
45
45
  Morale::Commands::Ticket.command command
46
46
  end
47
47
 
48
- desc "test", "Testing the ticket output."
49
- def test
50
- say "+-----+------+-----------------------------------------------------------------------------------------+----------------+----------+----------------+----------+"
51
- say "| id | type | title | created by | due date | assigned to | priority |"
52
- say "+-----+------+-----------------------------------------------------------------------------------------+----------------+----------+----------------+----------+"
53
- say "| 123 | task | hbsdbjhsdjhfdsjfhsdjfhsdjfhsdjfhsdf | Jimmy P. | 08/08/11 | Robert P. | 1 |"
54
- say "+-----+------+-----------------------------------------------------------------------------------------+----------------+----------+----------------+----------+"
48
+ desc "tickets", "Lists all the projects tickets."
49
+ def tickets
50
+ Morale::Commands::Ticket.list
55
51
  end
56
52
 
57
53
  class << self
@@ -1,36 +1,69 @@
1
1
  require 'morale/client'
2
2
  require 'morale/command'
3
3
  require 'morale/authorization'
4
+ require 'morale/flow'
4
5
  require 'hirb'
5
6
 
6
7
  module Morale::Commands
7
8
  class Ticket
8
9
  class << self
9
10
  include Morale::Platform
11
+ include Morale::Flow
10
12
 
11
13
  def command(command)
12
- ticket = Morale::Command.client.ticket Morale::Account.project, command
13
- print ticket
14
+ ask_for_project
15
+ print Morale::Command.client.ticket(Morale::Account.project, command) unless Morale::Account.project.nil?
16
+ end
17
+
18
+ def list
19
+ ask_for_project
20
+ print Morale::Command.client.tickets({ :project_id => Morale::Account.project }) unless Morale::Account.project.nil?
14
21
  end
15
22
 
16
23
  private
17
24
 
18
- def print(ticket)
19
- due_date = Date.parse(ticket['due_date']).strftime("%b. %d") unless ticket['due_date'].nil?
20
- assigned_to = "#{ticket['assigned_to']['user']['first_name']} #{(ticket['assigned_to']['user']['last_name']).to_s[0,1]}." unless ticket['assigned_to'].nil?
21
-
22
- say Hirb::Helpers::Table.render [{
23
- :id => ticket['identifier'],
24
- :type => ticket['type'],
25
- :title => ticket['title'],
26
- :created_by => "#{ticket['created_by']['user']['first_name']} #{(ticket['created_by']['user']['last_name']).to_s[0,1]}.",
27
- :due_date => due_date,
28
- :assigned_to => assigned_to,
29
- :priority => ticket['priority']
30
- }],
25
+ def ask_for_project
26
+ if Morale::Account.project.nil?
27
+ say "No project specified."
28
+ retryable(:retries => 1) do
29
+ Morale::Commands::Project.list true
30
+ end
31
+ end
32
+ end
33
+
34
+ def print(tickets)
35
+ say Hirb::Helpers::Table.render fetch(tickets),
31
36
  :fields => [:id, :type, :title, :created_by, :due_date, :assigned_to, :priority],
32
37
  :headers => { :created_by => "created by", :due_date => "due date", :assigned_to => "assigned to" }
33
38
  end
39
+
40
+ def fetch(tickets)
41
+ tickets = tickets.kind_of?(Array) ? tickets : Array.new(1, tickets)
42
+ data = []
43
+ tickets.each { |t|
44
+ ticket = t['task'] unless t['task'].nil?
45
+ ticket = t['bug'] unless t['bug'].nil?
46
+ ticket = t if ticket.nil?
47
+
48
+ due_date = ticket['due_date']
49
+ unless due_date.nil?
50
+ due_date = Date.parse(due_date) unless due_date.kind_of?(Time)
51
+ due_date = due_date.strftime("%b. %d")
52
+ end
53
+ assigned_to = "#{ticket['assigned_to']['user']['first_name']} #{(ticket['assigned_to']['user']['last_name']).to_s[0,1]}." unless ticket['assigned_to'].nil?
54
+
55
+ data << {
56
+ :id => ticket['identifier'],
57
+ :type => ticket['type'],
58
+ :title => ticket['title'],
59
+ :created_by => "#{ticket['created_by']['user']['first_name']} #{(ticket['created_by']['user']['last_name']).to_s[0,1]}.",
60
+ :due_date => due_date,
61
+ :assigned_to => assigned_to,
62
+ :priority => ticket['priority']
63
+ }
64
+ }
65
+ data
66
+ end
34
67
  end
35
68
  end
36
69
  end
data/lib/morale.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Morale
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
4
4
 
5
5
  require 'morale/command'
data/morale.gemspec CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.rubygems_version = '1.3.5'
6
6
 
7
7
  s.name = 'morale'
8
- s.version = '0.1.1'
9
- s.date = '2011-09-30'
8
+ s.version = '0.1.2'
9
+ s.date = '2011-10-01'
10
10
  s.rubyforge_project = 'morale'
11
11
 
12
12
  s.summary = "Command line interface to create & manage tickets on Morale."
@@ -89,4 +89,31 @@ describe Morale::Client do
89
89
  lambda { client.ticket('1', "This is a test that should create a new task as: Lester") }.should raise_error(Morale::Client::NotFound)
90
90
  end
91
91
  end
92
+
93
+ describe "#tickets" do
94
+ it "should return all active tickets when no options are specified" do
95
+ stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").to_return(:body =>
96
+ [{"ticket" => {"title" => "This is test #1","created_at" => "2011-07-31T21:40:24Z","updated_at" => "2011-07-31T21:40:24Z","project_id" => 1,"id" => 1,"identifier" => "1","type" => "Task","due_date" => "2011-10-15 16:00:00.000000","priority" => nil,"archived" => "f"}},
97
+ {"ticket" => {"title" => "This is test #2","created_at" => "2011-07-31T21:28:53Z","updated_at" => "2011-07-31T21:28:53Z","project_id" => 1,"id" => 2, "identifier" => "2","type" => "Bug","due_date" => nil,"priority" => "2","archived" => "f"}}].to_json)
98
+ client = Morale::Client.new('blah', '123456')
99
+ response = client.tickets({:project_id => 1})
100
+ response.count.should == 2
101
+ response[0]["ticket"]["title"].should == "This is test #1"
102
+ response[1]["ticket"]["title"].should == "This is test #2"
103
+ end
104
+
105
+ it "should raise unauthorized if a 401 is received" do
106
+ stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
107
+ to_return(:status => 401)
108
+ client = Morale::Client.new('blah', '123456')
109
+ lambda { client.tickets({:project_id => 1}) }.should raise_error(Morale::Client::Unauthorized)
110
+ end
111
+
112
+ it "should raise notfound if a 404 is received" do
113
+ stub_request(:get, "http://blah:123456@blah.lvh.me:3000/api/v1/projects/1/tickets").
114
+ to_return(:status => 404)
115
+ client = Morale::Client.new('blah', '123456')
116
+ lambda { client.tickets({ :project_id => 1 }) }.should raise_error(Morale::Client::NotFound)
117
+ end
118
+ end
92
119
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brilliant Fantastic
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-30 00:00:00 -04:00
17
+ date: 2011-10-01 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency