Commit d244c6317380c79098e85995c5cdde3c55cbfbe6
1 parent
b30ec443
Exists in
master
and in
29 other branches
[stoa] Check if the invitation code was already used
Showing
2 changed files
with
17 additions
and
3 deletions
Show diff stats
plugins/stoa/lib/ext/person.rb
... | ... | @@ -6,7 +6,7 @@ class Person |
6 | 6 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} |
7 | 7 | |
8 | 8 | def usp_id_or_invitation |
9 | - if usp_id.blank? && (invitation_code.blank? || !Task.find(:first, :conditions => {:code => invitation_code})) | |
9 | + if usp_id.blank? && (invitation_code.blank? || !Task.pending.find(:first, :conditions => {:code => invitation_code})) | |
10 | 10 | errors.add(:usp_id, "can't register without usp_id or invitation") |
11 | 11 | end |
12 | 12 | end | ... | ... |
plugins/stoa/test/unit/person.rb
... | ... | @@ -2,6 +2,13 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | |
3 | 3 | class StoaPlugin::Person < ActiveSupport::TestCase |
4 | 4 | |
5 | + def setup | |
6 | + @environment = Environment.default | |
7 | + @environment.enable_plugin(StoaPlugin) | |
8 | + end | |
9 | + | |
10 | + attr_reader :environment | |
11 | + | |
5 | 12 | should 'validates uniqueness of usp_id' do |
6 | 13 | usp_id = 87654321 |
7 | 14 | fast_create(Person, :usp_id => usp_id) |
... | ... | @@ -12,8 +19,6 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
12 | 19 | end |
13 | 20 | |
14 | 21 | should 'allow nil usp_id only if person has an invitation_code' do |
15 | - environment = Environment.default | |
16 | - environment.enable_plugin(StoaPlugin) | |
17 | 22 | person = Person.new(:environment => environment) |
18 | 23 | person.valid? |
19 | 24 | assert person.errors.invalid?(:usp_id) |
... | ... | @@ -34,5 +39,14 @@ class StoaPlugin::Person < ActiveSupport::TestCase |
34 | 39 | assert !person.errors.invalid?(:usp_id) |
35 | 40 | end |
36 | 41 | |
42 | + should 'not allow person register with a finished task' do | |
43 | + t = Task.create!(:code => 87654321) | |
44 | + t.finish | |
45 | + person = Person.new(:environment => environment, :invitation_code => 87654321) | |
46 | + person.valid? | |
47 | + | |
48 | + assert person.errors.invalid?(:usp_id) | |
49 | + end | |
50 | + | |
37 | 51 | end |
38 | 52 | ... | ... |