sorcery 0.1.4 → 0.2.1
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/Gemfile +4 -2
- data/Gemfile.lock +16 -13
- data/README.rdoc +30 -27
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/lib/sorcery/controller/submodules/activity_logging.rb +20 -7
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +9 -2
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +8 -3
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +26 -0
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +24 -0
- data/lib/sorcery/controller/submodules/oauth/providers/facebook.rb +64 -0
- data/lib/sorcery/controller/submodules/oauth/providers/twitter.rb +61 -0
- data/lib/sorcery/controller/submodules/oauth.rb +92 -0
- data/lib/sorcery/controller/submodules/remember_me.rb +14 -5
- data/lib/sorcery/controller/submodules/session_timeout.rb +6 -1
- data/lib/sorcery/controller.rb +29 -17
- data/lib/sorcery/engine.rb +9 -2
- data/lib/sorcery/model/submodules/activity_logging.rb +12 -7
- data/lib/sorcery/model/submodules/brute_force_protection.rb +11 -4
- data/lib/sorcery/model/submodules/oauth.rb +53 -0
- data/lib/sorcery/model/submodules/remember_me.rb +5 -3
- data/lib/sorcery/model/submodules/reset_password.rb +16 -13
- data/lib/sorcery/model/submodules/user_activation.rb +38 -19
- data/lib/sorcery/model/temporary_token.rb +22 -0
- data/lib/sorcery/model.rb +10 -3
- data/lib/sorcery/test_helpers.rb +84 -0
- data/lib/sorcery.rb +12 -0
- data/sorcery.gemspec +69 -40
- data/spec/Gemfile +3 -2
- data/spec/Gemfile.lock +15 -2
- data/spec/rails3/app_root/.rspec +1 -0
- data/spec/rails3/{Gemfile → app_root/Gemfile} +5 -3
- data/spec/rails3/{Gemfile.lock → app_root/Gemfile.lock} +25 -2
- data/spec/rails3/app_root/app/controllers/application_controller.rb +42 -1
- data/spec/rails3/app_root/app/models/authentication.rb +3 -0
- data/spec/rails3/app_root/app/models/user.rb +4 -1
- data/spec/rails3/app_root/config/application.rb +1 -3
- data/spec/rails3/app_root/config/routes.rb +1 -10
- data/spec/rails3/app_root/db/migrate/activation/20101224223622_add_activation_to_users.rb +6 -4
- data/spec/rails3/app_root/db/migrate/core/20101224223620_create_users.rb +4 -4
- data/spec/rails3/app_root/db/migrate/oauth/20101224223628_create_authentications.rb +14 -0
- data/spec/rails3/{controller_activity_logging_spec.rb → app_root/spec/controller_activity_logging_spec.rb} +13 -13
- data/spec/rails3/{controller_brute_force_protection_spec.rb → app_root/spec/controller_brute_force_protection_spec.rb} +16 -6
- data/spec/rails3/{controller_http_basic_auth_spec.rb → app_root/spec/controller_http_basic_auth_spec.rb} +3 -3
- data/spec/rails3/app_root/spec/controller_oauth2_spec.rb +117 -0
- data/spec/rails3/app_root/spec/controller_oauth_spec.rb +117 -0
- data/spec/rails3/{controller_remember_me_spec.rb → app_root/spec/controller_remember_me_spec.rb} +4 -4
- data/spec/rails3/{controller_session_timeout_spec.rb → app_root/spec/controller_session_timeout_spec.rb} +4 -4
- data/spec/rails3/{controller_spec.rb → app_root/spec/controller_spec.rb} +20 -13
- data/spec/rails3/app_root/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3/app_root/spec/spec_helper.rb +61 -0
- data/spec/rails3/{user_activation_spec.rb → app_root/spec/user_activation_spec.rb} +60 -20
- data/spec/rails3/{user_activity_logging_spec.rb → app_root/spec/user_activity_logging_spec.rb} +4 -4
- data/spec/rails3/{user_brute_force_protection_spec.rb → app_root/spec/user_brute_force_protection_spec.rb} +7 -7
- data/spec/rails3/app_root/spec/user_oauth_spec.rb +39 -0
- data/spec/rails3/{user_remember_me_spec.rb → app_root/spec/user_remember_me_spec.rb} +4 -4
- data/spec/rails3/{user_reset_password_spec.rb → app_root/spec/user_reset_password_spec.rb} +21 -41
- data/spec/rails3/{user_spec.rb → app_root/spec/user_spec.rb} +68 -38
- metadata +127 -58
- data/spec/rails3/app_root/test/fixtures/users.yml +0 -9
- data/spec/rails3/app_root/test/performance/browsing_test.rb +0 -9
- data/spec/rails3/app_root/test/test_helper.rb +0 -13
- data/spec/rails3/app_root/test/unit/user_test.rb +0 -8
- data/spec/rails3/spec_helper.rb +0 -135
- /data/spec/rails3/{Rakefile → app_root/Rakefile} +0 -0
data/spec/rails3/spec_helper.rb
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
|
|
2
|
-
|
|
3
|
-
# require 'simplecov'
|
|
4
|
-
# SimpleCov.root File.join(File.dirname(__FILE__), "app_root" )
|
|
5
|
-
# SimpleCov.start do
|
|
6
|
-
# add_filter "/config/"
|
|
7
|
-
#
|
|
8
|
-
# add_group 'Controllers', 'app/controllers'
|
|
9
|
-
# add_group 'Models', 'app/models'
|
|
10
|
-
# add_group 'Helpers', 'app/helpers'
|
|
11
|
-
# add_group 'Libraries', 'lib'
|
|
12
|
-
# add_group 'Plugins', 'vendor/plugins'
|
|
13
|
-
# add_group 'Migrations', 'db/migrate'
|
|
14
|
-
# end
|
|
15
|
-
|
|
16
|
-
# Set the default environment to sqlite3's in_memory database
|
|
17
|
-
ENV['RAILS_ENV'] ||= 'in_memory'
|
|
18
|
-
ENV['RAILS_ROOT'] = 'app_root'
|
|
19
|
-
|
|
20
|
-
# Load the Rails environment and testing framework
|
|
21
|
-
require "#{File.dirname(__FILE__)}/app_root/config/environment"
|
|
22
|
-
#require "#{File.dirname(__FILE__)}/../../init" # for plugins
|
|
23
|
-
require 'rspec/rails'
|
|
24
|
-
#require 'sorcery'
|
|
25
|
-
|
|
26
|
-
# Undo changes to RAILS_ENV
|
|
27
|
-
silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
|
|
28
|
-
|
|
29
|
-
RSpec.configure do |config|
|
|
30
|
-
config.use_transactional_fixtures = true
|
|
31
|
-
config.use_instantiated_fixtures = false
|
|
32
|
-
config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }#:file_path => /\bspec[\\\/]controllers[\\\/]/ }
|
|
33
|
-
|
|
34
|
-
config.before(:suite) do
|
|
35
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/core")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
config.after(:suite) do
|
|
39
|
-
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/core")
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
#----------------------------------------------------------------
|
|
44
|
-
# needed when running individual specs
|
|
45
|
-
require File.join(File.dirname(__FILE__), 'app_root','app','models','user')
|
|
46
|
-
|
|
47
|
-
class TestUser < ActiveRecord::Base
|
|
48
|
-
activate_sorcery!
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
class TestMailer < ActionMailer::Base
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
module Sorcery
|
|
56
|
-
module Model
|
|
57
|
-
module Submodules
|
|
58
|
-
module TestSubmodule
|
|
59
|
-
def my_instance_method
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [:register_last_activity_time_to_db, :deny_banned_user, :validate_session]
|
|
67
|
-
|
|
68
|
-
def create_new_user(attributes_hash = nil)
|
|
69
|
-
user_attributes_hash = attributes_hash || {:username => 'gizmo', :email => "bla@bla.com", :password => 'secret'}
|
|
70
|
-
@user = User.new(user_attributes_hash)
|
|
71
|
-
@user.save!
|
|
72
|
-
@user
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def login_user(user = nil)
|
|
76
|
-
user ||= @user
|
|
77
|
-
subject.send(:login_user,user)
|
|
78
|
-
subject.send(:after_login!,user,[user.username,'secret'])
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def logout_user
|
|
82
|
-
subject.send(:logout)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def clear_user_without_logout
|
|
86
|
-
subject.instance_variable_set(:@logged_in_user,nil)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# TODO: rename to sorcery_reload!(subs = [], model_opts = {}, controller_opts = {})
|
|
90
|
-
def plugin_model_configure(submodules = [], options = {})
|
|
91
|
-
reload_user_class
|
|
92
|
-
|
|
93
|
-
# return to no-module configuration
|
|
94
|
-
::Sorcery::Controller::Config.init!
|
|
95
|
-
::Sorcery::Controller::Config.reset!
|
|
96
|
-
|
|
97
|
-
# remove all plugin before_filters so they won't fail other tests.
|
|
98
|
-
# I don't like this way, but I didn't find another.
|
|
99
|
-
# hopefully it won't break until Rails 4.
|
|
100
|
-
ApplicationController._process_action_callbacks.delete_if {|c| SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS.include?(c.filter) }
|
|
101
|
-
|
|
102
|
-
# configure
|
|
103
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
104
|
-
::Sorcery::Controller::Config.user_class = nil # the next line will reset it to User
|
|
105
|
-
ActionController::Base.send(:include,::Sorcery::Controller)
|
|
106
|
-
|
|
107
|
-
User.activate_sorcery! do |config|
|
|
108
|
-
options.each do |property,value|
|
|
109
|
-
config.send(:"#{property}=", value)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# TODO: rename to sorcery_model_property_set(prop, val)
|
|
115
|
-
def plugin_set_model_config_property(property, *values)
|
|
116
|
-
User.class_eval do
|
|
117
|
-
sorcery_config.send(:"#{property}=", *values)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# TODO: rename to sorcery_controller_property_set(prop, val)
|
|
122
|
-
def plugin_set_controller_config_property(property, value)
|
|
123
|
-
ApplicationController.activate_sorcery! do |config|
|
|
124
|
-
config.send(:"#{property}=", value)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
private
|
|
129
|
-
|
|
130
|
-
# reload user class between specs
|
|
131
|
-
# so it will be possible to test the different submodules in isolation
|
|
132
|
-
def reload_user_class
|
|
133
|
-
Object.send(:remove_const,:User)
|
|
134
|
-
load 'user.rb'
|
|
135
|
-
end
|
|
File without changes
|