Skip to content

Commit

Permalink
Role spec created
Browse files Browse the repository at this point in the history
  • Loading branch information
bruparel committed Dec 10, 2010
1 parent 6d09963 commit 3fe4ce9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/models/role_spec.rb
@@ -0,0 +1,31 @@
require 'spec_helper'
describe Role do
describe 'validate name' do
it "Role cannot be saved without a name" do
role = Factory.build(:admin_role, :name => '')
role.should have(1).error_on(:name)
role.should_not be_valid
end
it "Role should be valid with a name" do
role = Factory.create(:admin_role)
role.should be_valid
end
it "Role should enforce uniqueness constraint on name" do
role1 = Factory.create(:admin_role)
role2 = Factory.build(:admin_role, :name => role1.name)
role2.should have(1).error_on(:name)
role2.should_not be_valid
end
end
describe "User associations" do
before(:each) do
@role = Factory.create(:admin_role)
@user1 = Factory.create(:admin_user, :role => @role)
@user2 = Factory.create(:admin_user, :role => @role, :email => "someone@example.com")
end
it "should have a users attribute" do
@role.should respond_to(:users)
@role.should have(2).users
end
end
end

0 comments on commit 3fe4ce9

Please sign in to comment.