- Clone the Cloud9 thibaudgg/rails-weblog-2 workspace. Go to https://c9.io/new/clone and then choose the
MAS-RAD / Ruby on Rails
team, click on the "Clone workspace" tab, then choose thethibaudgg/rails-weblog-2
workspace. - Ensure that PostgreSQL is still running with:
sudo service postgresql start
- Setup the TEST database with:
rails db:setup RAILS_ENV=test
(this will create and migrate theweblog_test
database) - Ensure that all tests are running with
rails test
andrails test:system
or both in one shot withrails test test
.
- Go to https://github.com/mas-rad/rails-weblog and fork the repository to your GitHub account.
- Copy your Cloud9 SSH key from https://c9.io/account/ssh (second one) to your GitHub account: https://github.com/settings/keys.
- From your Cloud9 workspace terminal run the following command to change the git origin to your new forked repository:
git remote set-url origin [email protected]:YOUR_GITHUB_ACCOUNT/rails-weblog.git
- Verify that the remote origin is well configured with
git remote -v
, you should see:
origin [email protected]:YOUR_GITHUB_ACCOUNT/rails-weblog.git (fetch)
origin [email protected]:YOUR_GITHUB_ACCOUNT/rails-weblog.git (push)
Run these commands before and after each exercise from your Cloud9 workspace terminal.
- Create a new branch for the exercise with:
git checkout -b exercise-NUMBER
- Ensure that all tests are passing with
rails test test
- Review your changes with:
git status
- Add any new files created with:
git add .
- Commit all changes with:
git commit -a -m "COMMIT MESSAGE"
- Push your changes to your GitHub forked repository with:
git push origin
- From your GitHub repository create and submit a new pull-request for the exercise.
Add two model tests for the User#display_name
method, one with the "bob" (admin) user fixture, and another one with the "jane" (non-admin) user fixture.
- Rails test fixtures documentation
- Use the
assert_equal(exp, act, msg = nil)
assertion method for them. (docs)
- Add a model test to ensure that a small user password (7 characters) is not valid (have a look at the existing Post model test), and check with
rails test test/models/user_test.rb
that the spec is failing (as the validation is not there yet). - Add the minimum length (8) validation on the
User#password
on theUser
model to make the spec pass. (length validation docs)
Add an authentication system test (test/system/authentication_test.b
) to ensure that the user creation and login is working properly.
The test should do the following actions:
- Visit the home page.
- Click on the sign up link.
- Fill and submit the sign up form.
- Click on the login link.
- Fill and submit the login form.
- Check that the user name is present in the header.
Use the Capybara DSL for doing so.
Add an admin system test (test/system/admin/posts_test.b
) to ensure than an admin can edit an existing post.
The test should do the following actions:
- Log-in the existing "bob" fixture user (visit and fill the login form).
- Visit the admin post index page.
- Click on an post edit link.
- Modify the title and/or body of the post and submit the form.
- Check that the modifications are present in the post page.
- Add a
user_id
reference column (with index and foreign key) to the "comments" table. (docs). - Add the
has_many :comments
association to theUser
model and abelongs_to :author, class_name: 'User', optional: true
association to theComment
model. - Add two model tests for a new
Comment#display_author_name
method, one for a comment with an author returning the author name, another one for a comment without an author returning simply'Guest'
.
Once the tests are implemented do the following:
- Check with
rails test test/models/comment_test.rb
that the new tests are failing. - Add the
Comment#display_author_name
method with its logic. - Check with
rails test test/models/comment_test.rb
that the tests are passing.
Add two comment system tests ensuring that a logged-in user and a guest can both create a comment.
The tests should do the following actions:
- Visit the home page.
- Log-in the user (or not if a guest).
- Click on a post link.
- Fill and submit the comment form
- Check that the comment and its author name are present.
Once the tests are implemented do the following:
- Check with
rails test test/models/comment_test.rb
that the tests are failing. - Modify the
CommentsController#create
action to merge thecurrent_user.id
as theuser_id
params. See that Stack Overflow thread for more details. - Check with
rails test test/models/comment_test.rb
that the tests are passing.
Use the Capybara DSL for doing so.