summaryrefslogtreecommitdiffstats
path: root/test/integration
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-05-18 08:57:27 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-05-18 08:57:27 +0000
commit8f7b69f77e7f92d3b81c0fbd9a0a70169b4d21e9 (patch)
tree31d2955a3ce8d0e02d6327e916cdfd261fdb9081 /test/integration
parent0d4bb7558fdc955e07b69cd4015f2ecb3b5803c7 (diff)
downloadredmine-8f7b69f77e7f92d3b81c0fbd9a0a70169b4d21e9.tar.gz
redmine-8f7b69f77e7f92d3b81c0fbd9a0a70169b4d21e9.zip
Removed some shoulda context.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11863 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/api_test/projects_test.rb426
-rw-r--r--test/integration/api_test/queries_test.rb37
-rw-r--r--test/integration/api_test/roles_test.rb88
-rw-r--r--test/integration/api_test/time_entries_test.rb196
-rw-r--r--test/integration/api_test/token_authentication_test.rb11
-rw-r--r--test/integration/api_test/trackers_test.rb37
-rw-r--r--test/integration/api_test/users_test.rb532
-rw-r--r--test/integration/api_test/versions_test.rb204
8 files changed, 672 insertions, 859 deletions
diff --git a/test/integration/api_test/projects_test.rb b/test/integration/api_test/projects_test.rb
index a37af3d37..1ff180540 100644
--- a/test/integration/api_test/projects_test.rb
+++ b/test/integration/api_test/projects_test.rb
@@ -27,271 +27,209 @@ class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
set_tmp_attachments_directory
end
- context "GET /projects" do
- context ".xml" do
- should "return projects" do
- get '/projects.xml'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
-
- assert_tag :tag => 'projects',
- :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
- end
- end
+ # TODO: A private project is needed because should_allow_api_authentication
+ # actually tests that authentication is *required*, not just allowed
+ should_allow_api_authentication(:get, "/projects/2.xml")
+ should_allow_api_authentication(:get, "/projects/2.json")
+ should_allow_api_authentication(:post,
+ '/projects.xml',
+ {:project => {:name => 'API test', :identifier => 'api-test'}},
+ {:success_code => :created})
+ should_allow_api_authentication(:put,
+ '/projects/2.xml',
+ {:project => {:name => 'API update'}},
+ {:success_code => :ok})
+ should_allow_api_authentication(:delete,
+ '/projects/2.xml',
+ {},
+ {:success_code => :ok})
+
+ test "GET /projects.xml should return projects" do
+ get '/projects.xml'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag :tag => 'projects',
+ :child => {:tag => 'project', :child => {:tag => 'id', :content => '1'}}
+ end
+
+ test "GET /projects.json should return projects" do
+ get '/projects.json'
+ assert_response :success
+ assert_equal 'application/json', @response.content_type
+
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert_kind_of Array, json['projects']
+ assert_kind_of Hash, json['projects'].first
+ assert json['projects'].first.has_key?('id')
+ end
+
+ test "GET /projects/:id.xml should return the project" do
+ get '/projects/1.xml'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag :tag => 'project',
+ :child => {:tag => 'id', :content => '1'}
+ assert_tag :tag => 'custom_field',
+ :attributes => {:name => 'Development status'}, :content => 'Stable'
+
+ assert_no_tag 'trackers'
+ assert_no_tag 'issue_categories'
+ end
+
+ test "GET /projects/:id.json should return the project" do
+ get '/projects/1.json'
+
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert_kind_of Hash, json['project']
+ assert_equal 1, json['project']['id']
+ end
+
+ test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
+ ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
+
+ get '/projects/1.xml'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+
+ assert_no_tag 'custom_field',
+ :attributes => {:name => 'Development status'}
+ end
- context ".json" do
- should "return projects" do
- get '/projects.json'
- assert_response :success
- assert_equal 'application/json', @response.content_type
-
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert_kind_of Array, json['projects']
- assert_kind_of Hash, json['projects'].first
- assert json['projects'].first.has_key?('id')
- end
+ test "GET /projects/:id.xml with include=issue_categories should return categories" do
+ get '/projects/1.xml?include=issue_categories'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag 'issue_categories',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'issue_category',
+ :attributes => {
+ :id => '2',
+ :name => 'Recipes'
+ }
+ }
+ end
+
+ test "GET /projects/:id.xml with include=trackers should return trackers" do
+ get '/projects/1.xml?include=trackers'
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag 'trackers',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'tracker',
+ :attributes => {
+ :id => '2',
+ :name => 'Feature request'
+ }
+ }
+ end
+
+ test "POST /projects.xml with valid parameters should create the project" do
+ Setting.default_projects_modules = ['issue_tracking', 'repository']
+
+ assert_difference('Project.count') do
+ post '/projects.xml',
+ {:project => {:name => 'API test', :identifier => 'api-test'}},
+ credentials('admin')
end
+
+ project = Project.first(:order => 'id DESC')
+ assert_equal 'API test', project.name
+ assert_equal 'api-test', project.identifier
+ assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
+ assert_equal Tracker.all.size, project.trackers.size
+
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
end
- context "GET /projects/:id" do
- context ".xml" do
- # TODO: A private project is needed because should_allow_api_authentication
- # actually tests that authentication is *required*, not just allowed
- should_allow_api_authentication(:get, "/projects/2.xml")
-
- should "return requested project" do
- get '/projects/1.xml'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
-
- assert_tag :tag => 'project',
- :child => {:tag => 'id', :content => '1'}
- assert_tag :tag => 'custom_field',
- :attributes => {:name => 'Development status'}, :content => 'Stable'
-
- assert_no_tag 'trackers'
- assert_no_tag 'issue_categories'
- end
-
- context "with hidden custom fields" do
- setup do
- ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
- end
-
- should "not display hidden custom fields" do
- get '/projects/1.xml'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
-
- assert_no_tag 'custom_field',
- :attributes => {:name => 'Development status'}
- end
- end
-
- should "return categories with include=issue_categories" do
- get '/projects/1.xml?include=issue_categories'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
-
- assert_tag 'issue_categories',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'issue_category',
- :attributes => {
- :id => '2',
- :name => 'Recipes'
- }
- }
- end
-
- should "return trackers with include=trackers" do
- get '/projects/1.xml?include=trackers'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
-
- assert_tag 'trackers',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'tracker',
- :attributes => {
- :id => '2',
- :name => 'Feature request'
- }
- }
- end
+ test "POST /projects.xml should accept enabled_module_names attribute" do
+ assert_difference('Project.count') do
+ post '/projects.xml',
+ {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
+ credentials('admin')
end
- context ".json" do
- should_allow_api_authentication(:get, "/projects/2.json")
+ project = Project.first(:order => 'id DESC')
+ assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
+ end
- should "return requested project" do
- get '/projects/1.json'
+ test "POST /projects.xml should accept tracker_ids attribute" do
+ assert_difference('Project.count') do
+ post '/projects.xml',
+ {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
+ credentials('admin')
+ end
+
+ project = Project.first(:order => 'id DESC')
+ assert_equal [1, 3], project.trackers.map(&:id).sort
+ end
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert_kind_of Hash, json['project']
- assert_equal 1, json['project']['id']
- end
+ test "POST /projects.xml with invalid parameters should return errors" do
+ assert_no_difference('Project.count') do
+ post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
end
+
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
end
- context "POST /projects" do
- context "with valid parameters" do
- setup do
- Setting.default_projects_modules = ['issue_tracking', 'repository']
- @parameters = {:project => {:name => 'API test', :identifier => 'api-test'}}
- end
-
- context ".xml" do
- should_allow_api_authentication(:post,
- '/projects.xml',
- {:project => {:name => 'API test', :identifier => 'api-test'}},
- {:success_code => :created})
-
-
- should "create a project with the attributes" do
- assert_difference('Project.count') do
- post '/projects.xml', @parameters, credentials('admin')
- end
-
- project = Project.first(:order => 'id DESC')
- assert_equal 'API test', project.name
- assert_equal 'api-test', project.identifier
- assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
- assert_equal Tracker.all.size, project.trackers.size
-
- assert_response :created
- assert_equal 'application/xml', @response.content_type
- assert_tag 'project', :child => {:tag => 'id', :content => project.id.to_s}
- end
-
- should "accept enabled_module_names attribute" do
- @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
-
- assert_difference('Project.count') do
- post '/projects.xml', @parameters, credentials('admin')
- end
-
- project = Project.first(:order => 'id DESC')
- assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
- end
-
- should "accept tracker_ids attribute" do
- @parameters[:project].merge!({:tracker_ids => [1, 3]})
-
- assert_difference('Project.count') do
- post '/projects.xml', @parameters, credentials('admin')
- end
-
- project = Project.first(:order => 'id DESC')
- assert_equal [1, 3], project.trackers.map(&:id).sort
- end
- end
+ test "PUT /projects/:id.xml with valid parameters should update the project" do
+ assert_no_difference 'Project.count' do
+ put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
end
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_equal 'application/xml', @response.content_type
+ project = Project.find(2)
+ assert_equal 'API update', project.name
+ end
- context "with invalid parameters" do
- setup do
- @parameters = {:project => {:name => 'API test'}}
- end
-
- context ".xml" do
- should "return errors" do
- assert_no_difference('Project.count') do
- post '/projects.xml', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
- assert_tag 'errors', :child => {:tag => 'error', :content => "Identifier can't be blank"}
- end
- end
+ test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
+ assert_no_difference 'Project.count' do
+ put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
end
+ assert_response :ok
+ assert_equal '', @response.body
+ project = Project.find(2)
+ assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
end
- context "PUT /projects/:id" do
- context "with valid parameters" do
- setup do
- @parameters = {:project => {:name => 'API update'}}
- end
-
- context ".xml" do
- should_allow_api_authentication(:put,
- '/projects/2.xml',
- {:project => {:name => 'API update'}},
- {:success_code => :ok})
-
- should "update the project" do
- assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, credentials('jsmith')
- end
- assert_response :ok
- assert_equal '', @response.body
- assert_equal 'application/xml', @response.content_type
- project = Project.find(2)
- assert_equal 'API update', project.name
- end
-
- should "accept enabled_module_names attribute" do
- @parameters[:project].merge!({:enabled_module_names => ['issue_tracking', 'news', 'time_tracking']})
-
- assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, credentials('admin')
- end
- assert_response :ok
- assert_equal '', @response.body
- project = Project.find(2)
- assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
- end
-
- should "accept tracker_ids attribute" do
- @parameters[:project].merge!({:tracker_ids => [1, 3]})
-
- assert_no_difference 'Project.count' do
- put '/projects/2.xml', @parameters, credentials('admin')
- end
- assert_response :ok
- assert_equal '', @response.body
- project = Project.find(2)
- assert_equal [1, 3], project.trackers.map(&:id).sort
- end
- end
+ test "PUT /projects/:id.xml should accept tracker_ids attribute" do
+ assert_no_difference 'Project.count' do
+ put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
end
+ assert_response :ok
+ assert_equal '', @response.body
+ project = Project.find(2)
+ assert_equal [1, 3], project.trackers.map(&:id).sort
+ end
- context "with invalid parameters" do
- setup do
- @parameters = {:project => {:name => ''}}
- end
-
- context ".xml" do
- should "return errors" do
- assert_no_difference('Project.count') do
- put '/projects/2.xml', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
- assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
- end
- end
+ test "PUT /projects/:id.xml with invalid parameters should return errors" do
+ assert_no_difference('Project.count') do
+ put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
end
+
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
end
- context "DELETE /projects/:id" do
- context ".xml" do
- should_allow_api_authentication(:delete,
- '/projects/2.xml',
- {},
- {:success_code => :ok})
-
- should "delete the project" do
- assert_difference('Project.count',-1) do
- delete '/projects/2.xml', {}, credentials('admin')
- end
- assert_response :ok
- assert_equal '', @response.body
- assert_nil Project.find_by_id(2)
- end
+ test "DELETE /projects/:id.xml should delete the project" do
+ assert_difference('Project.count',-1) do
+ delete '/projects/2.xml', {}, credentials('admin')
end
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_nil Project.find_by_id(2)
end
end
diff --git a/test/integration/api_test/queries_test.rb b/test/integration/api_test/queries_test.rb
index 57e8f6659..37cf9a6b8 100644
--- a/test/integration/api_test/queries_test.rb
+++ b/test/integration/api_test/queries_test.rb
@@ -31,28 +31,23 @@ class Redmine::ApiTest::QueriesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "/queries" do
- context "GET" do
+ test "GET /queries.xml should return queries" do
+ get '/queries.xml'
- should "return queries" do
- get '/queries.xml'
-
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'queries',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'query',
- :child => {
- :tag => 'id',
- :content => '4',
- :sibling => {
- :tag => 'name',
- :content => 'Public query for all projects'
- }
- }
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'queries',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'query',
+ :child => {
+ :tag => 'id',
+ :content => '4',
+ :sibling => {
+ :tag => 'name',
+ :content => 'Public query for all projects'
}
- end
- end
+ }
+ }
end
end
diff --git a/test/integration/api_test/roles_test.rb b/test/integration/api_test/roles_test.rb
index 87c4a9a18..5c66adbb8 100644
--- a/test/integration/api_test/roles_test.rb
+++ b/test/integration/api_test/roles_test.rb
@@ -24,66 +24,52 @@ class Redmine::ApiTest::RolesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "/roles" do
- context "GET" do
- context "xml" do
- should "return the roles" do
- get '/roles.xml'
+ test "GET /roles.xml should return the roles" do
+ get '/roles.xml'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_equal 3, assigns(:roles).size
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_equal 3, assigns(:roles).size
- assert_tag :tag => 'roles',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'role',
- :child => {
- :tag => 'id',
- :content => '2',
- :sibling => {
- :tag => 'name',
- :content => 'Developer'
- }
- }
- }
- end
- end
+ assert_tag :tag => 'roles',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'role',
+ :child => {
+ :tag => 'id',
+ :content => '2',
+ :sibling => {
+ :tag => 'name',
+ :content => 'Developer'
+ }
+ }
+ }
+ end
- context "json" do
- should "return the roles" do
- get '/roles.json'
+ test "GET /roles.json should return the roles" do
+ get '/roles.json'
- assert_response :success
- assert_equal 'application/json', @response.content_type
- assert_equal 3, assigns(:roles).size
+ assert_response :success
+ assert_equal 'application/json', @response.content_type
+ assert_equal 3, assigns(:roles).size
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert_kind_of Array, json['roles']
- assert_include({'id' => 2, 'name' => 'Developer'}, json['roles'])
- end
- end
- end
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert_kind_of Array, json['roles']
+ assert_include({'id' => 2, 'name' => 'Developer'}, json['roles'])
end
- context "/roles/:id" do
- context "GET" do
- context "xml" do
- should "return the role" do
- get '/roles/1.xml'
+ test "GET /roles/:id.xml should return the role" do
+ get '/roles/1.xml'
- assert_response :success
- assert_equal 'application/xml', @response.content_type
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
- assert_select 'role' do
- assert_select 'name', :text => 'Manager'
- assert_select 'role permissions[type=array]' do
- assert_select 'permission', Role.find(1).permissions.size
- assert_select 'permission', :text => 'view_issues'
- end
- end
- end
+ assert_select 'role' do
+ assert_select 'name', :text => 'Manager'
+ assert_select 'role permissions[type=array]' do
+ assert_select 'permission', Role.find(1).permissions.size
+ assert_select 'permission', :text => 'view_issues'
end
end
end
diff --git a/test/integration/api_test/time_entries_test.rb b/test/integration/api_test/time_entries_test.rb
index 4c87a57b6..6d77f0c81 100644
--- a/test/integration/api_test/time_entries_test.rb
+++ b/test/integration/api_test/time_entries_test.rb
@@ -31,134 +31,112 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "GET /time_entries.xml" do
- should "return time entries" do
- get '/time_entries.xml', {}, credentials('jsmith')
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'time_entries',
- :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
- end
+ test "GET /time_entries.xml should return time entries" do
+ get '/time_entries.xml', {}, credentials('jsmith')
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'time_entries',
+ :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
+ end
- context "with limit" do
- should "return limited results" do
- get '/time_entries.xml?limit=2', {}, credentials('jsmith')
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'time_entries',
- :children => {:count => 2}
- end
- end
+ test "GET /time_entries.xml with limit should return limited results" do
+ get '/time_entries.xml?limit=2', {}, credentials('jsmith')
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'time_entries',
+ :children => {:count => 2}
end
- context "GET /time_entries/2.xml" do
- should "return requested time entry" do
- get '/time_entries/2.xml', {}, credentials('jsmith')
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'time_entry',
- :child => {:tag => 'id', :content => '2'}
- end
+ test "GET /time_entries/:id.xml should return the time entry" do
+ get '/time_entries/2.xml', {}, credentials('jsmith')
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'time_entry',
+ :child => {:tag => 'id', :content => '2'}
end
- context "POST /time_entries.xml" do
- context "with issue_id" do
- should "return create time entry" do
- assert_difference 'TimeEntry.count' do
- post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
- end
- assert_response :created
- assert_equal 'application/xml', @response.content_type
-
- entry = TimeEntry.first(:order => 'id DESC')
- assert_equal 'jsmith', entry.user.login
- assert_equal Issue.find(1), entry.issue
- assert_equal Project.find(1), entry.project
- assert_equal Date.parse('2010-12-02'), entry.spent_on
- assert_equal 3.5, entry.hours
- assert_equal TimeEntryActivity.find(11), entry.activity
- end
-
- should "accept custom fields" do
- field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
-
- assert_difference 'TimeEntry.count' do
- post '/time_entries.xml', {:time_entry => {
- :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
- }}, credentials('jsmith')
- end
- assert_response :created
- assert_equal 'application/xml', @response.content_type
-
- entry = TimeEntry.first(:order => 'id DESC')
- assert_equal 'accepted', entry.custom_field_value(field)
- end
+ test "POST /time_entries.xml with issue_id should create time entry" do
+ assert_difference 'TimeEntry.count' do
+ post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+
+ entry = TimeEntry.first(:order => 'id DESC')
+ assert_equal 'jsmith', entry.user.login
+ assert_equal Issue.find(1), entry.issue
+ assert_equal Project.find(1), entry.project
+ assert_equal Date.parse('2010-12-02'), entry.spent_on
+ assert_equal 3.5, entry.hours
+ assert_equal TimeEntryActivity.find(11), entry.activity
+ end
+
+ test "POST /time_entries.xml with issue_id should accept custom fields" do
+ field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
- context "with project_id" do
- should "return create time entry" do
- assert_difference 'TimeEntry.count' do
- post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
- end
- assert_response :created
- assert_equal 'application/xml', @response.content_type
-
- entry = TimeEntry.first(:order => 'id DESC')
- assert_equal 'jsmith', entry.user.login
- assert_nil entry.issue
- assert_equal Project.find(1), entry.project
- assert_equal Date.parse('2010-12-02'), entry.spent_on
- assert_equal 3.5, entry.hours
- assert_equal TimeEntryActivity.find(11), entry.activity
- end
+ assert_difference 'TimeEntry.count' do
+ post '/time_entries.xml', {:time_entry => {
+ :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
+ }}, credentials('jsmith')
end
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
- context "with invalid parameters" do
- should "return errors" do
- assert_no_difference 'TimeEntry.count' do
- post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
- end
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
+ entry = TimeEntry.first(:order => 'id DESC')
+ assert_equal 'accepted', entry.custom_field_value(field)
+ end
- assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
- end
+ test "POST /time_entries.xml with project_id should create time entry" do
+ assert_difference 'TimeEntry.count' do
+ post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
end
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+
+ entry = TimeEntry.first(:order => 'id DESC')
+ assert_equal 'jsmith', entry.user.login
+ assert_nil entry.issue
+ assert_equal Project.find(1), entry.project
+ assert_equal Date.parse('2010-12-02'), entry.spent_on
+ assert_equal 3.5, entry.hours
+ assert_equal TimeEntryActivity.find(11), entry.activity
end
- context "PUT /time_entries/2.xml" do
- context "with valid parameters" do
- should "update time entry" do
- assert_no_difference 'TimeEntry.count' do
- put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
- end
- assert_response :ok
- assert_equal '', @response.body
- assert_equal 'API Update', TimeEntry.find(2).comments
- end
+ test "POST /time_entries.xml with invalid parameters should return errors" do
+ assert_no_difference 'TimeEntry.count' do
+ post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
end
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
+ end
- context "with invalid parameters" do
- should "return errors" do
- assert_no_difference 'TimeEntry.count' do
- put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
- end
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
+ test "PUT /time_entries/:id.xml with valid parameters should update time entry" do
+ assert_no_difference 'TimeEntry.count' do
+ put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
+ end
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_equal 'API Update', TimeEntry.find(2).comments
+ end
- assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
- end
+ test "PUT /time_entries/:id.xml with invalid parameters should return errors" do
+ assert_no_difference 'TimeEntry.count' do
+ put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
end
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+
+ assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
end
- context "DELETE /time_entries/2.xml" do
- should "destroy time entry" do
- assert_difference 'TimeEntry.count', -1 do
- delete '/time_entries/2.xml', {}, credentials('jsmith')
- end
- assert_response :ok
- assert_equal '', @response.body
- assert_nil TimeEntry.find_by_id(2)
+ test "DELETE /time_entries/:id.xml should destroy time entry" do
+ assert_difference 'TimeEntry.count', -1 do
+ delete '/time_entries/2.xml', {}, credentials('jsmith')
end
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_nil TimeEntry.find_by_id(2)
end
end
diff --git a/test/integration/api_test/token_authentication_test.rb b/test/integration/api_test/token_authentication_test.rb
index a20f1bbb6..e4122ebe6 100644
--- a/test/integration/api_test/token_authentication_test.rb
+++ b/test/integration/api_test/token_authentication_test.rb
@@ -37,13 +37,6 @@ class Redmine::ApiTest::TokenAuthenticationTest < Redmine::ApiTest::Base
end
# Using the NewsController because it's a simple API.
- context "get /news" do
- context "in :xml format" do
- should_allow_key_based_auth(:get, "/news.xml")
- end
-
- context "in :json format" do
- should_allow_key_based_auth(:get, "/news.json")
- end
- end
+ should_allow_key_based_auth(:get, "/news.xml")
+ should_allow_key_based_auth(:get, "/news.json")
end
diff --git a/test/integration/api_test/trackers_test.rb b/test/integration/api_test/trackers_test.rb
index 8141c952e..925d68962 100644
--- a/test/integration/api_test/trackers_test.rb
+++ b/test/integration/api_test/trackers_test.rb
@@ -24,28 +24,23 @@ class Redmine::ApiTest::TrackersTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "/trackers" do
- context "GET" do
+ test "GET /trackers.xml should return trackers" do
+ get '/trackers.xml'
- should "return trackers" do
- get '/trackers.xml'
-
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'trackers',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'tracker',
- :child => {
- :tag => 'id',
- :content => '2',
- :sibling => {
- :tag => 'name',
- :content => 'Feature request'
- }
- }
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'trackers',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'tracker',
+ :child => {
+ :tag => 'id',
+ :content => '2',
+ :sibling => {
+ :tag => 'name',
+ :content => 'Feature request'
}
- end
- end
+ }
+ }
end
end
diff --git a/test/integration/api_test/users_test.rb b/test/integration/api_test/users_test.rb
index f90e8cb3d..d4cec5006 100644
--- a/test/integration/api_test/users_test.rb
+++ b/test/integration/api_test/users_test.rb
@@ -24,76 +24,96 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "GET /users" do
- should_allow_api_authentication(:get, "/users.xml")
- should_allow_api_authentication(:get, "/users.json")
+ should_allow_api_authentication(:get, "/users.xml")
+ should_allow_api_authentication(:get, "/users.json")
+ should_allow_api_authentication(:post,
+ '/users.xml',
+ {:user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123'
+ }},
+ {:success_code => :created})
+ should_allow_api_authentication(:post,
+ '/users.json',
+ {:user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net'
+ }},
+ {:success_code => :created})
+ should_allow_api_authentication(:put,
+ '/users/2.xml',
+ {:user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'
+ }},
+ {:success_code => :ok})
+ should_allow_api_authentication(:put,
+ '/users/2.json',
+ {:user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'
+ }},
+ {:success_code => :ok})
+ should_allow_api_authentication(:delete,
+ '/users/2.xml',
+ {},
+ {:success_code => :ok})
+ should_allow_api_authentication(:delete,
+ '/users/2.xml',
+ {},
+ {:success_code => :ok})
+
+ test "GET /users/:id.xml should return the user" do
+ get '/users/2.xml'
+
+ assert_response :success
+ assert_tag :tag => 'user',
+ :child => {:tag => 'id', :content => '2'}
end
- context "GET /users/2" do
- context ".xml" do
- should "return requested user" do
- get '/users/2.xml'
-
- assert_response :success
- assert_tag :tag => 'user',
- :child => {:tag => 'id', :content => '2'}
- end
-
- context "with include=memberships" do
- should "include memberships" do
- get '/users/2.xml?include=memberships'
-
- assert_response :success
- assert_tag :tag => 'memberships',
- :parent => {:tag => 'user'},
- :children => {:count => 1}
- end
- end
- end
+ test "GET /users/:id.json should return the user" do
+ get '/users/2.json'
- context ".json" do
- should "return requested user" do
- get '/users/2.json'
-
- assert_response :success
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert_kind_of Hash, json['user']
- assert_equal 2, json['user']['id']
- end
-
- context "with include=memberships" do
- should "include memberships" do
- get '/users/2.json?include=memberships'
-
- assert_response :success
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Array, json['user']['memberships']
- assert_equal [{
- "id"=>1,
- "project"=>{"name"=>"eCookbook", "id"=>1},
- "roles"=>[{"name"=>"Manager", "id"=>1}]
- }], json['user']['memberships']
- end
- end
- end
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert_kind_of Hash, json['user']
+ assert_equal 2, json['user']['id']
end
- context "GET /users/current" do
- context ".xml" do
- should "require authentication" do
- get '/users/current.xml'
+ test "GET /users/:id.xml with include=memberships should include memberships" do
+ get '/users/2.xml?include=memberships'
- assert_response 401
- end
+ assert_response :success
+ assert_tag :tag => 'memberships',
+ :parent => {:tag => 'user'},
+ :children => {:count => 1}
+ end
- should "return current user" do
- get '/users/current.xml', {}, credentials('jsmith')
+ test "GET /users/:id.json with include=memberships should include memberships" do
+ get '/users/2.json?include=memberships'
- assert_tag :tag => 'user',
- :child => {:tag => 'id', :content => '2'}
- end
- end
+ assert_response :success
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Array, json['user']['memberships']
+ assert_equal [{
+ "id"=>1,
+ "project"=>{"name"=>"eCookbook", "id"=>1},
+ "roles"=>[{"name"=>"Manager", "id"=>1}]
+ }], json['user']['memberships']
+ end
+
+ test "GET /users/current.xml should require authentication" do
+ get '/users/current.xml'
+
+ assert_response 401
+ end
+
+ test "GET /users/current.xml should return current user" do
+ get '/users/current.xml', {}, credentials('jsmith')
+
+ assert_tag :tag => 'user',
+ :child => {:tag => 'id', :content => '2'}
end
test "GET /users/:id should not return login for other user" do
@@ -132,252 +152,176 @@ class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
assert_tag 'user', :child => {:tag => 'status', :content => User.find(1).status.to_s}
end
- context "POST /users" do
- context "with valid parameters" do
- setup do
- @parameters = {
- :user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123',
- :mail_notification => 'only_assigned'
- }
- }
- end
-
- context ".xml" do
- should_allow_api_authentication(:post,
- '/users.xml',
- {:user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net', :password => 'secret123'
- }},
- {:success_code => :created})
-
- should "create a user with the attributes" do
- assert_difference('User.count') do
- post '/users.xml', @parameters, credentials('admin')
- end
-
- user = User.first(:order => 'id DESC')
- assert_equal 'foo', user.login
- assert_equal 'Firstname', user.firstname
- assert_equal 'Lastname', user.lastname
- assert_equal 'foo@example.net', user.mail
- assert_equal 'only_assigned', user.mail_notification
- assert !user.admin?
- assert user.check_password?('secret123')
-
- assert_response :created
- assert_equal 'application/xml', @response.content_type
- assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s}
- end
- end
-
- context ".json" do
- should_allow_api_authentication(:post,
- '/users.json',
- {:user => {
- :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
- :mail => 'foo@example.net'
- }},
- {:success_code => :created})
-
- should "create a user with the attributes" do
- assert_difference('User.count') do
- post '/users.json', @parameters, credentials('admin')
- end
-
- user = User.first(:order => 'id DESC')
- assert_equal 'foo', user.login
- assert_equal 'Firstname', user.firstname
- assert_equal 'Lastname', user.lastname
- assert_equal 'foo@example.net', user.mail
- assert !user.admin?
-
- assert_response :created
- assert_equal 'application/json', @response.content_type
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert_kind_of Hash, json['user']
- assert_equal user.id, json['user']['id']
- end
- end
+ test "POST /users.xml with valid parameters should create the user" do
+ assert_difference('User.count') do
+ post '/users.xml', {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123',
+ :mail_notification => 'only_assigned'}
+ },
+ credentials('admin')
+ end
+
+ user = User.first(:order => 'id DESC')
+ assert_equal 'foo', user.login
+ assert_equal 'Firstname', user.firstname
+ assert_equal 'Lastname', user.lastname
+ assert_equal 'foo@example.net', user.mail
+ assert_equal 'only_assigned', user.mail_notification
+ assert !user.admin?
+ assert user.check_password?('secret123')
+
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'user', :child => {:tag => 'id', :content => user.id.to_s}
+ end
+
+ test "POST /users.json with valid parameters should create the user" do
+ assert_difference('User.count') do
+ post '/users.json', {
+ :user => {
+ :login => 'foo', :firstname => 'Firstname', :lastname => 'Lastname',
+ :mail => 'foo@example.net', :password => 'secret123',
+ :mail_notification => 'only_assigned'}
+ },
+ credentials('admin')
+ end
+
+ user = User.first(:order => 'id DESC')
+ assert_equal 'foo', user.login
+ assert_equal 'Firstname', user.firstname
+ assert_equal 'Lastname', user.lastname
+ assert_equal 'foo@example.net', user.mail
+ assert !user.admin?
+
+ assert_response :created
+ assert_equal 'application/json', @response.content_type
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert_kind_of Hash, json['user']
+ assert_equal user.id, json['user']['id']
+ end
+
+ test "POST /users.xml with with invalid parameters should return errors" do
+ assert_no_difference('User.count') do
+ post '/users.xml', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
+ end
+
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'errors', :child => {
+ :tag => 'error',
+ :content => "First name can't be blank"
+ }
+ end
+
+ test "POST /users.json with with invalid parameters should return errors" do
+ assert_no_difference('User.count') do
+ post '/users.json', {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}, credentials('admin')
end
- context "with invalid parameters" do
- setup do
- @parameters = {:user => {:login => 'foo', :lastname => 'Lastname', :mail => 'foo'}}
- end
-
- context ".xml" do
- should "return errors" do
- assert_no_difference('User.count') do
- post '/users.xml', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
- assert_tag 'errors', :child => {
- :tag => 'error',
- :content => "First name can't be blank"
- }
- end
- end
-
- context ".json" do
- should "return errors" do
- assert_no_difference('User.count') do
- post '/users.json', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/json', @response.content_type
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert json.has_key?('errors')
- assert_kind_of Array, json['errors']
- end
- end
+ assert_response :unprocessable_entity
+ assert_equal 'application/json', @response.content_type
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert json.has_key?('errors')
+ assert_kind_of Array, json['errors']
+ end
+
+ test "PUT /users/:id.xml with valid parameters should update the user" do
+ assert_no_difference('User.count') do
+ put '/users/2.xml', {
+ :user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'}
+ },
+ credentials('admin')
end
+
+ user = User.find(2)
+ assert_equal 'jsmith', user.login
+ assert_equal 'John', user.firstname
+ assert_equal 'Renamed', user.lastname
+ assert_equal 'jsmith@somenet.foo', user.mail
+ assert !user.admin?
+
+ assert_response :ok
+ assert_equal '', @response.body
end
- context "PUT /users/2" do
- context "with valid parameters" do
- setup do
- @parameters = {
- :user => {
- :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
- :mail => 'jsmith@somenet.foo'
- }
- }
- end
-
- context ".xml" do
- should_allow_api_authentication(:put,
- '/users/2.xml',
- {:user => {
- :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
- :mail => 'jsmith@somenet.foo'
- }},
- {:success_code => :ok})
-
- should "update user with the attributes" do
- assert_no_difference('User.count') do
- put '/users/2.xml', @parameters, credentials('admin')
- end
-
- user = User.find(2)
- assert_equal 'jsmith', user.login
- assert_equal 'John', user.firstname
- assert_equal 'Renamed', user.lastname
- assert_equal 'jsmith@somenet.foo', user.mail
- assert !user.admin?
-
- assert_response :ok
- assert_equal '', @response.body
- end
- end
-
- context ".json" do
- should_allow_api_authentication(:put,
- '/users/2.json',
- {:user => {
- :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
- :mail => 'jsmith@somenet.foo'
- }},
- {:success_code => :ok})
-
- should "update user with the attributes" do
- assert_no_difference('User.count') do
- put '/users/2.json', @parameters, credentials('admin')
- end
-
- user = User.find(2)
- assert_equal 'jsmith', user.login
- assert_equal 'John', user.firstname
- assert_equal 'Renamed', user.lastname
- assert_equal 'jsmith@somenet.foo', user.mail
- assert !user.admin?
-
- assert_response :ok
- assert_equal '', @response.body
- end
- end
+ test "PUT /users/:id.json with valid parameters should update the user" do
+ assert_no_difference('User.count') do
+ put '/users/2.json', {
+ :user => {
+ :login => 'jsmith', :firstname => 'John', :lastname => 'Renamed',
+ :mail => 'jsmith@somenet.foo'}
+ },
+ credentials('admin')
end
- context "with invalid parameters" do
- setup do
- @parameters = {
- :user => {
- :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
- :mail => 'foo'
- }
- }
- end
-
- context ".xml" do
- should "return errors" do
- assert_no_difference('User.count') do
- put '/users/2.xml', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/xml', @response.content_type
- assert_tag 'errors', :child => {
- :tag => 'error',
- :content => "First name can't be blank"
- }
- end
- end
-
- context ".json" do
- should "return errors" do
- assert_no_difference('User.count') do
- put '/users/2.json', @parameters, credentials('admin')
- end
-
- assert_response :unprocessable_entity
- assert_equal 'application/json', @response.content_type
- json = ActiveSupport::JSON.decode(response.body)
- assert_kind_of Hash, json
- assert json.has_key?('errors')
- assert_kind_of Array, json['errors']
- end
- end
+ user = User.find(2)
+ assert_equal 'jsmith', user.login
+ assert_equal 'John', user.firstname
+ assert_equal 'Renamed', user.lastname
+ assert_equal 'jsmith@somenet.foo', user.mail
+ assert !user.admin?
+
+ assert_response :ok
+ assert_equal '', @response.body
+ end
+
+ test "PUT /users/:id.xml with invalid parameters" do
+ assert_no_difference('User.count') do
+ put '/users/2.xml', {
+ :user => {
+ :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
+ :mail => 'foo'}
+ },
+ credentials('admin')
end
+
+ assert_response :unprocessable_entity
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'errors', :child => {
+ :tag => 'error',
+ :content => "First name can't be blank"
+ }
end
- context "DELETE /users/2" do
- context ".xml" do
- should_allow_api_authentication(:delete,
- '/users/2.xml',
- {},
- {:success_code => :ok})
-
- should "delete user" do
- assert_difference('User.count', -1) do
- delete '/users/2.xml', {}, credentials('admin')
- end
-
- assert_response :ok
- assert_equal '', @response.body
- end
+ test "PUT /users/:id.json with invalid parameters" do
+ assert_no_difference('User.count') do
+ put '/users/2.json', {
+ :user => {
+ :login => 'jsmith', :firstname => '', :lastname => 'Lastname',
+ :mail => 'foo'}
+ },
+ credentials('admin')
end
- context ".json" do
- should_allow_api_authentication(:delete,
- '/users/2.xml',
- {},
- {:success_code => :ok})
+ assert_response :unprocessable_entity
+ assert_equal 'application/json', @response.content_type
+ json = ActiveSupport::JSON.decode(response.body)
+ assert_kind_of Hash, json
+ assert json.has_key?('errors')
+ assert_kind_of Array, json['errors']
+ end
- should "delete user" do
- assert_difference('User.count', -1) do
- delete '/users/2.json', {}, credentials('admin')
- end
+ test "DELETE /users/:id.xml should delete the user" do
+ assert_difference('User.count', -1) do
+ delete '/users/2.xml', {}, credentials('admin')
+ end
- assert_response :ok
- assert_equal '', @response.body
- end
+ assert_response :ok
+ assert_equal '', @response.body
+ end
+
+ test "DELETE /users/:id.json should delete the user" do
+ assert_difference('User.count', -1) do
+ delete '/users/2.json', {}, credentials('admin')
end
+
+ assert_response :ok
+ assert_equal '', @response.body
end
end
diff --git a/test/integration/api_test/versions_test.rb b/test/integration/api_test/versions_test.rb
index 51f8e2b33..e4948a3a8 100644
--- a/test/integration/api_test/versions_test.rb
+++ b/test/integration/api_test/versions_test.rb
@@ -31,128 +31,112 @@ class Redmine::ApiTest::VersionsTest < Redmine::ApiTest::Base
Setting.rest_api_enabled = '1'
end
- context "/projects/:project_id/versions" do
- context "GET" do
- should "return project versions" do
- get '/projects/1/versions.xml'
-
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_tag :tag => 'versions',
- :attributes => {:type => 'array'},
- :child => {
- :tag => 'version',
- :child => {
- :tag => 'id',
- :content => '2',
- :sibling => {
- :tag => 'name',
- :content => '1.0'
- }
- }
+ test "GET /projects/:project_id/versions.xml should return project versions" do
+ get '/projects/1/versions.xml'
+
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_tag :tag => 'versions',
+ :attributes => {:type => 'array'},
+ :child => {
+ :tag => 'version',
+ :child => {
+ :tag => 'id',
+ :content => '2',
+ :sibling => {
+ :tag => 'name',
+ :content => '1.0'
}
- end
+ }
+ }
+ end
+
+ test "POST /projects/:project_id/versions.xml should create the version" do
+ assert_difference 'Version.count' do
+ post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
+ end
+
+ version = Version.first(:order => 'id DESC')
+ assert_equal 'API test', version.name
+
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
+ end
+
+ test "POST /projects/:project_id/versions.xml should create the version with due date" do
+ assert_difference 'Version.count' do
+ post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
end
- context "POST" do
- should "create the version" do
- assert_difference 'Version.count' do
- post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
- end
-
- version = Version.first(:order => 'id DESC')
- assert_equal 'API test', version.name
-
- assert_response :created
- assert_equal 'application/xml', @response.content_type
- assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
- end
-
- should "create the version with due date" do
- assert_difference 'Version.count' do
- post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
- end
-
- version = Version.first(:order => 'id DESC')
- assert_equal 'API test', version.name
- assert_equal Date.parse('2012-01-24'), version.due_date
-
- assert_response :created
- assert_equal 'application/xml', @response.content_type
- assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
- end
-
- should "create the version with custom fields" do
- field = VersionCustomField.generate!
-
- assert_difference 'Version.count' do
- post '/projects/1/versions.xml', {
- :version => {
- :name => 'API test',
- :custom_fields => [
- {'id' => field.id.to_s, 'value' => 'Some value'}
- ]
- }
- }, credentials('jsmith')
- end
-
- version = Version.first(:order => 'id DESC')
- assert_equal 'API test', version.name
- assert_equal 'Some value', version.custom_field_value(field)
-
- assert_response :created
- assert_equal 'application/xml', @response.content_type
- assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value'
- end
-
- context "with failure" do
- should "return the errors" do
- assert_no_difference('Version.count') do
- post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
- end
-
- assert_response :unprocessable_entity
- assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
- end
- end
+ version = Version.first(:order => 'id DESC')
+ assert_equal 'API test', version.name
+ assert_equal Date.parse('2012-01-24'), version.due_date
+
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+ assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
+ end
+
+ test "POST /projects/:project_id/versions.xml should create the version with custom fields" do
+ field = VersionCustomField.generate!
+
+ assert_difference 'Version.count' do
+ post '/projects/1/versions.xml', {
+ :version => {
+ :name => 'API test',
+ :custom_fields => [
+ {'id' => field.id.to_s, 'value' => 'Some value'}
+ ]
+ }
+ }, credentials('jsmith')
end
+
+ version = Version.first(:order => 'id DESC')
+ assert_equal 'API test', version.name
+ assert_equal 'Some value', version.custom_field_value(field)
+
+ assert_response :created
+ assert_equal 'application/xml', @response.content_type
+ assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value'
end
- context "/versions/:id" do
- context "GET" do
- should "return the version" do
- get '/versions/2.xml'
-
- assert_response :success
- assert_equal 'application/xml', @response.content_type
- assert_select 'version' do
- assert_select 'id', :text => '2'
- assert_select 'name', :text => '1.0'
- assert_select 'sharing', :text => 'none'
- end
- end
+ test "POST /projects/:project_id/versions.xml with failure should return the errors" do
+ assert_no_difference('Version.count') do
+ post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
end
- context "PUT" do
- should "update the version" do
- put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
+ assert_response :unprocessable_entity
+ assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
+ end
+
+ test "GET /versions/:id.xml should return the version" do
+ get '/versions/2.xml'
- assert_response :ok
- assert_equal '', @response.body
- assert_equal 'API update', Version.find(2).name
- end
+ assert_response :success
+ assert_equal 'application/xml', @response.content_type
+ assert_select 'version' do
+ assert_select 'id', :text => '2'
+ assert_select 'name', :text => '1.0'
+ assert_select 'sharing', :text => 'none'
end
+ end
- context "DELETE" do
- should "destroy the version" do
- assert_difference 'Version.count', -1 do
- delete '/versions/3.xml', {}, credentials('jsmith')
- end
+ test "PUT /versions/:id.xml should update the version" do
+ put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
- assert_response :ok
- assert_equal '', @response.body
- assert_nil Version.find_by_id(3)
- end
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_equal 'API update', Version.find(2).name
+ end
+
+ test "DELETE /versions/:id.xml should destroy the version" do
+ assert_difference 'Version.count', -1 do
+ delete '/versions/3.xml', {}, credentials('jsmith')
end
+
+ assert_response :ok
+ assert_equal '', @response.body
+ assert_nil Version.find_by_id(3)
end
end