Quick Tip: Rails Escaping Database Values and Storing/Inserting with Multi-Insert SQL Query

In this quick tip we’ll see how to escape values in Rails before passing them on to an SQL query (preventing injection attacks) and then also look into how to do multi-inserts (at the DB level). Let’s first see how to escape values to prevent SQL injections in Rails:

Continue reading “Quick Tip: Rails Escaping Database Values and Storing/Inserting with Multi-Insert SQL Query”

Single Sign On (SSO) for Multiple Applications with Devise, OmniAuth and Custom OAuth2 Implementation in Rails

Recently I had to implement Single Sign On (SSO) for one of the Rails app I’d been working on. Since Devise is already fairly popular to integrate an authentication system in Rails app, I was more inclined towards using it to achieve SSO. So essentially what was required is a single user manager app that can act as a Provider (OAuth2 ?) and different applications (or Clients) that can authenticate themselves using this same user manager. An important part of SSO is, once you sign in to one of the client, you should automatically be authorized to access all the other clients (their login-protected sections/modules). Similarly, logging out from one service should log out from all other services.

Continue reading “Single Sign On (SSO) for Multiple Applications with Devise, OmniAuth and Custom OAuth2 Implementation in Rails”

What is Rack and Rack Middlewares (Basis of Ruby Frameworks) ?

Rack is a very thin interface between Ruby frameworks and web servers that support Ruby. What it basically means is that it provides a minimal API for connecting web servers (supporting Ruby) and web frameworks (that implement it).

Continue reading “What is Rack and Rack Middlewares (Basis of Ruby Frameworks) ?”

Quick Walkthrough of RSpec Mocks (Introduction) in Code

Before we go through a lot of code samples, make sure you understand the different testing terms like mocks, stubs and test doubles. That’ll help you understand this article much better as I use a lot of those terminologies while going through different code samples.

A test double is a generic term (for stubs and mocks) that represents a real object (but sort of fake) to which messages can be passed (method calls) and fake return values can be specified. It’s used in unit testing to test a particular system or object in isolation. In this article we’ll go through test doubles (mocks) in RSpec. Let’s see how to create a test double representing the object being faked.

Continue reading “Quick Walkthrough of RSpec Mocks (Introduction) in Code”