Using faker to test your application

Recently I needed some data to test such features as pagination and search. I only had 10 fixtures in the database and this wasn’t enough to test on.

I could have created a bunch of records filling in the fields with random characters but that is a not a very eloquent solution. Instead I wrote a rake task saved as: lib/tasks/faker.rake.

Here is my code

  desc "Insert 100 projects using the faker gem"
  task :insert_projects => :environment do
    require 'faker'
    1..100.times do |i|
      b = Project.create( :name => Faker::Company.name,
                            :slogan => Faker::Company.bs)
    end
    puts "Faked project records"
  end

Originally I used .create! but I found occasionally there were conflicting records so a .save may pass false, now it won’t fail if it passes false and will carry on with the rest.

0 Comments

Crummy New Feature: Symbol Argument

I have just added a feature to Crummy where you can give an argument of a symbol which is then translated to get the instance variable and evaluated like so:


before_filter :load_comment
add_crumb :comment # => add_crumb(@comment.to_s, comment_path(@comment.to_param))

0 Comments

Introducing Crummy

It is a common task to produce an application with breadcrumbs. Before, there were many solutions to this issue, but now I have made it so there is only one needed: Crummy.

Crummy allows you to add breadcrumbs in the controller (class level and instance level) and the views. You can use instance variables, strings or symbols in some places. It’s very customizable and handles everything you’d need down to Rails helpers.

To install, type: script/plugin install git://github.com/zachinglis/crummy.git

2 Comments

Introducing Holler

One thing that separates us at Hashrocket is the fact that we have a great team of Ruby experts. This is great if you get stuck, there is always at least one person who can help you on something. We also follow the great agile principle of pairing, which means that if someone is doing something you are interested in, then you can watch and learn with them.

Everyone is hesitant to get into Backpack for the purposes of updating their status and it is too private to talk about on Twitter so I thought I would come up with my own solution. Originally the Backpack feature came from their In/Out application, my good friend David Smalley came up with his own Merb solution too, but I wanted something Rails and thus Holler was born.

Holler Almost v1

It has only taken me 4 hours so far but I would like to introduce Holler. There are a few big features that I am planning on: Fluid integration similar to Shout, Javascript where its needed, tags, twitter integration (direct messaging to the application), more ways to view statuses.

Feel free to fork it and make your own changes! Get Holler.

7 Comments

GMail Tips

Usually I do not like to post a topic so short but I learnt a few tricks that a few of you may not know. I know most people I know use Google Mail so thought it’d be helpful.

Suggesting your email is foobar@gmail.com, you may put periods in there as you please. foo.bar@gmail.com and f.o.o.b.a.r@gmail.com both work (Please do not use the latter; i beg).

Secondly, plus signs can be added onto the end followed by anything you want. You could have foobar+work@gmail.com and such and that works as a catch-all.

Obviously it can be used in conjunction with each other.

0 Comments

GeekThreads: Introducing: Git Push tshirt

I have been planning doing tshirts for a while under the company ‘Geek Threads’. I finally took the plunge and have shirts to sell here at RailsConf.

They are black shirts, with white monospaced text on the front and back. The front reads ‘Git push: just the tip’ and the back reads ‘just a little bit. just to see how it feels’. It’s a case of first come, first serve (I will be carrying some with me at all times but may not have your size). You can also custom order if I have run out or such. They are selling at $20 each (sorry guys, have to make a profit.)

I’m accepting ideas for both text-based and graphic based tshirts. So if you have any ideas, message me. I pay 25% profit royalties.

To find me, either look for one of the Hashrocketeers, email me or @zachinglis on twitter.

Cheers.

0 Comments

RailsConf

As always I forget to say until the last minute.

I and the rest of the Hashrocket team will be going to RailsConf next week, so if you see me there, do stop me and say Hi. :)

0 Comments

GTA IV Completed!

As I am in between projects and I am sick (glandular fever), I have been playing Grand Theft Auto 4. I completed it an hour ago and have since run around shooting everything I can and mucking about a bit.

It is a great game, the graphics are awesome and the gameplay is great. I find it is not that innovative. Nearly everything has been done before, just not so well. The two things about it the most (apart from multiplayer) is the small details it puts in. Cars get scratched, your phone interferes with the radio and such. Secondly is the story-line. You get to make small changes and you watch Niko make some well informed decisions but always the wrong ones.

For instance, there is small choices you can make ( would prefer there were more) and as opposed to games like Fable and Star Wars, i feel connected to Niko so I want the best things to happen to him, so you generally choose the good path.

X-Play had suggested that it would take 100 hours to complete. I think this includes running around and doing the jumps, flying under the bridges and such small “hidden achievements”. I have completed the game 70% (the storyline is completed) and it has taken me 35 hours.

There are a few things I dislike.

  • If you muck up a mission, you start from the very beginning of that mission. You have to do the chase and such again, and there are some LONG missions.
  • Learning how to disarm someone at the beginning of the game is only useful for that perticular scene, onwards from that you never need to use it again.
  • Often you will cover behind an object in the wrong manner, exposing yourself.
Stats
  • Playing time 35 hours
  • Longest game: 7hrs 30mins
  • Cash: $580,756
  • Missions attempted: 150 (all tries on all missions)
  • Missions passed: 94
1 Comment

Rails Tip: to_s

I haven’t posted much recently as I’ve been very busy at work (more on that later) so I thought I would post another Rails tip.


## Model
class Person < ActiveRecord::Base
def to_s
self.title
end
end

# View
link_to person

# Output
<a href=\"http://foo.bar/person/1\">Zach Inglis</a>

View Pastie

Furthermore you could extend it like this:

## Model
class Person < ActiveRecord::Base
def to_s
self.title
end

def to_param
self.slug
end
end

# View
link_to person

# Output
<a href=\"http://foo.bar/person/zach-inglis\">Zach Inglis</a>

View pastie

1 Comment

Ruby +1 for Google Apps == Ungrateful?

This post popped up on my feeds and after clicking it I thought I would share my opinion here. What I have to say is more an extension of myself than a comment could do for me.

The authors main argument is that people who want to program in Ruby over Python with the Google Apps Engine are ungrateful.

First things first, +1 is fricking annoying, agreed. The people should press the star button and not comment unless they have anything decent to say

But as for the matter of wanting Ruby in Google Apps is not unfair. I have coded Python but my Ruby-fu is far far stronger. I could create wonderful things with the tools I have.

Learning another language to use a tool is a crippled philosophy. If you downloaded software to write plugins and it was a vastly different language, it could be a deal breaker for you, right? Why should it be any less? Google are getting traffic and a bunch of other goodies out of locking you into their domain.

3 Comments