Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make buttons work #13473

Merged
merged 7 commits into from Mar 1, 2017
Merged

Make buttons work #13473

merged 7 commits into from Mar 1, 2017

Conversation

mehalshah
Copy link
Contributor

No description provided.

},

onPrintCertificateClick() {
const enrollmentCode = this.props.lastWorkshopSurveyUrl.substring(this.props.lastWorkshopSurveyUrl.lastIndexOf('/'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit odd to parse the enrollment code here, when this url was constructed from the enrollment code in the first place.

What about passing both urls, or even better passing just the enrollment code and constructing both urls in the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter sounds good to me

enrollment.try(:name) || '',
y: 444,
height: 100
)
Copy link
Contributor

@aoby aoby Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to just display a blank certificate on a bad enrollment code? I think 404 (not found) would make more sense.

Incidentally you get that for free with load_resource (above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that


def generate_certificate
enrollment = params[:enrollment_code] ? Pd::Enrollment.find_by(code: params[:enrollment_code]) : nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be loaded into @enrollment via CanCan's load_resource before action hook:

load_resource :enrollment, class: 'Pd::Enrollment', find_by: :code, id_param: :enrollment_code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - didn't know you could load via code. I'll do it that way

const csFundamentalsSection = landingPage.find('CsFundamentalsSection');
expect(csFundamentalsSection).to.have.length(1);
expect(csFundamentalsSection.prop('lastWorkshopSurveyUrl')).to.equal(null);
expect(csFundamentalsSection.prop('printCsfCertificateUrl')).to.equal('otherUrl');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'certificateUrl' instead of 'otherUrl'

def generate_certificate
image = create_certificate_image2(
dashboard_dir('app', 'assets', 'images', 'pd_workshop_certificate_csf.png'),
@enrollment.try(:name) || '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pd::Enrollment.name is deprecated. Use full_name instead.

As an aside, we need to remove name and other no longer used fields at some point.

class Pd::CsfCertificateController < ApplicationController
before_action :authenticate_user!
load_resource :enrollment, class: 'Pd::Enrollment', find_by: :code, id_param: :enrollment_code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some basic tests for this controller:

  • authenticated users can access
  • non-users cannot
  • valid enrollment code works
  • invalid enrollment code gets not found

@@ -15,13 +15,20 @@ def index

summarized_plc_enrollments = Plc::UserCourseEnrollment.where(user: current_user).map(&:summarize)

if courses_completed.include?(Pd::Workshop::COURSE_CSF)
enrollment = Pd::Enrollment.where(pd_workshop_id: ended_workshops.where(course: Pd::Workshop::COURSE_CSF).map(&:id), email: current_user.email).last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not ordered, so last won't necessarily be consistent.

Please add a test to verify this is working correctly, that it gets the latest enrollment for the given user in a CSF ended workshop, disregarding enrollments from other users and other workshops.

Make sure you also check user_id: current_user.id. In case a user changes email after the fact: where('email = ? OR user_id = ?', current_user.email, current_user.id)

This logic might better fit the enrollment model, with testing there. At least the user part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic might better fit the enrollment model, with testing there. At least the user part.

Like a scope?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, either a scope or static method.

get :generate_certificate, params: {enrollment_code: @enrollment.code}
assert_response :redirect
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized, after seeing these tests, that any enrollment code will work on this url, not just those for ended workshops. Not necessary in this PR, but we might want to add some more validation.

Copy link
Contributor

@aoby aoby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mehalshah mehalshah merged commit 244617a into staging Mar 1, 2017
@mehalshah mehalshah deleted the make_buttons_work branch March 1, 2017 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants