PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/plugins/responds_to_parent/test/assert_select_parent_test.rb

https://bitbucket.org/systech3/boxyroom
Ruby | 318 lines | 287 code | 31 blank | 0 comment | 0 complexity | ac9d1c10f5ddd089c626610c76167b72 MD5 | raw file
Possible License(s): JSON, MIT
  1. require File.dirname(__FILE__) + '/../../../../config/environment'
  2. require 'test/unit'
  3. require 'test_help'
  4. class AssertSelectParentTest < Test::Unit::TestCase
  5. class AssertSelectParentController < ActionController::Base
  6. def response_with=(content)
  7. @content = content
  8. end
  9. def response_with(&block)
  10. @update = block
  11. end
  12. def rjs
  13. responds_to_parent do
  14. render :update do |page|
  15. @update.call page
  16. end
  17. end
  18. @update = nil
  19. end
  20. def text
  21. responds_to_parent do
  22. render :text => @content, :layout => false
  23. end
  24. @content = nil
  25. end
  26. def not_respond_to_parent
  27. render :nothing => true
  28. end
  29. def rescue_action(e)
  30. raise e
  31. end
  32. end
  33. def setup
  34. @controller = AssertSelectParentController.new
  35. @request = ActionController::TestRequest.new
  36. @response = ActionController::TestResponse.new
  37. end
  38. def test_basic
  39. render_rjs do |page|
  40. page.replace "test", "<div id=\"1\">foo</div>"
  41. end
  42. found = false
  43. assert_select_parent do
  44. assert_select_rjs do
  45. assert_select "#1"
  46. found = true
  47. end
  48. end
  49. assert found
  50. end
  51. def test_bubble_up_failure
  52. render_rjs do |page|
  53. page.replace "test", "<div id=\"1\">foo</div>"
  54. end
  55. assert_raise(Test::Unit::AssertionFailedError) do
  56. assert_select_parent do
  57. assert_select_rjs do
  58. assert_select "#nonexistent"
  59. end
  60. end
  61. end
  62. end
  63. def test_fail_if_no_content_for_parent
  64. get :not_respond_to_parent
  65. assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
  66. end
  67. def test_quotes
  68. do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
  69. end
  70. def test_new_line
  71. do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
  72. end
  73. protected
  74. def render_rjs(&block)
  75. @controller.response_with &block
  76. get :rjs
  77. end
  78. def render_text(text)
  79. @controller.response_with = text
  80. get :text
  81. end
  82. def do_test_with_text(text)
  83. render_text text
  84. assert_select_parent do |text_for_parent|
  85. assert_equal text, text_for_parent
  86. end
  87. end
  88. end
  89. require File.dirname(__FILE__) + '/../../../../config/environment'
  90. require 'test/unit'
  91. require 'test_help'
  92. class AssertSelectParentTest < Test::Unit::TestCase
  93. class AssertSelectParentController < ActionController::Base
  94. def response_with=(content)
  95. @content = content
  96. end
  97. def response_with(&block)
  98. @update = block
  99. end
  100. def rjs
  101. responds_to_parent do
  102. render :update do |page|
  103. @update.call page
  104. end
  105. end
  106. @update = nil
  107. end
  108. def text
  109. responds_to_parent do
  110. render :text => @content, :layout => false
  111. end
  112. @content = nil
  113. end
  114. def not_respond_to_parent
  115. render :nothing => true
  116. end
  117. def rescue_action(e)
  118. raise e
  119. end
  120. end
  121. def setup
  122. @controller = AssertSelectParentController.new
  123. @request = ActionController::TestRequest.new
  124. @response = ActionController::TestResponse.new
  125. end
  126. def test_basic
  127. render_rjs do |page|
  128. page.replace "test", "<div id=\"1\">foo</div>"
  129. end
  130. found = false
  131. assert_select_parent do
  132. assert_select_rjs do
  133. assert_select "#1"
  134. found = true
  135. end
  136. end
  137. assert found
  138. end
  139. def test_bubble_up_failure
  140. render_rjs do |page|
  141. page.replace "test", "<div id=\"1\">foo</div>"
  142. end
  143. assert_raise(Test::Unit::AssertionFailedError) do
  144. assert_select_parent do
  145. assert_select_rjs do
  146. assert_select "#nonexistent"
  147. end
  148. end
  149. end
  150. end
  151. def test_fail_if_no_content_for_parent
  152. get :not_respond_to_parent
  153. assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
  154. end
  155. def test_quotes
  156. do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
  157. end
  158. def test_new_line
  159. do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
  160. end
  161. protected
  162. def render_rjs(&block)
  163. @controller.response_with &block
  164. get :rjs
  165. end
  166. def render_text(text)
  167. @controller.response_with = text
  168. get :text
  169. end
  170. def do_test_with_text(text)
  171. render_text text
  172. assert_select_parent do |text_for_parent|
  173. assert_equal text, text_for_parent
  174. end
  175. end
  176. end
  177. require File.dirname(__FILE__) + '/../../../../config/environment'
  178. require 'test/unit'
  179. require 'test_help'
  180. class AssertSelectParentTest < Test::Unit::TestCase
  181. class AssertSelectParentController < ActionController::Base
  182. def response_with=(content)
  183. @content = content
  184. end
  185. def response_with(&block)
  186. @update = block
  187. end
  188. def rjs
  189. responds_to_parent do
  190. render :update do |page|
  191. @update.call page
  192. end
  193. end
  194. @update = nil
  195. end
  196. def text
  197. responds_to_parent do
  198. render :text => @content, :layout => false
  199. end
  200. @content = nil
  201. end
  202. def not_respond_to_parent
  203. render :nothing => true
  204. end
  205. def rescue_action(e)
  206. raise e
  207. end
  208. end
  209. def setup
  210. @controller = AssertSelectParentController.new
  211. @request = ActionController::TestRequest.new
  212. @response = ActionController::TestResponse.new
  213. end
  214. def test_basic
  215. render_rjs do |page|
  216. page.replace "test", "<div id=\"1\">foo</div>"
  217. end
  218. found = false
  219. assert_select_parent do
  220. assert_select_rjs do
  221. assert_select "#1"
  222. found = true
  223. end
  224. end
  225. assert found
  226. end
  227. def test_bubble_up_failure
  228. render_rjs do |page|
  229. page.replace "test", "<div id=\"1\">foo</div>"
  230. end
  231. assert_raise(Test::Unit::AssertionFailedError) do
  232. assert_select_parent do
  233. assert_select_rjs do
  234. assert_select "#nonexistent"
  235. end
  236. end
  237. end
  238. end
  239. def test_fail_if_no_content_for_parent
  240. get :not_respond_to_parent
  241. assert_raise(Test::Unit::AssertionFailedError) { assert_select_parent }
  242. end
  243. def test_quotes
  244. do_test_with_text %(single' double" escaped\\' escaped\\" doubleescaped\\\\\\' doubleescaped\\\\\\")
  245. end
  246. def test_new_line
  247. do_test_with_text "line1\nline2\\nline2\\\nline3\\\\nline3\\\\\nline4\\\\\\nline4"
  248. end
  249. protected
  250. def render_rjs(&block)
  251. @controller.response_with &block
  252. get :rjs
  253. end
  254. def render_text(text)
  255. @controller.response_with = text
  256. get :text
  257. end
  258. def do_test_with_text(text)
  259. render_text text
  260. assert_select_parent do |text_for_parent|
  261. assert_equal text, text_for_parent
  262. end
  263. end
  264. end