Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

uniqueness of intent moved to validate_on_create

  • Loading branch information...
commit 6330364aa68db42880f4beb5404f19ff28dbe44d 1 parent 0f590ed
@matthewvermaak authored
Showing with 5 additions and 3 deletions.
  1. +3 −1 app/models/sanction/role.rb
  2. +2 −2 tasks/sanction_tasks.rake
View
4 app/models/sanction/role.rb
@@ -11,7 +11,8 @@ class Sanction::Role < ActiveRecord::Base
validates_presence_of :name
validate :valid_role_definition
- validate :uniqueness_of_intent
+
+ validate_on_create :uniqueness_of_intent
# Ensure the role is valid by definition
def valid_role_definition
@@ -33,6 +34,7 @@ def uniqueness_of_intent
conditions = conds.map {|c| self.class.merge_conditions(c)}.join(" AND ")
if Sanction::Role.exists?([conditions])
errors.add_to_base("This role is already captured by another.")
+ false
else
true
end
View
4 tasks/sanction_tasks.rake
@@ -41,7 +41,7 @@ namespace :sanction do
desc "Validate the current roles table by validating against the Sanction::Role::Definitions currently configured."
task :validate => :environment do
- invalid_roles, valid_roles = (Sanction::Role.all || []).partition {|role| role.is_valid?}
+ valid_roles, invalid_roles = (Sanction::Role.all || []).partition {|role| role.valid?}
puts "#{invalid_roles.size} invalid roles."
puts "#{valid_roles.size} valid roles."
@@ -49,7 +49,7 @@ namespace :sanction do
desc "Validates the current roles table and removes invalid roles according to the Sanction::Role::Definitions currently configured."
task :cleanse => :environment do
- invalid_roles, valid_roles = (Sanction::Role.all || []).partition {|role| role.is_valid?}
+ valid_roles, invalid_roles = (Sanction::Role.all || []).partition {|role| role.valid?}
puts "#{invalid_roles.size} invalid roles."
Please sign in to comment.
Something went wrong with that request. Please try again.