#192: added specs for model
This commit is contained in:
parent
c501331e52
commit
0c15e49c9f
|
@ -5,10 +5,11 @@ class Token < ActiveRecord::Base
|
|||
belongs_to :updater, :class_name => 'User'
|
||||
|
||||
validates :creator_id, :subject_id, :subject_type, :presence => true
|
||||
validates :authentication_token, :presence => true, :uniqueness => {:case_sensitive => true}
|
||||
|
||||
default_scope order("#{table_name}.created_at desc")
|
||||
|
||||
before_create :generate_token
|
||||
before_validation :generate_token, :on => :create
|
||||
|
||||
attr_accessible :description
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
FactoryGirl.define do
|
||||
factory :token do
|
||||
association :creator, :factory => :user
|
||||
end
|
||||
|
||||
factory :platform_token, :parent => :token do
|
||||
association :subject, :factory => :platform
|
||||
end
|
||||
end
|
|
@ -0,0 +1,32 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
require 'spec_helper'
|
||||
|
||||
describe Token do
|
||||
before { stub_symlink_methods }
|
||||
|
||||
describe 'platform token' do
|
||||
let!(:platform_token) { FactoryGirl.create(:platform_token) }
|
||||
|
||||
context 'ensures that validations and associations exist' do
|
||||
it { should belong_to(:subject) }
|
||||
it { should belong_to(:creator) }
|
||||
|
||||
it { should validate_presence_of(:creator_id) }
|
||||
it { should validate_presence_of(:subject_id) }
|
||||
it { should validate_presence_of(:subject_type) }
|
||||
|
||||
it { should_not allow_mass_assignment_of(:authentication_token) }
|
||||
it { should_not allow_mass_assignment_of(:creator_id) }
|
||||
it { should_not allow_mass_assignment_of(:subject_id) }
|
||||
it { should_not allow_mass_assignment_of(:subject_type) }
|
||||
|
||||
it 'ensures that authentication_token unique' do
|
||||
token = FactoryGirl.create(:platform_token)
|
||||
token.authentication_token = platform_token.authentication_token
|
||||
token.valid?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
Loading…
Reference in New Issue