Skip to content

Instantly share code, notes, and snippets.

@susanwere
Created April 16, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save susanwere/258d99d0c60ba2a3ec755861bfa85b0b to your computer and use it in GitHub Desktop.
Save susanwere/258d99d0c60ba2a3ec755861bfa85b0b to your computer and use it in GitHub Desktop.
spec/models/product_spec.rb
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Product, type: :model do
before do
@invalid_product = Product.new(title: '', description: '', price: '')
@valid_product = Product.new(title: 'One', description: 'description one', price: '100.00')
@invalid_price = Product.new(title: 'One', description: 'description one', price: '0.00')
end
describe 'title' do
it 'validates presence of title' do
product = @invalid_product
product.valid?
expect(product.errors[:title]).to include("can't be blank")
end
it 'validates uniqueness of a title' do
@valid_product.save
new_product = @valid_product.dup
new_product.valid?
expect(new_product.errors[:title]).to include('has already been taken')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment