migration_ror_42_to50_store_test.rb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Rails 5.0 has changed to only store and read ActiveSupport::HashWithIndifferentAccess from stores
  2. # we extended lib/core_ext/active_record/store/indifferent_coder.rb to read also ActionController::Parameters
  3. # and convert them to ActiveSupport::HashWithIndifferentAccess for migration in db/migrate/20170910000001_fixed_store_upgrade_45.rb.
  4. require 'test_helper'
  5. class MigrationRor42To50StoreTest < ActiveSupport::TestCase
  6. test 'store with ActionController::Parameters object - get ActiveSupport::HashWithIndifferentAccess' do
  7. user = User.last
  8. last_contact = '2017-09-01 10:10:00'
  9. state = "--- !ruby/hash-with-ivars:ActionController::Parameters
  10. elements:
  11. ticket: !ruby/hash-with-ivars:ActionController::Parameters
  12. elements: {}
  13. ivars:
  14. :@permitted: false
  15. article: !ruby/hash-with-ivars:ActionController::Parameters
  16. elements: {}
  17. ivars:
  18. :@permitted: false
  19. ivars:
  20. :@permitted: false
  21. "
  22. params = "--- !ruby/hash-with-ivars:ActionController::Parameters
  23. elements:
  24. ticket_id: 1234
  25. shown: true
  26. ivars:
  27. :@permitted: false
  28. "
  29. preferences = "--- !ruby/hash-with-ivars:ActionController::Parameters
  30. elements:
  31. tasks: &1
  32. - !ruby/hash-with-ivars:ActionController::Parameters
  33. elements:
  34. id: 99282
  35. user_id: 85370
  36. last_contact: 2017-09-08 11:28:00.289663000 Z
  37. changed: true
  38. ivars:
  39. :@permitted: false
  40. ivars:
  41. :@permitted: false
  42. :@converted_arrays: !ruby/object:Set
  43. hash:
  44. *1: true
  45. "
  46. sql = "INSERT INTO taskbars (`user_id`, `client_id`, `key`, `callback`, `state`, `params`, `prio`, `notify`, `active`, `preferences`, `last_contact`, `updated_at`, `created_at`) VALUES (#{user.id}, '123', 'Ticket-123', 'TicketZoom', '#{state}', '#{params}', 1, FALSE, TRUE, '#{preferences}', '#{last_contact}', '#{last_contact}', '#{last_contact}')"
  47. if ActiveRecord::Base.connection_config[:adapter] != 'mysql2'
  48. sql.delete!('`')
  49. end
  50. records_array = ActiveRecord::Base.connection.execute(sql)
  51. taskbar = Taskbar.last
  52. assert(taskbar)
  53. assert(taskbar.params)
  54. assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.params.class)
  55. assert_equal(1234, taskbar.params[:ticket_id])
  56. assert(taskbar.state)
  57. assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.state.class)
  58. assert(taskbar.state[:ticket].blank?)
  59. assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:ticket].class)
  60. assert(taskbar.state[:article].blank?)
  61. assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:article].class)
  62. taskbar.save!
  63. taskbar.reload
  64. assert(taskbar)
  65. assert(taskbar.params)
  66. assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.params.class)
  67. assert_equal(1234, taskbar.params[:ticket_id])
  68. assert(taskbar.state)
  69. assert_equal(ActiveSupport::HashWithIndifferentAccess, taskbar.state.class)
  70. assert(taskbar.state[:ticket].blank?)
  71. assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:ticket].class)
  72. assert(taskbar.state[:article].blank?)
  73. assert(ActiveSupport::HashWithIndifferentAccess, taskbar.state[:article].class)
  74. end
  75. end