Test Driven Development (TDD) – Part 2 – Integration Testing

Now that your RSpec environment is all set up, it’s time to start writing some actual tests.  Let’s start with integrations tests, which tests how different components (models, controllers etc.) interact with one another. Create the Integration Folder To start, make future you and any team members really happy by creating an integration folder, within...
Read More

Parsing HTML with Nokogiri

Parsing with Nokogiri is a breeze, especially if you’re super familiar with CSS selectors and you’re good at traversing the DOM. 1. First, you need to install the Nokogiri gem: gem install nokogiri   If you are parsing something that lives remotely, you might want to include the open-uri module, which will make it even...
Read More

Polymorphism in 6 steps

A slightly advanced association in ActiveRecord is called polymorphic association. This usually happens when a model can belong to more than one model, even if it behaves the same way, but it’s easier to understand with an example. Suppose you have a blog that has articles, photos, and events. You want to add comments on...
Read More

Model validations in Rails

Validations are pretty much a “check” that records won’t be saved unless certain attributes/params meet a specified criteria. They can all done in the models and they can be done in a single line per attribute. For example, if we have a Painting model, inside the class(model) we have: validates :name, presence: true, uniqueness: true...
Read More