Created
April 16, 2019 11:12
-
-
Save susanwere/258d99d0c60ba2a3ec755861bfa85b0b to your computer and use it in GitHub Desktop.
spec/models/product_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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