tag_test.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TagTest < ActiveSupport::TestCase
  4. test 'tags' do
  5. tests = [
  6. # test 1
  7. {
  8. :tag_add => {
  9. :item => 'tag1',
  10. :object => 'Object1',
  11. :o_id => 123,
  12. :created_by_id => 1
  13. },
  14. :verify => {
  15. :object => 'Object1',
  16. :items => {
  17. 'tag1' => true,
  18. 'tag2' => false,
  19. },
  20. },
  21. },
  22. # test 2
  23. {
  24. :tag_add => {
  25. :item => 'tag2',
  26. :object => 'Object1',
  27. :o_id => 123,
  28. :created_by_id => 1
  29. },
  30. :verify => {
  31. :object => 'Object1',
  32. :items => {
  33. 'tag1' => true,
  34. 'tag2' => true,
  35. },
  36. },
  37. },
  38. # test 2
  39. {
  40. :tag_add => {
  41. :item => 'tagöäüß1',
  42. :object => 'Object2',
  43. :o_id => 123,
  44. :created_by_id => 1
  45. },
  46. :verify => {
  47. :object => 'Object2',
  48. :items => {
  49. 'tagöäüß1' => true,
  50. 'tag2' => false,
  51. },
  52. },
  53. },
  54. # test 4
  55. {
  56. :tag_add => {
  57. :item => 'Tagöäüß2',
  58. :object => 'Object2',
  59. :o_id => 123,
  60. :created_by_id => 1
  61. },
  62. :verify => {
  63. :object => 'Object2',
  64. :items => {
  65. 'tagöäüß1' => true,
  66. 'tagöäüß2' => true,
  67. 'tagöäüß3' => false,
  68. },
  69. },
  70. },
  71. # test 5
  72. {
  73. :tag_remove => {
  74. :item => 'tag1',
  75. :object => 'Object1',
  76. :o_id => 123,
  77. :created_by_id => 1
  78. },
  79. :verify => {
  80. :object => 'Object1',
  81. :items => {
  82. 'tag1' => false,
  83. 'tag2' => true,
  84. },
  85. },
  86. },
  87. ]
  88. tests.each { |test|
  89. tags = nil
  90. if test[:tag_add]
  91. tags = test[:tag_add]
  92. success = Tag.tag_add( tags )
  93. assert( success, "Tag.tag_add successful")
  94. else
  95. tags = test[:tag_remove]
  96. success = Tag.tag_remove( tags )
  97. assert( success, "Tag.tag_remove successful")
  98. end
  99. list = Tag.tag_list( tags )
  100. test[:verify][:items].each {|key, value|
  101. if value == true
  102. assert( list.include?( key ), "Tag verify - should exists but exists #{ key }")
  103. else
  104. assert( !list.include?( key ), "Tag verify - exists but should not #{ key }")
  105. end
  106. }
  107. }
  108. # delete tags
  109. tests.each { |test|
  110. tags = nil
  111. if test[:tag_add]
  112. tags = test[:tag_add]
  113. else
  114. tags = test[:tag_remove]
  115. end
  116. success = Tag.tag_remove( tags )
  117. assert( success, "Tag.tag_remove successful")
  118. list = Tag.tag_list( tags )
  119. assert( !list.include?( tags[:item] ), "Tag entry destroyed")
  120. }
  121. end
  122. end