Skip to content

Instantly share code, notes, and snippets.

@romulostorel
Last active January 1, 2016 12:39
Show Gist options
  • Save romulostorel/8146377 to your computer and use it in GitHub Desktop.
Save romulostorel/8146377 to your computer and use it in GitHub Desktop.
def create_resource(object)
object.academic_year = current_academic_year
object.school = current_school
object.transaction do
if super
EnrollmentRenewalManager.renew_enrollments(object)
end
end
super
end
require 'spec_helper'
describe EnrollmentRenewalsController do
before do
create_customer
controller.stub(:check_user_context!)
controller.stub(:check_user_setting)
@user = create(:user, :profile => create(:profile), :administrator => true)
sign_in @user
end
describe 'POST create' do
context 'setting academic year, school and call Manager' do
before do
make_dependencies!
end
let :enrollment_renewal do
FactoryGirl.build(:enrollment_renewal, stage: stages(:stage), academic_year: @academic_year_2, approved_stage: @stage_2, school: schools(:school))
end
let :academic_year do
FactoryGirl.build(:temp_academic_year)
end
let :school do
FactoryGirl.build(:school)
end
it 'should set the academic_year' do
enrollment_renewal.should_receive :attributes
controller.stub(:current_academic_year).and_return(academic_year)
post :create, :enrollment_renewal => enrollment_renewal.attributes
expect(assigns(:enrollment_renewal).academic_year).to eq academic_year
end
it 'should set the school' do
enrollment_renewal.should_receive :attributes
controller.stub(:current_school).and_return(school)
post :create, :enrollment_renewal => enrollment_renewal.attributes
expect(assigns(:enrollment_renewal).school).to eq school
end
it 'should call the EnrollmentRenewalManager' do
EnrollmentRenewal.any_instance.should_receive(:transaction).and_yield
EnrollmentRenewal.any_instance.should_receive(:save).and_return true
EnrollmentRenewalManager.should_receive(:renew_enrollments)#.with(controller.object)
post :create, :enrollment_renewal => enrollment_renewal.attributes
end
end
end
describe 'New' do
context 'setting academic year and school' do
let :academic_year do
FactoryGirl.build(:temp_academic_year)
end
let :school do
FactoryGirl.build(:school)
end
it 'should set current_academic_year in enrollment_renewal' do
controller.stub(:current_academic_year).and_return(academic_year)
get :new
expect(assigns(:enrollment_renewal).academic_year).to eq academic_year
end
it 'should set the current_school in enrollment_renewal' do
controller.stub(:current_school).and_return(school)
get :new
expect(assigns(:enrollment_renewal).school).to eq school
end
end
end
def make_dependencies!
@academic_year_2 = create(:academic_year, last_academic_year: academic_years(:academic_year))
@turn_2 = create(:turn)
@course_2 = create(:course, :graduation => graduations(:graduation))
mec_stage_2 = create(:mec_stage, :graduation => graduations(:graduation))
@stage_2 = create(:stage, :mec_stage => mec_stage_2, :course => @course_2)
@demand_2 = create(:demand, :academic_year => academic_years(:academic_year), :school => schools(:school),
:course => @course_2)
@demand_stage_2 = create(:demand_stage, :turn => @turn_2, :stage => @stage_2,
:demand => @demand_2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment