authlogic_facebook_shim 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +76 -0
  3. data/Rakefile +39 -0
  4. data/VERSION +1 -0
  5. data/authlogic_facebook_shim.gemspec +30 -0
  6. data/init.rb +1 -0
  7. data/lib/authlogic_facebook_shim/acts_as_authentic.rb +20 -0
  8. data/lib/authlogic_facebook_shim/helper.rb +4 -0
  9. data/lib/authlogic_facebook_shim/session/adapter.rb +1 -0
  10. data/lib/authlogic_facebook_shim/session/adapters/koala_adapter.rb +35 -0
  11. data/lib/authlogic_facebook_shim/session/config.rb +82 -0
  12. data/lib/authlogic_facebook_shim/session/facebook.rb +72 -0
  13. data/lib/authlogic_facebook_shim/session.rb +12 -0
  14. data/lib/authlogic_facebook_shim.rb +15 -0
  15. data/rails/init.rb +1 -0
  16. data/test/rails_root/app/controllers/application_controller.rb +10 -0
  17. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  18. data/test/rails_root/app/models/user.rb +7 -0
  19. data/test/rails_root/app/models/user_session.rb +7 -0
  20. data/test/rails_root/config/boot.rb +110 -0
  21. data/test/rails_root/config/database.yml +10 -0
  22. data/test/rails_root/config/environment.rb +31 -0
  23. data/test/rails_root/config/environments/development.rb +0 -0
  24. data/test/rails_root/config/environments/test.rb +0 -0
  25. data/test/rails_root/config/facebook.yml +7 -0
  26. data/test/rails_root/config/initializers/authlogic_facebook_koala.rb +5 -0
  27. data/test/rails_root/config/initializers/new_rails_defaults.rb +21 -0
  28. data/test/rails_root/config/initializers/session_store.rb +15 -0
  29. data/test/rails_root/config/locales/en.yml +5 -0
  30. data/test/rails_root/config/routes.rb +43 -0
  31. data/test/rails_root/db/migrate/20101217000008_create_users.rb +37 -0
  32. data/test/rails_root/db/seeds.rb +7 -0
  33. data/test/rails_root/log/test.log +159 -0
  34. data/test/rails_root/script/console +3 -0
  35. data/test/rails_root/script/dbconsole +3 -0
  36. data/test/rails_root/script/generate +3 -0
  37. data/test/test_helper.rb +43 -0
  38. data/test/units/session/adapter_test.rb +182 -0
  39. data/test/units/session/config_test.rb +145 -0
  40. data/test/units/session/facebook_test.rb +221 -0
  41. metadata +234 -0
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
@@ -0,0 +1,37 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :users do |t|
5
+ t.datetime :created_at
6
+ t.datetime :updated_at
7
+ t.integer :lock_version, :default => 0
8
+ t.integer :company_id
9
+ t.string :login
10
+ t.string :crypted_password
11
+ t.string :password_salt
12
+ t.string :persistence_token
13
+ t.string :single_access_token
14
+ t.string :perishable_token
15
+ t.string :email
16
+ t.string :first_name
17
+ t.string :last_name
18
+ t.integer :login_count, :default => 0, :null => false
19
+ t.integer :failed_login_count, :default => 0, :null => false
20
+ t.datetime :last_request_at
21
+ t.datetime :current_login_at
22
+ t.datetime :last_login_at
23
+ t.string :current_login_ip
24
+ t.string :last_login_ip
25
+ t.boolean :active, :default => true
26
+ t.boolean :approved, :default => true
27
+ t.boolean :confirmed, :default => true
28
+ t.string :facebook_uid
29
+ end
30
+
31
+ end
32
+
33
+ def self.down
34
+ drop_table :users
35
+ end
36
+
37
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,159 @@
1
+ # Logfile created on Wed Jan 05 01:40:52 +0000 2011 SQL (0.2ms)  SELECT name
2
+ FROM sqlite_master
3
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
+ 
5
+ SQL (0.1ms) select sqlite_version(*)
6
+ SQL (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
7
+ SQL (7.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
8
+ SQL (0.1ms)  SELECT name
9
+ FROM sqlite_master
10
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
11
+ 
12
+ SQL (0.1ms) SELECT version FROM schema_migrations
13
+ Migrating to CreateUsers (20101217000008)
14
+ SQL (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "lock_version" integer DEFAULT 0, "company_id" integer, "login" varchar(255), "crypted_password" varchar(255), "password_salt" varchar(255), "persistence_token" varchar(255), "single_access_token" varchar(255), "perishable_token" varchar(255), "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255), "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" datetime, "current_login_at" datetime, "last_login_at" datetime, "current_login_ip" varchar(255), "last_login_ip" varchar(255), "active" boolean DEFAULT 't', "approved" boolean DEFAULT 't', "confirmed" boolean DEFAULT 't', "facebook_uid" varchar(255)) 
15
+ SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20101217000008')
16
+ SQL (0.2ms)  SELECT name
17
+ FROM sqlite_master
18
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
19
+ 
20
+ SQL (0.1ms) select sqlite_version(*)
21
+ SQL (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
22
+ SQL (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
23
+ SQL (0.1ms)  SELECT name
24
+ FROM sqlite_master
25
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
26
+ 
27
+ SQL (0.1ms) SELECT version FROM schema_migrations
28
+ Migrating to CreateUsers (20101217000008)
29
+ SQL (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "lock_version" integer DEFAULT 0, "company_id" integer, "login" varchar(255), "crypted_password" varchar(255), "password_salt" varchar(255), "persistence_token" varchar(255), "single_access_token" varchar(255), "perishable_token" varchar(255), "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255), "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" datetime, "current_login_at" datetime, "last_login_at" datetime, "current_login_ip" varchar(255), "last_login_ip" varchar(255), "active" boolean DEFAULT 't', "approved" boolean DEFAULT 't', "confirmed" boolean DEFAULT 't', "facebook_uid" varchar(255)) 
30
+ SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20101217000008')
31
+ SQL (0.2ms)  SELECT name
32
+ FROM sqlite_master
33
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
34
+ 
35
+ SQL (0.1ms) select sqlite_version(*)
36
+ SQL (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
37
+ SQL (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
38
+ SQL (0.1ms)  SELECT name
39
+ FROM sqlite_master
40
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
41
+ 
42
+ SQL (0.1ms) SELECT version FROM schema_migrations
43
+ Migrating to CreateUsers (20101217000008)
44
+ SQL (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "lock_version" integer DEFAULT 0, "company_id" integer, "login" varchar(255), "crypted_password" varchar(255), "password_salt" varchar(255), "persistence_token" varchar(255), "single_access_token" varchar(255), "perishable_token" varchar(255), "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255), "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" datetime, "current_login_at" datetime, "last_login_at" datetime, "current_login_ip" varchar(255), "last_login_ip" varchar(255), "active" boolean DEFAULT 't', "approved" boolean DEFAULT 't', "confirmed" boolean DEFAULT 't', "facebook_uid" varchar(255)) 
45
+ SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20101217000008')
46
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = '72a56332b80ccce18b13e24b0e193383419b63c3fb1798474d1d2fbc49e0e0c640d9eb328ea3949cfdbe9f4984ef51132dc821dcafe82291d6a7f9654578fdd0') LIMIT 1
47
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'o1TkjpoSNbRglu_Nny9i') LIMIT 1
48
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 01:47:31', 'o1TkjpoSNbRglu_Nny9i', NULL, NULL, 't', '2011-01-05 01:47:31', 'kbKVu_fzl3zAdkaKqm8k', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, '72a56332b80ccce18b13e24b0e193383419b63c3fb1798474d1d2fbc49e0e0c640d9eb328ea3949cfdbe9f4984ef51132dc821dcafe82291d6a7f9654578fdd0', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
49
+ User Update with optimistic locking (0.2ms)  UPDATE "users"
50
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 01:47:31', "perishable_token" = 'eBX7IHdAgmkD1NuYf6ks', "last_request_at" = '2011-01-05 01:47:31', "lock_version" = 1, "current_login_at" = '2011-01-05 01:47:31'
51
+ WHERE id = 1
52
+ AND "lock_version" = 0
53
+ 
54
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = 'ba949a3c116ccf90e278370aefe8d198b1c44b06d330d2785965d6d06932eab5e5d04a11eba78793981ce99709e040638af0187b94d0e02d5d348527c6403fe9') LIMIT 1
55
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'QBTbe977IaKzGNEmbGeT') LIMIT 1
56
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 01:47:31', 'QBTbe977IaKzGNEmbGeT', NULL, NULL, 't', '2011-01-05 01:47:31', 'EdnvXXaE3DgvItlwrQTE', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, 'ba949a3c116ccf90e278370aefe8d198b1c44b06d330d2785965d6d06932eab5e5d04a11eba78793981ce99709e040638af0187b94d0e02d5d348527c6403fe9', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
57
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
58
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 01:47:31', "perishable_token" = 'yfo9QWt0wyoR9cyueALR', "last_request_at" = '2011-01-05 01:47:31', "lock_version" = 1, "current_login_at" = '2011-01-05 01:47:31'
59
+ WHERE id = 2
60
+ AND "lock_version" = 0
61
+ 
62
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 01:47:31', NULL, NULL, NULL, 't', '2011-01-05 01:47:31', 'o9xqKY8m8w5YJNW6sAl4', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
63
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
64
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 01:47:31', "perishable_token" = 'P0kwHxl3Vx33kfdJnDeG', "last_request_at" = '2011-01-05 01:47:31', "lock_version" = 1, "current_login_at" = '2011-01-05 01:47:31'
65
+ WHERE id = 3
66
+ AND "lock_version" = 0
67
+ 
68
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 01:47:31', NULL, NULL, NULL, 't', '2011-01-05 01:47:31', 'bIvjHnDDx6lWoACx4RDq', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
69
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
70
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 01:47:31', "perishable_token" = 'RkxnsBc6tZx5cUseox5f', "last_request_at" = '2011-01-05 01:47:31', "lock_version" = 1, "current_login_at" = '2011-01-05 01:47:31'
71
+ WHERE id = 4
72
+ AND "lock_version" = 0
73
+ 
74
+ SQL (0.2ms)  SELECT name
75
+ FROM sqlite_master
76
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
77
+ 
78
+ SQL (0.1ms) select sqlite_version(*)
79
+ SQL (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
80
+ SQL (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
81
+ SQL (0.1ms)  SELECT name
82
+ FROM sqlite_master
83
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
84
+ 
85
+ SQL (0.1ms) SELECT version FROM schema_migrations
86
+ Migrating to CreateUsers (20101217000008)
87
+ SQL (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "lock_version" integer DEFAULT 0, "company_id" integer, "login" varchar(255), "crypted_password" varchar(255), "password_salt" varchar(255), "persistence_token" varchar(255), "single_access_token" varchar(255), "perishable_token" varchar(255), "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255), "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" datetime, "current_login_at" datetime, "last_login_at" datetime, "current_login_ip" varchar(255), "last_login_ip" varchar(255), "active" boolean DEFAULT 't', "approved" boolean DEFAULT 't', "confirmed" boolean DEFAULT 't', "facebook_uid" varchar(255)) 
88
+ SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20101217000008')
89
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = '2339319a4fd4b9e6aeb8aedd56dc78fdb960edcd9591edada9623f8494f29684aa1057a2279c68ef2f532e222fbf1584e2355f739405084910737239e6f6faac') LIMIT 1
90
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'x9trgkKYah_VHQOaSbq9') LIMIT 1
91
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:49:27', 'x9trgkKYah_VHQOaSbq9', NULL, NULL, 't', '2011-01-05 02:49:27', 'Xh4yvJBdbhgKKgOxBpbQ', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, '2339319a4fd4b9e6aeb8aedd56dc78fdb960edcd9591edada9623f8494f29684aa1057a2279c68ef2f532e222fbf1584e2355f739405084910737239e6f6faac', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
92
+ User Update with optimistic locking (0.2ms)  UPDATE "users"
93
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:49:27', "perishable_token" = '5jXBntUCMDJKgvCOcd6y', "last_request_at" = '2011-01-05 02:49:27', "lock_version" = 1, "current_login_at" = '2011-01-05 02:49:27'
94
+ WHERE id = 1
95
+ AND "lock_version" = 0
96
+ 
97
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = 'e13ed14d0711ed4f29218cdb9546b92aff7c89a83826f8b2368df24d5fb0fdb033401a1e670bb67ba686c171fdfeeb4203a87223de46c899a9ea7a706a249043') LIMIT 1
98
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'aFx5vHL_bbNpu7KfP9Sh') LIMIT 1
99
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:49:27', 'aFx5vHL_bbNpu7KfP9Sh', NULL, NULL, 't', '2011-01-05 02:49:27', 'lPEBVK4Axjveuiw2x8dB', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, 'e13ed14d0711ed4f29218cdb9546b92aff7c89a83826f8b2368df24d5fb0fdb033401a1e670bb67ba686c171fdfeeb4203a87223de46c899a9ea7a706a249043', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
100
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
101
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:49:27', "perishable_token" = 'Rui7XLyC1M8Vm0zlkAku', "last_request_at" = '2011-01-05 02:49:27', "lock_version" = 1, "current_login_at" = '2011-01-05 02:49:27'
102
+ WHERE id = 2
103
+ AND "lock_version" = 0
104
+ 
105
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:49:27', NULL, NULL, NULL, 't', '2011-01-05 02:49:27', 'kTXskzxx7WsMS61XcW6D', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
106
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
107
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:49:27', "perishable_token" = 'lwlqmU2qDSSOjGqNTd5a', "last_request_at" = '2011-01-05 02:49:27', "lock_version" = 1, "current_login_at" = '2011-01-05 02:49:27'
108
+ WHERE id = 3
109
+ AND "lock_version" = 0
110
+ 
111
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:49:27', NULL, NULL, NULL, 't', '2011-01-05 02:49:27', 'Lz2QOBzhZOXHtHdjL9bs', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
112
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
113
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:49:27', "perishable_token" = 'AV6UlHvtzrat83rWOY3Y', "last_request_at" = '2011-01-05 02:49:27', "lock_version" = 1, "current_login_at" = '2011-01-05 02:49:27'
114
+ WHERE id = 4
115
+ AND "lock_version" = 0
116
+ 
117
+ SQL (0.3ms)  SELECT name
118
+ FROM sqlite_master
119
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
120
+ 
121
+ SQL (0.1ms) select sqlite_version(*)
122
+ SQL (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
123
+ SQL (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
124
+ SQL (0.1ms)  SELECT name
125
+ FROM sqlite_master
126
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
127
+ 
128
+ SQL (0.1ms) SELECT version FROM schema_migrations
129
+ Migrating to CreateUsers (20101217000008)
130
+ SQL (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "created_at" datetime, "updated_at" datetime, "lock_version" integer DEFAULT 0, "company_id" integer, "login" varchar(255), "crypted_password" varchar(255), "password_salt" varchar(255), "persistence_token" varchar(255), "single_access_token" varchar(255), "perishable_token" varchar(255), "email" varchar(255), "first_name" varchar(255), "last_name" varchar(255), "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" datetime, "current_login_at" datetime, "last_login_at" datetime, "current_login_ip" varchar(255), "last_login_ip" varchar(255), "active" boolean DEFAULT 't', "approved" boolean DEFAULT 't', "confirmed" boolean DEFAULT 't', "facebook_uid" varchar(255)) 
131
+ SQL (0.1ms) INSERT INTO schema_migrations (version) VALUES ('20101217000008')
132
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = 'fcb5d9b05abae3defaf0a0d573341370376b1b5b34114634ab148b2db6477b86f32c092d289c4d76359ea0e9052374659a0bfeb59c656e9558c75c89ad634850') LIMIT 1
133
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'Jk4t2D8xIVzr-drf1g9D') LIMIT 1
134
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:56:52', 'Jk4t2D8xIVzr-drf1g9D', NULL, NULL, 't', '2011-01-05 02:56:52', 'YEqFCrp4ZlmtuDyIBoa2', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, 'fcb5d9b05abae3defaf0a0d573341370376b1b5b34114634ab148b2db6477b86f32c092d289c4d76359ea0e9052374659a0bfeb59c656e9558c75c89ad634850', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
135
+ User Update with optimistic locking (0.2ms)  UPDATE "users"
136
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:56:52', "perishable_token" = 'viIYjwY-It_i3eudsN2D', "last_request_at" = '2011-01-05 02:56:52', "lock_version" = 1, "current_login_at" = '2011-01-05 02:56:52'
137
+ WHERE id = 1
138
+ AND "lock_version" = 0
139
+ 
140
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."persistence_token" = 'fd0682ff46cc5f1d729924b839c32a0f94454562bc15b4cec105c48908eeca8673c70cb6449efc916b0eedb51c155714a9d1b0ed00ccd1cae1219565ee810fd3') LIMIT 1
141
+ User Load (0.1ms) SELECT "users".id FROM "users" WHERE ("users"."single_access_token" = 'J6zUBKnQNklM79gLDds5') LIMIT 1
142
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:56:52', 'J6zUBKnQNklM79gLDds5', NULL, NULL, 't', '2011-01-05 02:56:52', 'lQ5EWLf3AvmiNZuCWmF3', NULL, 0, 0, NULL, 't', NULL, NULL, NULL, 'fd0682ff46cc5f1d729924b839c32a0f94454562bc15b4cec105c48908eeca8673c70cb6449efc916b0eedb51c155714a9d1b0ed00ccd1cae1219565ee810fd3', NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
143
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
144
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:56:52', "perishable_token" = '4xCFZCZTyEJkuncNmwe2', "last_request_at" = '2011-01-05 02:56:52', "lock_version" = 1, "current_login_at" = '2011-01-05 02:56:52'
145
+ WHERE id = 2
146
+ AND "lock_version" = 0
147
+ 
148
+ User Create (0.2ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:56:53', NULL, NULL, NULL, 't', '2011-01-05 02:56:53', 'QPUSDFsbQNvlzmiKsMdQ', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
149
+ User Update with optimistic locking (0.2ms)  UPDATE "users"
150
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:56:53', "perishable_token" = 'zM5_WranpRa5tV_xGpOn', "last_request_at" = '2011-01-05 02:56:53', "lock_version" = 1, "current_login_at" = '2011-01-05 02:56:53'
151
+ WHERE id = 3
152
+ AND "lock_version" = 0
153
+ 
154
+ User Create (0.1ms) INSERT INTO "users" ("created_at", "single_access_token", "last_request_at", "crypted_password", "confirmed", "updated_at", "perishable_token", "facebook_uid", "lock_version", "failed_login_count", "current_login_ip", "approved", "password_salt", "current_login_at", "company_id", "persistence_token", "last_name", "login_count", "last_login_ip", "login", "last_login_at", "email", "first_name", "active") VALUES('2011-01-05 02:56:53', NULL, NULL, NULL, 't', '2011-01-05 02:56:53', 'c342yHUJlfrSqwKLL_I8', 'mockuid', 0, 0, NULL, 't', NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, 't')
155
+ User Update with optimistic locking (0.1ms)  UPDATE "users"
156
+ SET "login_count" = 1, "current_login_ip" = '1.1.1.1', "updated_at" = '2011-01-05 02:56:53', "perishable_token" = 'R35njl1Msiul4-GbHuQD', "last_request_at" = '2011-01-05 02:56:53', "lock_version" = 1, "current_login_at" = '2011-01-05 02:56:53'
157
+ WHERE id = 4
158
+ AND "lock_version" = 0
159
+ 
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/dbconsole'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../config/boot', __FILE__)
3
+ require 'commands/generate'
@@ -0,0 +1,43 @@
1
+ # Load the environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+ rails_root = File.dirname(__FILE__) + '/rails_root'
4
+ require "#{rails_root}/config/environment.rb"
5
+
6
+ # Load the testing framework
7
+ require 'test_help'
8
+ require 'flexmock/test_unit'
9
+ require "authlogic/test_case"
10
+
11
+ silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
12
+
13
+ # Run the migrations
14
+ ActiveRecord::Migration.verbose = false
15
+ ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
16
+
17
+ # Setup the fixtures path
18
+
19
+ class ActiveSupport::TestCase #:nodoc:
20
+ self.fixture_path = File.join(File.dirname(__FILE__), "fixtures")
21
+ self.use_transactional_fixtures = false
22
+ self.use_instantiated_fixtures = false
23
+ self.pre_loaded_fixtures = false
24
+
25
+ fixtures :all
26
+ setup :activate_authlogic
27
+
28
+ end
29
+
30
+ # --- Sample valid cookie hash generated with the code below
31
+ # cookie_hash = {'fbs_233423200151' => 'access_token=233423200151|6892d62675cd952ade8b3f9b-6184456410|xrNaOlTCUF0QFZrJCHmVWzTb5Mk.&expires=0&secret=339a00cdafe6959c3caa1b8004e5f8db&session_key=6892d62675cd952ade8b3f9b-6184456410&sig=19d3c9ccb5b5a55d680ed1cf18698f57&uid=6184456410'}
32
+
33
+ # --- Generates user params from cookie for this app_id & secret
34
+ # oauth = Koala::Facebook::OAuth.new('233423200151', '8371c9fc95a7d0a3d9cdb6bbacfea306')
35
+ # params = oauth.get_user_from_cookie(cookie_hash)
36
+
37
+ # --- Generates a signature for a cookie hash
38
+ # fb_cookie = cookie_hash["fbs_233423200151"]
39
+ # components = {}
40
+ # fb_cookie.split("&").map {|param| param = param.split("="); components[param[0]] = param[1]}
41
+ # auth_string = components.keys.sort.collect {|a| a == "sig" ? nil : "#{a}=#{components[a]}"}.reject {|a| a.nil?}.join("")
42
+ # sig = Digest::MD5.hexdigest(auth_string + '8371c9fc95a7d0a3d9cdb6bbacfea306')
43
+
@@ -0,0 +1,182 @@
1
+ require File.expand_path( '../../test_helper.rb', File.dirname(__FILE__) )
2
+
3
+ class AuthlogicFacebookShim::Session::AdapterTest < ActiveSupport::TestCase
4
+
5
+ setup :activate_authlogic
6
+
7
+ context "Session::Adapter" do
8
+ setup do
9
+ @user_info = {
10
+ 'session_key' => 'mocksessionkey',
11
+ 'expires' => '0',
12
+ 'uid' => 'mockuid',
13
+ 'sig' => 'cbd80b97f124bf392f76e2ee61168990',
14
+ 'secret' => 'mocksecret',
15
+ 'access_token' => 'mockaccesstoken'
16
+ }
17
+ @mock_cookies = MockCookieJar.new
18
+ @mock_cookies['fbs_mockappid'] = {:value => 'access_token=mockaccesstoken&expires=0&secret=mocksecret&session_key=mocksessionkey&sig=cbd80b97f124bf392f76e2ee61168990&uid=mockuid'}
19
+ @session = flexmock(UserSession.new)
20
+ @controller = flexmock('Controller')
21
+
22
+ @session.should_receive(:facebook_app_id).and_return('mockappid').by_default
23
+ @session.should_receive(:facebook_api_key).and_return('mockapikey').by_default
24
+ @session.should_receive(:facebook_secret_key).and_return('mocksecret').by_default
25
+ @session.should_receive(:controller).and_return(@controller).by_default
26
+ @controller.should_receive(:cookies).and_return(@mock_cookies).by_default
27
+ end
28
+
29
+ context "setup - for my own sanity" do
30
+
31
+ should "set the controller" do
32
+ assert_equal @controller, @session.controller
33
+ end
34
+
35
+ should "set the cookies" do
36
+ assert_equal @mock_cookies, @session.controller.cookies
37
+ end
38
+
39
+ should "set the facebook_app_id" do
40
+ assert_equal 'mockappid', @session.facebook_app_id
41
+ end
42
+
43
+ should "set the facebook_secret_key" do
44
+ assert_equal 'mocksecret', @session.facebook_secret_key
45
+ end
46
+
47
+ should "set the facebook_api_key" do
48
+ assert_equal 'mockapikey', @session.facebook_api_key
49
+ end
50
+
51
+ end
52
+
53
+ context "facebook_session" do
54
+
55
+ context "with a valid facebook cookie" do
56
+
57
+ context "and koala support for get_user_info_from_cookie" do
58
+
59
+ should "return a session_key" do
60
+ assert_equal 'mocksessionkey', @session.facebook_session.session_key
61
+ end
62
+
63
+ should "return a uid" do
64
+ assert_equal 'mockuid', @session.facebook_session.uid
65
+ end
66
+
67
+ should "return a secret" do
68
+ assert_equal 'mocksecret', @session.facebook_session.secret
69
+ end
70
+
71
+ should "return a sig" do
72
+ assert_equal 'cbd80b97f124bf392f76e2ee61168990', @session.facebook_session.sig
73
+ end
74
+
75
+ should "return an access_token" do
76
+ assert_equal 'mockaccesstoken', @session.facebook_session.access_token
77
+ end
78
+
79
+ end
80
+
81
+ context "with previous koala api" do
82
+
83
+ should "get user info with the get_user_from_cookie method" do
84
+ @oauth = flexmock('oauth')
85
+ flexmock(Koala::Facebook::OAuth).should_receive(:new).and_return(@oauth).once
86
+ @oauth.should_receive(:respond_to?).with(:get_user_info_from_cookie).and_return(false).once
87
+ @oauth.should_receive(:get_user_from_cookie).with(@mock_cookies).and_return(@user_info).once
88
+
89
+ assert_equal 'mocksessionkey', @session.facebook_session.session_key
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ context "with no valid facebook cookie" do
97
+
98
+ should "return nil" do
99
+ @session.should_receive('facebook_app_id').and_return(nil).once
100
+ assert_nil @session.facebook_session
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+
107
+ context "facebook_session?" do
108
+
109
+ context "with a valid facebook session" do
110
+
111
+ should "be true" do
112
+ assert @session.facebook_session?
113
+ end
114
+
115
+ end
116
+
117
+ context "without a valid facebook session" do
118
+
119
+ should "return nil" do
120
+ @session.should_receive('facebook_app_id').and_return(nil).once
121
+ assert_equal false, @session.facebook_session?
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+
128
+ context "facebook_user" do
129
+
130
+ context "with a valid facebook session" do
131
+
132
+ setup do
133
+ @user = {
134
+ "id" => "mockid",
135
+ "name" => "Full name",
136
+ "first_name" => "First name",
137
+ "last_name" => "Last name"
138
+ }
139
+
140
+ @access_token = flexmock('access token')
141
+ @session.should_receive('facebook_session.access_token').and_return(@access_token).by_default
142
+ @session.should_receive('facebook_session?').and_return(true).by_default
143
+
144
+ @graph_api = flexmock('graph api', :get_object => @user)
145
+ flexmock(Koala::Facebook::GraphAPI).should_receive(:new).and_return(@graph_api).by_default
146
+ end
147
+
148
+ should "initialize the graph api" do
149
+ flexmock(Koala::Facebook::GraphAPI).should_receive(:new).with(@access_token).and_return(@graph_api).once
150
+ @session.facebook_user
151
+ end
152
+
153
+ should "return an OpenStruct" do
154
+ assert @session.facebook_user.is_a?(OpenStruct)
155
+ end
156
+
157
+ should "return the user details" do
158
+ assert_equal 'Full name', @session.facebook_user.name
159
+ assert_equal 'First name', @session.facebook_user.first_name
160
+ assert_equal 'Last name', @session.facebook_user.last_name
161
+ end
162
+
163
+ should "return the facebook id as uid" do
164
+ assert_equal 'mockid', @session.facebook_user.uid
165
+ end
166
+
167
+ end
168
+
169
+ context "with no valid facebook session" do
170
+
171
+ should "return nil" do
172
+ @session.should_receive('facebook_session?').and_return(false).once
173
+ assert_nil @session.facebook_user
174
+ end
175
+
176
+ end
177
+
178
+ end
179
+
180
+ end
181
+
182
+ end