Guest User

Untitled

a guest
Feb 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. module Arts
  2. include ActionView::Helpers::PrototypeHelper
  3. include ActionView::Helpers::ScriptaculousHelper
  4. include ActionView::Helpers::JavaScriptHelper
  5.  
  6. include ActionView::Helpers::UrlHelper
  7. include ActionView::Helpers::TagHelper
  8.  
  9. def assert_rjs(action, *args, &block)
  10. case action.to_sym
  11. when :insert_html
  12. return assert_rjs_insert_html(*args)
  13. when :replace_html
  14. return assert_rjs_replace_html(*args)
  15. when :replace
  16. return assert_rjs_replace(*args)
  17. else
  18. assert lined_response.include?(create_generator.send(action, *args, &block)),
  19. generic_error(action, args)
  20. end
  21. end
  22.  
  23. def assert_no_rjs(action, *args, &block)
  24. assert_raises(Test::Unit::AssertionFailedError) { assert_rjs(action, *args, &block) }
  25. end
  26.  
  27. def assert_rjs_insert_html(*args)
  28. position = args.shift
  29. item_id = args.shift
  30. content = create_generator.send(:arguments_for_call, args)
  31.  
  32. unless content.blank?
  33. assert lined_response.include?("new Insertion.#{position.to_s.camelize}(\"#{item_id}\", #{content});"),
  34. "No insert_html call found for \n" +
  35. " position: '#{position}' id: '#{item_id}' \ncontent: \n" +
  36. "#{content}\n" +
  37. "in response:\n#{lined_response}"
  38. else
  39. assert_match Regexp.new("new Insertion\.#{position.to_s.camelize}(.*#{item_id}.*,.*?);"),
  40. @response.body
  41. end
  42. end
  43.  
  44. def assert_rjs_replace_html(*args)
  45. div = args.shift
  46. content = create_generator.send(:arguments_for_call, args)
  47.  
  48. unless content.blank?
  49. assert lined_response.include?("Element.update(\"#{div}\", #{content});"),
  50. "No replace_html call found on div: '#{div}' and content: \n#{content}\n" +
  51. "in response:\n#{lined_response}"
  52. else
  53. assert_match Regexp.new("Element.update(.*#{div}.*,.*?);"), @response.body
  54. end
  55. end
  56.  
  57. def assert_rjs_replace(*args)
  58. div = args.shift
  59. content = create_generator.send(:arguments_for_call, args)
  60.  
  61. unless content.blank?
  62. assert lined_response.include?("Element.replace(\"#{div}\", #{content});"),
  63. "No replace call found on div: '#{div}' and content: \n#{content}\n" +
  64. "in response:\n#{lined_response}"
  65. else
  66. assert_match Regexp.new("Element.replace(.*#{div}.*,.*?);"), @response.body
  67. end
  68. end
  69.  
  70. protected
  71.  
  72. def lined_response
  73. @response.body.split("\n")
  74. end
  75.  
  76. def create_generator
  77. block = Proc.new { |*args| yield *args if block_given? }
  78. JavaScriptGenerator.new self, &block
  79. end
  80.  
  81. def generic_error(action, args)
  82. "#{action} with args [#{args.join(" ")}] does not show up in response:\n#{lined_response}"
  83. end
  84. end
Add Comment
Please, Sign In to add comment