vendredi 22 septembre 2017

what's the mean about the rails rspec code`to_not be_valid`?

when i user the ruby on rails to learn how to test a code use the rails rspec,some code i can't understand, here is the code, it is just a code about parking meter test.

db/migrate/xxxxx_create_parking.rb

class CreateParkings < ActiveRecord::Migration[5.0]

def change
    create_table :parkings do |t|
      t.string :parking_type   #guest, short-term, long-term
      t.datetime :start_at   
      t.datetime :end_at     
      t.integer :amount      

      t.integer :user_id, index: true 

app/spec/models/parking_spec.rb

    require 'rails_helper'

RSpec.describe Parking, type: :model do
  #pending "add some examples to (or delete) #{__FILE__}"

 describe ".validate_end_at_with_amount" do

   it "is invalid without amount" do
     parking = Parking.new( :parking_type => "guest",
                            :start_at => Time.now - 6.hours,
                            :end_at => Time.now)
      expect(parking).to_not be_valid
    end

    it "is invalid without end_at" do
      parking = Parking.new( :parking_type => "guest",
                             :start_at => Time.now - 6.hours,
                             :amount => 999)
       expect(parking).to_not be_valid
     end
   end
end

so, what is the mean about the to_not be_valid and t.integer :user_id, index: true ? thanks.

Aucun commentaire:

Enregistrer un commentaire