validation_presence_of instead of validate :presence => true
This commit is contained in:
parent
484f1388cb
commit
22d59b4e67
@ -51,10 +51,9 @@ class DmsfFile < ActiveRecord::Base
|
|||||||
scope :visible, -> { where(:deleted => STATUS_ACTIVE) }
|
scope :visible, -> { where(:deleted => STATUS_ACTIVE) }
|
||||||
scope :deleted, -> { where(:deleted => STATUS_DELETED) }
|
scope :deleted, -> { where(:deleted => STATUS_DELETED) }
|
||||||
|
|
||||||
validates :name, :presence => true
|
validates_presence_of :name, :project
|
||||||
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
||||||
:message => l(:error_contains_invalid_character)
|
:message => l(:error_contains_invalid_character)
|
||||||
validates :project, :presence => true
|
|
||||||
validate :validates_name_uniqueness
|
validate :validates_name_uniqueness
|
||||||
|
|
||||||
def validates_name_uniqueness
|
def validates_name_uniqueness
|
||||||
|
|||||||
@ -65,13 +65,10 @@ class DmsfFileRevision < ActiveRecord::Base
|
|||||||
:scope => DmsfFileRevision.joins(:dmsf_file).
|
:scope => DmsfFileRevision.joins(:dmsf_file).
|
||||||
joins("JOIN #{Project.table_name} ON #{Project.table_name}.id = #{DmsfFile.table_name}.project_id").visible
|
joins("JOIN #{Project.table_name} ON #{Project.table_name}.id = #{DmsfFile.table_name}.project_id").visible
|
||||||
|
|
||||||
validates :title, :presence => true
|
validates_presence_of :title, :major_version, :minor_version, :dmsf_file
|
||||||
validates :major_version, :presence => true
|
|
||||||
validates :minor_version, :presence => true
|
|
||||||
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
validates_format_of :name, :with => /\A[^#{DmsfFolder::INVALID_CHARACTERS}]*\z/,
|
||||||
:message => l(:error_contains_invalid_character)
|
:message => l(:error_contains_invalid_character)
|
||||||
validates :description, length: { maximum: 1.kilobyte }
|
validates :description, length: { maximum: 1.kilobyte }
|
||||||
validates :dmsf_file, :presence => true
|
|
||||||
|
|
||||||
def project
|
def project
|
||||||
self.dmsf_file.project if self.dmsf_file
|
self.dmsf_file.project if self.dmsf_file
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class DmsfFileRevisionAccess < ActiveRecord::Base
|
|||||||
delegate :dmsf_file, :to => :dmsf_file_revision, :allow_nil => false
|
delegate :dmsf_file, :to => :dmsf_file_revision, :allow_nil => false
|
||||||
delegate :project, :to => :dmsf_file, :allow_nil => false
|
delegate :project, :to => :dmsf_file, :allow_nil => false
|
||||||
|
|
||||||
validates :dmsf_file_revision, :presence => true
|
validates_presence_of :dmsf_file_revision
|
||||||
|
|
||||||
DownloadAction = 0
|
DownloadAction = 0
|
||||||
EmailAction = 1
|
EmailAction = 1
|
||||||
|
|||||||
@ -90,14 +90,13 @@ class DmsfFolder < ActiveRecord::Base
|
|||||||
:datetime => Proc.new {|o| o.updated_at },
|
:datetime => Proc.new {|o| o.updated_at },
|
||||||
:author => Proc.new {|o| o.user }
|
:author => Proc.new {|o| o.user }
|
||||||
|
|
||||||
validates :title, :presence => true
|
validates_presence_of :title, :project
|
||||||
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted],
|
validates_uniqueness_of :title, :scope => [:dmsf_folder_id, :project_id, :deleted],
|
||||||
conditions: -> { where(:deleted => STATUS_ACTIVE) }
|
conditions: -> { where(:deleted => STATUS_ACTIVE) }
|
||||||
validates_format_of :title, :with => /\A[^#{INVALID_CHARACTERS}]*\z/,
|
validates_format_of :title, :with => /\A[^#{INVALID_CHARACTERS}]*\z/,
|
||||||
:message => l(:error_contains_invalid_character)
|
:message => l(:error_contains_invalid_character)
|
||||||
validate :check_cycle
|
validate :check_cycle
|
||||||
validates_length_of :description, :maximum => 65535
|
validates_length_of :description, :maximum => 65535
|
||||||
validates :project, :presence => true
|
|
||||||
|
|
||||||
before_create :default_values
|
before_create :default_values
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class DmsfFolderPermission < ActiveRecord::Base
|
|||||||
|
|
||||||
belongs_to :dmsf_folder
|
belongs_to :dmsf_folder
|
||||||
|
|
||||||
validates :dmsf_folder, :presence => true
|
validates_presence_of :dmsf_folder
|
||||||
|
|
||||||
scope :users, -> { where(:object_type => User.model_name.to_s) }
|
scope :users, -> { where(:object_type => User.model_name.to_s) }
|
||||||
scope :roles, -> { where(:object_type => Role.model_name.to_s) }
|
scope :roles, -> { where(:object_type => Role.model_name.to_s) }
|
||||||
|
|||||||
@ -27,11 +27,10 @@ class DmsfLink < ActiveRecord::Base
|
|||||||
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id'
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
validates :name, :presence => true
|
validates_presence_of :name, :project
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 255
|
||||||
validates_length_of :external_url, :maximum => 255
|
validates_length_of :external_url, :maximum => 255
|
||||||
validate :validate_url
|
validate :validate_url
|
||||||
validates :project, :presence => true
|
|
||||||
|
|
||||||
def validate_url
|
def validate_url
|
||||||
if self.target_type == 'DmsfUrl'
|
if self.target_type == 'DmsfUrl'
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class DmsfWorkflow < ActiveRecord::Base
|
|||||||
scope :status, lambda { |arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
scope :status, lambda { |arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
||||||
|
|
||||||
validate :name_validation
|
validate :name_validation
|
||||||
validates :name, :presence => true
|
validates_presence_of :name
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 255
|
||||||
|
|
||||||
def name_validation
|
def name_validation
|
||||||
|
|||||||
@ -24,10 +24,7 @@ class DmsfWorkflowStep < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :dmsf_workflow_step_assignments, :dependent => :destroy
|
has_many :dmsf_workflow_step_assignments, :dependent => :destroy
|
||||||
|
|
||||||
validates :dmsf_workflow, :presence => true
|
validates_presence_of :dmsf_workflow, :step, :user, :operator
|
||||||
validates :step, :presence => true
|
|
||||||
validates :user, :presence => true
|
|
||||||
validates :operator, :presence => true
|
|
||||||
validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
|
validates_uniqueness_of :user_id, :scope => [:dmsf_workflow_id, :step]
|
||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
|
|
||||||
|
|||||||
@ -23,10 +23,8 @@ class DmsfWorkflowStepAction < ActiveRecord::Base
|
|||||||
belongs_to :dmsf_workflow_step_assignment
|
belongs_to :dmsf_workflow_step_assignment
|
||||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||||
|
|
||||||
validates :dmsf_workflow_step_assignment, :presence => true
|
validates_presence_of :dmsf_workflow_step_assignment, :action, :author_id
|
||||||
validates :action, :presence => true
|
validates_presence_of :note, :unless => lambda { self.action == DmsfWorkflowStepAction::ACTION_APPROVE }
|
||||||
validates :note, :presence => true, :unless => lambda { self.action == DmsfWorkflowStepAction::ACTION_APPROVE }
|
|
||||||
validates :author_id, :presence => true
|
|
||||||
validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action],
|
validates_uniqueness_of :dmsf_workflow_step_assignment_id, :scope => [:action],
|
||||||
:unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE}
|
:unless => lambda {self.action == DmsfWorkflowStepAction::ACTION_DELEGATE}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class DmsfWorkflowStepAssignment < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :dmsf_workflow_step_actions, :dependent => :destroy
|
has_many :dmsf_workflow_step_actions, :dependent => :destroy
|
||||||
|
|
||||||
validates :dmsf_workflow_step, :dmsf_file_revision, :presence => true
|
validates_presence_of :dmsf_workflow_step, :dmsf_file_revision
|
||||||
validates_uniqueness_of :dmsf_workflow_step_id, :scope => [:dmsf_file_revision_id]
|
validates_uniqueness_of :dmsf_workflow_step_id, :scope => [:dmsf_file_revision_id]
|
||||||
|
|
||||||
def add?(dmsf_file_revision_id)
|
def add?(dmsf_file_revision_id)
|
||||||
|
|||||||
@ -240,7 +240,20 @@ class DmsfFileRevisionTest < RedmineDmsf::Test::UnitTest
|
|||||||
User.current = @jsmith
|
User.current = @jsmith
|
||||||
assert !@revision1.obsolete
|
assert !@revision1.obsolete
|
||||||
assert_equal 1, @revision1.errors.count
|
assert_equal 1, @revision1.errors.count
|
||||||
@revision1.errors.full_messages.to_sentence.include?(l(:error_file_is_locked))
|
assert @revision1.errors.full_messages.to_sentence.include?(l(:error_file_is_locked))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_minor_version_cannot_be_nil
|
||||||
|
@revision1.minor_version = nil
|
||||||
|
assert !@revision1.save
|
||||||
|
assert @revision1.errors.full_messages.to_sentence.include?('Minor version cannot be blank')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_major_version_cannot_be_nil
|
||||||
|
@revision1.major_version = nil
|
||||||
|
assert !@revision1.save
|
||||||
|
puts @revision1.errors.full_messages.to_sentence
|
||||||
|
assert @revision1.errors.full_messages.to_sentence.include?('Major version cannot be blank')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user