From 771278ce96635ac86d36d91e108e684af41603bc Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 7 May 2015 14:46:06 +0200 Subject: [PATCH] Fix specs for coursera and edX course workers #128 --- .../users/registrations_controller.rb | 11 ++-- app/controllers/users_controller.rb | 3 +- spec/controllers/users_controller_spec.rb | 2 +- spec/workers/coursera_course_worker_spec.rb | 52 ++++++++++++------- spec/workers/edx_course_worker_spec.rb | 36 ++++++++----- 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 25bf31cd6..605f75622 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -40,7 +40,6 @@ def create end def update - puts 'blub' flash['error'] ||= [] self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) @@ -50,8 +49,11 @@ def update yield resource if block_given? if resource_updated if is_flashing_format? - flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? - :update_needs_confirmation : :updated + if update_needs_confirmation?(resource, prev_unconfirmed_email) + flash_key = :update_needs_confirmation + else + flash_key = :updated + end set_flash_message :notice, flash_key end sign_in resource_name, resource, bypass: true @@ -59,14 +61,11 @@ def update resource.errors.each do |key, value| flash['error'] << "#{t('users.sign_in_up.' + key.to_s)} #{value}" end - puts 'resource_not_updated' clean_up_passwords resource end redirect_to "/users/#{current_user.id}/settings?subsite=account" - end - protected def after_sign_up_path_for(resource) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6b86de2d4..957ea696f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -102,7 +102,6 @@ def mooc_provider_settings def settings prepare_mooc_provider_settings - puts @subsite = params['subsite'] end def oauth_callback @@ -178,7 +177,7 @@ def prepare_mooc_provider_settings @mooc_providers = MoocProvider.all.map do |mooc_provider| provider_connector = get_connector_by_mooc_provider mooc_provider if provider_connector.present? && mooc_provider.api_support_state == 'oauth' - oauth_link = provider_connector.oauth_link(user_settings_path(current_user)+'?subsite=mooc_provider', masked_authenticity_token(session)) + oauth_link = provider_connector.oauth_link("#{user_settings_path(current_user)}?subsite=mooc_provider", masked_authenticity_token(session)) end {id: mooc_provider.id, logo_id: mooc_provider.logo_id, diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 3913ac23d..7e94980f7 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -170,7 +170,7 @@ expect(mooc_provider[:logo_id]).to eql MoocProvider.all[index].logo_id expect(mooc_provider[:api_support_state]).to eql MoocProvider.all[index].api_support_state if MoocProvider.all[index].name == 'coursera' - oauth_link = CourseraConnector.new.oauth_link(user_settings_path(user), 'my_csrf_token') + oauth_link = CourseraConnector.new.oauth_link("#{user_settings_path(user)}?subsite=mooc_provider", 'my_csrf_token') expect(mooc_provider[:oauth_link]).to eql oauth_link end end diff --git a/spec/workers/coursera_course_worker_spec.rb b/spec/workers/coursera_course_worker_spec.rb index 28162b947..2afe7494d 100644 --- a/spec/workers/coursera_course_worker_spec.rb +++ b/spec/workers/coursera_course_worker_spec.rb @@ -95,16 +95,22 @@ allow(RestClient).to receive(:get).and_return(course_fields) coursera_course_worker.handle_response_data json_session_data course = Course.find_by(provider_course_id: json_course['id'].to_s + '|' + json_session['id'].to_s, mooc_provider_id: mooc_provider.id) - expect(course.tracks[0].track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement - expect(course.tracks[0].costs).to be_nil - expect(course.tracks[0].credit_points).to be_nil - expect(course.tracks[1].track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement - expect(course.tracks[1].costs).to be_nil - expect(course.tracks[1].credit_points).to be_nil - expect(course.tracks[2].track_type.type_of_achievement).to eql signature_course_track_type.type_of_achievement - expect(course.tracks[2].costs).to eql 100.0 - expect(course.tracks[2].costs_currency).to eql '$' - expect(course.tracks[2].credit_points).to be_nil + (course.tracks).each do |course_track| + case course_track.track_type + when free_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when certificate_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when signature_course_track_type then + expect(course_track.costs).to eql 100.0 + expect(course_track.costs_currency).to eql '$' + expect(course_track.credit_points).to be_nil + end + end end it 'creates a signature course track type with price' do @@ -116,16 +122,22 @@ allow(RestClient).to receive(:get).and_return(course_fields) coursera_course_worker.handle_response_data json_session_data course = Course.find_by(provider_course_id: json_course['id'].to_s + '|' + json_session['id'].to_s, mooc_provider_id: mooc_provider.id) - expect(course.tracks[0].track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement - expect(course.tracks[0].costs).to be_nil - expect(course.tracks[0].credit_points).to be_nil - expect(course.tracks[1].track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement - expect(course.tracks[1].costs).to be_nil - expect(course.tracks[1].credit_points).to be_nil - expect(course.tracks[2].track_type.type_of_achievement).to eql signature_course_track_type.type_of_achievement - expect(course.tracks[2].costs).to eql 50.0 - expect(course.tracks[2].costs_currency).to eql '$' - expect(course.tracks[2].credit_points).to be_nil + (course.tracks).each do |course_track| + case course_track.track_type + when free_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when certificate_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when signature_course_track_type then + expect(course_track.costs).to eql 50.0 + expect(course_track.costs_currency).to eql '$' + expect(course_track.credit_points).to be_nil + end + end end it 'sets the targetAudience to Basic Undergraduate' do diff --git a/spec/workers/edx_course_worker_spec.rb b/spec/workers/edx_course_worker_spec.rb index bea2c2bf8..f1b79c8ec 100644 --- a/spec/workers/edx_course_worker_spec.rb +++ b/spec/workers/edx_course_worker_spec.rb @@ -72,12 +72,18 @@ json_course['course:verified'] = '1' edx_course_worker.handle_response_data json_course_data course = Course.find_by(provider_course_id: json_course['course:id'], mooc_provider_id: mooc_provider.id) - expect(course.tracks[0].track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement - expect(course.tracks[0].costs).to be_nil - expect(course.tracks[0].credit_points).to be_nil - expect(course.tracks[1].track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement - expect(course.tracks[1].costs).to be_nil - expect(course.tracks[1].credit_points).to be_nil + (course.tracks).each do |course_track| + case course_track.track_type + when free_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when certificate_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql certificate_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + end + end end it 'creates a xseries course track type' do @@ -85,12 +91,18 @@ json_course['course:xseries'] = '1' edx_course_worker.handle_response_data json_course_data course = Course.find_by(provider_course_id: json_course['course:id'], mooc_provider_id: mooc_provider.id) - expect(course.tracks[0].track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement - expect(course.tracks[0].costs).to be_nil - expect(course.tracks[0].credit_points).to be_nil - expect(course.tracks[1].track_type.type_of_achievement).to eql xseries_course_track_type.type_of_achievement - expect(course.tracks[1].costs).to be_nil - expect(course.tracks[1].credit_points).to be_nil + (course.tracks).each do |course_track| + case course_track.track_type + when free_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql free_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + when xseries_course_track_type then + expect(course_track.track_type.type_of_achievement).to eql xseries_course_track_type.type_of_achievement + expect(course_track.costs).to be_nil + expect(course_track.credit_points).to be_nil + end + end end it 'creates a profed course track type' do