#1617 make code conform to the style used, add tests for false boolean to improve coverage
This commit is contained in:
parent
c63e6e5be3
commit
76ceb4e9b3
3 changed files with 110 additions and 36 deletions
|
@ -80,6 +80,7 @@ test:unit:mysql:
|
|||
- rake test:units
|
||||
- rake test:controllers
|
||||
- ruby -I test/ test/integration/object_manager_test.rb
|
||||
- ruby -I test/ test/integration/object_manager_attributes_controller_test.rb
|
||||
- ruby -I test/ test/integration/package_test.rb
|
||||
- rake db:drop
|
||||
|
||||
|
@ -96,6 +97,7 @@ test:unit:postgresql:
|
|||
- rake test:units
|
||||
- rake test:controllers
|
||||
- ruby -I test/ test/integration/object_manager_test.rb
|
||||
- ruby -I test/ test/integration/object_manager_attributes_controller_test.rb
|
||||
- ruby -I test/ test/integration/package_test.rb
|
||||
- rake db:drop
|
||||
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
@headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
|
||||
|
||||
# create agent
|
||||
roles = Role.where(name: 'Admin')
|
||||
groups = Group.all
|
||||
|
||||
UserInfo.current_user_id = 1
|
||||
@admin = User.create_or_update(
|
||||
login: 'tickets-admin',
|
||||
firstname: 'Tickets',
|
||||
lastname: 'Admin',
|
||||
email: 'tickets-admin@example.com',
|
||||
password: 'adminpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
end
|
||||
test '01 converts string to boolean for default value for boolean data type' do
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw')
|
||||
|
||||
post '/api/v1/object_manager_attributes', params: { 'name' => 'customdescription2', 'object' => 'Ticket', 'display' => 'custom description 2', 'active' => true, 'data_type' => 'boolean', 'data_option' => { 'options' => { 'true' => '', 'false' => '' }, 'default' => 'true' }, 'screens' => { 'create_middle' => { 'ticket.customer' => { 'shown' => true, 'item_class' => 'column' }, 'ticket.agent' => { 'shown' => true, 'item_class' => 'column' } }, 'edit' => { 'ticket.customer' => { 'shown' => true }, 'ticket.agent' => { 'shown' => true } } }, 'id' => 'c-192' }.to_json, headers: @headers.merge('Authorization' => credentials)
|
||||
assert_response :success
|
||||
result = JSON.parse @response.body
|
||||
object = ObjectManager::Attribute.find result['id']
|
||||
assert_equal true, object.data_option['default']
|
||||
assert_equal 'boolean', object.data_type
|
||||
object.destroy
|
||||
end
|
||||
end
|
|
@ -3,6 +3,8 @@ require 'test_helper'
|
|||
require 'rake'
|
||||
|
||||
class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest
|
||||
self.use_transactional_tests = false
|
||||
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
|
@ -446,4 +448,110 @@ class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_equal(result['display'], 'Test 7')
|
||||
end
|
||||
|
||||
test '01 converts string to boolean for default value for boolean data type with true' do
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw')
|
||||
|
||||
params = {
|
||||
'name': "customerdescription#{rand(999_999_999)}",
|
||||
'object': 'Ticket',
|
||||
'display': "custom description#{rand(999_999_999)}",
|
||||
'active': true,
|
||||
'data_type': 'boolean',
|
||||
'data_option': {
|
||||
'options': {
|
||||
'true': '',
|
||||
'false': '',
|
||||
},
|
||||
'default': 'true',
|
||||
'screens': {
|
||||
'create_middle': {
|
||||
'ticket.customer': {
|
||||
'shown': true,
|
||||
'item_class': 'column'
|
||||
},
|
||||
'ticket.agent': {
|
||||
'shown': true,
|
||||
'item_class': 'column'
|
||||
}
|
||||
},
|
||||
'edit': {
|
||||
'ticket.customer': {
|
||||
'shown': true
|
||||
},
|
||||
'ticket.agent': {
|
||||
'shown': true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'id': 'c-201'
|
||||
}
|
||||
|
||||
post '/api/v1/object_manager_attributes', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
|
||||
|
||||
migration = ObjectManager::Attribute.migration_execute
|
||||
assert_equal(migration, true)
|
||||
|
||||
assert_response(201) # created
|
||||
result = JSON.parse(@response.body)
|
||||
|
||||
assert(result)
|
||||
assert(result['data_option']['default'])
|
||||
assert_equal(result['data_option']['default'], true)
|
||||
assert_equal(result['data_type'], 'boolean')
|
||||
end
|
||||
|
||||
test '02 converts string to boolean for default value for boolean data type with false' do
|
||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw')
|
||||
|
||||
params = {
|
||||
'name': "customerdescription_#{rand(999_999_999)}",
|
||||
'object': 'Ticket',
|
||||
'display': "custom description #{rand(999_999_999)}",
|
||||
'active': true,
|
||||
'data_type': 'boolean',
|
||||
'data_option': {
|
||||
'options': {
|
||||
'true': '',
|
||||
'false': '',
|
||||
},
|
||||
'default': 'false',
|
||||
'screens': {
|
||||
'create_middle': {
|
||||
'ticket.customer': {
|
||||
'shown': true,
|
||||
'item_class': 'column'
|
||||
},
|
||||
'ticket.agent': {
|
||||
'shown': true,
|
||||
'item_class': 'column'
|
||||
}
|
||||
},
|
||||
'edit': {
|
||||
'ticket.customer': {
|
||||
'shown': true
|
||||
},
|
||||
'ticket.agent': {
|
||||
'shown': true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'id': 'c-202'
|
||||
}
|
||||
|
||||
post '/api/v1/object_manager_attributes', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
|
||||
|
||||
migration = ObjectManager::Attribute.migration_execute
|
||||
assert_equal(migration, true)
|
||||
|
||||
assert_response(201) # created
|
||||
result = JSON.parse(@response.body)
|
||||
|
||||
assert(result)
|
||||
assert_not(result['data_option']['default'])
|
||||
assert_equal(result['data_option']['default'], false)
|
||||
assert_equal(result['data_type'], 'boolean')
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue