Skip to content

Commit

Permalink
connect logic
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrippi authored and maxwell committed Aug 23, 2011
1 parent 7a5fc11 commit 27049e5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ group :test do
gem 'rspec-instafail', '>= 0.1.7', :require => false
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
21 changes: 10 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ GIT
acts-as-taggable-on (2.0.6)
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
remote: git://github.com/iain/http_accept_language.git
revision: 0b78aa7849fc90cf9e12586af162fa4c408a795d
Expand All @@ -63,6 +52,16 @@ GIT
jwt (0.1.3)
json (>= 1.2.4)

PATH
remote: ~/workspace/diaspora-client
specs:
diaspora-client (0.0.0)
activerecord
faraday
jwt (>= 0.1.3)
oauth2
sinatra

GEM
remote: http://rubygems.org/
specs:
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/authorizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class AuthorizationsController < ApplicationController
def new
@requested_scopes = params["scope"].split(',')
@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

def create
Expand Down
21 changes: 16 additions & 5 deletions features/oauth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ Feature: oauth
And I should see my "profile.birthday"
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
When I try to authorize Chubbies

When I press "No"
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
Given Chubbies is registered on my pod
Expand Down Expand Up @@ -80,16 +89,18 @@ Feature: oauth

Scenario: Login in with Chubbies when you already authorized it
Given Chubbies is registered on my pod
And I should have 0 user on Chubbies

When I try to authorize Chubbies
When I press "Authorize"
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
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 debug
Then I should be on "/account" on Chubbies
And I should have 1 user on Chubbies


12 changes: 10 additions & 2 deletions features/step_definitions/oauth_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# as we are clearing the Diaspora DB every scenario
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"'
Then 'I should be on the new user session page'
And "I fill in \"Username\" with \"#{@me.username}\""
Expand All @@ -46,8 +46,16 @@
And 'I should see "The best way to chub."'
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
Capybara.app_host = "localhost:#{Chubbies::PORT}"
visit(path)
Expand Down
15 changes: 13 additions & 2 deletions spec/chubbies/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def self.reset_db
end
add_index :access_tokens, :user_id, :unique => true
create_table :users do |t|
t.string :username, :limit => 127
t.timestamps
end
end
Expand Down Expand Up @@ -60,7 +61,7 @@ class User < ActiveRecord::Base

class App < DiasporaClient::App
def current_user
User.first
@user = User.first
end

def redirect_path
Expand All @@ -71,6 +72,13 @@ def after_oauth_redirect_path
'/account?id=1'
end

def account_const
User
end
def create_account(*args)
account_const.create(args)
end

get '/account' do
if params['id'] && user = User.where(:id => params['id']).first
if user.access_token
Expand All @@ -89,7 +97,6 @@ def after_oauth_redirect_path
end

get '/new' do
@user = User.create
haml :home
end

Expand All @@ -104,5 +111,9 @@ def after_oauth_redirect_path
post '/register' do
DiasporaClient::ResourceServer.create!(params)
end

get '/user_count' do
User.count.to_s
end
end
end

0 comments on commit 27049e5

Please sign in to comment.