ateam-merb-auth-old 0.0.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/LICENSE +44 -0
- data/README +212 -0
- data/Rakefile +50 -0
- data/TODO +14 -0
- data/activerecord_generators/ma_migration/ma_migration_generator.rb +41 -0
- data/activerecord_generators/ma_migration/templates/schema/migrations/%time_stamp%_add_ma_user.rb +21 -0
- data/app/controllers/application.rb +7 -0
- data/app/controllers/sessions.rb +3 -0
- data/app/controllers/users.rb +3 -0
- data/app/helpers/application_helper.rb +64 -0
- data/app/mailers/user_mailer.rb +24 -0
- data/app/mailers/views/user_mailer/activation.text.erb +1 -0
- data/app/mailers/views/user_mailer/forgot_password.text.erb +5 -0
- data/app/mailers/views/user_mailer/signup.text.erb +7 -0
- data/app/views/layout/merb_auth.html.erb +16 -0
- data/app/views/sessions/new.html.erb +13 -0
- data/app/views/users/new.html.erb +21 -0
- data/datamapper_generators/ma_migration/ma_migration_generator.rb +38 -0
- data/datamapper_generators/ma_migration/templates/schema/migrations/add_ma_user.rb +21 -0
- data/lib/ateam-merb-auth-old.rb +1 -0
- data/lib/merb-auth.rb +184 -0
- data/lib/merb-auth/adapters/activerecord/init.rb +26 -0
- data/lib/merb-auth/adapters/activerecord/map.rb +44 -0
- data/lib/merb-auth/adapters/activerecord/model.rb +81 -0
- data/lib/merb-auth/adapters/common.rb +161 -0
- data/lib/merb-auth/adapters/datamapper/init.rb +28 -0
- data/lib/merb-auth/adapters/datamapper/map.rb +35 -0
- data/lib/merb-auth/adapters/datamapper/model.rb +72 -0
- data/lib/merb-auth/adapters/map.rb +0 -0
- data/lib/merb-auth/adapters/sequel/init.rb +26 -0
- data/lib/merb-auth/adapters/sequel/map.rb +36 -0
- data/lib/merb-auth/adapters/sequel/model.rb +86 -0
- data/lib/merb-auth/controller/controller.rb +113 -0
- data/lib/merb-auth/controller/sessions_base.rb +41 -0
- data/lib/merb-auth/controller/users_base.rb +58 -0
- data/lib/merb-auth/initializer.rb +47 -0
- data/lib/merb-auth/merbtasks.rb +168 -0
- data/lib/merb-auth/slicetasks.rb +102 -0
- data/plugins/forgotten_password/app/controllers/passwords.rb +90 -0
- data/plugins/forgotten_password/app/models/user.rb +52 -0
- data/plugins/forgotten_password/app/views/passwords/edit.html.erb +9 -0
- data/plugins/forgotten_password/app/views/passwords/new.html.erb +4 -0
- data/plugins/forgotten_password/forgotten_password.rb +6 -0
- data/plugins/forgotten_password/init.rb +8 -0
- data/plugins/forgotten_password/spec/controller_spec.rb +236 -0
- data/plugins/forgotten_password/spec/model_spec.rb +52 -0
- data/plugins/forgotten_password/spec/spec_helper.rb +36 -0
- data/public/javascripts/master.js +0 -0
- data/public/stylesheets/master.css +2 -0
- data/spec/controllers/plugins/test_plugin.rb +17 -0
- data/spec/controllers/sessions_spec.rb +118 -0
- data/spec/controllers/users_spec.rb +119 -0
- data/spec/mailers/user_mailer_spec.rb +75 -0
- data/spec/merb_auth_spec.rb +231 -0
- data/spec/models/ar_model_spec.rb +50 -0
- data/spec/models/common_spec.rb +0 -0
- data/spec/models/model_spec.rb +23 -0
- data/spec/models/sq_model_spec.rb +50 -0
- data/spec/shared_specs/shared_model_spec.rb +445 -0
- data/spec/spec_helper.rb +114 -0
- data/spec/spec_helpers/helpers.rb +18 -0
- data/spec/spec_helpers/valid_model_hashes.rb +10 -0
- data/stubs/app/controllers/application.rb +2 -0
- data/stubs/app/controllers/main.rb +2 -0
- data/stubs/app/mailers/views/activation.text.erb +1 -0
- data/stubs/app/mailers/views/signup.text.erb +7 -0
- data/stubs/app/views/sessions/new.html.erb +14 -0
- data/stubs/app/views/users/new.html.erb +18 -0
- metadata +120 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec'
|
5
|
+
require 'merb-core'
|
6
|
+
require 'merb-slices'
|
7
|
+
|
8
|
+
Merb::BootLoader.before_app_loads do
|
9
|
+
Merb::Slices::config[:merb_auth][:forgotten_password] = true
|
10
|
+
end
|
11
|
+
|
12
|
+
require File.join(File.expand_path(dir), "..", "..", "..", "spec", "spec_helper.rb")
|
13
|
+
|
14
|
+
|
15
|
+
module Merb
|
16
|
+
def self.orm_generator_scope
|
17
|
+
"datamapper"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
23
|
+
adapter_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "merb-auth", "adapters"))
|
24
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
25
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
26
|
+
MA.load_slice
|
27
|
+
|
28
|
+
class User
|
29
|
+
include MA::Adapter::DataMapper
|
30
|
+
end
|
31
|
+
|
32
|
+
User.auto_migrate!
|
33
|
+
MA.activate
|
34
|
+
Merb::Router.prepare{|r| r.add_slice(:MerbAuth)}
|
35
|
+
MA.load_plugins!
|
36
|
+
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MerbAuth
|
2
|
+
module Controller
|
3
|
+
module Tester
|
4
|
+
def self.included(base)
|
5
|
+
base.send(:include, InstanceMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def new
|
10
|
+
"NEW TEST"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Users.send(:include, Controller::Tester) # include the plugin into the Users controller to override the behaviour
|
17
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe MA::Sessions, "Index action" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Object.class_eval do
|
7
|
+
remove_const("User") if defined?(User)
|
8
|
+
end
|
9
|
+
|
10
|
+
MA[:use_activation] = true
|
11
|
+
|
12
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
13
|
+
Merb.stub!(:orm_generator_scope).and_return("datamapper")
|
14
|
+
|
15
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
16
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
17
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
18
|
+
MA.load_slice
|
19
|
+
|
20
|
+
class User
|
21
|
+
include MA::Adapter::DataMapper
|
22
|
+
include MerbAuth::Adapter::DataMapper::DefaultModelSetup
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
User.clear_database_table
|
29
|
+
u = User.new
|
30
|
+
u.valid?
|
31
|
+
@quentin = User.create(valid_user_hash.with(:email => "quentin@example.com", :password => "test", :password_confirmation => "test"))
|
32
|
+
@controller = MA::Sessions.new(fake_request)
|
33
|
+
@quentin.activate
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have a route to Sessions#new from '/login'" do
|
37
|
+
request_to("/merb-auth/login") do |params|
|
38
|
+
params[:controller].should == "Sessions"
|
39
|
+
params[:action].should == "create"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should route to Sessions#create from '/login' via post" do
|
44
|
+
request_to("/merb-auth/login", :post) do |params|
|
45
|
+
params[:controller].should == "Sessions"
|
46
|
+
params[:action].should == "create"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should have a named route :login" do
|
51
|
+
@controller.url(:login).should == "/merb-auth/login"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have route to Sessions#destroy from '/logout' via delete" do
|
55
|
+
request_to("/merb-auth/logout", :delete) do |params|
|
56
|
+
params[:controller].should == "Sessions"
|
57
|
+
params[:action].should == "destroy"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should route to Sessions#destroy from '/logout' via get" do
|
62
|
+
request_to("/merb-auth/logout") do |params|
|
63
|
+
params[:controller].should == "Sessions"
|
64
|
+
params[:action].should == "destroy"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'logins and redirects' do
|
69
|
+
controller = post "/merb-auth/login", :email => 'quentin@example.com', :password => 'test'
|
70
|
+
controller.session[:user].should_not be_nil
|
71
|
+
controller.session[:user].should == @quentin.id
|
72
|
+
controller.should redirect_to("/")
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'fails login and does not redirect' do
|
76
|
+
controller = post "/merb-auth/login", :email => 'quentin@example.com', :password => 'bad password'
|
77
|
+
controller.session[:user].should be_nil
|
78
|
+
controller.should be_successful
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'logs out' do
|
82
|
+
controller = get("/merb-auth/logout"){|controller| controller.stub!(:current_user).and_return(@quentin) }
|
83
|
+
controller.session[:user].should be_nil
|
84
|
+
controller.should redirect
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'remembers me' do
|
88
|
+
controller = post "/merb-auth/login", :email => 'quentin@example.com', :password => 'test', :remember_me => "1"
|
89
|
+
controller.cookies["auth_token"].should_not be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does not remember me' do
|
93
|
+
controller = post "/merb-auth/login", :email => 'quentin@example.com', :password => 'test', :remember_me => "0"
|
94
|
+
controller.cookies["auth_token"].should be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'deletes token on logout' do
|
98
|
+
controller = get("/merb-auth/logout") {|request| request.stub!(:current_user).and_return(@quentin) }
|
99
|
+
controller.cookies["auth_token"].should == nil
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
it 'logs in with cookie' do
|
104
|
+
@quentin.remember_me
|
105
|
+
controller = get "/merb-auth/login" do |c|
|
106
|
+
c.request.env[Merb::Const::HTTP_COOKIE] = "auth_token=#{@quentin.remember_token}"
|
107
|
+
end
|
108
|
+
controller.should be_logged_in
|
109
|
+
end
|
110
|
+
|
111
|
+
def auth_token(token)
|
112
|
+
CGI::Cookie.new('name' => 'auth_token', 'value' => token)
|
113
|
+
end
|
114
|
+
|
115
|
+
def cookie_for(user)
|
116
|
+
auth_token user.remember_token
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe MA::Users do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
|
7
|
+
|
8
|
+
MA[:use_activation] = true
|
9
|
+
|
10
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
11
|
+
Merb.stub!(:orm_generator_scope).and_return("datamapper")
|
12
|
+
|
13
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
14
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
15
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
16
|
+
MA.load_slice
|
17
|
+
MA.activate
|
18
|
+
|
19
|
+
class User
|
20
|
+
include MA::Adapter::DataMapper
|
21
|
+
include MerbAuth::Adapter::DataMapper::DefaultModelSetup
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
User.clear_database_table
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have MixinSessionContainer mixed into the User Controller" do
|
30
|
+
Merb::Controller.should include(::Merb::SessionMixin)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should provide a current_ma_user method" do
|
34
|
+
MA::Users.new({}).should respond_to(:current_ma_user)
|
35
|
+
MA::Users.new({}).should respond_to(:current_user)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should provide a current_user method" do
|
39
|
+
MA::Users.new({}).should respond_to(:current_ma_user=)
|
40
|
+
MA::Users.new({}).should respond_to(:current_user=)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'allows signup' do
|
44
|
+
# lambda do
|
45
|
+
users = User.count
|
46
|
+
controller = create_user
|
47
|
+
controller.should redirect
|
48
|
+
User.count.should == (users + 1)
|
49
|
+
# end.should change(User, :count).by(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'requires password on signup' do
|
53
|
+
lambda do
|
54
|
+
controller = create_user(:password => nil)
|
55
|
+
controller.assigns(:user).errors.on(:password).should_not be_nil
|
56
|
+
controller.should respond_successfully
|
57
|
+
end.should_not change(User, :count)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'requires password confirmation on signup' do
|
61
|
+
lambda do
|
62
|
+
controller = create_user(:password_confirmation => nil)
|
63
|
+
controller.assigns(:user).errors.should_not be_empty
|
64
|
+
controller.should respond_successfully
|
65
|
+
end.should_not change(User, :count)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'requires email on signup' do
|
69
|
+
lambda do
|
70
|
+
controller = create_user(:email => nil)
|
71
|
+
controller.assigns(:user).errors.on(:email).should_not be_nil
|
72
|
+
controller.should respond_successfully
|
73
|
+
end.should_not change(User, :count)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have a route for user activation" do
|
77
|
+
request_to("/merb-auth/users/activate/1234") do |params|
|
78
|
+
params[:controller].should == "Users"
|
79
|
+
params[:action].should == "activate"
|
80
|
+
params[:activation_code].should == "1234"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'activates user' do
|
85
|
+
controller = create_user(:email => "aaron@example.com", :password => "test", :password_confirmation => "test")
|
86
|
+
@user = controller.assigns(:user)
|
87
|
+
User.authenticate('aaron@example.com', 'test').should be_nil
|
88
|
+
controller = get "/merb-auth/users/activate/#{@user.activation_code}"
|
89
|
+
controller.should redirect_to("/")
|
90
|
+
User.authenticate('aaron@example.com', 'test').should_not be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should log the user in automatically on creation if :use_activation is false" do
|
94
|
+
MA[:use_activation] = false
|
95
|
+
dispatch_to(MA::Users, :create, :user => {:email => "aaron@example.com", :password => "test", :password_confirmation => "test"}) do |c|
|
96
|
+
u = mock("user")
|
97
|
+
User.should_receive(:new).and_return(u)
|
98
|
+
u.should_receive(:save).and_return(true)
|
99
|
+
c.should_receive(:current_ma_user=).with(u)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not log the user in automatically on creation if :use_activation is true" do
|
104
|
+
MA[:use_activation] = true
|
105
|
+
dispatch_to(MA::Users, :create, :user => {:email => "aaron@example.com", :password => "test", :password_confirmation => "test"}) do |c|
|
106
|
+
u = mock("user")
|
107
|
+
User.should_receive(:new).and_return(u)
|
108
|
+
u.should_receive(:save).and_return(true)
|
109
|
+
c.should_not_receive(:current_ma_user=)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
def create_user(options = {})
|
117
|
+
post "/merb-auth/users/", :user => valid_user_hash.merge(options)
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe MA::UserMailer do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
MA[:use_activation] = true
|
7
|
+
|
8
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
9
|
+
Merb.stub!(:orm_generator_scope).and_return("datamapper")
|
10
|
+
|
11
|
+
adapter_path = File.join( File.dirname(__FILE__), "..", "..", "lib", "merb-auth", "adapters")
|
12
|
+
MA.register_adapter :datamapper, "#{adapter_path}/datamapper"
|
13
|
+
MA.register_adapter :activerecord, "#{adapter_path}/activerecord"
|
14
|
+
MA.loaded
|
15
|
+
|
16
|
+
class User
|
17
|
+
include MA::Adapter::DataMapper
|
18
|
+
include MerbAuth::Adapter::DataMapper::DefaultModelSetup
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def deliver(action, mail_opts= {},opts = {})
|
23
|
+
MA::UserMailer.dispatch_and_deliver action, mail_opts, opts
|
24
|
+
@delivery = Merb::Mailer.deliveries.last
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
@u = MA[:user].new(:email => "homer@simpsons.com", :login => "homer", :activation_code => "12345")
|
29
|
+
@mailer_params = { :from => "info@mysite.com",
|
30
|
+
:to => @u.email,
|
31
|
+
:subject => "Welcome to MySite.com" }
|
32
|
+
end
|
33
|
+
|
34
|
+
after(:each) do
|
35
|
+
Merb::Mailer.deliveries.clear
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should send mail to homer@simpsons.com for the signup email" do
|
39
|
+
deliver(:signup, @mailer_params, :user => @u)
|
40
|
+
@delivery.assigns(:headers).should include("to: homer@simpsons.com")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should send the mail from 'info@mysite.com' for the signup email" do
|
44
|
+
deliver(:signup, @mailer_params, :user => @u)
|
45
|
+
@delivery.assigns(:headers).should include("from: info@mysite.com")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should mention the users login in the text signup mail" do
|
49
|
+
deliver(:signup, @mailer_params, :user => @u)
|
50
|
+
@delivery.text.should include(@u.email)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should mention the activation link in the signup emails" do
|
54
|
+
deliver(:signup, @mailer_params, :user => @u)
|
55
|
+
the_url = MA::UserMailer.new.url(:user_activation, :activation_code => @u.activation_code)
|
56
|
+
the_url.should_not be_nil
|
57
|
+
@delivery.text.should include( the_url )
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should send mail to homer@simpson.com for the activation email" do
|
61
|
+
deliver(:activation, @mailer_params, :user => @u)
|
62
|
+
@delivery.assigns(:headers).should include("to: homer@simpsons.com")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should send the mail from 'info@mysite.com' for the activation email" do
|
66
|
+
deliver(:activation, @mailer_params, :user => @u)
|
67
|
+
@delivery.assigns(:headers).should include("from: info@mysite.com")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should mention ther users login in the text activation mail" do
|
71
|
+
deliver(:activation, @mailer_params, :user => @u)
|
72
|
+
@delivery.text.should include(@u.email)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'activerecord'
|
3
|
+
require 'dm-core'
|
4
|
+
|
5
|
+
# For note purposes
|
6
|
+
# Merb::Slices.register_and_load(../../lib/merb-auth.rb)
|
7
|
+
|
8
|
+
describe MerbAuth do
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
@adapter_path = File.dirname(__FILE__) / ".." / "lib" / "merb-auth" / "adapters"
|
12
|
+
@ar_path = @adapter_path / "activerecord"
|
13
|
+
@config = Merb::Slices::config[:merb_auth]
|
14
|
+
DataMapper.setup(:default, 'sqlite3::memory:')
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
register_activerecord!
|
19
|
+
register_datamapper!
|
20
|
+
register_sequel!
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
MA.clear_adapter_list!
|
25
|
+
MA[:user] = nil
|
26
|
+
::DataMapper::Resource.descendants.delete(User) if defined?(User)
|
27
|
+
Object.class_eval do
|
28
|
+
remove_const("User") if defined?(User)
|
29
|
+
end
|
30
|
+
MA::Adapter.module_eval do
|
31
|
+
remove_const("DataMapper") if defined?(MA::Adapter::DataMapper)
|
32
|
+
end if defined?(MA::Adapter)
|
33
|
+
end
|
34
|
+
|
35
|
+
def stub_orm_scope(scope = "datamapper")
|
36
|
+
Merb.stub!(:orm_generator_scope).and_return(scope)
|
37
|
+
end
|
38
|
+
|
39
|
+
def register_activerecord!
|
40
|
+
MA.register_adapter :activerecord, "#{@adapter_path}/activerecord"
|
41
|
+
end
|
42
|
+
|
43
|
+
def register_datamapper!
|
44
|
+
MA.register_adapter :datamapper, "#{@adapter_path}/datamapper"
|
45
|
+
end
|
46
|
+
|
47
|
+
def register_sequel!
|
48
|
+
MA.register_adapter :sequel, "#{@adapter_path}/sequel"
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Adapter Loading" do
|
52
|
+
|
53
|
+
it "should allow adapters to register themselves" do
|
54
|
+
MA.adapters[:activerecord][:path].should == @ar_path
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should clear the registered adapters (for specs only)" do
|
58
|
+
MA.adapters.should_not be_empty
|
59
|
+
MA.clear_adapter_list!
|
60
|
+
MA.adapters.should be_empty
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return a hash of registered adapters" do
|
64
|
+
MA.adapters.should be_a_kind_of(Hash)
|
65
|
+
MA.adapters.keys.should include(:activerecord)
|
66
|
+
MA.adapters.keys.should include(:datamapper)
|
67
|
+
MA.adapters.keys.should include(:sequel)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should load the adapter" do
|
71
|
+
defined?(MA::Adapter::DataMapper).should be_nil
|
72
|
+
MA.load_adapter!(:datamapper)
|
73
|
+
defined?(MA::Adapter::DataMapper).should_not be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise an error if an adapter is loaded that has not been registered" do
|
77
|
+
lambda do
|
78
|
+
MA.load_adapter!(:no_adapter)
|
79
|
+
end.should raise_error(RuntimeError, "MerbAuth: Adapter Not Registered - no_adapter")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should load the adapter scope as the type if there is no specified adapter type" do
|
83
|
+
Merb.should_receive(:orm_generator_scope).and_return("datamapper")
|
84
|
+
MA.load_adapter!
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should load the correct adapter in the loaded hook" do
|
88
|
+
stub_orm_scope
|
89
|
+
defined?(MA::Adapter::DataMapper).should be_nil
|
90
|
+
MA.loaded
|
91
|
+
defined?(MA::Adapter::DataMapper).should_not be_nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should expose the adapter model class via the configuration" do
|
95
|
+
stub_orm_scope
|
96
|
+
MA.load_adapter!
|
97
|
+
class User
|
98
|
+
include MA::Adapter::DataMapper
|
99
|
+
end
|
100
|
+
MA[:user].should == User
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should allow DM to create it's table correctly" do
|
104
|
+
stub_orm_scope
|
105
|
+
MA[:user] = nil
|
106
|
+
MA.load_adapter!
|
107
|
+
class User
|
108
|
+
include MA::Adapter::DataMapper
|
109
|
+
include MA::Adapter::DataMapper::DefaultModelSetup
|
110
|
+
end
|
111
|
+
|
112
|
+
results = DataMapper.auto_migrate!
|
113
|
+
results.should include(User)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "controller Plugin loading" do
|
119
|
+
|
120
|
+
def add_test_plugin!
|
121
|
+
MA.plugins["Tester"] = File.join(File.dirname(__FILE__), "controllers", "plugins", "test_plugin.rb")
|
122
|
+
end
|
123
|
+
|
124
|
+
before(:each) do
|
125
|
+
reload_ma!
|
126
|
+
end
|
127
|
+
|
128
|
+
after(:all) do
|
129
|
+
reload_ma!
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should allow for registration" do
|
133
|
+
defined?(MA::Controller::Tester).should be_nil
|
134
|
+
reload_ma!("User"){ add_test_plugin! }
|
135
|
+
defined?(MA::Controller::Tester).should_not be_nil
|
136
|
+
MA::Users.should include(MA::Controller::Tester)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should overwrite the new method" do
|
140
|
+
Object.class_eval <<-EOS
|
141
|
+
class User
|
142
|
+
include MerbAuth::Adapter::DataMapper
|
143
|
+
include MerbAuth::Adapter::DataMapper::DefaultModelSetup
|
144
|
+
end
|
145
|
+
EOS
|
146
|
+
controller = dispatch_to(MA::Users, :new)
|
147
|
+
controller.body.should_not == "NEW TEST"
|
148
|
+
reload_ma!("User"){ add_test_plugin!}
|
149
|
+
controller = dispatch_to(MA::Users, :new)
|
150
|
+
controller.body.should == "NEW TEST"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "MerbAuth (module)" do
|
157
|
+
|
158
|
+
# Feel free to remove the specs below
|
159
|
+
|
160
|
+
it "should be registered in Merb::Slices.slices" do
|
161
|
+
Merb::Slices.slices.should include(MerbAuth)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should have an :identifier property" do
|
165
|
+
MerbAuth.identifier.should == "merb-auth"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should have an :identifier_sym property" do
|
169
|
+
MerbAuth.identifier_sym.should == :merb_auth
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should have a :root property" do
|
173
|
+
MerbAuth.root.should == current_slice_root
|
174
|
+
MerbAuth.root_path('app').should == current_slice_root / 'app'
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should have metadata properties" do
|
178
|
+
MerbAuth.description.should == "MerbAuth is a Merb slice that provides authentication"
|
179
|
+
MerbAuth.version.should == "0.1.0"
|
180
|
+
MerbAuth.author.should == "Merb Core"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should have a config property (Hash)" do
|
184
|
+
MerbAuth.config.should be_kind_of(Hash)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should have a :layout config option set" do
|
188
|
+
MerbAuth.config[:layout].should == :merb_auth
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should have a dir_for method" do
|
192
|
+
app_path = MerbAuth.dir_for(:application)
|
193
|
+
app_path.should == current_slice_root / 'app'
|
194
|
+
[:view, :model, :controller, :helper, :mailer, :part].each do |type|
|
195
|
+
MerbAuth.dir_for(type).should == app_path / "#{type}s"
|
196
|
+
end
|
197
|
+
public_path = MerbAuth.dir_for(:public)
|
198
|
+
public_path.should == current_slice_root / 'public'
|
199
|
+
[:stylesheet, :javascript, :image].each do |type|
|
200
|
+
MerbAuth.dir_for(type).should == public_path / "#{type}s"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should have a app_dir_for method" do
|
205
|
+
root_path = MerbAuth.app_dir_for(:root)
|
206
|
+
root_path.should == Merb.root / 'slices' / 'merb-auth'
|
207
|
+
app_path = MerbAuth.app_dir_for(:application)
|
208
|
+
app_path.should == root_path / 'app'
|
209
|
+
[:view, :model, :controller, :helper, :mailer, :part].each do |type|
|
210
|
+
MerbAuth.app_dir_for(type).should == app_path / "#{type}s"
|
211
|
+
end
|
212
|
+
public_path = MerbAuth.app_dir_for(:public)
|
213
|
+
public_path.should == Merb.dir_for(:public) / 'slices' / 'merb-auth'
|
214
|
+
[:stylesheet, :javascript, :image].each do |type|
|
215
|
+
MerbAuth.app_dir_for(type).should == public_path / "#{type}s"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should have a public_dir_for method" do
|
220
|
+
public_path = MerbAuth.public_dir_for(:public)
|
221
|
+
public_path.should == '/slices' / 'merb-auth'
|
222
|
+
[:stylesheet, :javascript, :image].each do |type|
|
223
|
+
MerbAuth.public_dir_for(type).should == public_path / "#{type}s"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should keep a list of path component types to use when copying files" do
|
228
|
+
(MerbAuth.mirrored_components & MerbAuth.slice_paths.keys).length.should == MerbAuth.mirrored_components.length
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|