authlogic_facebook_koala 0.0.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +60 -2
- data/Rakefile +28 -1
- data/VERSION +1 -1
- data/authlogic_facebook_koala.gemspec +12 -45
- data/lib/authlogic_facebook_koala.rb +10 -4
- data/lib/authlogic_facebook_koala/adapter.rb +35 -0
- data/lib/authlogic_facebook_koala/config.rb +78 -4
- data/lib/authlogic_facebook_koala/session.rb +50 -116
- data/test/rails_root/app/controllers/application_controller.rb +10 -0
- data/test/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails_root/app/models/user.rb +7 -0
- data/test/{libs → rails_root/app/models}/user_session.rb +0 -0
- data/test/rails_root/config/boot.rb +110 -0
- data/test/rails_root/config/database.yml +10 -0
- data/test/rails_root/config/environment.rb +31 -0
- data/test/rails_root/config/environments/development.rb +0 -0
- data/test/rails_root/config/environments/test.rb +0 -0
- data/test/rails_root/config/facebook.yml +7 -0
- data/test/rails_root/config/initializers/authlogic_facebook_koala.rb +5 -0
- data/test/rails_root/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails_root/config/initializers/session_store.rb +15 -0
- data/test/rails_root/config/locales/en.yml +5 -0
- data/test/rails_root/config/routes.rb +43 -0
- data/test/rails_root/db/migrate/20101217000008_create_users.rb +37 -0
- data/test/rails_root/db/seeds.rb +7 -0
- data/test/rails_root/script/console +3 -0
- data/test/rails_root/script/dbconsole +3 -0
- data/test/rails_root/script/generate +3 -0
- data/test/test_helper.rb +19 -58
- data/test/units/adapter_test.rb +182 -0
- data/test/units/config_test.rb +145 -0
- data/test/units/session_test.rb +221 -0
- metadata +139 -27
- data/lib/authlogic_facebook_koala/controller.rb +0 -59
- data/test/libs/user.rb +0 -3
- data/test/session_test.rb +0 -30
@@ -0,0 +1,10 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
7
|
+
|
8
|
+
# Scrub sensitive parameters from your log
|
9
|
+
# filter_parameter_logging :password
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
Rails::GemDependency.add_frozen_gem_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class GemBoot < Boot
|
52
|
+
def load_initializer
|
53
|
+
self.class.load_rubygems
|
54
|
+
load_rails_gem
|
55
|
+
require 'initializer'
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_rails_gem
|
59
|
+
if version = self.class.gem_version
|
60
|
+
gem 'rails', version
|
61
|
+
else
|
62
|
+
gem 'rails'
|
63
|
+
end
|
64
|
+
rescue Gem::LoadError => load_error
|
65
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
|
69
|
+
class << self
|
70
|
+
def rubygems_version
|
71
|
+
Gem::RubyGemsVersion rescue nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def gem_version
|
75
|
+
if defined? RAILS_GEM_VERSION
|
76
|
+
RAILS_GEM_VERSION
|
77
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
78
|
+
ENV['RAILS_GEM_VERSION']
|
79
|
+
else
|
80
|
+
parse_gem_version(read_environment_rb)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def load_rubygems
|
85
|
+
min_version = '1.3.2'
|
86
|
+
require 'rubygems'
|
87
|
+
unless rubygems_version >= min_version
|
88
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
rescue LoadError
|
93
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
94
|
+
exit 1
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_gem_version(text)
|
98
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def read_environment_rb
|
103
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# All that for this:
|
110
|
+
Rails.boot!
|
@@ -0,0 +1,31 @@
|
|
1
|
+
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
2
|
+
|
3
|
+
# Bootstrap the Rails environment, frameworks, and default configuration
|
4
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
5
|
+
|
6
|
+
Rails::Initializer.run do |config|
|
7
|
+
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
8
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
9
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
10
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
|
11
|
+
# config.i18n.default_locale = :de
|
12
|
+
# config.active_record.schema_format = :sql
|
13
|
+
|
14
|
+
config.gem "authlogic"
|
15
|
+
config.gem 'flexmock'
|
16
|
+
config.gem "koala"
|
17
|
+
config.gem "shoulda"
|
18
|
+
config.gem "test-unit", :lib => "test/unit"
|
19
|
+
|
20
|
+
config.frameworks -= [ :active_resource, :action_mailer ]
|
21
|
+
config.log_level = :debug
|
22
|
+
config.cache_classes = false
|
23
|
+
config.whiny_nils = true
|
24
|
+
config.action_controller.consider_all_requests_local = true
|
25
|
+
config.action_controller.perform_caching = false
|
26
|
+
config.action_view.cache_template_loading = true
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
config.action_mailer.delivery_method = :test
|
29
|
+
config.time_zone = 'UTC'
|
30
|
+
|
31
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
4
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
5
|
+
|
6
|
+
if defined?(ActiveRecord)
|
7
|
+
# Include Active Record class name as root for JSON serialized output.
|
8
|
+
ActiveRecord::Base.include_root_in_json = true
|
9
|
+
|
10
|
+
# Store the full class name (including module namespace) in STI type column.
|
11
|
+
ActiveRecord::Base.store_full_sti_class = true
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionController::Routing.generate_best_match = false
|
15
|
+
|
16
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
17
|
+
ActiveSupport.use_standard_json_time_format = true
|
18
|
+
|
19
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
20
|
+
# if you're including raw json in an HTML page.
|
21
|
+
ActiveSupport.escape_html_entities_in_json = false
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying cookie session data integrity.
|
4
|
+
# If you change this key, all old sessions will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
ActionController::Base.session = {
|
8
|
+
:key => '_rails_root_session',
|
9
|
+
:secret => '4deb5b6e05377d982fa6ef37582c0be6de39e1473cc99a4a0f32fd61ec735cd9e86276b2c25fc781e7df8cd6afdc819208f7f497a755e217bff75728d05f543b'
|
10
|
+
}
|
11
|
+
|
12
|
+
# Use the database for sessions instead of the cookie-based default,
|
13
|
+
# which shouldn't be used to store highly confidential information
|
14
|
+
# (create the session table with "rake db:sessions:create")
|
15
|
+
# ActionController::Base.session_store = :active_record_store
|
@@ -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)
|
data/test/test_helper.rb
CHANGED
@@ -1,69 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "
|
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
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
ActiveRecord::Schema.define(:version => 1) do
|
10
|
-
create_table :users do |t|
|
11
|
-
t.datetime :created_at
|
12
|
-
t.datetime :updated_at
|
13
|
-
t.integer :lock_version, :default => 0
|
14
|
-
t.string :login
|
15
|
-
t.string :crypted_password
|
16
|
-
t.string :password_salt
|
17
|
-
t.string :persistence_token
|
18
|
-
t.string :single_access_token
|
19
|
-
t.string :perishable_token
|
20
|
-
t.string :openid_identifier
|
21
|
-
t.string :email
|
22
|
-
t.string :first_name
|
23
|
-
t.string :last_name
|
24
|
-
t.integer :login_count, :default => 0, :null => false
|
25
|
-
t.integer :failed_login_count, :default => 0, :null => false
|
26
|
-
t.datetime :last_request_at
|
27
|
-
t.datetime :current_login_at
|
28
|
-
t.datetime :last_login_at
|
29
|
-
t.string :current_login_ip
|
30
|
-
t.string :last_login_ip
|
31
|
-
t.string :facebook_uid
|
32
|
-
t.string :facebook_session_key
|
33
|
-
t.string :facebook_access_token
|
34
|
-
t.string :facebook_expires
|
35
|
-
t.string :facebook_secret
|
36
|
-
t.string :facebook_sig
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
require "active_record/fixtures"
|
42
|
-
require 'action_controller'
|
43
|
-
Rails = true # to trick authlogic into loading the rails adapter
|
44
|
-
require "authlogic"
|
6
|
+
# Load the testing framework
|
7
|
+
require 'test_help'
|
8
|
+
require 'flexmock/test_unit'
|
45
9
|
require "authlogic/test_case"
|
46
|
-
require File.dirname(__FILE__) + '/../lib/authlogic_facebook_koala' unless defined?(AuthlogicFacebookKoala)
|
47
|
-
require File.dirname(__FILE__) + '/libs/user'
|
48
|
-
require File.dirname(__FILE__) + '/libs/user_session'
|
49
10
|
|
50
|
-
|
51
|
-
|
52
|
-
|
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")
|
53
21
|
self.use_transactional_fixtures = false
|
54
22
|
self.use_instantiated_fixtures = false
|
55
23
|
self.pre_loaded_fixtures = false
|
24
|
+
|
56
25
|
fixtures :all
|
57
26
|
setup :activate_authlogic
|
58
|
-
|
59
|
-
private
|
60
|
-
def activate_authlogic
|
61
|
-
Authlogic::Session::Base.controller = controller
|
62
|
-
end
|
63
|
-
|
64
|
-
def controller
|
65
|
-
@controller ||= Authlogic::ControllerAdapters::RailsAdapter.new(ActionController.new)
|
66
|
-
end
|
27
|
+
|
67
28
|
end
|
68
29
|
|
69
30
|
# --- Sample valid cookie hash generated with the code below
|