From 8b7e6675b6de755ccdf16eba5aa662753346c490 Mon Sep 17 00:00:00 2001 From: Richard Moss Date: Thu, 7 Apr 2016 15:15:33 +0100 Subject: [PATCH] adds failing test for #create for student profiles controller --- app/controllers/student_profiles_controller.rb | 2 +- spec/controllers/student_profiles_controller_spec.rb | 9 +++++++++ spec/rails_helper.rb | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/student_profiles_controller.rb b/app/controllers/student_profiles_controller.rb index a0afccb..d98e2ee 100644 --- a/app/controllers/student_profiles_controller.rb +++ b/app/controllers/student_profiles_controller.rb @@ -20,7 +20,7 @@ def save_profile_and_redirect @profile = StudentProfile.create(profile_params) current_student.student_profile = @profile if @profile.save - redirect_to student_profile_path(:id => current_student.id) + redirect_to student_profile_path(id: current_student.id) else render 'new' end diff --git a/spec/controllers/student_profiles_controller_spec.rb b/spec/controllers/student_profiles_controller_spec.rb index 7ffb510..64f873f 100644 --- a/spec/controllers/student_profiles_controller_spec.rb +++ b/spec/controllers/student_profiles_controller_spec.rb @@ -12,6 +12,15 @@ expect(response).to render_template("new") end end + + describe 'POST create' do + it 'creates and saves a new profile' do + current_student = create(:student) + expect{ + post :create, student_profile: FactoryGirl.attributes_for(:student_profile) + }.to change(StudentProfile,:count).by(1) + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 01f8f98..b6c6740 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -33,6 +33,8 @@ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" config.include FactoryGirl::Syntax::Methods + config.include Devise::TestHelpers, :type => :controller + config.use_transactional_fixtures = false