Commit 55c79e0ce0e931758addd3f883fc42588ddc13d9
1 parent
692325d6
Exists in
master
and in
28 other branches
Do not allow usp id as empty string
Showing
2 changed files
with
11 additions
and
0 deletions
Show diff stats
plugins/stoa/lib/ext/person.rb
| ... | ... | @@ -5,6 +5,10 @@ class Person |
| 5 | 5 | settings_items :invitation_code |
| 6 | 6 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} |
| 7 | 7 | |
| 8 | + before_validation do |person| | |
| 9 | + person.usp_id = nil if person.usp_id.blank? | |
| 10 | + end | |
| 11 | + | |
| 8 | 12 | def usp_id_or_invitation |
| 9 | 13 | if usp_id.blank? && (invitation_code.blank? || !invitation_task) |
| 10 | 14 | errors.add(:usp_id, "can't register without usp_id or a valid invitation code") | ... | ... |
plugins/stoa/test/unit/person_test.rb
| ... | ... | @@ -18,6 +18,13 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
| 18 | 18 | assert another_person.errors.invalid?(:usp_id) |
| 19 | 19 | end |
| 20 | 20 | |
| 21 | + should 'not allow usp_id as an empty string' do | |
| 22 | + person = Person.new(:usp_id => '') | |
| 23 | + person.valid? | |
| 24 | + | |
| 25 | + assert_nil person.usp_id | |
| 26 | + end | |
| 27 | + | |
| 21 | 28 | should 'allow nil usp_id only if person has an invitation_code' do |
| 22 | 29 | person = Person.new(:environment => environment) |
| 23 | 30 | person.valid? | ... | ... |