added a couple of validations on the Oauth models, added an index on a user's authorizations

This commit is contained in:
Ilya Zhitomirskiy 2011-06-20 18:27:21 -07:00
parent 75a1012c1c
commit c09fb776fb
5 changed files with 37 additions and 2 deletions

View file

@ -0,0 +1,4 @@
class OAuth2::Provider::Models::ActiveRecord::Authorization
validates_presence_of :resource_owner_id, :resource_owner_type
validates_uniqueness_of [:resource_owner_id, :resource_owner_type] , :scope => :client_id
end

View file

@ -32,9 +32,13 @@ class AddOauth2Tables < ActiveRecord::Migration
t.datetime 'created_at'
t.datetime 'updated_at'
end
add_index "oauth_authorizations", ["resource_owner_id", "resource_owner_type", "client_id"], :unque => true, :name => "index_oauth_authorizations_on_resource_owner_and_client_id"
end
def self.down
remove_index "oauth_authorizations", ["resource_owner_id", "resource_owner_type", "client_id"]
drop_table 'oauth_access_tokens'
drop_table 'oauth_authorizations'
drop_table 'oauth_authorization_codes'

View file

@ -221,6 +221,8 @@ ActiveRecord::Schema.define(:version => 20110614005205) do
t.datetime "expires_at"
end
add_index "oauth_authorizations", ["resource_owner_id", "resource_owner_type", "client_id"], :name => "index_oauth_authorizations_on_resource_owner_and_client_id"
create_table "oauth_clients", :force => true do |t|
t.string "name"
t.string "oauth_identifier", :limit => 32, :null => false

View file

@ -0,0 +1,23 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
require 'spec_helper'
describe OAuth2::Provider::Models::ActiveRecord::Authorization do
describe 'validations'do
before do
@client = OAuth2::Provider::Models::ActiveRecord::Client.create!(:name => "APP!!!")
end
it 'validates uniqueness on resource owner and client' do
OAuth2::Provider::Models::ActiveRecord::Authorization.create!(:client => @client, :resource_owner => alice)
OAuth2::Provider::Models::ActiveRecord::Authorization.new(:client => @client, :resource_owner => alice).valid?.should be_false
end
it 'requires a resource owner for an authorization' do
OAuth2::Provider::Models::ActiveRecord::Authorization.new(:client => @client).valid?.should be_false
end
end
end

View file

@ -5,9 +5,11 @@
require 'spec_helper'
describe OAuth2::Provider::Models::ActiveRecord::Client do
#TODO
describe 'validations'do
it 'is pending for now'
it 'validates uniqueness on identifier' do
OAuth2::Provider::Models::ActiveRecord::Client.create(:oauth_identifier => "three")
OAuth2::Provider::Models::ActiveRecord::Client.new(:oauth_identifier => "three").valid?.should be_false
end
end
end