Skip to content

Instantly share code, notes, and snippets.

@borisd
Last active January 3, 2016 18:29
Show Gist options
  • Save borisd/8501998 to your computer and use it in GitHub Desktop.
Save borisd/8501998 to your computer and use it in GitHub Desktop.

Create a new rails project "catz"

Git

In the beginning and after each successful step you make

Create model "User"

  • email: string
  • first_name: string
  • last_name: string
  • username: string
  • age: integer

Add validations

  • email:
    • 5-100 characts and unique
  • first_name:
    • 2-100 characters
  • last_name:
    • 2-100 characters
  • username:
    • 3-100 characters
    • unique
    • NOT in [:admin, :system, :public, :guest]
  • age:
    • Between 13-120

Read

ActiveRecord callbacks

Add callbacks

  • username validation should fail both for :username => :admin and :username => 'admin' (always work with symbol)
  • username should be saved and validated "downcased"

Add controller (and routes) for users

Add gems

  • 'sextant'
  • 'hirb'
  • 'faker'

Misc

If you want to generate users for testing, add this to User model:

def self.random_user
  User.create(
    first_name: Faker::Name.first_name,
    last_name: Faker::Name.last_name,
    age: rand(18..100),
    username: Faker::Name.first_name.downcase
  )
end

Run from console with: 100.times { User.random_user }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment