From 67eaafe3a94e571d2a63c9503b4594071bcd9c17 Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Mon, 6 Jun 2011 15:42:58 -0700
Subject: [PATCH] Chubbies no longer saves diaspora_handle from the browser

---
 config/application.yml.example                |   2 +-
 db/schema.rb                                  |   1 -
 features/oauth.feature                        |   3 +-
 features/step_definitions/oauth_steps.rb      |  27 ++++++++++++------
 spec/{support => }/chubbies/Gemfile           |   2 +-
 spec/{support => }/chubbies/Gemfile.lock      |  18 ++++++------
 spec/{support => }/chubbies/README            |   0
 spec/{support => }/chubbies/app.rb            |  24 ++++++++++------
 spec/{support => }/chubbies/config.ru         |   0
 .../chubbies/public/chubbies.jpeg             | Bin
 spec/{support => }/chubbies/views/home.haml   |   0
 .../chubbies/views/response.haml              |   0
 12 files changed, 47 insertions(+), 30 deletions(-)
 rename spec/{support => }/chubbies/Gemfile (77%)
 rename spec/{support => }/chubbies/Gemfile.lock (69%)
 rename spec/{support => }/chubbies/README (100%)
 rename spec/{support => }/chubbies/app.rb (87%)
 rename spec/{support => }/chubbies/config.ru (100%)
 rename spec/{support => }/chubbies/public/chubbies.jpeg (100%)
 rename spec/{support => }/chubbies/views/home.haml (100%)
 rename spec/{support => }/chubbies/views/response.haml (100%)

diff --git a/config/application.yml.example b/config/application.yml.example
index b4a92f3b06..72083ba19f 100644
--- a/config/application.yml.example
+++ b/config/application.yml.example
@@ -139,7 +139,7 @@ production:
 # Do not touch unless you know what you're doing
 test:
   <<: *defaults
-  pod_url: "http://example.org"
+  pod_url: "http://localhost:9887"
   socket_port: 8081
   enable_splunk_logging: false
 
diff --git a/db/schema.rb b/db/schema.rb
index 9ed9700102..9f7bfa013a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -283,7 +283,6 @@ ActiveRecord::Schema.define(:version => 20110603212633) do
     t.string   "provider_display_name"
     t.string   "actor_url"
     t.integer  "objectId"
-    t.integer  "root_id"
     t.string   "status_message_guid"
   end
 
diff --git a/features/oauth.feature b/features/oauth.feature
index b4ca72831e..4826252361 100644
--- a/features/oauth.feature
+++ b/features/oauth.feature
@@ -3,7 +3,8 @@ Feature: oauth
   Exchanging oauth credentials
 
   Background:
-    Given Chubbies is running
+    Given Chubbies has been killed
+    And Chubbies is running
     When I visit "/" on Chubbies
     And a user with username "bob" and password "secret"
 
diff --git a/features/step_definitions/oauth_steps.rb b/features/step_definitions/oauth_steps.rb
index 9092b1adf8..326b8b14be 100644
--- a/features/step_definitions/oauth_steps.rb
+++ b/features/step_definitions/oauth_steps.rb
@@ -1,12 +1,9 @@
 Given /^Chubbies is running$/ do
-  if Chubbies.running?
-    puts "Chubbies is already running.  Killing it."
-    Chubbies.kill
-  end
-  Chubbies.run
-  at_exit do
-    Chubbies.kill
-  end
+  Chubbies.run unless Chubbies.running?
+end
+
+Given /^Chubbies has been killed$/ do
+  Chubbies.ensure_killed
 end
 
 Given /^Chubbies is registered on my pod$/ do
@@ -47,8 +44,13 @@ class Chubbies
 
   def self.run
     @pid = fork do
-      Process.exec "cd #{Rails.root}/spec/support/chubbies/ && BUNDLE_GEMFILE=Gemfile DIASPORA_PORT=9887 bundle exec rackup -p #{PORT} 2> /dev/null"
+      Process.exec "cd #{Rails.root}/spec/chubbies/ && BUNDLE_GEMFILE=Gemfile DIASPORA_PORT=9887 bundle exec rackup -p #{PORT} 2> /dev/null"
     end
+
+    at_exit do
+      Chubbies.kill
+    end
+    
     while(!running?) do
       sleep(1)
     end
@@ -58,6 +60,13 @@ class Chubbies
     `kill -9 #{get_pid}`
   end
 
+  def self.ensure_killed
+    if !(@killed) && self.running?
+      self.kill
+      @killed = true
+    end
+  end
+
   def self.running?
     begin
       RestClient.get("localhost:#{PORT}")
diff --git a/spec/support/chubbies/Gemfile b/spec/chubbies/Gemfile
similarity index 77%
rename from spec/support/chubbies/Gemfile
rename to spec/chubbies/Gemfile
index b0a9d933cd..dded43bc26 100644
--- a/spec/support/chubbies/Gemfile
+++ b/spec/chubbies/Gemfile
@@ -7,4 +7,4 @@ gem 'httparty'
 gem 'json'
 gem 'shotgun'
 gem 'sqlite3'
-gem 'activerecord'
+gem 'activerecord', '3.0.3'
diff --git a/spec/support/chubbies/Gemfile.lock b/spec/chubbies/Gemfile.lock
similarity index 69%
rename from spec/support/chubbies/Gemfile.lock
rename to spec/chubbies/Gemfile.lock
index cbe76139ac..43ab98117d 100644
--- a/spec/support/chubbies/Gemfile.lock
+++ b/spec/chubbies/Gemfile.lock
@@ -1,23 +1,23 @@
 GEM
   remote: http://rubygems.org/
   specs:
-    activemodel (3.0.7)
-      activesupport (= 3.0.7)
+    activemodel (3.0.3)
+      activesupport (= 3.0.3)
       builder (~> 2.1.2)
-      i18n (~> 0.5.0)
-    activerecord (3.0.7)
-      activemodel (= 3.0.7)
-      activesupport (= 3.0.7)
+      i18n (~> 0.4)
+    activerecord (3.0.3)
+      activemodel (= 3.0.3)
+      activesupport (= 3.0.3)
       arel (~> 2.0.2)
       tzinfo (~> 0.3.23)
-    activesupport (3.0.7)
+    activesupport (3.0.3)
     arel (2.0.10)
     builder (2.1.2)
     crack (0.1.8)
     haml (3.0.18)
     httparty (0.7.4)
       crack (= 0.1.8)
-    i18n (0.5.0)
+    i18n (0.6.0)
     json (1.4.6)
     rack (1.2.2)
     shotgun (0.9)
@@ -33,7 +33,7 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
-  activerecord
+  activerecord (= 3.0.3)
   haml
   httparty
   json
diff --git a/spec/support/chubbies/README b/spec/chubbies/README
similarity index 100%
rename from spec/support/chubbies/README
rename to spec/chubbies/README
diff --git a/spec/support/chubbies/app.rb b/spec/chubbies/app.rb
similarity index 87%
rename from spec/support/chubbies/app.rb
rename to spec/chubbies/app.rb
index 8d55f86d9b..cf1bb1cf9b 100644
--- a/spec/support/chubbies/app.rb
+++ b/spec/chubbies/app.rb
@@ -5,9 +5,10 @@ require 'haml'
 require 'httparty'
 require 'json'
 require 'active_record'
+require 'pp'
 
 # models ======================================
-`rm -f chubbies.sqlite3`
+`rm -f #{File.expand_path('../chubbies.sqlite3', __FILE__)}`
 ActiveRecord::Base.establish_connection(
     :adapter => "sqlite3",
     :database  => "chubbies.sqlite3"
@@ -75,9 +76,9 @@ get '/callback' do
       :code => params["code"],
       :grant_type => 'authorization_code'}
     )
-
-    user = pod.users.create!(:access_token => response["access_token"], :diaspora_handle => params['diaspora_handle'])
-    redirect "/account?diaspora_handle=#{user.diaspora_handle}"
+    
+    user = pod.users.create!(:access_token => response["access_token"] )
+    redirect "/account?id=#{user.id}"
   else
     "What is your major malfunction?"
   end
@@ -85,12 +86,14 @@ end
 
 get '/account' do
   # have diaspora handle
-  host = domain_from_handle
-  unless pod = Pod.where(:host => host).first
-    pod = register_with_pod
+  if params[:diaspora_handle]
+    host = domain_from_handle
+    unless pod = Pod.where(:host => host).first
+      pod = register_with_pod
+    end
   end
 
-  if user = pod.users.where(:diaspora_handle => params['diaspora_handle']).first
+  if params['id'] && user = User.where(:id => params['id']).first
     @resource_response = get_with_access_token(user, "/api/v0/me")
     haml :response
   else
@@ -107,6 +110,11 @@ get '/manifest' do
   }.to_json
 end
 
+get '/reset' do
+  User.delete_all
+  Pod.delete_all
+  "reset."
+end
 #=============================
 #helpers
 #
diff --git a/spec/support/chubbies/config.ru b/spec/chubbies/config.ru
similarity index 100%
rename from spec/support/chubbies/config.ru
rename to spec/chubbies/config.ru
diff --git a/spec/support/chubbies/public/chubbies.jpeg b/spec/chubbies/public/chubbies.jpeg
similarity index 100%
rename from spec/support/chubbies/public/chubbies.jpeg
rename to spec/chubbies/public/chubbies.jpeg
diff --git a/spec/support/chubbies/views/home.haml b/spec/chubbies/views/home.haml
similarity index 100%
rename from spec/support/chubbies/views/home.haml
rename to spec/chubbies/views/home.haml
diff --git a/spec/support/chubbies/views/response.haml b/spec/chubbies/views/response.haml
similarity index 100%
rename from spec/support/chubbies/views/response.haml
rename to spec/chubbies/views/response.haml
-- 
GitLab