1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00

Add category spec and uniqueness check.

This commit is contained in:
Dan Barber 2013-06-05 08:31:17 +01:00
parent 34c9faa778
commit e8e89ebc8b
3 changed files with 23 additions and 0 deletions

View File

@ -1,6 +1,7 @@
class Category < ActiveRecord::Base
has_and_belongs_to_many :photos
validates_presence_of :name, :slug
validates_uniqueness_of :name, :slug
has_slug :slug, from: :name
end

View File

@ -0,0 +1,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :category do
name "Test Category"
end
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
describe Category do
it { should have_and_belong_to_many(:photos) }
it { should validate_presence_of(:name) }
it { should validate_presence_of(:slug) }
it { should validate_uniqueness_of(:name) }
it { should validate_uniqueness_of(:slug) }
let(:category) { create(:category, name: "A Test Category") }
it "should have a slug generated from name" do
expect(category.slug).to eql("a-test-category")
end
end