Skip to content

Instantly share code, notes, and snippets.

@maker-leo
Forked from Ptico/shoulda_am.rb
Created May 24, 2013 10:03
Show Gist options
  • Save maker-leo/5642535 to your computer and use it in GitHub Desktop.
Save maker-leo/5642535 to your computer and use it in GitHub Desktop.
# Shoulda activemodel cheatsheet
# DB
should have_db_column(:title).of_type(:string).with_options(default: 'Untitled', null: false)
should have_db_index(:email).unique(:true)
# Associations
should belong_to :company
should have_one(:profile).dependent(:destroy)
should have_many(:posts).dependent(:nullify)
should have_and_belong_to_many :tags
# Validations
should allow_value("[email protected]").for(:email)
should_not allow_value("adlkj").for(:email)
should ensure_inclusion_of(:age).in_range(18..90)
should validate_numericality_of(:age)
should ensure_length_of(:title).is_at_least(3).is_at_most(40)
should ensure_length_of(:state).is_equal_to(3)
should validate_presence_of(:title)
should validate_acceptance_of(:agreement)
should validate_uniqueness_of(:email)
should_not allow_mass_assignment_of(:password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment