Refactoring the workflow
We are going to add some scenarios to certificate_generation.feature
First a small re-factoring:
# features/certificate_generation.feature
...
# change Scenario title to:
Scenario: Generate certificates
# add step:
And I should see 3 "view certificate" links
...Add a new step definition to your application_steps.rb:
# features/step_definitions/application_steps.rb
...
And(/^I should see ([^"]*) "([^"]*)" links$/) do |count, element|
expect(page).to have_link(element, count: count)
end
...We only want the user to be able to generate certificates if no certificates have been generated, right? If we put that in a User Story, it could look something like this:
In the certificate_generation.feature file, add the following scenario:
In order to get the Certificate model to validate, we want to slightly change the way we generate the pdf's. We are going to remove the after :create callback from that class:
And add that command to our controller. Along with some other changes.
Let's update our controller method:
With this implementation we are:
Preventing unauthorized access to the route
Preventing certificates to be created if there already exists certificates for that course delivery
Creating a certificate for each student
Giving the user feedback on performed actions with a flash
We need to make an addition to the Delivery model - letting each Delivery know what Certificates are associated to it using whatever Certificates are associated to the Deliveries Students.
We start by writing a spec for that:
Then the implementation:
We also want to open this view for non logged in users but only allowing actions to be performed if a user is logged in. In that way, we do not need to create separate views for those contexts. Make sure you are not using the auth: :user method on the route to get that view:
The next step will be to re-factor the view:
This change is introducing several changes:
Generate certificateslink will only be visible if a) there is acurrent_userAND no certificates has been generated (!@delivery.certificates.any?).The upload data file interface (the form) is visible only if there is a
current_userpresent and there are no students associated to the delivery.On the students list, a link to the certificate is visible IF there is a certificate associated with that student.
We are displaying the delivery date.
We add class
'button'to links to give it look and feel of a button.
We want to be able to retrieve the files from S3 using a http request. For that we need to have access to a URL.
Add the following specs to your certificate_spec.rb
We know that the links to AWS are build in a specific way and we can use that to dynamically create our own urls. Add the following methods to your certificate.rb
If you run all your tests, they should pass. However, our tests are not very extensive and there are many scenarios that we have failed to write coverage for. I would like you to take a few minutes and think about what else we should be testing for in Cucumber.
Last updated