Guest User

Untitled

a guest
Jul 28th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.25 KB | None | 0 0
  1. require File.dirname(__FILE__) + '/../test_helper'
  2.  
  3. class ParentProfilesControllerTest < ActionController::TestCase
  4. fast_context "parent_profiles" do
  5. setup do
  6. Notification.delete_all
  7. login_as_parent
  8. Factory(:lesson)
  9. @user.stubs(:update).returns(@user)
  10. @parent.children.first.courses = Course.all
  11. end
  12.  
  13. fast_context "on GET show" do
  14. setup {
  15. get :show, :child_id => @parent.children.first.id
  16. }
  17. should_render_template :show
  18. should_respond_with :success
  19. end
  20.  
  21. fast_context "on GET show the edit partial for parent child" do
  22. setup do
  23. get :show
  24. end
  25. should_render_template :show
  26. should_respond_with :success
  27. end
  28. fast_context "on GET index with params" do
  29. setup { get :show, :child_id => @parent.children.first }
  30. should_respond_with :success
  31. end
  32.  
  33. fast_context "on PUT to :update with valid data" do
  34. User.stubs(:update).returns(@parent)
  35. setup { put :update, :parent_profile => Factory.attributes_for(:parent_profile, :country => "India", :user_id => @parent.user_id, :city =>"Kolkata", :about_me => "abcdef ghijkl") }
  36. should_change("Parent About me") { @parent.about_me }
  37. should_set_the_flash_to "Profile updated."
  38. end
  39.  
  40. fast_context "on PUT to :update with valid data during ajax call" do
  41. User.stubs(:update).returns(@parent)
  42. setup { xhr :put, :update, :parent_profile => Factory.attributes_for(:parent_profile, :country => "India", :user_id => @parent.user_id, :city =>"Kolkata", :about_me => "abcdef ghijkl") }
  43. should_change("Parent About me") { @parent.about_me }
  44. should_set_the_flash_to "Profile updated."
  45. end
  46.  
  47. fast_context "on PUT to :update with invalid data" do
  48. setup { xhr :put, :update, :id => @parent, :profile => Factory.attributes_for(:parent_profile, :id => @parent.id,:screen_name => nil) }
  49. should_not_change("Parent reload screen_name") { @parent.reload.screen_name }
  50. end
  51.  
  52. fast_context "on GET to :flip_child_info" do
  53. setup {xhr :get, :flip_child_info, :child_id => @parent.children.first.id}
  54. should_respond_with_content_type "text/javascript"
  55. end
  56.  
  57. fast_context "on PUT do" do
  58. fast_context "on PUT to :update_child_info with invalid data" do
  59. setup do
  60. User.any_instance.expects(:update).returns(nil)
  61. StudentProfile.any_instance.expects(:user).returns(@student_user)
  62. xhr :put, :update_child_info, :child_id => @parent.children.first.id
  63. @profile.reload
  64. end
  65. should_not_change("Profile screen name") { @profile.screen_name }
  66. should_respond_with :success
  67. end
  68.  
  69. fast_context "on PUT to :update_child_info with valid data" do
  70. setup do
  71. User.any_instance.expects(:update).returns(@student_user)
  72. StudentProfile.any_instance.expects(:user).returns(@student_user)
  73. xhr :put, :update_child_info, :profile => Factory.attributes_for(:student_profile, :first_name => "Peter", :last_name => "Parker", :grade => "7", :user_id => @student_user.id,:screen_name => "raghunath"), :child_id =>@parent.children.first.id
  74. @profile.reload
  75. end
  76. should_change("Profile screen name") { @profile.screen_name }
  77. should_respond_with :success
  78. end
  79. end
  80.  
  81. fast_context "on PUT to :cancel_update_child_info" do
  82. setup { xhr :get, :cancel_update_child_info }
  83. should_respond_with :success
  84. end
  85. context "Login as" do
  86.  
  87. fast_context " Parent can view the courses for their children" do
  88. setup do
  89. xhr :put, :subject_list, :child_id => @parent.children.first.id
  90. end
  91. should "have children" do
  92. children = assigns(:children)
  93. assert_not_nil children
  94. end
  95. should_respond_with :success
  96. end
  97.  
  98. fast_context "Parent select selecting courses" do
  99. setup do
  100. xhr :put, :update_courses, :profile => {:course_ids => Course.all.map {|course| [course.id] }.flatten!} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
  101. end
  102. should "change the assigned courses" do
  103. assert_equal assigns(:profile).course_ids.size,Course.all.size
  104. end
  105. should_respond_with :success
  106. end
  107.  
  108. fast_context "Parent select selecting courses with profile cources" do
  109. setup do
  110. xhr :put, :update_courses, :profile_id => @parent.id, :child_id => @parent.children.first.id
  111. end
  112. should "not assign any courses" do
  113. assert_not_equal assigns(:profile).course_ids.size,Course.all.size
  114. end
  115. should_respond_with :success
  116. end
  117.  
  118. fast_context "Parent can't able to update the child profile without grade and region" do
  119. setup do
  120. get :child_grade_region, :profile => {:grade => "", :region_id => ""} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
  121. end
  122. should "not change the value of grade and region" do
  123. assert_equal @parent.children.first.grade,assigns(:child).grade
  124. end
  125. should_respond_with :success
  126. end
  127.  
  128. fast_context "Parent select selecting child grade region" do
  129. setup do
  130. get :child_grade_region, :profile => {:grade => 6, :region_id => 1} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
  131. end
  132. should "not change the value of grade" do
  133. assert_equal 6,assigns(:child).grade
  134. end
  135. should_respond_with :success
  136. end
  137.  
  138. fast_context "Parent select selecting child grade region with course" do
  139. setup do
  140. @region = Region.create(:title => "Alberta", :description =>"Testregion")
  141. @course = @parent.children.first.courses.first
  142. @course.grade = 6
  143. @course.region_id = @region.id
  144. @course.save
  145. get :child_grade_region, :profile => {:grade => 6, :region_id => @region.id} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
  146. end
  147. should_respond_with :success
  148. end
  149.  
  150. fast_context " GET: check_child_email with valid email " do
  151. setup do
  152. @new_child = User.new(:id => -2, :email=>"child@email.com")
  153. User.stubs(:check_user).returns(@new_child)
  154. @request.env["HTTPS"] = "on"
  155. xhr :get, :check_child_email, :user => {:email => @new_child.email}
  156. end
  157. should "respond with rjs" do
  158. assert_equal 'text/javascript', @response.content_type
  159. end
  160. should_respond_with :success
  161. end
  162.  
  163. fast_context " GET: check_child_email with invalid email" do
  164. setup do
  165. User.stubs(:check_user).returns(nil)
  166. @request.env["HTTPS"] = "on"
  167. xhr :get, :check_child_email, :user => {:email => "test@castlerock.com"}
  168. end
  169. should "respond with rjs" do
  170. assert_equal 'text/javascript', @response.content_type
  171. end
  172. should_respond_with :success
  173. end
  174.  
  175. fast_context "parent with valid child email" do
  176. setup do
  177. @user.id = @parent.user_id
  178. User.stubs(:check_user).returns(@user)
  179. @notification = Notification.create(:from_email=>APP_CONFIG['support']['mail'], :to_email => @user.email, :request_type =>Notification::Type::CHILD_REQUEST, :status => "pending", :profile_id => @profile.id)
  180. end
  181. fast_context "and notification pending" do
  182. setup do
  183. @request.env["HTTPS"] = "on"
  184. xhr :get, :check_child_email, :user => {:email => @user.email}
  185. end
  186. should "respond with rjs" do
  187. assert_equal 'text/javascript', @response.content_type
  188. end
  189. should_respond_with :success
  190. end
  191.  
  192. fast_context "and notification approved" do
  193. setup do
  194. @notification.approve!
  195. @request.env["HTTPS"] = "on"
  196. xhr :get, :check_child_email, :user => {:email => @user.email}
  197. end
  198. should "respond with rjs" do
  199. assert_equal 'text/javascript', @response.content_type
  200. end
  201. should_respond_with :success
  202. end
  203.  
  204. fast_context "and notification rejected" do
  205. setup do
  206. @notification.reject!
  207. @request.env["HTTPS"] = "on"
  208. xhr :get, :check_child_email, :user => {:email => @user.email}
  209. end
  210. should_respond_with :success
  211. should "respond with rjs" do
  212. assert_equal 'text/javascript', @response.content_type
  213. end
  214. end
  215. end
  216.  
  217. fast_context " POST: register child with valid attributes(invite_child) " do
  218. setup do
  219. User.stubs(:register).returns(@user)
  220. @user.id = -1
  221. profile = Factory(:student_profile, :user_id =>@user.id)
  222. Notification.create(:from_email=>APP_CONFIG['support']['mail'], :to_email => @user.email, :request_type =>Notification::Type::CHILD_REQUEST, :status => "pending", :profile_id => profile.id)
  223. @request.env["HTTPS"] = "on"
  224. xhr :post, :invite_child, :user => {:screen_name => "sample123", :password => "sample123", :password_confirmation => "sample123", :email => "test@gmail.com"}
  225. end
  226. should "respond with rjs" do
  227. assert_equal 'text/javascript', @response.content_type
  228. end
  229. should_respond_with :success
  230. end
  231.  
  232. fast_context " POST: not register child with invalid attributes(invite_child) " do
  233. setup do
  234. @user.errors.add_to_base("Email can't be blank")
  235. User.stubs(:register).returns(@user)
  236. @request.env["HTTPS"] = "on"
  237. xhr :post, :invite_child, :user => {:screen_name => "sample123", :password => "sample123", :password_confirmation => "sample123", :email => ""}
  238. end
  239. should "respond with rjs" do
  240. assert_equal 'text/javascript', @response.content_type
  241. end
  242. should_respond_with :success
  243. end
  244.  
  245. fast_context "POST: create a notification and send mail with valid attributes(add_child_by_email)" do
  246. setup do
  247. User.stubs(:register).returns(@user)
  248. @request.env["HTTPS"] = "on"
  249. xhr :post, :add_child_by_email, :email => @user.email
  250. end
  251. should "respond with rjs" do
  252. notification = assigns(:notification)
  253. assert_equal notification.to_email , @user.email
  254. assert_equal 'text/javascript', @response.content_type
  255. end
  256. should_respond_with :success
  257. end
  258.  
  259. fast_context "POST: not create a notification with invalid attributes(add_child_by_email) " do
  260. setup do
  261. @request.env["HTTPS"] = "on"
  262. xhr :post, :add_child_by_email
  263. end
  264. should "respond with rjs" do
  265. notification = assigns(:notification)
  266. assert_nil notification
  267. assert_equal 'text/javascript', @response.content_type
  268. end
  269. should_respond_with :success
  270. end
  271.  
  272. fast_context "GET : parent" do
  273. setup do
  274. @user = User.mock(:first_name => 'vishnu', :last_name => 'sharma')
  275. StudentProfile.any_instance.stubs(:user).returns(@user)
  276. @student = Factory.build(:user, :id => -1)
  277. @student_profile = Factory(:student_profile, :user_id => @student.id)
  278. User.stubs(:register).returns(@user)
  279. StudentProfile.any_instance.stubs(:full_name).returns(@student_profile.screen_name)
  280. @notification = Notification.create(:from_email => @student.email, :to_email => @user.email, :request_type => Notification::Type::PARENT_REQUEST, :status =>"pending",:profile_id => @student_profile.id )
  281.  
  282. end
  283. fast_context "accept the child (accept_child)" do
  284. setup do
  285. xhr :get, :accept_child, :id => @notification.id
  286. end
  287. should "respond with rjs" do
  288. notification = assigns(:notification)
  289. assert notification.approved?
  290. assert_equal 'text/javascript', @response.content_type
  291. end
  292. should_respond_with :success
  293. end
  294.  
  295. fast_context "reject the child (reject_child)" do
  296. setup do
  297. xhr :get, :reject_child, :id => @notification.id
  298. end
  299. should "respond with rjs" do
  300. notification = assigns(:notification)
  301. assert notification.rejected?
  302. assert_equal 'text/javascript', @response.content_type
  303. end
  304. should_respond_with :success
  305. end
  306. end
  307. end
  308. end
  309.  
  310. fast_context "student_profile" do
  311. setup do
  312. login_as_student
  313. end
  314. fast_context "on GET show" do
  315. setup { get :show }
  316. should_respond_with_content_type :html
  317. should_respond_with :unauthorized
  318. should_not_set_the_flash
  319. end
  320. end
  321.  
  322. fast_context "parent profile without child" do
  323. setup do
  324. login_as_parent_without_child
  325. end
  326.  
  327. fast_context "on GET show" do
  328. setup { get :show}
  329. should_respond_with :success
  330. #should_redirect_to('new child path') {"#{configatron.account_url}/children/new"}
  331. end
  332. end
  333.  
  334.  
  335. end
Add Comment
Please, Sign In to add comment