Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Fix specs for coursera and edX course workers
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSerth committed May 7, 2015
1 parent cd3b9f9 commit 771278c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
11 changes: 5 additions & 6 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,23 +49,23 @@ 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
else
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)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def mooc_provider_settings

def settings
prepare_mooc_provider_settings
puts @subsite = params['subsite']
end

def oauth_callback
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 32 additions & 20 deletions spec/workers/coursera_course_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 24 additions & 12 deletions spec/workers/edx_course_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,37 @@
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
json_course = json_course_data['value']['items'][0]
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
Expand Down

0 comments on commit 771278c

Please sign in to comment.