#192: added specs for model

This commit is contained in:
Vokhmin Alexey V 2013-06-26 10:57:53 +04:00
parent c501331e52
commit 0c15e49c9f
3 changed files with 44 additions and 1 deletions

View File

@ -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

10
spec/factories/token.rb Normal file
View File

@ -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

32
spec/models/token_spec.rb Normal file
View File

@ -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