##// END OF EJS Templates
Convert tests to shoulda...
Eric Davis -
r3651:f484fe855662
parent child
Show More
@@ -45,85 +45,140 class IssuesApiTest < ActionController::IntegrationTest
45 def setup
45 def setup
46 Setting.rest_api_enabled = '1'
46 Setting.rest_api_enabled = '1'
47 end
47 end
48
48
49 def test_index
49 context "/index.xml" do
50 get '/issues.xml'
50 setup do
51 assert_response :success
51 get '/issues.xml'
52 assert_equal 'application/xml', @response.content_type
52 end
53
54 should_respond_with :success
55 should_respond_with_content_type 'application/xml'
53 end
56 end
54
57
55 def test_index_with_filter
58 context "/index.xml with filter" do
56 get '/issues.xml?status_id=5'
59 setup do
57 assert_response :success
60 get '/issues.xml?status_id=5'
58 assert_equal 'application/xml', @response.content_type
61 end
59 assert_tag :tag => 'issues',
60 :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
61 :only => { :tag => 'issue' } }
62 end
63
62
64 def test_show
63 should_respond_with :success
65 get '/issues/1.xml'
64 should_respond_with_content_type 'application/xml'
66 assert_response :success
65 should "show only issues with the status_id" do
67 assert_equal 'application/xml', @response.content_type
66 assert_tag :tag => 'issues',
67 :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}),
68 :only => { :tag => 'issue' } }
69 end
68 end
70 end
71
72 context "/issues/1.xml" do
73 setup do
74 get '/issues/1.xml'
75 end
69
76
70 def test_create
77 should_respond_with :success
71 attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
78 should_respond_with_content_type 'application/xml'
72 assert_difference 'Issue.count' do
79 end
73 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
80
81 context "POST /issues.xml" do
82 setup do
83 @issue_count = Issue.count
84 @attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}
85 post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
74 end
86 end
75 assert_response :created
87
76 assert_equal 'application/xml', @response.content_type
88 should_respond_with :created
77 issue = Issue.first(:order => 'id DESC')
89 should_respond_with_content_type 'application/xml'
78 attributes.each do |attribute, value|
90
79 assert_equal value, issue.send(attribute)
91 should "create an issue with the attributes" do
92 assert_equal Issue.count, @issue_count + 1
93
94 issue = Issue.first(:order => 'id DESC')
95 @attributes.each do |attribute, value|
96 assert_equal value, issue.send(attribute)
97 end
80 end
98 end
81 end
99 end
82
100
83 def test_create_failure
101 context "POST /issues.xml with failure" do
84 attributes = {:project_id => 1}
102 setup do
85 assert_no_difference 'Issue.count' do
103 @attributes = {:project_id => 1}
86 post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith')
104 post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
87 end
105 end
88 assert_response :unprocessable_entity
106
89 assert_equal 'application/xml', @response.content_type
107 should_respond_with :unprocessable_entity
90 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
108 should_respond_with_content_type 'application/xml'
109
110 should "have an errors tag" do
111 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
112 end
91 end
113 end
92
114
93 def test_update
115 context "PUT /issues/1.xml" do
94 attributes = {:subject => 'API update'}
116 setup do
95 assert_no_difference 'Issue.count' do
117 @issue_count = Issue.count
96 assert_difference 'Journal.count' do
118 @journal_count = Journal.count
97 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
119 @attributes = {:subject => 'API update'}
98 end
120
121 put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
99 end
122 end
100 assert_response :ok
123
101 assert_equal 'application/xml', @response.content_type
124 should_respond_with :ok
102 issue = Issue.find(1)
125 should_respond_with_content_type 'application/xml'
103 attributes.each do |attribute, value|
126
104 assert_equal value, issue.send(attribute)
127 should "not create a new issue" do
128 assert_equal Issue.count, @issue_count
105 end
129 end
106 end
130
107
131 should "create a new journal" do
108 def test_update_failure
132 assert_equal Journal.count, @journal_count + 1
109 attributes = {:subject => ''}
133 end
110 assert_no_difference 'Issue.count' do
134
111 assert_no_difference 'Journal.count' do
135 should "update the issue" do
112 put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith')
136 issue = Issue.find(1)
137 @attributes.each do |attribute, value|
138 assert_equal value, issue.send(attribute)
113 end
139 end
114 end
140 end
115 assert_response :unprocessable_entity
141
116 assert_equal 'application/xml', @response.content_type
117 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
118 end
142 end
143
144 context "PUT /issues/1.xml with failed update" do
145 setup do
146 @attributes = {:subject => ''}
147 @issue_count = Issue.count
148 @journal_count = Journal.count
149
150 put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith')
151 end
119
152
120 def test_destroy
153 should_respond_with :unprocessable_entity
121 assert_difference 'Issue.count', -1 do
154 should_respond_with_content_type 'application/xml'
155
156 should "not create a new issue" do
157 assert_equal Issue.count, @issue_count
158 end
159
160 should "not create a new journal" do
161 assert_equal Journal.count, @journal_count
162 end
163
164 should "have an errors tag" do
165 assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"}
166 end
167 end
168
169 context "DELETE /issues/1.xml" do
170 setup do
171 @issue_count = Issue.count
122 delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
172 delete '/issues/1.xml', {}, :authorization => credentials('jsmith')
123 end
173 end
124 assert_response :ok
174
125 assert_equal 'application/xml', @response.content_type
175 should_respond_with :ok
126 assert_nil Issue.find_by_id(1)
176 should_respond_with_content_type 'application/xml'
177
178 should "delete the issue" do
179 assert_equal Issue.count, @issue_count -1
180 assert_nil Issue.find_by_id(1)
181 end
127 end
182 end
128
183
129 def credentials(user, password=nil)
184 def credentials(user, password=nil)
General Comments 0
You need to be logged in to leave comments. Login now