sinatra-authentication 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -1
- data/lib/models/abstract_user.rb +39 -1
- data/lib/models/datamapper_user.rb +2 -1
- data/lib/models/dm_adapter.rb +15 -4
- data/lib/models/mm_adapter.rb +21 -9
- data/lib/models/mongoid_adapter.rb +67 -0
- data/lib/models/mongoid_user.rb +41 -0
- data/lib/models/mongomapper_user.rb +4 -8
- data/lib/models/rufus_tokyo_user.rb +48 -19
- data/lib/models/sequel_adapter.rb +68 -0
- data/lib/models/sequel_user.rb +53 -0
- data/lib/models/tc_adapter.rb +20 -2
- data/lib/sinatra-authentication.rb +35 -23
- data/lib/sinatra-authentication/models.rb +5 -0
- data/lib/views/edit.haml +1 -1
- data/lib/views/login.haml +3 -3
- data/lib/views/signup.haml +4 -4
- data/readme.markdown +53 -3
- data/sinatra-authentication-0.3.2.gem +0 -0
- data/sinatra-authentication.gemspec +86 -60
- data/spec/run_all_specs.rb +8 -0
- data/spec/unit/dm_model_spec.rb +3 -0
- data/spec/unit/mm_model_spec.rb +3 -0
- data/spec/unit/mongoid_model_spec.rb +3 -0
- data/spec/unit/sequel_model_spec.rb +10 -0
- data/spec/unit/tc_model_spec.rb +3 -0
- data/spec/unit/user_specs.rb +119 -0
- data/test/lib/dm_app.rb +1 -0
- data/test/lib/dm_extend_app.rb +1 -0
- data/test/lib/extend_views/edit.haml +4 -0
- data/test/lib/extend_views/signup.haml +4 -4
- data/test/lib/helper.rb +4 -0
- data/test/lib/mm_app.rb +16 -15
- data/test/lib/mongoid_app.rb +29 -0
- data/test/lib/sequel_app.rb +22 -0
- data/test/lib/tc_app.rb +2 -0
- data/test/mongoid_test.rb +5 -0
- data/test/mongomapper_test.rb +36 -35
- data/test/sequel_test.rb +5 -0
- metadata +40 -24
- data/.gitignore +0 -4
Binary file
|
@@ -1,85 +1,111 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sinatra-authentication}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Max Justus Spransy"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{Simple authentication plugin for sinatra.}
|
14
14
|
s.email = %q{maxjustus@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"TODO"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
19
|
+
"History.txt",
|
20
|
+
"Manifest",
|
21
|
+
"Rakefile",
|
22
|
+
"TODO",
|
23
|
+
"example/dm_extend_app.rb",
|
24
|
+
"example/dm_sinbook.rb",
|
25
|
+
"example/extend_views/edit.haml",
|
26
|
+
"example/extend_views/index.haml",
|
27
|
+
"example/extend_views/login.haml",
|
28
|
+
"example/extend_views/show.haml",
|
29
|
+
"example/extend_views/signup.haml",
|
30
|
+
"example/mm_app.rb",
|
31
|
+
"example/tc_app.rb",
|
32
|
+
"example/tc_sinbook.rb",
|
33
|
+
"lib/models/abstract_user.rb",
|
34
|
+
"lib/models/datamapper_user.rb",
|
35
|
+
"lib/models/dm_adapter.rb",
|
36
|
+
"lib/models/mm_adapter.rb",
|
37
|
+
"lib/models/mongoid_adapter.rb",
|
38
|
+
"lib/models/mongoid_user.rb",
|
39
|
+
"lib/models/mongomapper_user.rb",
|
40
|
+
"lib/models/rufus_tokyo_user.rb",
|
41
|
+
"lib/models/sequel_adapter.rb",
|
42
|
+
"lib/models/sequel_user.rb",
|
43
|
+
"lib/models/tc_adapter.rb",
|
44
|
+
"lib/sinatra-authentication.rb",
|
45
|
+
"lib/sinatra-authentication/models.rb",
|
46
|
+
"lib/views/edit.haml",
|
47
|
+
"lib/views/index.haml",
|
48
|
+
"lib/views/login.haml",
|
49
|
+
"lib/views/show.haml",
|
50
|
+
"lib/views/signup.haml",
|
51
|
+
"readme.markdown",
|
52
|
+
"sinatra-authentication-0.3.2.gem",
|
53
|
+
"sinatra-authentication.gemspec",
|
54
|
+
"spec/run_all_specs.rb",
|
55
|
+
"spec/unit/dm_model_spec.rb",
|
56
|
+
"spec/unit/mm_model_spec.rb",
|
57
|
+
"spec/unit/mongoid_model_spec.rb",
|
58
|
+
"spec/unit/sequel_model_spec.rb",
|
59
|
+
"spec/unit/tc_model_spec.rb",
|
60
|
+
"spec/unit/user_specs.rb",
|
61
|
+
"test/datamapper_test.rb",
|
62
|
+
"test/lib/dm_app.rb",
|
63
|
+
"test/lib/dm_extend_app.rb",
|
64
|
+
"test/lib/dm_sinbook.rb",
|
65
|
+
"test/lib/extend_views/edit.haml",
|
66
|
+
"test/lib/extend_views/index.haml",
|
67
|
+
"test/lib/extend_views/login.haml",
|
68
|
+
"test/lib/extend_views/show.haml",
|
69
|
+
"test/lib/extend_views/signup.haml",
|
70
|
+
"test/lib/helper.rb",
|
71
|
+
"test/lib/mm_app.rb",
|
72
|
+
"test/lib/mongoid_app.rb",
|
73
|
+
"test/lib/sequel_app.rb",
|
74
|
+
"test/lib/tc_app.rb",
|
75
|
+
"test/lib/tc_sinbook.rb",
|
76
|
+
"test/mongoid_test.rb",
|
77
|
+
"test/mongomapper_test.rb",
|
78
|
+
"test/route_tests.rb",
|
79
|
+
"test/rufus_tokyo_test.rb",
|
80
|
+
"test/sequel_test.rb"
|
65
81
|
]
|
66
82
|
s.homepage = %q{http://github.com/maxjustus/sinatra-authentication}
|
67
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
68
83
|
s.require_paths = ["lib"]
|
69
84
|
s.rubygems_version = %q{1.3.7}
|
70
85
|
s.summary = %q{Simple authentication plugin for sinatra.}
|
71
86
|
s.test_files = [
|
87
|
+
"spec/run_all_specs.rb",
|
88
|
+
"spec/unit/dm_model_spec.rb",
|
89
|
+
"spec/unit/mm_model_spec.rb",
|
90
|
+
"spec/unit/mongoid_model_spec.rb",
|
91
|
+
"spec/unit/sequel_model_spec.rb",
|
92
|
+
"spec/unit/tc_model_spec.rb",
|
93
|
+
"spec/unit/user_specs.rb",
|
94
|
+
"test/datamapper_test.rb",
|
95
|
+
"test/lib/dm_app.rb",
|
96
|
+
"test/lib/dm_extend_app.rb",
|
72
97
|
"test/lib/dm_sinbook.rb",
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
98
|
+
"test/lib/helper.rb",
|
99
|
+
"test/lib/mm_app.rb",
|
100
|
+
"test/lib/mongoid_app.rb",
|
101
|
+
"test/lib/sequel_app.rb",
|
102
|
+
"test/lib/tc_app.rb",
|
103
|
+
"test/lib/tc_sinbook.rb",
|
104
|
+
"test/mongoid_test.rb",
|
105
|
+
"test/mongomapper_test.rb",
|
106
|
+
"test/route_tests.rb",
|
107
|
+
"test/rufus_tokyo_test.rb",
|
108
|
+
"test/sequel_test.rb"
|
83
109
|
]
|
84
110
|
|
85
111
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../../test/lib/sequel_app')
|
2
|
+
require File.join(File.dirname(__FILE__), '../../test/lib/helper')
|
3
|
+
require File.join(File.dirname(__FILE__), 'user_specs')
|
4
|
+
|
5
|
+
describe User do
|
6
|
+
describe '#get' do
|
7
|
+
it 'Should pass arguments to the underlying ORM' do
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
describe User do
|
2
|
+
before :each do
|
3
|
+
User.all.each do |u|
|
4
|
+
User.delete(u.id)
|
5
|
+
end
|
6
|
+
|
7
|
+
@user = User.set(TestHelper.gen_user_for_model)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'instance' do
|
11
|
+
describe '#update' do
|
12
|
+
before :each do
|
13
|
+
@user.update(:password => 'password', :password_confirmation => 'password')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'Returns an instance if User' do
|
17
|
+
@user.class.should == User
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'Should return true on success' do
|
21
|
+
@user.update(:email => 'max@max.com', :password => 'hi', :password_confirmation => 'hi').should == true
|
22
|
+
@user.update(:email => 'max@max.com').should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Does not allow duplicate email addresses on update' do
|
26
|
+
@user_two = User.set(:email => 'steve@steve.com', :password => 'hi', :password_confirmation => 'hi')
|
27
|
+
@user.update(:email => 'steve@steve.com').should == false
|
28
|
+
#@user.class.should == User
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'Should say saved is false when invalid' do
|
32
|
+
@user.update(:password => 'paz')
|
33
|
+
@user.saved.should == false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#errors' do
|
38
|
+
it 'Returns a string of errors' do
|
39
|
+
@user.update(:password => 'paz')
|
40
|
+
@user.errors.class.should == String && @user.errors.length.should > 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#valid' do
|
45
|
+
it 'Should return false when invalid' do
|
46
|
+
@user.update(:password => 'hi')
|
47
|
+
@user.valid.should == false
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'Should validate format of email' do
|
51
|
+
@user.update(:email => 'meeewewe!!')
|
52
|
+
@user.valid.should == false
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'Should return true when valid' do
|
56
|
+
@user.valid.should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#all' do
|
62
|
+
it 'Should return an array of instances of User' do
|
63
|
+
User.all[0].class.should == User
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'Should return users in descending order of creation time' do
|
67
|
+
@newest_user = User.set(:email => 'hey@hi.com', :password => 'hihihi', :password_confirmation => 'hihihi', :created_at => Time.now + 1)
|
68
|
+
User.all[0].email.should == @newest_user.email
|
69
|
+
end
|
70
|
+
|
71
|
+
#it 'Should accept a page argument in a hash and limit results to 20 by default' do
|
72
|
+
# 40.times do |n|
|
73
|
+
# @newest_user = User.set(:email => "#{n}hey@hi.com", :password => 'hihihi', :password_confirmation => 'hihihi', :created_at => Time.now + n)
|
74
|
+
# end
|
75
|
+
# users = User.all(:page => 0)
|
76
|
+
# users[0].email.should == @newest_user.email
|
77
|
+
# users.size.should == 20
|
78
|
+
# User.all(:page => 1)[0].email.should == "19hey@hi.com"
|
79
|
+
#end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#set' do
|
83
|
+
it 'Returns an instance if User' do
|
84
|
+
@user.class.should == User
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'Timestamps user with Time' do
|
88
|
+
@user.created_at.class.should == Time
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'Should set first user in database as site admin' do
|
92
|
+
@user.site_admin.should == true
|
93
|
+
end
|
94
|
+
|
95
|
+
#it 'Should say saved is true' do
|
96
|
+
# @user.saved.should == true
|
97
|
+
#end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#set!' do
|
101
|
+
before :each do
|
102
|
+
@user = User.set!({:password => 'hi'})
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'Returns an instance if User' do
|
106
|
+
@user.class.should == User
|
107
|
+
end
|
108
|
+
|
109
|
+
#it 'Should say saved is true' do
|
110
|
+
# @user.saved.should == true
|
111
|
+
#end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#delete' do
|
115
|
+
it 'Returns a boolean' do
|
116
|
+
User.delete(@user.id).should == true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/test/lib/dm_app.rb
CHANGED
data/test/lib/dm_extend_app.rb
CHANGED
@@ -16,6 +16,10 @@
|
|
16
16
|
.label
|
17
17
|
%label{:for => "user_email"} Email
|
18
18
|
%input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text", :value => @user.email }
|
19
|
+
.field
|
20
|
+
.label
|
21
|
+
%label{:for => "user_email"} Name
|
22
|
+
%input{ :id => "user_email", :name => "user[name]", :size => 30, :type => "text", :value => @user.name }
|
19
23
|
.field
|
20
24
|
.label
|
21
25
|
%label{:for => "user_password"} New password
|
@@ -6,14 +6,14 @@
|
|
6
6
|
.label
|
7
7
|
%label{:for => "user_email"} Email
|
8
8
|
%input{ :id => "user_email", :name => "user[email]", :size => 30, :type => "text" }
|
9
|
-
.field
|
10
|
-
.label
|
11
|
-
%label{:for => "user_password"} Password
|
12
|
-
%input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" }
|
13
9
|
.field
|
14
10
|
.label
|
15
11
|
%label{:for => "user_name"} Name
|
16
12
|
%input{ :id => "user_name", :name => "user[name]", :size => 30, :type => "text" }
|
13
|
+
.field
|
14
|
+
.label
|
15
|
+
%label{:for => "user_password"} Password
|
16
|
+
%input{ :id => "user_password", :name => "user[password]", :size => 30, :type => "password" }
|
17
17
|
.field
|
18
18
|
.label
|
19
19
|
%label{:for => "user_password_confirmation"} Confirm Password
|
data/test/lib/helper.rb
CHANGED
@@ -2,6 +2,10 @@ class TestHelper
|
|
2
2
|
def self.gen_user
|
3
3
|
{'user[email]' => 'yodawg@gmail.com', 'user[password]' => 'password', 'user[password_confirmation]' => 'password'}
|
4
4
|
end
|
5
|
+
|
6
|
+
def self.gen_user_for_model
|
7
|
+
{:email => 'yodawg@gmail.com', :password => 'password', :password_confirmation => 'password'}
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
def app
|
data/test/lib/mm_app.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'sinatra
|
2
|
+
require 'sinatra'
|
3
3
|
require 'haml'
|
4
|
+
require 'rack-flash'
|
4
5
|
require 'mongo_mapper'
|
5
|
-
require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
|
6
6
|
|
7
|
-
logger = Logger.new($stdout)
|
8
|
-
MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :logger => logger)
|
9
|
-
MongoMapper.database = "fdbk"
|
10
|
-
MongoMapper.database.authenticate(ENV['mongohq_user'], ENV['mongohq_pass'])
|
7
|
+
#logger = Logger.new($stdout)
|
8
|
+
#MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :logger => logger)
|
9
|
+
#MongoMapper.database = "fdbk"
|
10
|
+
#MongoMapper.database.authenticate(ENV['mongohq_user'], ENV['mongohq_pass'])
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
|
11
13
|
|
12
|
-
|
13
|
-
use Rack::Session::Cookie, :secret => "heyhihello"
|
14
|
+
MongoMapper.database = "sinatraauthtest"
|
14
15
|
|
15
|
-
|
16
|
+
use Rack::Session::Cookie, :secret => "heyhihello"
|
17
|
+
use Rack::Flash
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
set :environment, 'development'
|
20
|
+
set :public, 'public'
|
21
|
+
set :views, 'views'
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
23
|
+
get '/' do
|
24
|
+
haml "= render_login_logout", :layout => :layout
|
24
25
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'haml'
|
4
|
+
require 'rack-flash'
|
5
|
+
require 'mongoid'
|
6
|
+
|
7
|
+
#logger = Logger.new($stdout)
|
8
|
+
#MongoMapper.connection = Mongo::Connection.new('db.mongohq.com', 27017, :logger => logger)
|
9
|
+
#MongoMapper.database = "fdbk"
|
10
|
+
#MongoMapper.database.authenticate(ENV['mongohq_user'], ENV['mongohq_pass'])
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), '../../lib/sinatra-authentication')
|
13
|
+
|
14
|
+
Mongoid.configure do |config|
|
15
|
+
name = "sinatraauth_test"
|
16
|
+
host = "localhost"
|
17
|
+
config.master = Mongo::Connection.new.db(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
use Rack::Session::Cookie, :secret => "heyhihello"
|
21
|
+
use Rack::Flash
|
22
|
+
|
23
|
+
set :environment, 'development'
|
24
|
+
set :public, 'public'
|
25
|
+
set :views, 'views'
|
26
|
+
|
27
|
+
get '/' do
|
28
|
+
haml "= render_login_logout", :layout => :layout
|
29
|
+
end
|