Commit 2340a574b286dd8597c8541894187f7eb4f04820
1 parent
3a971de0
Exists in
master
and in
28 other branches
[stoa] Validating uniqueness of usp_id
(ActionItem2293)
Showing
4 changed files
with
24 additions
and
1 deletions
Show diff stats
plugins/stoa/controllers/stoa_plugin_controller.rb
@@ -26,7 +26,7 @@ class StoaPluginController < PublicController | @@ -26,7 +26,7 @@ class StoaPluginController < PublicController | ||
26 | 26 | ||
27 | def check_usp_id | 27 | def check_usp_id |
28 | begin | 28 | begin |
29 | - render :text => { :exists => StoaPlugin::UspUser.exists?(params[:usp_id]) }.to_json | 29 | + render :text => { :exists => StoaPlugin::UspUser.exists?(params[:usp_id]) && Person.find_by_usp_id(params[:usp_id]).nil? }.to_json |
30 | rescue Exception => exception | 30 | rescue Exception => exception |
31 | render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json | 31 | render :text => { :exists => false, :error => {:message => exception.to_s, :backtrace => exception.backtrace} }.to_json |
32 | end | 32 | end |
plugins/stoa/lib/stoa_plugin.rb
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | + | ||
3 | +class StoaPlugin::Person < ActiveSupport::TestCase | ||
4 | + | ||
5 | + should 'validates uniqueness of usp_id' do | ||
6 | + usp_id = 12345678 | ||
7 | + person = create_user('some-person').person | ||
8 | + person.usp_id = usp_id | ||
9 | + person.save! | ||
10 | + another_person = Person.new(:name => "Another person", :identifier => 'another-person', :usp_id => usp_id) | ||
11 | + | ||
12 | + assert !another_person.valid? | ||
13 | + assert another_person.errors.invalid?(:usp_id) | ||
14 | + end | ||
15 | + | ||
16 | +end | ||
17 | + |