* VRFS-773 - isp page avaible
This commit is contained in:
parent
f7d31668d4
commit
482c2cece3
|
|
@ -0,0 +1,5 @@
|
|||
ActiveAdmin.register JamRuby::IspScoreBatch, :as => 'Isp Score Data' do
|
||||
|
||||
config.sort_order = 'created_at_desc'
|
||||
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
ActiveAdmin.register JamRuby::ArtifactUpdate do
|
||||
ActiveAdmin.register JamRuby::ArtifactUpdate, :as => 'Artifacts' do
|
||||
menu :label => 'Artifacts'
|
||||
|
||||
config.sort_order = 'product,environment'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
ActiveAdmin.register JamRuby::InvitedUser do
|
||||
ActiveAdmin.register JamRuby::InvitedUser, :as => 'Invited Users' do
|
||||
menu :label => 'Invite Users'
|
||||
|
||||
config.sort_order = 'created_at'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
ActiveAdmin.register JamRuby::User do
|
||||
ActiveAdmin.register JamRuby::User, :as => 'Users' do
|
||||
|
||||
menu :label => 'Jam User'
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ require "will_paginate/active_record"
|
|||
require "action_mailer"
|
||||
require "devise"
|
||||
require "sendgrid"
|
||||
require 'postgres-copy'
|
||||
require "postgres-copy"
|
||||
require "jam_ruby/lib/module_overrides"
|
||||
require "jam_ruby/constants/limits"
|
||||
require "jam_ruby/constants/notification_types"
|
||||
require "jam_ruby/constants/validation_messages"
|
||||
|
|
@ -75,9 +76,10 @@ require "jam_ruby/models/recorded_track"
|
|||
require "jam_ruby/models/mix"
|
||||
require "jam_ruby/models/claimed_recording"
|
||||
require "jam_ruby/models/crash_dump"
|
||||
require "jam_ruby/models/isp_score_batch"
|
||||
|
||||
include Jampb
|
||||
|
||||
module JamRuby
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
require 'json'
|
||||
|
||||
class String
|
||||
def is_json?
|
||||
begin
|
||||
!!JSON.parse(self)
|
||||
rescue
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
module JamRuby
|
||||
class IspScoreBatch < ActiveRecord::Base
|
||||
|
||||
self.primary_key = 'id'
|
||||
self.table_name = 'isp_score_batch'
|
||||
attr_accessible :json_scoring_data
|
||||
|
||||
validates :json_scoring_data, :presence => true
|
||||
|
||||
validate :json_format
|
||||
|
||||
def json_format
|
||||
errors[:json_scoring_data] << "not in json format" unless !json_scoring_data.nil? && json_scoring_data.is_json?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe IspScoreBatch do
|
||||
|
||||
let (:score) {IspScoreBatch.new}
|
||||
it "valid json" do
|
||||
score.json_scoring_data = "{}"
|
||||
score.save.should be_true
|
||||
end
|
||||
|
||||
it "no json" do
|
||||
score.save.should be_false
|
||||
end
|
||||
|
||||
it "invalid json" do
|
||||
score.json_scoring_data = "blurp a durp"
|
||||
score.save.should be_false
|
||||
end
|
||||
end
|
||||
|
|
@ -420,13 +420,14 @@ class ApiUsersController < ApiController
|
|||
end
|
||||
|
||||
def isp_scoring
|
||||
if request.post?
|
||||
data = request.body.read
|
||||
User.connection.execute("INSERT INTO isp_score_batch(json_scoring_data) VALUES ('#{data}')")
|
||||
data = request.body.read
|
||||
score = IspScoreBatch.new
|
||||
score.json_scoring_data = data
|
||||
if score.save
|
||||
render :text => 'scoring recorded'
|
||||
return
|
||||
else
|
||||
render :text => "score invalid: #{score.errors.inspect}", status:422
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
################# AVATAR #####################
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Isp Scores", :type => :api do
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
it "valid score" do
|
||||
post "/api/users/isp_scoring", { :some_data => 100} .to_json
|
||||
last_response.status.should == 200
|
||||
last_response.body.should == "scoring recorded"
|
||||
end
|
||||
|
||||
it "invalid score - not json" do
|
||||
post "/api/users/isp_scoring", "some data = 100"
|
||||
last_response.status.should == 422
|
||||
last_response.body.include?("score invalid").should be_true
|
||||
end
|
||||
end
|
||||
|
|
@ -973,7 +973,6 @@ describe "User API", :type => :api do
|
|||
describe "hidden permissions" do
|
||||
it { other_user_response["email"].should be_nil }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue