Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Sonnek committed Oct 14, 2011
1 parent 5317652 commit 8c75f9b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/models/devise/oauth2_providable/client.rb
@@ -1,6 +1,7 @@
class Devise::Oauth2Providable::Client < ActiveRecord::Base
has_many :access_tokens
has_many :refresh_tokens
has_many :authorization_codes

before_validation :init_identifier, :on => :create, :unless => :identifier?
before_validation :init_secret, :on => :create, :unless => :secret?
Expand Down
4 changes: 2 additions & 2 deletions lib/devise/oauth2_providable/model.rb
Expand Up @@ -5,8 +5,8 @@ module Models
module Oauth2Providable
extend ActiveSupport::Concern
included do
has_many :access_tokens
has_many :authorization_codes
has_many :access_tokens, :class_name => 'Devise::Oauth2Providable::AccessToken'
has_many :authorization_codes, :class_name => 'Devise::Oauth2Providable::AuthorizationCode'
end
end
end
Expand Down
Expand Up @@ -8,7 +8,7 @@ def grant_type
end

def authenticate!
if client && code = AuthorizationCode.valid.find_by_token(params[:code])
if client && code = client.authorization_codes.valid.find_by_token(params[:code])
success! code.user
elsif !halted?
oauth_error! :invalid_grant, 'invalid authorization code request'
Expand Down
Expand Up @@ -6,7 +6,7 @@
context 'with valid params' do
before do
@user = User.create! :email => 'ryan@socialcast.com', :password => 'test'
@client = Client.create! :name => 'example', :redirect_uri => 'http://localhost', :website => 'http://localhost'
@client = Devise::Oauth2Providable::Client.create! :name => 'example', :redirect_uri => 'http://localhost', :website => 'http://localhost'
@refresh_token = @client.refresh_tokens.create! :user => @user
params = {
:grant_type => 'refresh_token',
Expand All @@ -20,7 +20,7 @@
it { response.code.to_i.should == 200 }
it { response.content_type.should == 'application/json' }
it 'returns json' do
token = AccessToken.last
token = Devise::Oauth2Providable::AccessToken.last
refresh_token = @refresh_token
expected = {
:token_type => 'bearer',
Expand All @@ -34,7 +34,7 @@
context 'with invalid refresh_token' do
before do
@user = User.create! :email => 'ryan@socialcast.com', :password => 'test'
@client = Client.create! :name => 'example', :redirect_uri => 'http://localhost', :website => 'http://localhost'
@client = Devise::Oauth2Providable::Client.create! :name => 'example', :redirect_uri => 'http://localhost', :website => 'http://localhost'
@refresh_token = @client.refresh_tokens.create! :user => @user
params = {
:grant_type => 'refresh_token',
Expand All @@ -48,7 +48,7 @@
it { response.code.to_i.should == 400 }
it { response.content_type.should == 'application/json' }
it 'returns json' do
token = AccessToken.last
token = Devise::Oauth2Providable::AccessToken.last
refresh_token = @refresh_token
expected = {
:error => 'invalid_grant',
Expand Down
1 change: 1 addition & 0 deletions spec/models/client_spec.rb
Expand Up @@ -17,5 +17,6 @@
it { should_not allow_mass_assignment_of :identifier }
it { should_not allow_mass_assignment_of :secret }
it { should have_many :refresh_tokens }
it { should have_many :authorization_codes }
end
end

0 comments on commit 8c75f9b

Please sign in to comment.