From 5d899f57dd238f180aa6974807486783ffabbb26 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sat, 1 Mar 2014 20:36:51 -0600 Subject: [PATCH] complete unit tests for api_scoring_controller and add some better test data --- db/manifest | 1 + db/up/scores_better_test_data.sql | 71 +++++++ ruby/lib/jam_ruby/models/jam_isp.rb | 10 +- web/app/controllers/api_scoring_controller.rb | 34 +-- .../api_scoring_controller_spec.rb | 200 ++++++++++++------ 5 files changed, 228 insertions(+), 88 deletions(-) create mode 100644 db/up/scores_better_test_data.sql diff --git a/db/manifest b/db/manifest index f82a62034..175b7a29b 100755 --- a/db/manifest +++ b/db/manifest @@ -125,3 +125,4 @@ scores_mod_connections2.sql track_download_counts.sql scores_mod_users2.sql user_bio.sql +scores_better_test_data.sql diff --git a/db/up/scores_better_test_data.sql b/db/up/scores_better_test_data.sql new file mode 100644 index 000000000..89ad5f388 --- /dev/null +++ b/db/up/scores_better_test_data.sql @@ -0,0 +1,71 @@ +-- cooking up some better test data for use with findblah + +delete from GeoIPLocations; +insert into GeoIPLocations (locId, countryCode, region, city, postalCode, latitude, longitude, metroCode, areaCode) values + (17192,'US','TX','Austin','78749',30.2076,-97.8587,635,'512'), + (667,'US','TX','Dallas','75207',32.7825,-96.8207,623,'214'), + (30350,'US','TX','Houston','77001',29.7633,-95.3633,618,'713'), + (31423,'US','CO','Denver','80201',39.7392,-104.9847,751,'303'), + (1807,'US','TX','San Antonio','78201',29.4713,-98.5353,641,'210'), + (23565,'US','FL','Miami','33101',25.7743,-80.1937,528,'305'), + (11704,'US','FL','Tampa','33601',27.9475,-82.4584,539,'813'), + (26424,'US','MA','Boston','02101',42.3584,-71.0598,506,'617'), + (5059,'US','ME','Portland','04101',43.6589,-70.2615,500,'207'), + (2739,'US','OR','Portland','97201',45.5073,-122.6932,820,'503'), + (1539,'US','WA','Seattle','98101',47.6103,-122.3341,819,'206'), + (2720,'US','CA','Mountain View','94040',37.3845,-122.0881,807,'650'), + (154078,'US','AR','Mountain View','72560',35.8732,-92.0717,693,'870'), + (3964,'US','CA','Barstow','92311',34.9701,-116.9929,803,'760'), + (14447,'US','OK','Tulsa','74101',36.154,-95.9928,671,'918'), + (162129,'US','TN','Memphis','37501',35.1693,-89.9904,640,'713'); + +delete from GeoIPBlocks; +insert into GeoIPBlocks (beginIp, endIp, locId) values + (x'00000000'::bigint,x'0FFFFFFF'::bigint,17192), + (x'10000000'::bigint,x'1FFFFFFF'::bigint,667), + (x'20000000'::bigint,x'2FFFFFFF'::bigint,30350), + (x'30000000'::bigint,x'3FFFFFFF'::bigint,31423), + (x'40000000'::bigint,x'4FFFFFFF'::bigint,1807), + (x'50000000'::bigint,x'5FFFFFFF'::bigint,23565), + (x'60000000'::bigint,x'6FFFFFFF'::bigint,11704), + (x'70000000'::bigint,x'7FFFFFFF'::bigint,26424), + (x'80000000'::bigint,x'8FFFFFFF'::bigint,5059), + (x'90000000'::bigint,x'9FFFFFFF'::bigint,2739), + (x'A0000000'::bigint,x'AFFFFFFF'::bigint,1539), + (x'B0000000'::bigint,x'BFFFFFFF'::bigint,2720), + (x'C0000000'::bigint,x'CFFFFFFF'::bigint,154078), + (x'D0000000'::bigint,x'DFFFFFFF'::bigint,3964), + (x'E0000000'::bigint,x'EFFFFFFF'::bigint,14447), + (x'F0000000'::bigint,x'FFFEFFFF'::bigint,162129); +-- (x'FFFF0000'::bigint,x'FFFFFFFF'::bigint,bogus) + +delete from GeoIPISP; +insert into GeoIPISP values + (x'00000000'::bigint,x'0FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'10000000'::bigint,x'1FFFFFFF'::bigint,'Powerful Pipes'), + (x'20000000'::bigint,x'2FFFFFFF'::bigint,'Powerful Pipes'), + (x'30000000'::bigint,x'3FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'40000000'::bigint,x'4FFFFFFF'::bigint,'Tangled Webs'), + (x'50000000'::bigint,x'5FFFFFFF'::bigint,'Tangled Webs'), + (x'60000000'::bigint,x'6FFFFFFF'::bigint,'Powerful Pipes'), + (x'70000000'::bigint,x'7FFFFFFF'::bigint,'Intergalactic Boogie'), + (x'80000000'::bigint,x'8FFFFFFF'::bigint,'Greasy Lightning'), + (x'90000000'::bigint,x'9FFFFFFF'::bigint,'Powerful Pipes'), + (x'A0000000'::bigint,x'AFFFFFFF'::bigint,'Intergalactic Boogie'), + (x'B0000000'::bigint,x'BFFFFFFF'::bigint,'Tangled Webs'), + (x'C0000000'::bigint,x'CFFFFFFF'::bigint,'Greasy Lightning'), + (x'D0000000'::bigint,x'DFFFFFFF'::bigint,'Tangled Webs'), + (x'E0000000'::bigint,x'EFFFFFFF'::bigint,'Intergalactic Boogie'), + (x'F0000000'::bigint,x'FFFEFFFF'::bigint,'Powerful Pipes'); +-- (x'FFFF0000'::bigint,x'FFFFFFFF'::bigint,'bogus') + +DELETE FROM jamcompany; +ALTER SEQUENCE jamcompany_coid_seq RESTART WITH 1; +INSERT INTO jamcompany (company) SELECT DISTINCT company FROM geoipisp ORDER BY company; + +DELETE FROM jamisp; +INSERT INTO jamisp (beginip, endip, coid) SELECT x.beginip, x.endip, y.coid FROM geoipisp x, jamcompany y WHERE x.company = y.company; + +UPDATE geoiplocations SET geog = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography; +UPDATE geoipblocks SET geom = ST_MakeEnvelope(beginip, -1, endip, 1); +UPDATE jamisp SET geom = ST_MakeEnvelope(beginip, -1, endip, 1); diff --git a/ruby/lib/jam_ruby/models/jam_isp.rb b/ruby/lib/jam_ruby/models/jam_isp.rb index 680cd302a..3c2c7bb81 100644 --- a/ruby/lib/jam_ruby/models/jam_isp.rb +++ b/ruby/lib/jam_ruby/models/jam_isp.rb @@ -6,9 +6,13 @@ module JamRuby self.table_name = 'jamisp' def self.ip_to_num(ip_addr) - i = IPAddr.new(ip_addr) - return i.to_i if i.ipv4? - nil + begin + i = IPAddr.new(ip_addr) + return i.to_i if i.ipv4? + nil + rescue IPAddr::InvalidAddressError + nil + end end def self.lookup(ipnum) diff --git a/web/app/controllers/api_scoring_controller.rb b/web/app/controllers/api_scoring_controller.rb index eff9dd485..5ba61122d 100644 --- a/web/app/controllers/api_scoring_controller.rb +++ b/web/app/controllers/api_scoring_controller.rb @@ -4,32 +4,32 @@ class ApiScoringController < ApiController before_filter :api_signed_in_user def work # clientid; returns another clientid - client_id = params[:clientid] - if client_id.nil? then render :json => {message: 'client_id not specified'}, :status => 400; return end + clientid = params[:clientid] + if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - c = Connection.where(client_id: client_id).first - if c.nil? then render :json => {message: 'connection not found'}, :status => 404; return end - if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end + conn = Connection.where(client_id: clientid).first + if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end + if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end # todo this method is a stub - #puts "ApiScoringController#work(#{client_id}) => locidispid #{c.locidispid}" - result_client_id = JamRuby::GetWork.get_work(c.locidispid) - #result_client_id = client_id+'peer' + #puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}" + result_client_id = JamRuby::GetWork.get_work(conn.locidispid) + #result_client_id = clientid+'peer' render :json => {:clientid => result_client_id}, :status => 200 end def worklist # clientid; returns a list of clientid - client_id = params[:clientid] - if client_id.nil? then render :json => {message: 'client_id not specified'}, :status => 400; return end + clientid = params[:clientid] + if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end - c = Connection.where(client_id: client_id).first - if c.nil? then render :json => {message: 'connection not found'}, :status => 404; return end - if !c.user.id.eql?(current_user.id) then render :json => {message: 'user does not own client_id'}, :status => 403; return end + conn = Connection.where(client_id: clientid).first + if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end + if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end # todo this method is a stub - result_client_ids = JamRuby::GetWork.get_work_list(c.locidispid) - #result_client_ids = [client_id+'peer1', client_id+'peer2'] + result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid) + #result_client_ids = [clientid+'peer1', clientid+'peer2'] render :json => {:clientids => result_client_ids}, :status => 200 end @@ -49,7 +49,7 @@ class ApiScoringController < ApiController if bip_address.nil? then render :json => {message: 'bAddr not specified'}, :status => 400; return end # no score means the test was run but failed, details should still be recorded for later consideration - if score.nil? then render :json => {message: 'score not specified'}, :status => 200; return end + if score.nil? then render :json => {message: 'score not specified'}, :status => 400; return end aAddr = JamRuby::JamIsp.ip_to_num(aip_address) if aAddr.nil? then render :json => {message: 'aAddr not valid ip_address'}, :status => 400; return end @@ -64,7 +64,7 @@ class ApiScoringController < ApiController aconn = Connection.where(client_id: aclientid).first if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end - if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\' session not owned by user'}, :status => 403; return end + if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not owned by user'}, :status => 403; return end bconn = Connection.where(client_id: bclientid).first if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end diff --git a/web/spec/controllers/api_scoring_controller_spec.rb b/web/spec/controllers/api_scoring_controller_spec.rb index 0cc5399dc..7a3b71911 100644 --- a/web/spec/controllers/api_scoring_controller_spec.rb +++ b/web/spec/controllers/api_scoring_controller_spec.rb @@ -4,17 +4,21 @@ describe ApiScoringController do render_views BOGUS_CLIENT_ID = 'nobodyclientid' - BOGUS_IP_ADDRESS = '0.0.0.0' + BOGUS_IP_ADDRESS = '1.2.3.4' + BAD_IP_ADDRESS = 'a.b.c.d' MARY_IP_ADDRESS = '75.92.54.210' # 1264334546, 4B.5C.36.D2 MARY_ADDR = 1264334546 + MARY_LOCIDISPID = 17192008423 MIKE_IP_ADDRESS = '173.172.108.1' # 2913758209, AD.AC.6C.01 MIKE_ADDR = 2913758209 - - MARY_LOCIDISPID = 17192008423 MIKE_LOCIDISPID = 17192043640 + JOHN_IP_ADDRESS = '255.255.1.2' # 4294902018, FF.FF.01.02 + JOHN_ADDR = 4294902018 + JOHN_LOCIDISPID = 0 + before do @mary = FactoryGirl.create(:user, first_name: 'mary') @mary_connection = FactoryGirl.create(:connection, user: @mary, ip_address: MARY_IP_ADDRESS, addr: MARY_ADDR, locidispid: MARY_LOCIDISPID) @@ -23,6 +27,10 @@ describe ApiScoringController do @mike = FactoryGirl.create(:user, first_name: 'mike') @mike_connection = FactoryGirl.create(:connection, user: @mike, ip_address: MIKE_IP_ADDRESS, addr: MIKE_ADDR, locidispid: MIKE_LOCIDISPID) @mike_client_id = @mike_connection.client_id + + @john = FactoryGirl.create(:user, first_name: 'john') + @john_connection = FactoryGirl.create(:connection, user: @john, ip_address: JOHN_IP_ADDRESS, addr: JOHN_ADDR, locidispid: JOHN_LOCIDISPID) + @john_client_id = @john_connection.client_id end after do @@ -30,6 +38,8 @@ describe ApiScoringController do @mary.delete @mike_connection.delete @mike.delete + @john_connection.delete + @john.delete end before(:each) do @@ -40,34 +50,34 @@ describe ApiScoringController do describe 'work' do - it 'try work with nobody and nobody' do - controller.current_user = nil - get :work, {} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'try work with mary and nobody' do - controller.current_user = @mary - get :work, {} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'try work with nobody and mary' do + it 'try work with nobody login and mary' do controller.current_user = nil get :work, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try work with mary and mary' do + it 'try work with mary login and nothing' do + controller.current_user = @mary + get :work, {} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('clientid not specified') + end + + it 'try work with mary login and bogus' do + controller.current_user = @mary + get :work, {clientid: BOGUS_CLIENT_ID} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('session not found') + end + + it 'try work with mary login and mary' do controller.current_user = @mary get :work, {clientid: @mary_client_id} response.should be_success @@ -77,7 +87,7 @@ describe ApiScoringController do [@mary_client_id, @mike_client_id].should include(json[:clientid]) end - it 'try work with mike and mike' do + it 'try work with mike login and mike' do controller.current_user = @mike get :work, {clientid: @mike_client_id} response.should be_success @@ -87,47 +97,56 @@ describe ApiScoringController do [@mary_client_id, @mike_client_id].should include(json[:clientid]) end - it 'try work with mike and mary' do + it 'try work with mary login and mike' do + controller.current_user = @mary + get :work, {clientid: @mike_client_id} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('session not owned by user') + end + + it 'try work with mike login and mary' do controller.current_user = @mike get :work, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('session not owned by user') end end describe 'worklist' do - it 'try worklist with nobody and nobody' do + it 'try worklist with nobody login and nobody' do controller.current_user = nil get :worklist, {} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try worklist with mary and nobody' do + it 'try worklist with mary login and nobody' do controller.current_user = @mary get :worklist, {} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('clientid not specified') end - it 'try worklist with nobody and mary' do + it 'try worklist with nobody login and mary' do controller.current_user = nil get :worklist, {clientid: @mary_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end - it 'try worklist with mary and mary' do + it 'try worklist with mary login and mary' do controller.current_user = @mary get :worklist, {clientid: @mary_client_id} response.should be_success @@ -142,7 +161,7 @@ describe ApiScoringController do end - it 'try worklist with mike and mike' do + it 'try worklist with mike login and mike' do controller.current_user = @mike get :worklist, {clientid: @mike_client_id} response.should be_success @@ -156,26 +175,26 @@ describe ApiScoringController do json[:clientids][0].should_not eql(json[:clientids][1]) end - it 'try worklist with mary and mike' do + it 'try worklist with mary login and mike' do controller.current_user = @mary get :worklist, {clientid: @mike_client_id} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('session not owned by user') end end describe 'record' do - it 'record with no login, mary, mary_ip_address, mike, mike_addr, score' do + it 'record with nobody login, mary, mary_ip_address, mike, mike_addr, score' do controller.current_user = nil post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('not logged in') end it 'record with mary login, nil, mary_addr, mike, mike_addr, score' do @@ -184,7 +203,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aclientid not specified') end it 'record with mary login, mary, nil, mike, mike_addr, score' do @@ -193,7 +212,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aAddr not specified') end it 'record with mary login, mary, mary_addr, nil, mike_addr, score' do @@ -202,7 +221,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('bclientid not specified') end it 'record with mary login, mary, mary_addr, mike, nil, score' do @@ -211,7 +230,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('bAddr not specified') end it 'record with mary login, mary, mary_addr, mike, mike_addr, nil' do @@ -220,7 +239,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('score not specified') end it 'record with mary login, bogus, mary_addr, mike, mike_addr, score' do @@ -229,7 +248,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session not found') end it 'record with mary login, mary, mary_addr, bogus, mike_addr, score' do @@ -238,7 +257,16 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('b\'s session not found') + end + + it 'record with mary login, mary, bogus, mike, mike_addr, score' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => BAD_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('aAddr not valid ip_address') end it 'record with mary login, mary, bogus, mike, mike_addr, score' do @@ -247,7 +275,16 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session addr does not match aAddr') + end + + it 'record with mary login, mary, mary_addr, mike, bogus, score' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => BAD_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('bAddr not valid ip_address') end it 'record with mary login, mary, mary_addr, mike, bogus, score' do @@ -256,7 +293,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('b\'s session addr does not match bAddr') end it 'record with mary login, mike, mike_addr, mary, mary_addr, score' do @@ -265,25 +302,7 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil - end - - it 'record with mary login, mary, mary_addr, mike, mike_addr, -1' do - controller.current_user = @mary - post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => -1} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil - end - - it 'record with mary login, mary, mary_addr, mike, mike_addr, 1000' do - controller.current_user = @mary - post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 1000} - response.should_not be_success - json = JSON.parse(response.body, :symbolize_names => true) - json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('a\'s session not owned by user') end it 'record with mary login, mary, mary_addr, mary, mary_addr, score' do @@ -292,7 +311,52 @@ describe ApiScoringController do response.should_not be_success json = JSON.parse(response.body, :symbolize_names => true) json.length.should == 1 - json[:message].should_not be_nil + json[:message].should eql('aAddr and bAddr are the same') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, -1' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => -1} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score < 0 or score > 999') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, 1000' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 1000} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score < 0 or score > 999') + end + + it 'record with mary login, mary, mary_addr, mike, mike_addr, bogus' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 'abc'} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('score not valid numeric') + end + + it 'record with john login, john, john_addr, mike, mike_addr, bogus' do + controller.current_user = @john + post :record, {:format => 'json', :aclientid => @john_client_id, :aAddr => JOHN_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('a\'s location or isp not found') + end + + it 'record with mary login, mary, mary_addr, john, john_addr, bogus' do + controller.current_user = @mary + post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @john_client_id, :bAddr => JOHN_IP_ADDRESS, :score => 20} + response.should_not be_success + json = JSON.parse(response.body, :symbolize_names => true) + json.length.should == 1 + json[:message].should eql('b\'s location or isp not found') end it 'record with mary login, mary, mary_addr, mike, mike_addr, score' do