rally_rest_api 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -41,11 +41,12 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
41
  p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
42
42
  p.test_globs = ["test/*.rb"]
43
43
  p.clean_globs = CLEAN #An array of file patterns to delete on clean.
44
- p.extra_deps = ["builder"]
44
+
45
+ p.extra_deps = []
46
+ p.extra_deps << ["builder"]
45
47
 
46
48
  # == Optional
47
49
  #p.changes - A description of the release's latest changes.
48
-
49
50
  #p.spec_extras - A hash of extra values to set in the gemspec.
50
51
  end
51
52
 
@@ -79,6 +79,7 @@ class RestQuery
79
79
  def initialize(type, args = {}, &block)
80
80
  @type = type
81
81
  @query_string = "query=" << URI.escape(QueryBuilder.new("and", &block).to_q) if block_given?
82
+ @query_string.gsub!("&", "%26")
82
83
  @args_for_paging = {}
83
84
  [:workspace, :project, :project_scope_down, :project_scope_up].each { |k| @args_for_paging[k] = args[k] if args.key?(k) }
84
85
  @query_params = process_args(args)
@@ -69,6 +69,7 @@ class QueryResult < RestObject
69
69
 
70
70
  # Are there more pages?
71
71
  def more_pages?
72
+ return false if start_index == 0
72
73
  (self.start_index + self.page_length) -1 < self.total_result_count
73
74
  end
74
75
  end
@@ -179,6 +179,8 @@ class RestObject
179
179
  end
180
180
 
181
181
  def ==(other)
182
+ return true if self.equal other
183
+ return false unless other.kind_of? RestObject
182
184
  other.ref == self.ref
183
185
  end
184
186
 
@@ -2,7 +2,7 @@ module RallyRestVersion #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 6
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'builder'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/rally_rest_api/query_result'
6
+
7
+ context "A QueryResult" do
8
+
9
+ setup do
10
+ @api = mock("RallyRestAPI")
11
+ @api.stub! :username
12
+ @api.stub! :password
13
+ end
14
+
15
+ def make_result(total, page_size, start_index)
16
+ result_count = total > page_size ? page_size : total
17
+
18
+ b = Builder::XmlMarkup.new(:indent => 2)
19
+ xml = b.QueryResult {
20
+ b.TotalResultCount total
21
+ b.PageSize page_size
22
+ b.StartIndex start_index
23
+
24
+ if (result_count > 0)
25
+ b.Results {
26
+ result_count.times { |i| b.RefElement(:ref => "http", :refObjectName => "name#{i}") }
27
+ }
28
+ else
29
+ b.Results
30
+ end
31
+ }
32
+
33
+ QueryResult.new(nil, @api, xml)
34
+ end
35
+
36
+ specify "should have the total result count" do
37
+ make_result(20, 20, 1).total_result_count.should_be 20
38
+ end
39
+
40
+ specify "should have the page size" do
41
+ make_result(20, 20, 1).page_size.should_be 20
42
+ end
43
+
44
+ specify "should have the start_index" do
45
+ make_result(20, 20, 1).start_index.should_be 1
46
+ end
47
+
48
+ specify "should have no more pages when no results are returned" do
49
+ make_result(0, 20, 0).more_pages?.should_be false
50
+ end
51
+
52
+ specify "should have not more pages when the total result count is less then the page size" do
53
+ make_result(1, 20, 1).more_pages?.should_be false
54
+ make_result(19, 20, 1).more_pages?.should_be false
55
+ make_result(20, 20, 1).more_pages?.should_be false
56
+ end
57
+
58
+ specify "should have more pages when total result count is more then the page size" do
59
+ make_result(21, 20, 1).more_pages?.should_be true
60
+ make_result(39, 20, 1).more_pages?.should_be true
61
+ end
62
+
63
+ specify "an empty query should not iteratate on each" do
64
+ start = 0
65
+ make_result(0, 20, 0).each { start += 1 }
66
+ start.should_be 0
67
+ end
68
+
69
+ end
70
+
71
+ context "A QueryResult with 2 pages" do
72
+
73
+ end
@@ -27,6 +27,12 @@ class QueryResultTestCase < Test::Unit::TestCase
27
27
  assert_equal(20, result.page_length)
28
28
  end
29
29
 
30
+ def test_more_pages_when_enpty
31
+ query_result_xml = make_result(0, 0, 0)
32
+ result = QueryResult.new(nil, @api, query_result_xml)
33
+ assert(! result.more_pages?, "No more pages when results empty")
34
+ end
35
+
30
36
  def test_more_pages_when_no_pages
31
37
  query_result_xml = make_result(20, 20, 1)
32
38
  result = QueryResult.new(nil, @api, query_result_xml)
@@ -66,6 +66,25 @@ class RestObjectTestCase < Test::Unit::TestCase
66
66
  MyRestBuilder.test = self
67
67
  o
68
68
  end
69
+
70
+ def test_equal_same_instance
71
+ xml = %Q(<Object><TextNode>text</TextNode></Object>)
72
+ r1 = r2 = rest_object(xml)
73
+ assert(r1 == r2)
74
+ end
75
+
76
+ def test_equal_with_nil
77
+ xml = %Q(<Object><TextNode>text</TextNode></Object>)
78
+ r1 = rest_object(xml)
79
+ assert(r1 != nil)
80
+ end
81
+
82
+ def test_equal_refs
83
+ r1 = rest_object(%Q(<Object ref="bla"><TextNode>text</TextNode></Object>))
84
+ r2 = rest_object(%Q(<Object ref="bla"><TextNode>not text</TextNode></Object>))
85
+ assert_equal(r1, r2)
86
+ end
87
+
69
88
 
70
89
  def test_basic_text_node
71
90
  xml = %Q(<Object><TextNode>text</TextNode></Object>)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rally_rest_api
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.0
7
- date: 2006-12-13 00:00:00 -07:00
6
+ version: 0.6.1
7
+ date: 2006-12-18 00:00:00 -07:00
8
8
  summary: A ruby-ized interface to Rally's REST webservices API
9
9
  require_paths:
10
10
  - lib
@@ -51,6 +51,7 @@ files:
51
51
  test_files:
52
52
  - test/tc_rest_api.rb
53
53
  - test/tc_rest_object.rb
54
+ - test/query_result_spec.rb
54
55
  - test/tc_rest_query.rb
55
56
  - test/test_helper.rb
56
57
  - test/tc_query_result.rb