Skip to content

Instantly share code, notes, and snippets.

@susanwere
susanwere / product_spec.rb
Created April 16, 2019 11:12
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
@susanwere
susanwere / before_model_hook
Created April 16, 2019 10:47
before hook for model
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
@susanwere
susanwere / test.py
Last active October 17, 2018 11:22
Test for the Authors Haven codebase
from django.test import TestCase
from authors.apps.authentication.models.UserManager import create_user
class UserTestCase(TestCase):
def test_to_create_user(self):
"""user can be registered"""
create_user.user = (username="patty", email="patty@gmail.com", password="patty123")
new_user = create_user.user
self.assertEqual(new_user.username, "patty")
self.assertEqual(new_user.email, "patty@gmail.com")