Commit c43cb98b authored by jplang's avatar jplang

Removed some shoulda context.

git-svn-id: https://svn.redmine.org/redmine/trunk@11863 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent f7962368
This diff is collapsed.
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
This diff is collapsed.
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment