peaty 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.4.6
data/lib/peaty/base.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Peaty
2
2
 
3
3
  class Base
4
- attr_accessor :attributes, :connection
4
+ attr_accessor :attributes, :connection, :error
5
5
 
6
6
  FILTERS = [
7
7
  :id, :type, :state, :label, :has_attachment,
@@ -50,9 +50,17 @@ module Peaty
50
50
  id.nil? or id.to_i.zero?
51
51
  end
52
52
 
53
+ def error?
54
+ !!@error
55
+ end
56
+
53
57
  def save
54
- query_string = @attributes.map{ |k,v| "#{CGI.escape("%s[%s]" % [self.class.element, k.to_s])}=#{CGI.escape(v.to_s)}" }.join('&')
55
- @attributes.replace self.class.parse(self.connection["%s?%s" % [self.class.collection_path(@attributes), query_string]].post(:params => @attributes).body, self.class.element).first.attributes
58
+ @error = nil # reset error
59
+ @attributes.delete_if{ |(k,v)| v.nil? } # ignore nil attributes
60
+ @attributes.replace self.class.parse(self.connection[self.class.collection_path(@attributes)].post(self.class.element => @attributes).body, self.class.element).first.attributes
61
+ rescue RestClient::UnprocessableEntity => e
62
+ @error = JSON.parse(XmlToJson.transform(e.response.body))["message"]
63
+ false
56
64
  end
57
65
 
58
66
  class << self
data/lib/peaty.rb CHANGED
@@ -26,7 +26,7 @@ require 'peaty/user'
26
26
 
27
27
  module Peaty
28
28
 
29
- VERSION = "0.4.0"
29
+ VERSION = "0.4.6"
30
30
 
31
31
  def self.root
32
32
  @root ||= Pathname.new(__FILE__).dirname.parent
data/peaty.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{peaty}
8
- s.version = "0.4.5"
8
+ s.version = "0.4.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Todd"]
12
- s.date = %q{2011-03-09}
12
+ s.date = %q{2011-03-15}
13
13
  s.description = %q{Just another Pivotal Tracker API Implementation}
14
14
  s.email = %q{chiology@gmail.com}
15
15
  s.files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "test/fixtures/bugs.xml",
32
32
  "test/fixtures/chores.xml",
33
33
  "test/fixtures/create_story.xml",
34
+ "test/fixtures/create_story_error.xml",
34
35
  "test/fixtures/features.xml",
35
36
  "test/fixtures/iterations.xml",
36
37
  "test/fixtures/iterations_done.xml",
@@ -0,0 +1,2 @@
1
+ <?xml version=\"1.0\" encoding=\"UTF-8\"?>
2
+ <message>unknown attribute: title</message>
data/test/peaty_test.rb CHANGED
@@ -79,6 +79,10 @@ class PeatyTest < Test::Unit::TestCase
79
79
  end
80
80
 
81
81
  def test_user_can_create_a_new_story_for_a_project
82
+ FakeWeb.register_uri(:post, Regexp.new(PT_BASE_URI + "/projects/#{PROJECT_ID}/stories"),
83
+ :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "create_story.xml")))
84
+ # http://www.pivotaltracker.com/services/v3/projects/153937/stories?story%5Bname%5D=Test&story%5Bproject_id%5D=153937&story%5Bestimate%5D=3
85
+
82
86
  story = @user.pivotal_tracker_projects.find(PROJECT_ID).stories.build(:name => name = "Test")
83
87
  assert story.is_a?(Peaty::Story)
84
88
  assert story.new_record?
@@ -90,6 +94,17 @@ class PeatyTest < Test::Unit::TestCase
90
94
  assert !story.new_record?
91
95
  end
92
96
 
97
+ def test_user_can_get_error_messages_when_trying_to_create_a_new_story_for_a_project_that_fails
98
+ FakeWeb.register_uri(:post, Regexp.new(PT_BASE_URI + "/projects/#{PROJECT_ID}/stories"),
99
+ :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "create_story_error.xml")),
100
+ :status => 422)
101
+
102
+ story = @user.pivotal_tracker_projects.find(PROJECT_ID).stories.build(:title => "Title Doesn't Exist")
103
+ assert !story.save
104
+ assert story.new_record?
105
+ assert_equal "unknown attribute: title", story.error
106
+ end
107
+
93
108
  # Tests for Iterations
94
109
  def test_user_can_fetch_a_projects_iterations
95
110
  project = @user.pivotal_tracker_projects.find(PROJECT_ID)
data/test/test_helper.rb CHANGED
@@ -16,7 +16,7 @@ PROJECT_ID = 153937
16
16
  STORY_ID = 6821071
17
17
  RELEASE_ID = 6821121
18
18
 
19
- uri = "https://www.pivotaltracker.com/services/v3"
19
+ PT_BASE_URI = "https://www.pivotaltracker.com/services/v3"
20
20
  { "/projects" => "projects",
21
21
  "/projects/#{PROJECT_ID}" => "project",
22
22
  "/projects/#{PROJECT_ID}/stories" => "stories",
@@ -30,13 +30,9 @@ uri = "https://www.pivotaltracker.com/services/v3"
30
30
  "/projects/#{PROJECT_ID}/stories?filter=type%3Abug" => "bugs",
31
31
  "/projects/#{PROJECT_ID}/stories?filter=includedone%3Atrue" => "stories_with_done",
32
32
  }.each do |(path, fixture)|
33
- FakeWeb.register_uri(:get, uri + path, :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "%s.xml" % fixture)))
33
+ FakeWeb.register_uri(:get, PT_BASE_URI + path, :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "%s.xml" % fixture)))
34
34
  end
35
35
 
36
- FakeWeb.register_uri(:post, Regexp.new(uri + "/projects/#{PROJECT_ID}/stories"),
37
- :body => File.read(File.join(File.dirname(__FILE__), "fixtures", "create_story.xml")))
38
- # http://www.pivotaltracker.com/services/v3/projects/153937/stories?story%5Bname%5D=Test&story%5Bproject_id%5D=153937&story%5Bestimate%5D=3
39
-
40
36
  class User < Struct.new(:pivotal_tracker_api_key)
41
37
  pivotal_tracker_for :pivotal_tracker_api_key
42
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peaty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Todd
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-09 00:00:00 -05:00
18
+ date: 2011-03-15 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -227,6 +227,7 @@ files:
227
227
  - test/fixtures/bugs.xml
228
228
  - test/fixtures/chores.xml
229
229
  - test/fixtures/create_story.xml
230
+ - test/fixtures/create_story_error.xml
230
231
  - test/fixtures/features.xml
231
232
  - test/fixtures/iterations.xml
232
233
  - test/fixtures/iterations_done.xml