connect logic

This commit is contained in:
danielgrippi 2011-08-09 17:22:22 -07:00 committed by Maxwell Salzberg
parent 7a5fc11505
commit 27049e52b5
6 changed files with 55 additions and 22 deletions

View file

@ -119,6 +119,6 @@ group :test do
gem 'rspec-instafail', '>= 0.1.7', :require => false gem 'rspec-instafail', '>= 0.1.7', :require => false
gem 'fuubar' gem 'fuubar'
gem 'diaspora-client', :git => 'git://github.com/diaspora/diaspora-client.git' gem 'diaspora-client', :path => '~/workspace/diaspora-client' #:git => 'git://github.com/diaspora/diaspora-client.git'
end end

View file

@ -29,17 +29,6 @@ GIT
acts-as-taggable-on (2.0.6) acts-as-taggable-on (2.0.6)
rails (>= 3.0) rails (>= 3.0)
GIT
remote: git://github.com/diaspora/diaspora-client.git
revision: 9dc2c29495c7bf040ceceecdf88800f4c91f870c
specs:
diaspora-client (0.0.0)
activerecord
faraday
jwt (>= 0.1.3)
oauth2
sinatra
GIT GIT
remote: git://github.com/iain/http_accept_language.git remote: git://github.com/iain/http_accept_language.git
revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d
@ -63,6 +52,16 @@ GIT
jwt (0.1.3) jwt (0.1.3)
json (>= 1.2.4) json (>= 1.2.4)
PATH
remote: ~/workspace/diaspora-client
specs:
diaspora-client (0.0.0)
activerecord
faraday
jwt (>= 0.1.3)
oauth2
sinatra
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:

View file

@ -11,7 +11,11 @@ class AuthorizationsController < ApplicationController
def new def new
@requested_scopes = params["scope"].split(',') @requested_scopes = params["scope"].split(',')
@client = oauth2_authorization_request.client @client = oauth2_authorization_request.client
#render :layout => "popup" if params[:popup]
if current_user.applications.present?
tokens = current_user.authorizations.first.access_tokens.first
redirect_to "#{params[:redirect_uri]}&access_token=#{tokens.access_token}&refresh_token=#{tokens.refresh_token}"
end
end end
def create def create

View file

@ -16,12 +16,21 @@ Feature: oauth
And I should see my "profile.birthday" And I should see my "profile.birthday"
And I should see my "name" And I should see my "name"
Scenario: Signup+login (Diaspora Connect) with Chubbies
When I visit "/reset" on Chubbies
And I should have 0 user on Chubbies
And I try to authorize Chubbies
And I press "Authorize"
Then I should be on "/account" on Chubbies
And I should have 1 user on Chubbies
Scenario: Not authorize Chubbies Scenario: Not authorize Chubbies
When I try to authorize Chubbies When I try to authorize Chubbies
When I press "No" When I press "No"
Then I should be on "/account" on Chubbies Then I should be on "/account" on Chubbies
Then I should see "No access token." And I should have 0 user on Chubbies
Scenario: Authorize Chubbies when Chubbies is already connected Scenario: Authorize Chubbies when Chubbies is already connected
Given Chubbies is registered on my pod Given Chubbies is registered on my pod
@ -80,16 +89,18 @@ Feature: oauth
Scenario: Login in with Chubbies when you already authorized it Scenario: Login in with Chubbies when you already authorized it
Given Chubbies is registered on my pod Given Chubbies is registered on my pod
And I should have 0 user on Chubbies
When I try to authorize Chubbies When I try to authorize Chubbies
When I press "Authorize" When I press "Authorize"
Then I should be on "/account" on Chubbies Then I should be on "/account" on Chubbies
And I should see my "profile.birthday"
And I should see my "name"
And I should have 1 user on Chubbies
Then I visit "/new" on Chubbies Then I visit "/new" on Chubbies
And I fill in "Diaspora Handle" with "#{@me.diaspora_handle}" And I fill in my Diaspora ID to connect
And I press "Connect to Diaspora" And I press "Connect to Diaspora"
And I debug
Then I should be on "/account" on Chubbies Then I should be on "/account" on Chubbies
And I should have 1 user on Chubbies

View file

@ -35,7 +35,7 @@ When /^I try to authorize Chubbies$/ do
# as we are clearing the Diaspora DB every scenario # as we are clearing the Diaspora DB every scenario
Then 'I visit "/new" on Chubbies' Then 'I visit "/new" on Chubbies'
### ###
And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\"" And "I fill in my Diaspora ID to connect"
And 'I press "Connect to Diaspora"' And 'I press "Connect to Diaspora"'
Then 'I should be on the new user session page' Then 'I should be on the new user session page'
And "I fill in \"Username\" with \"#{@me.username}\"" And "I fill in \"Username\" with \"#{@me.username}\""
@ -46,8 +46,16 @@ When /^I try to authorize Chubbies$/ do
And 'I should see "The best way to chub."' And 'I should see "The best way to chub."'
end end
When /^I visit "([^"]+)" on Chubbies$/ do |path| And /^I fill in my Diaspora ID to connect$/ do
And "I fill in \"Diaspora Handle\" with \"#{@me.diaspora_handle}\""
end
And /^I should have (\d) user on Chubbies$/ do |num|
When "I visit \"/user_count\" on Chubbies"
Then "I should see \"#{num}\""
end
When /^I visit "([^"]+)" on Chubbies$/ do |path|
former_host = Capybara.app_host former_host = Capybara.app_host
Capybara.app_host = "localhost:#{Chubbies::PORT}" Capybara.app_host = "localhost:#{Chubbies::PORT}"
visit(path) visit(path)

View file

@ -31,6 +31,7 @@ module Chubbies
end end
add_index :access_tokens, :user_id, :unique => true add_index :access_tokens, :user_id, :unique => true
create_table :users do |t| create_table :users do |t|
t.string :username, :limit => 127
t.timestamps t.timestamps
end end
end end
@ -60,7 +61,7 @@ module Chubbies
class App < DiasporaClient::App class App < DiasporaClient::App
def current_user def current_user
User.first @user = User.first
end end
def redirect_path def redirect_path
@ -71,6 +72,13 @@ module Chubbies
'/account?id=1' '/account?id=1'
end end
def account_const
User
end
def create_account(*args)
account_const.create(args)
end
get '/account' do get '/account' do
if params['id'] && user = User.where(:id => params['id']).first if params['id'] && user = User.where(:id => params['id']).first
if user.access_token if user.access_token
@ -89,7 +97,6 @@ module Chubbies
end end
get '/new' do get '/new' do
@user = User.create
haml :home haml :home
end end
@ -104,5 +111,9 @@ module Chubbies
post '/register' do post '/register' do
DiasporaClient::ResourceServer.create!(params) DiasporaClient::ResourceServer.create!(params)
end end
get '/user_count' do
User.count.to_s
end
end end
end end