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:
parent
34c9faa778
commit
e8e89ebc8b
@ -1,6 +1,7 @@
|
|||||||
class Category < ActiveRecord::Base
|
class Category < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :photos
|
has_and_belongs_to_many :photos
|
||||||
validates_presence_of :name, :slug
|
validates_presence_of :name, :slug
|
||||||
|
validates_uniqueness_of :name, :slug
|
||||||
|
|
||||||
has_slug :slug, from: :name
|
has_slug :slug, from: :name
|
||||||
end
|
end
|
||||||
|
|||||||
7
spec/factories/categories.rb
Normal file
7
spec/factories/categories.rb
Normal 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
|
||||||
15
spec/models/category_spec.rb
Normal file
15
spec/models/category_spec.rb
Normal 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
|
||||||
Loading…
Reference in New Issue
Block a user