Hope School: A Rails app with RSpec, PostgreSQL, Authentication and Omniauth

This is not a how-to post, rather a post on why I built this app and some of the challenges I came across in the process.

The inspiration for my app came from Hope Schools in East London, South Africa. Hope Schools is a Christian school for children who are affected, infected and/or orphaned by HIV/AIDS. I traveled twice in 2017 on a missionary trip with my church to work with the children and show them God’s love in a practical way.

I thought it would be great to have a grading system that teachers could track their students’ information by classroom and semester. The result is Hope Schools: Rails app with RSpec, PostgreSQL, Authentication and Omniauth.

Some challenges I encountered

Adding Tests

Since I started Flatiron School, the labs in the online program were built with Test Driven Development or TDD for short. It was challenging to understand at first, working my way through errors, etc.

I saw this app as an opportunity to add tests and really learn how to keep my app clean and free from potential bugs.

Thouhgtbot has plenty of posts on integrating RSpec and Capybara into your Rails application. They also created an e-book with the corresponding repository. With this information, I integrated tests for the models to set up validations, associations and database columns were set up. Thoughtbot created a gem called shoulda-matchers that makes it simple to add these kinds of tests to your application.

teacher_spec.rb with tests for associations and validations

I also added the Faker and FactoryBot gems to call in the tests. Set up was ok because I used a few different resources to help with the process. I did have a bit of a challenge setting up specific tests for the models such as class scope methods. I plan to review the documentation further to set up these kinds of tests.

Seeding my data

Next up I worked on seeding my data. In my Sinatra project, I manually entered the information because I had two models and a smaller database. This time around I set up Faker to add more data to work with as I built the application. I initially had some challenges connecting the different models, partially due to validations, etc. I got the database to seed the data nicely, but the associations were off. I would definitely recommend being verbose with the seed data if you have a lot associations to work with.

Setting up PostgreSQL

Setting up PostgreSQL wasn’t too challenging. I used a mix of two articles, one from Medium and one from Coderwall. Once you follow the instructions to set up PostgreSQL on your computer and add the gem to your computer using Homebrew (if you are using a Mac), these articles will help with connecting PostgreSQL to either Postico or pgAdmin to interact with your database on the backend.

When you start your new Rails application, you can use the following command on the command line: rails new myapp --database=postgresql

One thing to note, when you start your Rails server, start the PostgreSQL database or your Rails app will not load in the browser.

PostgreSQL server running

Overall, this was a challenging application to build. I had a lot of help along the way from the section leads to other students in the program as well as StackOverFlow and Google. I learned a lot and still have more features to add to my project. I also plan to create the same app in Python once I begin to learn Python.

Check out the repo here on GitHub and the video here on Youtube.