Tag Archives: Rails

How To Use The VCR Gem With Rails And Rspec

21 Oct

So yesterday I spent way too much time trying to make this really cool VCR gem work with my rspec tests. The problem was that most of the tutorials out there were pretty outdated, and things have changed a bit.

The VCR gem is really useful if you have methods that need to make an api request. You don’t want to make api requests during tests, especially if the api has some kind of rate limit (I’m looking at you Twitter!).

So what you could do is create a text file mocking the response you get from the web service you’re making the api to and do the tests that way, or you can use the VCR gem! The VCR gem makes an api request once, and records the response to a cassette, which it then uses in future tests. Clever, no?

Here’s how you set up the VCR gem in your Rails App with Rspec:
Continue reading

Advertisements

When To Optimize For Pleasure

1 Oct

This weekend, I finally got to watch DHH (the guy who started Rails) talk about Rails and Backbone.js in a recent meetup at Manilla that I missed. The talk was almost two hours, but I highly recommend watching all of it. Here it is in case you missed it:

Here are a few takeaways that I absolutely loved:

Continue reading

My Rails New Workflow With Testing

21 Sep

After playing around with Django a few weekends ago, I decided to stick to Rails for my personal projects. This Quora answer sums up pretty well why I’m choosing Rails.

Another reason I love Rails is because I love test driven development, and Rails has testing at it’s core. I started a new project this morning, and wanted to share my workflow for starting a Rails app with all the Testing gems and configurations set up properly:

Continue reading

Django != Rails

9 Sep

Yesterday, I had a few hours to spare on fun learning, so I decided to check out Django. I’m learning Python now, so I figured I should be able to “quickly” make web apps by relying solely on Python and the relavent web framework instead of going back to my Ruby on Rails comfort zone.

I started going through this tutorial and was even able to deploy something to Heroku (I would really prefer Heroku over AppEngine…). Unfortunately, I ran into some serious errors that would take me a lot more time to figure out than I had, so I had to leave Django, at least for now.

Continue reading

How To Configure Your “$ Rails New” Defaults

7 Aug

If you’ve used Ruby on Rails before, you’re probably familiar with the standard way of generating a new rails project:

$ rails new myAwesomeApp

However, did you know that you can add default options for your rails app? For example, if you want rails to skip test unit (if you’re using rspec instead), skip bundle install, and set your default database to PostgreSQL you can run:

$ rails new myAwesomeApp --skip-test-unit --skip-bundle -d postgresql

If you have specific defaults that you always use, here is a simple to configure the default rails command (“$ rails new myAwesomeApp”) to always include your options:

Continue reading

Rails: Active Record VS The Database

28 Jul

After working with pure SQL and Ruby for the past few weeks, coming back to Rails and working with Active Record became a little confusing. When creating a database table with pure SQL, you have to think about things like whether each column in the table can be NULL or UNIQUE and which FOREIGN KEYS you need to add. In contrast, Active Record comes with a ton of validations outside of the database.

So when do you add validations and foreign keys at the database level vs at the active record level? Here’s what I learned.

Continue reading

RVM Tutorial: Keep Your Gems In Order

28 Jul

This is a guest post by my friend Ivan Stroganov, a fellow Ruby on Rails developer attending Dev Bootcamp with me. You can read more from Ivan on his blog and check out his projects on Github

I’ll start from afar. One thing that seemed like absolute magic as a Ruby beginner was the whole “gem install …” process. Now I have a little better idea, and RVM really brings it together. Here’s how:

Continue reading