From 749fe8df5e0570212ba9a1ff0a7cc52b16c3da57 Mon Sep 17 00:00:00 2001 From: Umar Sheikh Date: Tue, 7 Nov 2017 15:01:12 +0500 Subject: [PATCH 1/5] cast 'true' to true and 'false' to false in case of boolean column addition, fixes #1613 --- app/controllers/object_manager_attributes_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb index 33e1ad304..208ee5fda 100644 --- a/app/controllers/object_manager_attributes_controller.rb +++ b/app/controllers/object_manager_attributes_controller.rb @@ -108,6 +108,11 @@ class ObjectManagerAttributesController < ApplicationController params[:data_option][:options][true] = params[:data_option][:options][:true] params[:data_option][:options].delete(:true) end + if params[:data_option][:default] == 'true' + params[:data_option][:default] = true + elsif params[:data_option][:default] == 'false' + params[:data_option][:default] = false + end end end if params[:data_option] && !params[:data_option].key?(:default) From 35d8a05e8a9f159cf98f172a47c8e7b2376efb1e Mon Sep 17 00:00:00 2001 From: Umar Sheikh Date: Tue, 7 Nov 2017 15:40:58 +0500 Subject: [PATCH 2/5] whitespace --- app/controllers/object_manager_attributes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/object_manager_attributes_controller.rb b/app/controllers/object_manager_attributes_controller.rb index 208ee5fda..312b7dfc1 100644 --- a/app/controllers/object_manager_attributes_controller.rb +++ b/app/controllers/object_manager_attributes_controller.rb @@ -108,7 +108,7 @@ class ObjectManagerAttributesController < ApplicationController params[:data_option][:options][true] = params[:data_option][:options][:true] params[:data_option][:options].delete(:true) end - if params[:data_option][:default] == 'true' + if params[:data_option][:default] == 'true' params[:data_option][:default] = true elsif params[:data_option][:default] == 'false' params[:data_option][:default] = false From c1f2fb77fe87de901f5e6f835b1a1aff6dd41109 Mon Sep 17 00:00:00 2001 From: Umar Sheikh Date: Thu, 9 Nov 2017 15:53:34 +0500 Subject: [PATCH 3/5] tests for #1613, ensure that string is converted to boolean --- ...ject_manager_attributes_controller_test.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/controllers/object_manager_attributes_controller_test.rb diff --git a/test/controllers/object_manager_attributes_controller_test.rb b/test/controllers/object_manager_attributes_controller_test.rb new file mode 100644 index 000000000..69073eeeb --- /dev/null +++ b/test/controllers/object_manager_attributes_controller_test.rb @@ -0,0 +1,37 @@ +# encoding: utf-8 +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 'converts string to boolean for default option' 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 + obj = ObjectManager::Attribute.find result['id'] + assert_equal true, obj.data_option['default'] + assert_equal 'boolean', obj.data_type + obj.destroy + end +end From 509450fd304b24e22ae85243deb6caf8920443d3 Mon Sep 17 00:00:00 2001 From: Umar Sheikh Date: Thu, 9 Nov 2017 17:06:13 +0500 Subject: [PATCH 4/5] stick to test naming convention and better variable name --- .../object_manager_attributes_controller_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/controllers/object_manager_attributes_controller_test.rb b/test/controllers/object_manager_attributes_controller_test.rb index 69073eeeb..ac810c5af 100644 --- a/test/controllers/object_manager_attributes_controller_test.rb +++ b/test/controllers/object_manager_attributes_controller_test.rb @@ -23,15 +23,15 @@ class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest groups: groups, ) end - test 'converts string to boolean for default option' do + 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 - obj = ObjectManager::Attribute.find result['id'] - assert_equal true, obj.data_option['default'] - assert_equal 'boolean', obj.data_type - obj.destroy + object = ObjectManager::Attribute.find result['id'] + assert_equal true, object.data_option['default'] + assert_equal 'boolean', object.data_type + object.destroy end end From c45e826551f2ab87974dcd311a54af21221a28e9 Mon Sep 17 00:00:00 2001 From: Umar Sheikh Date: Sun, 4 Feb 2018 20:54:24 +0500 Subject: [PATCH 5/5] rubocop fix --- test/controllers/object_manager_attributes_controller_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/controllers/object_manager_attributes_controller_test.rb b/test/controllers/object_manager_attributes_controller_test.rb index ac810c5af..7888b8b98 100644 --- a/test/controllers/object_manager_attributes_controller_test.rb +++ b/test/controllers/object_manager_attributes_controller_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 require 'test_helper' class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest