Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/time_entries_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
32 Setting.rest_api_enabled = '1' | 32 Setting.rest_api_enabled = '1' |
33 end | 33 end |
34 | 34 |
35 context "GET /time_entries.xml" do | 35 context "GET /time_entries.xml" do |
36 should "return time entries" do | 36 should "return time entries" do |
37 get '/time_entries.xml', {}, :authorization => credentials('jsmith') | 37 get '/time_entries.xml', {}, credentials('jsmith') |
38 assert_response :success | 38 assert_response :success |
39 assert_equal 'application/xml', @response.content_type | 39 assert_equal 'application/xml', @response.content_type |
40 assert_tag :tag => 'time_entries', | 40 assert_tag :tag => 'time_entries', |
41 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} | 41 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} |
42 end | 42 end |
43 | 43 |
44 context "with limit" do | 44 context "with limit" do |
45 should "return limited results" do | 45 should "return limited results" do |
46 get '/time_entries.xml?limit=2', {}, :authorization => credentials('jsmith') | 46 get '/time_entries.xml?limit=2', {}, credentials('jsmith') |
47 assert_response :success | 47 assert_response :success |
48 assert_equal 'application/xml', @response.content_type | 48 assert_equal 'application/xml', @response.content_type |
49 assert_tag :tag => 'time_entries', | 49 assert_tag :tag => 'time_entries', |
50 :children => {:count => 2} | 50 :children => {:count => 2} |
51 end | 51 end |
52 end | 52 end |
53 end | 53 end |
54 | 54 |
55 context "GET /time_entries/2.xml" do | 55 context "GET /time_entries/2.xml" do |
56 should "return requested time entry" do | 56 should "return requested time entry" do |
57 get '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | 57 get '/time_entries/2.xml', {}, credentials('jsmith') |
58 assert_response :success | 58 assert_response :success |
59 assert_equal 'application/xml', @response.content_type | 59 assert_equal 'application/xml', @response.content_type |
60 assert_tag :tag => 'time_entry', | 60 assert_tag :tag => 'time_entry', |
61 :child => {:tag => 'id', :content => '2'} | 61 :child => {:tag => 'id', :content => '2'} |
62 end | 62 end |
64 | 64 |
65 context "POST /time_entries.xml" do | 65 context "POST /time_entries.xml" do |
66 context "with issue_id" do | 66 context "with issue_id" do |
67 should "return create time entry" do | 67 should "return create time entry" do |
68 assert_difference 'TimeEntry.count' do | 68 assert_difference 'TimeEntry.count' do |
69 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith') | 69 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
70 end | 70 end |
71 assert_response :created | 71 assert_response :created |
72 assert_equal 'application/xml', @response.content_type | 72 assert_equal 'application/xml', @response.content_type |
73 | 73 |
74 entry = TimeEntry.first(:order => 'id DESC') | 74 entry = TimeEntry.first(:order => 'id DESC') |
77 assert_equal Project.find(1), entry.project | 77 assert_equal Project.find(1), entry.project |
78 assert_equal Date.parse('2010-12-02'), entry.spent_on | 78 assert_equal Date.parse('2010-12-02'), entry.spent_on |
79 assert_equal 3.5, entry.hours | 79 assert_equal 3.5, entry.hours |
80 assert_equal TimeEntryActivity.find(11), entry.activity | 80 assert_equal TimeEntryActivity.find(11), entry.activity |
81 end | 81 end |
82 | |
83 should "accept custom fields" do | |
84 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') | |
85 | |
86 assert_difference 'TimeEntry.count' do | |
87 post '/time_entries.xml', {:time_entry => { | |
88 :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] | |
89 }}, credentials('jsmith') | |
90 end | |
91 assert_response :created | |
92 assert_equal 'application/xml', @response.content_type | |
93 | |
94 entry = TimeEntry.first(:order => 'id DESC') | |
95 assert_equal 'accepted', entry.custom_field_value(field) | |
96 end | |
82 end | 97 end |
83 | 98 |
84 context "with project_id" do | 99 context "with project_id" do |
85 should "return create time entry" do | 100 should "return create time entry" do |
86 assert_difference 'TimeEntry.count' do | 101 assert_difference 'TimeEntry.count' do |
87 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith') | 102 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
88 end | 103 end |
89 assert_response :created | 104 assert_response :created |
90 assert_equal 'application/xml', @response.content_type | 105 assert_equal 'application/xml', @response.content_type |
91 | 106 |
92 entry = TimeEntry.first(:order => 'id DESC') | 107 entry = TimeEntry.first(:order => 'id DESC') |
100 end | 115 end |
101 | 116 |
102 context "with invalid parameters" do | 117 context "with invalid parameters" do |
103 should "return errors" do | 118 should "return errors" do |
104 assert_no_difference 'TimeEntry.count' do | 119 assert_no_difference 'TimeEntry.count' do |
105 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, :authorization => credentials('jsmith') | 120 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') |
106 end | 121 end |
107 assert_response :unprocessable_entity | 122 assert_response :unprocessable_entity |
108 assert_equal 'application/xml', @response.content_type | 123 assert_equal 'application/xml', @response.content_type |
109 | 124 |
110 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | 125 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
114 | 129 |
115 context "PUT /time_entries/2.xml" do | 130 context "PUT /time_entries/2.xml" do |
116 context "with valid parameters" do | 131 context "with valid parameters" do |
117 should "update time entry" do | 132 should "update time entry" do |
118 assert_no_difference 'TimeEntry.count' do | 133 assert_no_difference 'TimeEntry.count' do |
119 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith') | 134 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') |
120 end | 135 end |
121 assert_response :ok | 136 assert_response :ok |
137 assert_equal '', @response.body | |
122 assert_equal 'API Update', TimeEntry.find(2).comments | 138 assert_equal 'API Update', TimeEntry.find(2).comments |
123 end | 139 end |
124 end | 140 end |
125 | 141 |
126 context "with invalid parameters" do | 142 context "with invalid parameters" do |
127 should "return errors" do | 143 should "return errors" do |
128 assert_no_difference 'TimeEntry.count' do | 144 assert_no_difference 'TimeEntry.count' do |
129 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, :authorization => credentials('jsmith') | 145 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') |
130 end | 146 end |
131 assert_response :unprocessable_entity | 147 assert_response :unprocessable_entity |
132 assert_equal 'application/xml', @response.content_type | 148 assert_equal 'application/xml', @response.content_type |
133 | 149 |
134 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | 150 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
137 end | 153 end |
138 | 154 |
139 context "DELETE /time_entries/2.xml" do | 155 context "DELETE /time_entries/2.xml" do |
140 should "destroy time entry" do | 156 should "destroy time entry" do |
141 assert_difference 'TimeEntry.count', -1 do | 157 assert_difference 'TimeEntry.count', -1 do |
142 delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | 158 delete '/time_entries/2.xml', {}, credentials('jsmith') |
143 end | 159 end |
144 assert_response :ok | 160 assert_response :ok |
161 assert_equal '', @response.body | |
145 assert_nil TimeEntry.find_by_id(2) | 162 assert_nil TimeEntry.find_by_id(2) |
146 end | 163 end |
147 end | 164 end |
148 | |
149 def credentials(user, password=nil) | |
150 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
151 end | |
152 end | 165 end |