devise_sequel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 3.0.0"
4
+ gem "oa-oauth", :require => "omniauth/oauth"
5
+ gem "oa-openid", :require => "omniauth/openid"
6
+
7
+ group :test do
8
+ gem "webrat", "0.7.2", :require => false
9
+ gem "mocha", :require => false
10
+ gem 'sqlite3-ruby'
11
+ end
12
+
13
+ gem 'sequel'
14
+ gem 'sequel-rails'
15
+
16
+ gem "warden", "~> 1.0.3"
17
+ gem "orm_adapter", "~> 0.0.3"
18
+ gem "orm_adapter-sequel", :path => '/home/mooman/git/orm_adapter-sequel'
19
+ gem "bcrypt-ruby", "~> 2.1.2", :require => "bcrypt"
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 Rachot Moragraan (janechii AT gmail)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ Sequel mapping to Devise
2
+ ========================
3
+
4
+ **At least version 1.2.rc of Devise is required**
5
+
6
+ Please report any issues.
7
+
8
+ I like to extend only the models I need for Devise:
9
+
10
+ class User < Sequel::Model
11
+ extend Devise::Models
12
+ extend Devise::Orm::Sequel::Hook
13
+
14
+ # usually active_model is included already in any Sequel Rails 3 connectors
15
+ # plugin :active_model
16
+
17
+ devise ...
18
+ end
19
+
20
+ But if you want them to be globally available for all your Sequal models, then uncomment the lines at the bottom of the sequel.rb file in the plugin. Hopefully this can be more elegant in the future where you can set an option somewhere.
21
+
22
+ Let us know if you have any suggestions and/or questions by creating a new issue.
23
+
24
+ Credits / Contributors
25
+ ======================
26
+
27
+ Rachot Moragraan
28
+ Daniel Lyons
29
+
30
+ A lot of testing designs are from dm-devise.
31
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Run Devise tests using Sequel. Specify path to devise with DEVISE_PATH'
5
+ Rake::TestTask.new(:test) do |test|
6
+ ENV['DEVISE_ORM'] ||= 'sequel'
7
+ ENV['DEVISE_PATH'] ||= File.expand_path('../devise')
8
+ unless File.exist?(ENV['DEVISE_PATH'])
9
+ puts "Specify the path to devise (e.g. rake DEVISE_PATH=/path/to/devise). Not found at #{ENV['DEVISE_PATH']}"
10
+ exit
11
+ end
12
+ test.libs << 'lib' << 'test'
13
+ test.libs << "#{ENV['DEVISE_PATH']}/lib"
14
+ test.libs << "#{ENV['DEVISE_PATH']}/test"
15
+ test.test_files = FileList["#{ENV['DEVISE_PATH']}/test/**/*_test.rb"] + FileList['test/**/*_test.rb']
16
+ test.verbose = true
17
+ end
@@ -0,0 +1,46 @@
1
+ require 'devise/orm/sequel/schema'
2
+ require 'devise/orm/sequel/compatibility'
3
+
4
+ module Devise
5
+ module Orm
6
+ module Sequel
7
+ module Hook
8
+ def devise_modules_hook!
9
+ extend Schema
10
+ include Compatibility
11
+ include ActiveModel::Validations
12
+
13
+ # obviously this doesn't work yet
14
+ def self.validates_uniqueness_of(*fields)
15
+ end
16
+
17
+ yield
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # this is an issue with anonymous classes being selected too, which #name returns nil
25
+ # raises lots of errors with Sequel. suggested fix from
26
+ # https://rails.lighthouseapp.com/projects/8994/tickets/5252-activemodel-naming-should-take-care-of-anonymous-classes
27
+ module ActiveModel
28
+ module Translation
29
+ def lookup_ancestors
30
+ self.ancestors.select { |x| not x.anonymous? and x.respond_to?(:model_name) }
31
+ end
32
+ end
33
+ end
34
+
35
+ if defined?(Sequel) then
36
+ # extend Sequel Model
37
+ # uncomment the following lines to have ALL sequel models compatible with Devise
38
+
39
+ # Sequel::Model.extend(Devise::Models)
40
+ # Sequel::Model.extend(Devise::Orm::Sequel::Hook)
41
+ # Sequel::Model.plugin :active_model
42
+ # Sequel::Model.plugin :validation_class_methods
43
+
44
+ # probably just need the apply_schema method
45
+ Sequel::Schema::Generator.send(:include, Devise::Orm::Sequel::Schema)
46
+ end
@@ -0,0 +1,83 @@
1
+ module Devise
2
+ module Orm
3
+ module Sequel
4
+
5
+ module Compatibility
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+
10
+ # for some reason devise tests still use create! from the model itself
11
+ def create! (*args)
12
+ # to_adapter.create!(*args)
13
+ o = new(*args)
14
+ raise unless o.save
15
+ o
16
+ end
17
+
18
+ # Hooks for confirmable
19
+ def before_create (*args)
20
+ wrap_hook(:before_create, *args)
21
+ end
22
+
23
+ def after_create (*args)
24
+ wrap_hook(:after_create, *args)
25
+ end
26
+
27
+ def before_save (*args)
28
+ wrap_hook(:before_save, *args)
29
+ end
30
+
31
+ def wrap_hook (action, *args)
32
+ options = args.extract_options!
33
+ callbacks = []
34
+
35
+ # basically creates a new callback method with _devise_hook suffix
36
+ # so that the if option can be supported
37
+ # and then rewrite the original hook method to run the new callbacks
38
+ # and continue with original hook (it's not pretty)
39
+ args.each do |callback|
40
+ callbacks << new_callback = :"#{callback}_devise_hook"
41
+
42
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
43
+ def #{new_callback}
44
+ #{callback} if #{options[:if] || true}
45
+ end
46
+ METHOD
47
+ end
48
+
49
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
50
+ alias_method :orig_#{action}, :#{action}
51
+
52
+ def #{action}
53
+ #{callbacks.join(';')}
54
+
55
+ # original method can still call super
56
+ orig_#{action}
57
+ end
58
+ METHOD
59
+ end
60
+ end # ClassMethods
61
+
62
+ def changed?
63
+ modified?
64
+ end
65
+
66
+ def save!
67
+ save(:raise_on_failure => true)
68
+ end
69
+
70
+ def update_attributes (*args)
71
+ update(*args)
72
+ end
73
+
74
+ def attributes= (hash, guarded=true)
75
+ (guarded) ? set(hash) : set_all(hash)
76
+ end
77
+
78
+ end # Compatibility
79
+
80
+ end # Sequel
81
+
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ require 'devise_sequel'
2
+ require 'devise/schema'
3
+
4
+ module Devise
5
+ module Orm
6
+ module Sequel
7
+
8
+ module Schema
9
+ include Devise::Schema
10
+
11
+ SCHEMA_OPTIONS = {
12
+ :limit => :size
13
+ # there's also precision and scale
14
+ }
15
+
16
+ def apply_devise_schema(name, type, options={})
17
+ SCHEMA_OPTIONS.each do |old_key, new_key|
18
+ next unless options.key?(old_key)
19
+ options[new_key] = options.delete(old_key)
20
+ end
21
+
22
+ cname = name.to_s.to_sym
23
+ if cname == :email then
24
+ # special case for "authenticable" method to also add
25
+ # auto incrementing id, since sequel doesn't do this automatically
26
+ primary_key(:id)
27
+ end
28
+
29
+ column(cname, type, options)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ require 'devise'
2
+ require 'sequel'
3
+ require 'sequel-rails'
@@ -0,0 +1,10 @@
1
+ Sequel.extension :migration
2
+ Sequel::Migrator.apply(Sequel::Model.db, "#{File.dirname(__FILE__)}/../rails_app/db/migrate")
3
+ puts 'db migrated'
4
+
5
+ class ActiveSupport::TestCase
6
+ setup do
7
+ User.delete
8
+ Admin.delete
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'shared_admin'
2
+
3
+ class Admin < Sequel::Model
4
+ include Shim
5
+ include SharedAdmin
6
+ end
@@ -0,0 +1,31 @@
1
+ module Shim
2
+ extend ::ActiveSupport::Concern
3
+
4
+ included do |base|
5
+ extend ::Devise::Models
6
+ extend ::Devise::Orm::Sequel::Hook
7
+
8
+ base.raise_on_save_failure = false
9
+ base.raise_on_typecast_failure = false
10
+
11
+ # these methods are not supported, and probably should not be supported,
12
+ # only here to pass some tests
13
+ def update_attribute (name, value)
14
+ send(name.to_s + '=', value)
15
+ save
16
+ end
17
+
18
+ def == (obj)
19
+ obj.equal?(self) ||
20
+ ((obj.class == model) && (obj.pk == pk) && !obj.new?)
21
+ end
22
+
23
+ def base.destroy_all
24
+ delete
25
+ end
26
+
27
+ def base.last (ord)
28
+ order(ord[:order].to_sym).last
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ require 'shared_user'
2
+
3
+ class User < Sequel::Model
4
+ include Shim
5
+ include SharedUser
6
+ end
@@ -0,0 +1,29 @@
1
+ APP_ROOT = File.expand_path("#{DEVISE_PATH}/test/rails_app")
2
+ require "#{APP_ROOT}/config/boot"
3
+
4
+ require "action_controller/railtie"
5
+ require "action_mailer/railtie"
6
+ require "active_resource/railtie"
7
+ require "rails/test_unit/railtie"
8
+
9
+ require "sequel"
10
+ require "sequel-rails/railtie"
11
+ require "orm_adapter-sequel"
12
+ require "devise"
13
+
14
+ module RailsApp
15
+ class Application < Rails::Application
16
+ # Add additional load paths for your own custom dirs
17
+ config.root = APP_ROOT
18
+ config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers views).include?($1) }
19
+ config.autoload_paths += [ File.expand_path("#{File.dirname(__FILE__)}/../app/sequel") ]
20
+
21
+ # Configure sensitive parameters which will be filtered from the log file.
22
+ config.filter_parameters << :password
23
+
24
+ config.action_mailer.default_url_options = { :host => "localhost:3000" }
25
+
26
+ require 'omniauth/oauth'
27
+ require 'omniauth/openid'
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1 @@
1
+ puts 'i am loaded'
@@ -0,0 +1,37 @@
1
+ Sequel.migration do
2
+ up do
3
+ create_table :users do
4
+ primary_key :id
5
+ String :username
6
+ String :facebook_token
7
+
8
+ database_authenticatable :null => false
9
+ confirmable
10
+ recoverable
11
+ rememberable
12
+ trackable
13
+ lockable
14
+ token_authenticatable
15
+
16
+ DateTime :created_at
17
+ DateTime :updated_at
18
+ end
19
+
20
+ create_table :admins do
21
+ primary_key :id
22
+ database_authenticatable :null => true
23
+ encryptable
24
+ rememberable :use_salt => false
25
+ recoverable
26
+ lockable
27
+
28
+ DateTime :created_at
29
+ DateTime :updated_at
30
+ end
31
+ end
32
+
33
+ down do
34
+ drop_table :users
35
+ drop_table :admins
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ DEVISE_ORM = :sequel
3
+ DEVISE_PATH = ENV['DEVISE_PATH']
4
+
5
+ $:.unshift File.dirname(__FILE__)
6
+ puts "\n==> Devise.orm = :sequel"
7
+
8
+ require "rails_app/config/environment"
9
+ require "rails/test_help"
10
+ require "orm/sequel"
11
+
12
+
13
+ I18n.load_path << "#{DEVISE_PATH}/test/support/locale/en.yml"
14
+ require 'mocha'
15
+ require 'webrat'
16
+
17
+ Webrat.configure do |config|
18
+ config.mode = :rails
19
+ config.open_error_files = false
20
+ end
21
+
22
+ Devise::OmniAuth.test_mode!
23
+
24
+ # Add support to load paths so we can overwrite broken webrat setup
25
+ $:.unshift "#{DEVISE_PATH}/test/support"
26
+ Dir["#{DEVISE_PATH}/test/support/**/*.rb"].each { |f| require f }
27
+
28
+ # For generators
29
+ require "rails/generators/test_case"
30
+ require "generators/devise/install_generator"
31
+ require "generators/devise/views_generator"
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_sequel
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Rachot Moragraan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-11 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activemodel
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: devise
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - rc
45
+ version: 1.2.rc
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: sequel
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ description: Sequel support for Devise
62
+ email: janechii@gmail.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - Gemfile
71
+ - MIT-LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/devise/orm/sequel.rb
75
+ - lib/devise/orm/sequel/compatibility.rb
76
+ - lib/devise/orm/sequel/schema.rb
77
+ - lib/devise_sequel.rb
78
+ - test/orm/sequel.rb
79
+ - test/rails_app/app/sequel/admin.rb
80
+ - test/rails_app/app/sequel/shim.rb
81
+ - test/rails_app/app/sequel/user.rb
82
+ - test/rails_app/config/application.rb
83
+ - test/rails_app/config/environment.rb
84
+ - test/rails_app/config/initializers/blah.rb
85
+ - test/rails_app/db/migrate/20100401102949_create_tables.rb
86
+ - test/test_helper.rb
87
+ has_rdoc: false
88
+ homepage: http://github.com/mooman/devise_sequel
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options: []
93
+
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 1
111
+ - 3
112
+ - 6
113
+ version: 1.3.6
114
+ requirements: []
115
+
116
+ rubyforge_project: devise_sequel
117
+ rubygems_version: 1.3.7
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Sequel support for Devise
121
+ test_files: []
122
+