taskmapper-redmine 0.4.0 → 0.5.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -1,13 +1,55 @@
1
1
  module TaskMapper::Provider
2
2
  module Redmine
3
- # The comment class for taskmapper-yoursystem
4
- #
5
- # Do any mapping between taskmapper and your system's comment model here
6
- # versions of the ticket.
7
- #
3
+ # The comment class for taskmapper-redmine
8
4
  class Comment < TaskMapper::Provider::Base::Comment
9
- # declare needed overloaded methods here
10
-
5
+ API = RedmineAPI::Issue
6
+
7
+ def initialize(ticket_id, *object)
8
+ if object.first
9
+ object = object.first
10
+ unless object.is_a? Hash
11
+ author = object.respond_to?(:user) ? object.user : object.author
12
+ hash = {:id => object.id.to_i,
13
+ :author => author.name,
14
+ :body => object.notes,
15
+ :update_at => object.created_on,
16
+ :created_at => object.created_on,
17
+ :ticket_id => ticket_id
18
+ }
19
+ else
20
+ hash = object
21
+ end
22
+ super hash
23
+ end
24
+ end
25
+
26
+ def self.find_by_id(project_id, ticket_id, id)
27
+ self.search(ticket_id).select { |journal| journal.id == id.to_i }.first
28
+ end
29
+
30
+ def self.find_by_attributes(project_id, ticket_id, attributes = {})
31
+ search_by_attribute(self.search(ticket_id), attributes)
32
+ end
33
+
34
+ def self.search(ticket_id)
35
+ API.find(ticket_id).journals.inject([]) do |arr, journal|
36
+ arr << self.new(ticket_id, journal) if journal.notes.present?
37
+ arr
38
+ end
39
+ end
40
+
41
+ def self.create(*options)
42
+ attributes = options.first
43
+ self.new(attributes[:ticket_id], create_journal_for_issue(attributes))
44
+ end
45
+
46
+ private
47
+ def self.create_journal_for_issue(attributes)
48
+ journal = API.find(attributes[:ticket_id])
49
+ journal.notes = attributes[:body]
50
+ journal.save
51
+ journal
52
+ end
11
53
  end
12
54
  end
13
55
  end
@@ -52,7 +52,7 @@ module TaskMapper::Provider
52
52
  end
53
53
 
54
54
  def self.find_by_id(project_id, ticket_id)
55
- self.new API.find(:first, :id => ticket_id)
55
+ self.new API.find(ticket_id)
56
56
  end
57
57
 
58
58
  def self.find_by_attributes(project_id, attributes = {})
@@ -73,21 +73,6 @@ module TaskMapper::Provider
73
73
  to_issue.new? ? to_issue.save : update
74
74
  end
75
75
 
76
- def comments
77
- warn "Redmine doesn't support comments"
78
- []
79
- end
80
-
81
- def comment
82
- warn "Redmine doesn't support comments"
83
- nil
84
- end
85
-
86
- def comment!
87
- warn "Redmine doesn't support comments"
88
- []
89
- end
90
-
91
76
  private
92
77
  def find_issue
93
78
  issue = API.find id, :params => {:project_id => self.project_id}
@@ -31,6 +31,19 @@ module RedmineAPI
31
31
  end
32
32
 
33
33
  class Issue < Base
34
+ def self.find(*arguments)
35
+ scope = arguments.slice!(0)
36
+ options = arguments.slice!(0) || {}
37
+ # By including journals, we can get Notes aka Comments
38
+ # RedmineAPI::Issue.find(2180, :params => {:include => 'journals'})
39
+ get_comments = {:include => 'journals'}
40
+ if options[:params].nil?
41
+ options[:params] = get_comments
42
+ else
43
+ options[:params].merge!(get_comments)
44
+ end
45
+ super scope, options
46
+ end
34
47
  end
35
48
 
36
49
  class Project < Base
@@ -1,5 +1,71 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe TaskMapper::Provider::Redmine::Comment do
4
- it "should have specs for comments"
4
+
5
+ let(:project_id) { 1 }
6
+ let(:ticket_id) { 1 }
7
+ let(:comment_id) { 1 }
8
+ let(:klass) { TaskMapper::Provider::Redmine::Comment }
9
+ let(:taskmapper) { TaskMapper.new :redmine, :server => 'http://demo.redmine.org/', :token => 'abcdefghijk' }
10
+ let(:project) { taskmapper.project(project_id) }
11
+
12
+ before(:all) do
13
+ headers = {'X-Redmine-API-Key' => 'abcdefghijk', 'Accept' => 'application/xml'}
14
+ headers_post_put = {'X-Redmine-API-Key' => 'abcdefghijk', 'Content-Type' => 'application/xml'}
15
+ ActiveResource::HttpMock.respond_to do |mock|
16
+ mock.get '/projects.xml', headers, fixture_for('projects'), 200
17
+ mock.get '/projects/1.xml', headers, fixture_for('projects/test-repo12'), 200
18
+ mock.get '/issues.xml?project_id=1', headers, fixture_for('issues'), 200
19
+ mock.get '/issues.xml', headers, fixture_for('issues'), 200
20
+ mock.get '/issues/1.xml?include=journals', headers, fixture_for('issues/1'), 200
21
+ mock.put '/issues/1.xml', headers_post_put, '', 200
22
+ mock.post '/issues.xml', headers_post_put, '', 200
23
+ end
24
+ end
25
+
26
+ before(:each) do
27
+ @ticket = project.ticket(ticket_id)
28
+ end
29
+
30
+ it "should be able to load all comments" do
31
+ comments = @ticket.comments
32
+ comments.size.should eq(2)
33
+ comments.should be_an_instance_of(Array)
34
+ comments.first.should be_an_instance_of(klass)
35
+ end
36
+
37
+ it "should be able to load all comments based on 'id's" do
38
+ comments = @ticket.comments([comment_id])
39
+ comments.should be_an_instance_of(Array)
40
+ comments.first.should be_an_instance_of(klass)
41
+ comments.first.id.should == comment_id
42
+ end
43
+
44
+ it "should be able to load all comments based on attributes" do
45
+ comments = @ticket.comments(:id => comment_id)
46
+ comments.should be_an_instance_of(Array)
47
+ comments.first.should be_an_instance_of(klass)
48
+ end
49
+
50
+ it "should be able to load a comment based on id" do
51
+ comment = @ticket.comment(comment_id)
52
+ comment.should be_an_instance_of(klass)
53
+ comment.id.should == comment_id
54
+ end
55
+
56
+ it "should be able to load a comment based on attributes" do
57
+ comment = @ticket.comment(:id => comment_id)
58
+ comment.should be_an_instance_of(klass)
59
+ end
60
+
61
+ it "should return the class" do
62
+ @ticket.comment.should == klass
63
+ end
64
+
65
+ it "should be able to create a comment for a given task" do
66
+ comment = @ticket.comment!(:body => 'hello there boys and girls')
67
+ comment.should be_an_instance_of(klass)
68
+ comment.ticket_id.should_not be_nil
69
+ comment.ticket_id.should_not == 0
70
+ end
5
71
  end
@@ -1 +1 @@
1
- <?xml version="1.0" encoding="UTF-8"?><issue><id>1</id><project name="test-repo" id="1"/><tracker name="Bug" id="1"/><status name="New" id="1"/><priority name="Normal" id="4"/><author name="Redmine Admin" id="1"/><subject>test-issue</subject><description></description><start_date>2010-12-22</start_date><due_date></due_date><done_ratio>0</done_ratio><estimated_hours></estimated_hours><spent_hours>0.0</spent_hours><created_on>2010-12-22T17:55:58-06:00</created_on><updated_on>2010-12-22T17:55:58-06:00</updated_on></issue>
1
+ <?xml version="1.0" encoding="UTF-8"?><issue><id>1</id><project name="test-repo" id="1"/><tracker name="Bug" id="1"/><status name="New" id="1"/><priority name="Normal" id="4"/><author name="Redmine Admin" id="1"/><subject>test-issue</subject><description></description><start_date>2010-12-22</start_date><due_date></due_date><done_ratio>0</done_ratio><estimated_hours></estimated_hours><spent_hours>0.0</spent_hours><created_on>2010-12-22T17:55:58-06:00</created_on><updated_on>2010-12-22T17:55:58-06:00</updated_on><journals type="array"><journal id="1"><user name="Redmine Admin" id="1"/><notes>hello there boys and girls</notes><created_on>2012-05-08T11:02:18+10:00</created_on><details type="array"><detail property="attr" name="status_id"><old_value>1</old_value><new_value>2</new_value></detail><detail property="attr" name="assigned_to_id"><old_value></old_value><new_value>1</new_value></detail><detail property="attr" name="done_ratio"><old_value>0</old_value><new_value>50</new_value></detail></details></journal><journal id="2"><user name="Redmine Admin" id="1"/><notes>Hello World</notes><created_on>2012-05-17T06:26:15+10:00</created_on><details type="array"><detail property="attr" name="status_id"><old_value>2</old_value><new_value>3</new_value></detail><detail property="attr" name="done_ratio"><old_value>50</old_value><new_value>100</new_value></detail></details></journal><journal id="6626"><user name="Redmine User" id="20"/><notes></notes><created_on>2011-03-23T20:08:02-07:00</created_on><details type="array"><detail name="fixed_version_id" property="attr"><old_value></old_value><new_value>118</new_value></detail></details></journal></journals></issue>
data/spec/tickets_spec.rb CHANGED
@@ -8,9 +8,9 @@ describe TaskMapper::Provider::Redmine::Ticket do
8
8
  ActiveResource::HttpMock.respond_to do |mock|
9
9
  mock.get '/projects.xml', headers, fixture_for('projects'), 200
10
10
  mock.get '/projects/1.xml', headers, fixture_for('projects/test-repo12'), 200
11
- mock.get '/issues.xml?project_id=1', headers, fixture_for('issues'), 200
11
+ mock.get '/issues.xml?include=journals&project_id=1', headers, fixture_for('issues'), 200
12
12
  mock.get '/issues.xml', headers, fixture_for('issues'), 200
13
- mock.get '/issues/1.xml', headers, fixture_for('issues/1'), 200
13
+ mock.get '/issues/1.xml?include=journals', headers, fixture_for('issues/1'), 200
14
14
  mock.put '/issues/1.xml', headers_post_put, '', 200
15
15
  mock.post '/issues.xml', headers_post_put, '', 200
16
16
  end
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "taskmapper-redmine"
8
+ s.version = "0.5.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rafael George"]
12
+ s.date = "2012-06-20"
13
+ s.description = "Allows taskmapper to interact with Your System."
14
+ s.email = "rafael@hybridgroup.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".rbenv-gemsets",
21
+ ".rvmrc",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/provider/api-extensions.rb",
30
+ "lib/provider/comment.rb",
31
+ "lib/provider/project.rb",
32
+ "lib/provider/redmine.rb",
33
+ "lib/provider/ticket.rb",
34
+ "lib/redmine/redmine-api.rb",
35
+ "lib/taskmapper-redmine.rb",
36
+ "spec/comments_spec.rb",
37
+ "spec/fixtures/issues.xml",
38
+ "spec/fixtures/issues/1.xml",
39
+ "spec/fixtures/projects.xml",
40
+ "spec/fixtures/projects/test-repo12.xml",
41
+ "spec/projects_spec.rb",
42
+ "spec/spec.opts",
43
+ "spec/spec_helper.rb",
44
+ "spec/taskmapper-redmine_spec.rb",
45
+ "spec/tickets_spec.rb",
46
+ "taskmapper-redmine.gemspec",
47
+ "ticketmaster-redmine.gemspec"
48
+ ]
49
+ s.homepage = "http://github.com/hybridgroup/taskmapper-redmine"
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = "1.8.17"
52
+ s.summary = "taskmapper Provider for Redmine"
53
+
54
+ if s.respond_to? :specification_version then
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
+ s.add_runtime_dependency(%q<taskmapper>, ["~> 0.8"])
59
+ s.add_development_dependency(%q<rspec>, ["~> 2.8"])
60
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
61
+ s.add_development_dependency(%q<simplecov>, ["~> 0.5"])
62
+ s.add_development_dependency(%q<rcov>, ["~> 1.0"])
63
+ else
64
+ s.add_dependency(%q<taskmapper>, ["~> 0.8"])
65
+ s.add_dependency(%q<rspec>, ["~> 2.8"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
67
+ s.add_dependency(%q<simplecov>, ["~> 0.5"])
68
+ s.add_dependency(%q<rcov>, ["~> 1.0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<taskmapper>, ["~> 0.8"])
72
+ s.add_dependency(%q<rspec>, ["~> 2.8"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.6"])
74
+ s.add_dependency(%q<simplecov>, ["~> 0.5"])
75
+ s.add_dependency(%q<rcov>, ["~> 1.0"])
76
+ end
77
+ end
78
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: taskmapper-redmine
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.5.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rafael George
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-14 00:00:00 Z
13
+ date: 2012-06-20 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: taskmapper
@@ -103,6 +103,7 @@ files:
103
103
  - spec/spec_helper.rb
104
104
  - spec/taskmapper-redmine_spec.rb
105
105
  - spec/tickets_spec.rb
106
+ - taskmapper-redmine.gemspec
106
107
  - ticketmaster-redmine.gemspec
107
108
  homepage: http://github.com/hybridgroup/taskmapper-redmine
108
109
  licenses: []