calendar_test.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class CalendarTest < ActiveSupport::TestCase
  4. test 'default test' do
  5. Calendar.delete_all
  6. calendar1 = Calendar.create_or_update(
  7. name: 'US 1',
  8. timezone: 'America/Los_Angeles',
  9. business_hours: {
  10. mon: { '09:00' => '17:00' },
  11. tue: { '09:00' => '17:00' },
  12. wed: { '09:00' => '17:00' },
  13. thu: { '09:00' => '17:00' },
  14. fri: { '09:00' => '17:00' }
  15. },
  16. default: true,
  17. ical_url: nil,
  18. updated_by_id: 1,
  19. created_by_id: 1,
  20. )
  21. travel 1.second
  22. calendar2 = Calendar.create_or_update(
  23. name: 'US 2',
  24. timezone: 'America/Los_Angeles',
  25. business_hours: {
  26. mon: { '09:00' => '17:00' },
  27. tue: { '09:00' => '17:00' },
  28. wed: { '09:00' => '17:00' },
  29. thu: { '09:00' => '17:00' },
  30. fri: { '09:00' => '17:00' }
  31. },
  32. default: false,
  33. ical_url: nil,
  34. updated_by_id: 1,
  35. created_by_id: 1,
  36. )
  37. calendar3 = Calendar.create_or_update(
  38. name: 'US 3',
  39. timezone: 'America/Los_Angeles',
  40. business_hours: {
  41. mon: { '09:00' => '17:00' },
  42. tue: { '09:00' => '17:00' },
  43. wed: { '09:00' => '17:00' },
  44. thu: { '09:00' => '17:00' },
  45. fri: { '09:00' => '17:00' }
  46. },
  47. default: true,
  48. ical_url: nil,
  49. updated_by_id: 1,
  50. created_by_id: 1,
  51. )
  52. calendar1 = Calendar.find_by(name: 'US 1')
  53. calendar2 = Calendar.find_by(name: 'US 2')
  54. calendar3 = Calendar.find_by(name: 'US 3')
  55. assert_equal(false, calendar1.default)
  56. assert_equal(false, calendar2.default)
  57. assert_equal(true, calendar3.default)
  58. calendar2.default = true
  59. calendar2.save
  60. calendar1 = Calendar.find_by(name: 'US 1')
  61. calendar2 = Calendar.find_by(name: 'US 2')
  62. calendar3 = Calendar.find_by(name: 'US 3')
  63. assert_equal(false, calendar1.default)
  64. assert_equal(true, calendar2.default)
  65. assert_equal(false, calendar3.default)
  66. calendar2.default = false
  67. calendar2.save
  68. calendar1 = Calendar.find_by(name: 'US 1')
  69. calendar2 = Calendar.find_by(name: 'US 2')
  70. calendar3 = Calendar.find_by(name: 'US 3')
  71. assert_equal(true, calendar1.default)
  72. assert_equal(false, calendar2.default)
  73. assert_equal(false, calendar3.default)
  74. calendar1.destroy
  75. calendar2 = Calendar.find_by(name: 'US 2')
  76. calendar3 = Calendar.find_by(name: 'US 3')
  77. assert_equal(true, calendar2.default)
  78. assert_equal(false, calendar3.default)
  79. travel_back
  80. end
  81. end