Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.dirname(__FILE__) + '/../test_helper'
- class ParentProfilesControllerTest < ActionController::TestCase
- fast_context "parent_profiles" do
- setup do
- Notification.delete_all
- login_as_parent
- Factory(:lesson)
- @user.stubs(:update).returns(@user)
- @parent.children.first.courses = Course.all
- end
- fast_context "on GET show" do
- setup {
- get :show, :child_id => @parent.children.first.id
- }
- should_render_template :show
- should_respond_with :success
- end
- fast_context "on GET show the edit partial for parent child" do
- setup do
- get :show
- end
- should_render_template :show
- should_respond_with :success
- end
- fast_context "on GET index with params" do
- setup { get :show, :child_id => @parent.children.first }
- should_respond_with :success
- end
- fast_context "on PUT to :update with valid data" do
- User.stubs(:update).returns(@parent)
- setup { put :update, :parent_profile => Factory.attributes_for(:parent_profile, :country => "India", :user_id => @parent.user_id, :city =>"Kolkata", :about_me => "abcdef ghijkl") }
- should_change("Parent About me") { @parent.about_me }
- should_set_the_flash_to "Profile updated."
- end
- fast_context "on PUT to :update with valid data during ajax call" do
- User.stubs(:update).returns(@parent)
- setup { xhr :put, :update, :parent_profile => Factory.attributes_for(:parent_profile, :country => "India", :user_id => @parent.user_id, :city =>"Kolkata", :about_me => "abcdef ghijkl") }
- should_change("Parent About me") { @parent.about_me }
- should_set_the_flash_to "Profile updated."
- end
- fast_context "on PUT to :update with invalid data" do
- setup { xhr :put, :update, :id => @parent, :profile => Factory.attributes_for(:parent_profile, :id => @parent.id,:screen_name => nil) }
- should_not_change("Parent reload screen_name") { @parent.reload.screen_name }
- end
- fast_context "on GET to :flip_child_info" do
- setup {xhr :get, :flip_child_info, :child_id => @parent.children.first.id}
- should_respond_with_content_type "text/javascript"
- end
- fast_context "on PUT do" do
- fast_context "on PUT to :update_child_info with invalid data" do
- setup do
- User.any_instance.expects(:update).returns(nil)
- StudentProfile.any_instance.expects(:user).returns(@student_user)
- xhr :put, :update_child_info, :child_id => @parent.children.first.id
- @profile.reload
- end
- should_not_change("Profile screen name") { @profile.screen_name }
- should_respond_with :success
- end
- fast_context "on PUT to :update_child_info with valid data" do
- setup do
- User.any_instance.expects(:update).returns(@student_user)
- StudentProfile.any_instance.expects(:user).returns(@student_user)
- 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
- @profile.reload
- end
- should_change("Profile screen name") { @profile.screen_name }
- should_respond_with :success
- end
- end
- fast_context "on PUT to :cancel_update_child_info" do
- setup { xhr :get, :cancel_update_child_info }
- should_respond_with :success
- end
- context "Login as" do
- fast_context " Parent can view the courses for their children" do
- setup do
- xhr :put, :subject_list, :child_id => @parent.children.first.id
- end
- should "have children" do
- children = assigns(:children)
- assert_not_nil children
- end
- should_respond_with :success
- end
- fast_context "Parent select selecting courses" do
- setup do
- xhr :put, :update_courses, :profile => {:course_ids => Course.all.map {|course| [course.id] }.flatten!} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
- end
- should "change the assigned courses" do
- assert_equal assigns(:profile).course_ids.size,Course.all.size
- end
- should_respond_with :success
- end
- fast_context "Parent select selecting courses with profile cources" do
- setup do
- xhr :put, :update_courses, :profile_id => @parent.id, :child_id => @parent.children.first.id
- end
- should "not assign any courses" do
- assert_not_equal assigns(:profile).course_ids.size,Course.all.size
- end
- should_respond_with :success
- end
- fast_context "Parent can't able to update the child profile without grade and region" do
- setup do
- get :child_grade_region, :profile => {:grade => "", :region_id => ""} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
- end
- should "not change the value of grade and region" do
- assert_equal @parent.children.first.grade,assigns(:child).grade
- end
- should_respond_with :success
- end
- fast_context "Parent select selecting child grade region" do
- setup do
- get :child_grade_region, :profile => {:grade => 6, :region_id => 1} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
- end
- should "not change the value of grade" do
- assert_equal 6,assigns(:child).grade
- end
- should_respond_with :success
- end
- fast_context "Parent select selecting child grade region with course" do
- setup do
- @region = Region.create(:title => "Alberta", :description =>"Testregion")
- @course = @parent.children.first.courses.first
- @course.grade = 6
- @course.region_id = @region.id
- @course.save
- get :child_grade_region, :profile => {:grade => 6, :region_id => @region.id} ,:profile_id => @parent.id, :child_id => @parent.children.first.id
- end
- should_respond_with :success
- end
- fast_context " GET: check_child_email with valid email " do
- setup do
- @new_child = User.new(:id => -2, :email=>"child@email.com")
- User.stubs(:check_user).returns(@new_child)
- @request.env["HTTPS"] = "on"
- xhr :get, :check_child_email, :user => {:email => @new_child.email}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context " GET: check_child_email with invalid email" do
- setup do
- User.stubs(:check_user).returns(nil)
- @request.env["HTTPS"] = "on"
- xhr :get, :check_child_email, :user => {:email => "test@castlerock.com"}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "parent with valid child email" do
- setup do
- @user.id = @parent.user_id
- User.stubs(:check_user).returns(@user)
- @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)
- end
- fast_context "and notification pending" do
- setup do
- @request.env["HTTPS"] = "on"
- xhr :get, :check_child_email, :user => {:email => @user.email}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "and notification approved" do
- setup do
- @notification.approve!
- @request.env["HTTPS"] = "on"
- xhr :get, :check_child_email, :user => {:email => @user.email}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "and notification rejected" do
- setup do
- @notification.reject!
- @request.env["HTTPS"] = "on"
- xhr :get, :check_child_email, :user => {:email => @user.email}
- end
- should_respond_with :success
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- end
- end
- fast_context " POST: register child with valid attributes(invite_child) " do
- setup do
- User.stubs(:register).returns(@user)
- @user.id = -1
- profile = Factory(:student_profile, :user_id =>@user.id)
- Notification.create(:from_email=>APP_CONFIG['support']['mail'], :to_email => @user.email, :request_type =>Notification::Type::CHILD_REQUEST, :status => "pending", :profile_id => profile.id)
- @request.env["HTTPS"] = "on"
- xhr :post, :invite_child, :user => {:screen_name => "sample123", :password => "sample123", :password_confirmation => "sample123", :email => "test@gmail.com"}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context " POST: not register child with invalid attributes(invite_child) " do
- setup do
- @user.errors.add_to_base("Email can't be blank")
- User.stubs(:register).returns(@user)
- @request.env["HTTPS"] = "on"
- xhr :post, :invite_child, :user => {:screen_name => "sample123", :password => "sample123", :password_confirmation => "sample123", :email => ""}
- end
- should "respond with rjs" do
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "POST: create a notification and send mail with valid attributes(add_child_by_email)" do
- setup do
- User.stubs(:register).returns(@user)
- @request.env["HTTPS"] = "on"
- xhr :post, :add_child_by_email, :email => @user.email
- end
- should "respond with rjs" do
- notification = assigns(:notification)
- assert_equal notification.to_email , @user.email
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "POST: not create a notification with invalid attributes(add_child_by_email) " do
- setup do
- @request.env["HTTPS"] = "on"
- xhr :post, :add_child_by_email
- end
- should "respond with rjs" do
- notification = assigns(:notification)
- assert_nil notification
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "GET : parent" do
- setup do
- @user = User.mock(:first_name => 'vishnu', :last_name => 'sharma')
- StudentProfile.any_instance.stubs(:user).returns(@user)
- @student = Factory.build(:user, :id => -1)
- @student_profile = Factory(:student_profile, :user_id => @student.id)
- User.stubs(:register).returns(@user)
- StudentProfile.any_instance.stubs(:full_name).returns(@student_profile.screen_name)
- @notification = Notification.create(:from_email => @student.email, :to_email => @user.email, :request_type => Notification::Type::PARENT_REQUEST, :status =>"pending",:profile_id => @student_profile.id )
- end
- fast_context "accept the child (accept_child)" do
- setup do
- xhr :get, :accept_child, :id => @notification.id
- end
- should "respond with rjs" do
- notification = assigns(:notification)
- assert notification.approved?
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- fast_context "reject the child (reject_child)" do
- setup do
- xhr :get, :reject_child, :id => @notification.id
- end
- should "respond with rjs" do
- notification = assigns(:notification)
- assert notification.rejected?
- assert_equal 'text/javascript', @response.content_type
- end
- should_respond_with :success
- end
- end
- end
- end
- fast_context "student_profile" do
- setup do
- login_as_student
- end
- fast_context "on GET show" do
- setup { get :show }
- should_respond_with_content_type :html
- should_respond_with :unauthorized
- should_not_set_the_flash
- end
- end
- fast_context "parent profile without child" do
- setup do
- login_as_parent_without_child
- end
- fast_context "on GET show" do
- setup { get :show}
- should_respond_with :success
- #should_redirect_to('new child path') {"#{configatron.account_url}/children/new"}
- end
- end
- end
Add Comment
Please, Sign In to add comment