Wednesday, June 19, 2013

DropThot, my next web app.

I'm attempting to build a web application (dropthot.herokuapp.com) similar to ruminations.com before it closed down. Basically it's going to be an app where people can post their random day-to-day thoughts, upvote thoughts, and follow other users. More info on the project's Github page: http://github.com/alexsung/dropthot

This time I'm actually doing test-driven development, with RSpec, and trying out the new Rails 4.0!

I've been using Michael Hartl's tutorial (ruby.railstutorial.org) as a reference, since my app's functionality is somewhat similar to his. However, I've ran into a few issues so far.

For example, testing in RSpec:

describe "when email is already taken" do
    before do
      user_same_email = @user.dup
      user_same_email.name = "different_name"
      user_same_email.save
    end

    it { should_not be_valid }
end

Running this spec caused a problem, because the 4th line saves user_same_email to the test database, and then fails more specs the next run because of the persisting duplicate email address in the database.

Running "rake test:prepare" seems to fix it temporarily, but running the specs more than once results in a failure. I didn't have this issue when I was using Rails 3.2 on Michael Hartl's tutorial, so I'm assuming it's because of Rails 4. It makes sense because my tests run much faster in Rails 4 than in 3.2, so I'm guessing Rails 4 doesn't automatically clear the test database each time you run your specs. (edit/correction at the bottom of post)

I enjoy the fast test times since I can't get Spork to work with Rails 4, so I'm okay with this as long as I find a simple solution.

describe "when email is already taken" do
    before do
      @user_same_email = @user.dup
      @user_same_email.name = "different_name"
      @user_same_email.save
    end

    it { should_not be_valid }
    after { @user_same_email.destroy } # Changed to instance variable due to variable scope
end

That works.

Edit: It appears that the version of RSpec I was using (2.13.0) was the problem. I have updated my RSpec to 2.14.0.rc1 and it now works fine; my tests run equally fast and the test database clears between each run as expected.

Wednesday, June 12, 2013

The First Post: Why Ruby on Rails?

It was a few months after graduation in 2012 when I discovered Ruby on Rails. I was immediately impressed by the community and also surprised at how pleasant it was to code in Ruby. Having taken classes in Java and C++  in high school and college, I've always had a somewhat misguided impression of what programming really was.

However, learning Ruby showed me that programming can actually be fun, expressive, and even artistic.













So after some contemplation, I decided, "forget finance and marketing. I'm going into web development."
Because I knew this was something I would actually enjoy doing full-time.

Well, that and also the fact that the current job market clearly needs more web devs. I'm always looking to learn new things, so why not learn some new valuable skills and contribute to a great demand? All the resources I need are already at the tip of my fingers.

I have learned basic programming and made websites before all of this, but I really started to dig into web development in late 2012. Since then, I've been studying everything from Ruby to jQuery. Needless to say, it has been quite an overwhelming experience, but I think I'm beginning to have a solid foundation for everything.

A couple examples of web apps I've built:
www.lightshow.me, a for-fun project I built using Wordpress and PhpBB3 before getting into Rails.
And during my self-education for the past many months, I developed a real Ruby on Rails app for my mini-business, www.inkmasks.com. It was done using the Spree Commerce gem which took care of most of the e-commerce functionality, so it felt a bit like cheating. That's not to say I didn't learn a lot; I definitely gained valuable experience taking a real application from scratch to production.

The next step will be for me to build a Rails app the old-fashioned wayimplementing the main functionality with my own code instead of using a gem.