Restaurantly Restaurant Data Model
John Davison photo
Get notifications about new tutorials, code and events.

click: follow along with the source code

git checkout -b restaurant_model

rails g model restaurant name:string address:string

pro tip setup ‘be’ in ~/.bash_profile or ~/.bashrc

  alias be='bundle exec'

then type source ~/.bash_profile or ~/.bashrc

be rake db:migrate

be rake db:test:prepare

sublime .

modify spec/spec_helper.rb

  config.expect_with :rspec do |c|
    c.syntax = :expect
  end

modify spec/models/restaurant_spec.rb

  require 'spec_helper'

  describe Restaurant do
    subject(:restaurant) { FactoryGirl.build(:restaurant, name: nil)}
    it {expect(restaurant.valid?).to be_false}
  end

expect red

rspec spec/models/restaurant_spec.rb

modify app/models/restaurant.rb

  class Restaurant < ActiveRecord::Base
    validates_presence_of :name
  end

expect green

rspec spec/models/restaurant_spec.rb

rails console

Restaurant.new

resturant = Restaurant.new(name: “john’s cafe”)

restaurant.save

Restaurant.count

Restaurant.last

Get notifications about new tutorials, code and events.