jsmestad-merb-auth-slice-activation 1.0.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.textile +205 -0
- data/Rakefile +57 -0
- data/app/controllers/activations.rb +24 -0
- data/app/controllers/application.rb +5 -0
- data/app/helpers/application_helper.rb +64 -0
- data/app/helpers/mailer_helper.rb +29 -0
- data/app/mailers/activation_mailer.rb +18 -0
- data/app/mailers/views/activation_mailer/activation.text.erb +1 -0
- data/app/mailers/views/activation_mailer/signup.text.erb +7 -0
- data/app/views/layout/merb_auth_slice_activation.html.erb +16 -0
- data/config/init.rb +84 -0
- data/lib/merb-auth-slice-activation.rb +91 -0
- data/lib/merb-auth-slice-activation/merbtasks.rb +112 -0
- data/lib/merb-auth-slice-activation/mixins/activated_user.rb +118 -0
- data/lib/merb-auth-slice-activation/mixins/activated_user/ar_activated_user.rb +21 -0
- data/lib/merb-auth-slice-activation/mixins/activated_user/dm_activated_user.rb +24 -0
- data/lib/merb-auth-slice-activation/mixins/activated_user/sq_activated_user.rb +23 -0
- data/lib/merb-auth-slice-activation/slicetasks.rb +18 -0
- data/lib/merb-auth-slice-activation/spectasks.rb +75 -0
- data/merb-auth-slice-activation.gemspec +48 -0
- data/public/javascripts/master.js +0 -0
- data/public/stylesheets/master.css +2 -0
- data/spec/controllers/activations_spec.rb +83 -0
- data/spec/mailers/activation_mailer_spec.rb +68 -0
- data/spec/mixins/activated_user_spec.rb +122 -0
- data/spec/spec_helper.rb +61 -0
- data/stubs/app/controllers/activations.rb +8 -0
- data/stubs/app/mailers/views/activation_mailer/activation.text.erb +1 -0
- data/stubs/app/mailers/views/activation_mailer/signup.text.erb +7 -0
- metadata +99 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "merb-auth-slice-activation"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.date = "2008-12-08"
|
5
|
+
s.summary = "Adding Activation to merb-auth"
|
6
|
+
s.email = "justin.smestad@gmail.com"
|
7
|
+
s.homepage = "http://github.com/jsmestad/merb-auth-slice-activation"
|
8
|
+
s.description = "Adding activation via email to merb-auth"
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.authors = ["Christian Kebekus", "Justin Smestad"]
|
11
|
+
s.files = [
|
12
|
+
"README.textile",
|
13
|
+
"Rakefile",
|
14
|
+
"merb-auth-slice-activation.gemspec",
|
15
|
+
"app/controllers/activations.rb",
|
16
|
+
"app/controllers/application.rb",
|
17
|
+
"app/helpers/application_helper.rb",
|
18
|
+
"app/helpers/mailer_helper.rb",
|
19
|
+
"app/mailers/activation_mailer.rb",
|
20
|
+
"app/mailers/views/activation_mailer/activation.text.erb",
|
21
|
+
"app/mailers/views/activation_mailer/signup.text.erb",
|
22
|
+
"app/views/layout/merb_auth_slice_activation.html.erb",
|
23
|
+
"config/init.rb",
|
24
|
+
"lib/merb-auth-slice-activation.rb",
|
25
|
+
"lib/merb-auth-slice-activation/merbtasks.rb",
|
26
|
+
"lib/merb-auth-slice-activation/slicetasks.rb",
|
27
|
+
"lib/merb-auth-slice-activation/spectasks.rb",
|
28
|
+
"lib/merb-auth-slice-activation/mixins/activated_user.rb",
|
29
|
+
"lib/merb-auth-slice-activation/mixins/activated_user/ar_activated_user.rb",
|
30
|
+
"lib/merb-auth-slice-activation/mixins/activated_user/dm_activated_user.rb",
|
31
|
+
"lib/merb-auth-slice-activation/mixins/activated_user/sq_activated_user.rb",
|
32
|
+
"public/javascripts/master.js",
|
33
|
+
"public/stylesheets/master.css",
|
34
|
+
"stubs/app/controllers/activations.rb",
|
35
|
+
"stubs/app/mailers/views/activation_mailer/activation.text.erb",
|
36
|
+
"stubs/app/mailers/views/activation_mailer/signup.text.erb"
|
37
|
+
]
|
38
|
+
s.test_files = [
|
39
|
+
"spec/spec_helper.rb",
|
40
|
+
"spec/controllers/activations_spec.rb",
|
41
|
+
"spec/mailers/activation_mailer_spec.rb",
|
42
|
+
"spec/mixins/activated_user_spec.rb"
|
43
|
+
]
|
44
|
+
s.rdoc_options = ["--main", "README.textile"]
|
45
|
+
s.extra_rdoc_files = ["README.textile"]
|
46
|
+
s.add_dependency("merb", ["> 1.0.0"])
|
47
|
+
s.add_dependency("merb-auth", ["> 1.0.0"])
|
48
|
+
end
|
File without changes
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Activation in the controller" do
|
4
|
+
before(:all) do
|
5
|
+
Merb::Router.reset!
|
6
|
+
Merb::Router.prepare do
|
7
|
+
match("/foos").to(:controller => "foo", :action => "index")
|
8
|
+
add_slice(:merb_auth_slice_activation, :path_prefix => "activation")
|
9
|
+
end
|
10
|
+
|
11
|
+
User.all.destroy!
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
Merb::Router.reset!
|
16
|
+
end
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@active_user = User.create( user_attributes(:login => "fred") )
|
20
|
+
@active_user.activate!
|
21
|
+
@user = User.create( user_attributes(:login => "barney", :email => "barney@example.com"))
|
22
|
+
|
23
|
+
class TestStrategy < Merb::Authentication::Strategy
|
24
|
+
def run!
|
25
|
+
User.first(:login => request.params[:login])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Foo < Merb::Controller
|
30
|
+
before :ensure_authenticated
|
31
|
+
def index ; "INDEX" ; end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
after(:each) do
|
37
|
+
User.all.destroy!
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Authenticating the session" do
|
41
|
+
|
42
|
+
it "should successfully login a user who is activated" do
|
43
|
+
@active_user.should be_active
|
44
|
+
result = request("/foos", :params => {:login => "fred"})
|
45
|
+
result.status.should == 200
|
46
|
+
result.body.should == "INDEX"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise an error for a user who is not activated" do
|
50
|
+
@user.should_not be_active
|
51
|
+
result = request("/foos", :params => {:login => "barney"})
|
52
|
+
result.should_not be_successful
|
53
|
+
result.status.should == 401
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should refuse entry until activated" do
|
57
|
+
@user.should_not be_active
|
58
|
+
result = request("/foos", :params => {:login => "barney"})
|
59
|
+
result.status.should == 401
|
60
|
+
@user.activate!
|
61
|
+
result = request("/foos", :params => {:login => "barney"})
|
62
|
+
result.should be_successful
|
63
|
+
result.body.should == "INDEX"
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "activating a user" do
|
69
|
+
it "should activate a user with the correct activation code" do
|
70
|
+
ac = @user.activation_code
|
71
|
+
ac.should_not be_nil
|
72
|
+
@user.should_not be_active
|
73
|
+
request("/activation/activate/#{ac}")
|
74
|
+
User.first(:login => "barney").should be_active
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should redirect after activation" do
|
78
|
+
r = request("/activation/activate/#{@user.activation_code}")
|
79
|
+
r.should redirect
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "ActivationMailer" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
Merb::Router.prepare { add_slice(:merb_auth_slice_activation)}
|
7
|
+
User.auto_migrate!
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
Merb::Router.reset!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe MerbAuthSliceActivation::ActivationMailer do
|
15
|
+
|
16
|
+
def deliver(action, mail_opts= {},opts = {})
|
17
|
+
MerbAuthSliceActivation::ActivationMailer.dispatch_and_deliver action, mail_opts, opts
|
18
|
+
@delivery = Merb::Mailer.deliveries.last
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
@u = User.new(:email => "homer@simpsons.com", :login => "homer", :activation_code => "12345")
|
23
|
+
@mailer_params = { :from => "info@mysite.com", :to => @u.email, :subject => "Welcome to MySite.com" }
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:each) do
|
27
|
+
Merb::Mailer.deliveries.clear
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send mail to homer@simpsons.com for the signup email" do
|
31
|
+
deliver(:signup, @mailer_params, :user => @u)
|
32
|
+
@delivery.assigns(:headers).should include("to: homer@simpsons.com")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should send the mail from 'info@mysite.com' for the signup email" do
|
36
|
+
deliver(:signup, @mailer_params, :user => @u)
|
37
|
+
@delivery.assigns(:headers).should include("from: info@mysite.com")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should mention the users login in the text signup mail" do
|
41
|
+
deliver(:signup, @mailer_params, :user => @u)
|
42
|
+
@delivery.text.should include(@u.login)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should mention the activation link in the signup emails" do
|
46
|
+
deliver(:signup, @mailer_params, :user => @u)
|
47
|
+
the_url = MerbAuthSliceActivation::ActivationMailer.new.slice_url(:activate, :activation_code => @u.activation_code)
|
48
|
+
the_url.should_not be_nil
|
49
|
+
@delivery.text.should include( the_url )
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should send mail to homer@simpson.com for the activation email" do
|
53
|
+
deliver(:activation, @mailer_params, :user => @u)
|
54
|
+
@delivery.assigns(:headers).should include("to: homer@simpsons.com")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should send the mail from 'info@mysite.com' for the activation email" do
|
58
|
+
deliver(:activation, @mailer_params, :user => @u)
|
59
|
+
@delivery.assigns(:headers).should include("from: info@mysite.com")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should mention ther users login in the text activation mail" do
|
63
|
+
deliver(:activation, @mailer_params, :user => @u)
|
64
|
+
@delivery.text.should include(@u.email)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Actviated User" do
|
4
|
+
before(:all) do
|
5
|
+
Merb::Router.prepare { add_slice(:merb_auth_slice_activation)}
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:all) do
|
9
|
+
Merb::Router.reset!
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "ActivatedUser Mixin" do
|
13
|
+
|
14
|
+
include ActivatedUserSpecHelper
|
15
|
+
|
16
|
+
before(:all) do
|
17
|
+
User.auto_migrate!
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@user = User.new(user_attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
User.all.destroy!
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should add the 'activated_at' property to the user model" do
|
29
|
+
@user.should respond_to(:activated_at)
|
30
|
+
@user.should respond_to(:activated_at=)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should add the 'activation_code' property to the user model" do
|
34
|
+
@user.should respond_to(:activation_code)
|
35
|
+
@user.should respond_to(:activation_code=)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should mark all new users as not activated" do
|
39
|
+
@user.activated?.should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should mark all new users as not active" do
|
43
|
+
@user.active?.should == false
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
describe "ActivatedUser Mixin Activation Code" do
|
50
|
+
|
51
|
+
include ActivatedUserSpecHelper
|
52
|
+
|
53
|
+
before(:all) do
|
54
|
+
User.auto_migrate!
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:each) do
|
58
|
+
User.all.destroy!
|
59
|
+
end
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
@user = User.new(user_attributes)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set the activation_code" do
|
66
|
+
@user.activation_code.should be_nil
|
67
|
+
@user.save
|
68
|
+
@user.activation_code.should_not be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
describe "Activation" do
|
74
|
+
|
75
|
+
include ActivatedUserSpecHelper
|
76
|
+
|
77
|
+
before(:all) do
|
78
|
+
User.auto_migrate!
|
79
|
+
end
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
User.all.destroy!
|
83
|
+
@user = User.create(user_attributes)
|
84
|
+
end
|
85
|
+
|
86
|
+
after(:each) do
|
87
|
+
User.all.destroy!
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should mark users as active" do
|
91
|
+
@user.should_not be_active
|
92
|
+
@user.activate!
|
93
|
+
@user.should be_active
|
94
|
+
@user.reload
|
95
|
+
@user.should be_active
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should mark user as (just) activated" do
|
99
|
+
@user.activate!
|
100
|
+
@user.should be_recently_activated
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should set the activated_at property to the current date and time" do
|
104
|
+
now = DateTime.now
|
105
|
+
DateTime.should_receive(:now).and_return(now)
|
106
|
+
@user.activate!
|
107
|
+
@user.activated_at.should == now
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should clear out the activation code" do
|
111
|
+
@user.activation_code.should_not be_nil
|
112
|
+
@user.activate!
|
113
|
+
@user.activation_code.should be_nil
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should send out the activation notification" do
|
117
|
+
@user.should_receive(:send_activation_notification)
|
118
|
+
@user.activate!
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'merb-core'
|
3
|
+
require 'merb-slices'
|
4
|
+
require 'spec'
|
5
|
+
require 'dm-core'
|
6
|
+
require 'dm-validations'
|
7
|
+
|
8
|
+
# Add merb-auth-slice-activation.rb to the search path
|
9
|
+
Merb::Plugins.config[:merb_slices][:auto_register] = true
|
10
|
+
Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb-auth-slice-activation.rb')
|
11
|
+
|
12
|
+
# Using Merb.root below makes sure that the correct root is set for
|
13
|
+
# - testing standalone, without being installed as a gem and no host application
|
14
|
+
# - testing from within the host application; its root will be used
|
15
|
+
Merb.start_environment(
|
16
|
+
:testing => true,
|
17
|
+
:adapter => 'runner',
|
18
|
+
:environment => ENV['MERB_ENV'] || 'test',
|
19
|
+
:merb_root => Merb.root,
|
20
|
+
:session_store => :memory,
|
21
|
+
:exception_details => true
|
22
|
+
)
|
23
|
+
|
24
|
+
module Merb
|
25
|
+
module Test
|
26
|
+
module SliceHelper
|
27
|
+
|
28
|
+
# The absolute path to the current slice
|
29
|
+
def current_slice_root
|
30
|
+
@current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
31
|
+
end
|
32
|
+
|
33
|
+
# Whether the specs are being run from a host application or standalone
|
34
|
+
def standalone?
|
35
|
+
Merb.root == ::MerbAuthSliceActivation.root
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module ActivatedUserSpecHelper
|
43
|
+
def user_attributes(options = {})
|
44
|
+
{ :login => 'fred',
|
45
|
+
:email => 'fred@example.com'
|
46
|
+
}.merge(options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Merb::Mailer
|
51
|
+
self.delivery_method = :test_send
|
52
|
+
end
|
53
|
+
|
54
|
+
Spec::Runner.configure do |config|
|
55
|
+
config.include(Merb::Test::ViewHelper)
|
56
|
+
config.include(Merb::Test::RouteHelper)
|
57
|
+
config.include(Merb::Test::ControllerHelper)
|
58
|
+
config.include(Merb::Test::SliceHelper)
|
59
|
+
config.include(ActivatedUserSpecHelper)
|
60
|
+
config.before(:all){ User.auto_migrate! }
|
61
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Your email has been authenticated <%= @user.email %>
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jsmestad-merb-auth-slice-activation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Kebekus
|
8
|
+
- Justin Smestad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-12-08 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: merb
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: merb-auth
|
27
|
+
version_requirement:
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
version:
|
34
|
+
description: Adding activation via email to merb-auth
|
35
|
+
email: justin.smestad@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README.textile
|
42
|
+
files:
|
43
|
+
- README.textile
|
44
|
+
- Rakefile
|
45
|
+
- merb-auth-slice-activation.gemspec
|
46
|
+
- app/controllers/activations.rb
|
47
|
+
- app/controllers/application.rb
|
48
|
+
- app/helpers/application_helper.rb
|
49
|
+
- app/helpers/mailer_helper.rb
|
50
|
+
- app/mailers/activation_mailer.rb
|
51
|
+
- app/mailers/views/activation_mailer/activation.text.erb
|
52
|
+
- app/mailers/views/activation_mailer/signup.text.erb
|
53
|
+
- app/views/layout/merb_auth_slice_activation.html.erb
|
54
|
+
- config/init.rb
|
55
|
+
- lib/merb-auth-slice-activation.rb
|
56
|
+
- lib/merb-auth-slice-activation/merbtasks.rb
|
57
|
+
- lib/merb-auth-slice-activation/slicetasks.rb
|
58
|
+
- lib/merb-auth-slice-activation/spectasks.rb
|
59
|
+
- lib/merb-auth-slice-activation/mixins/activated_user.rb
|
60
|
+
- lib/merb-auth-slice-activation/mixins/activated_user/ar_activated_user.rb
|
61
|
+
- lib/merb-auth-slice-activation/mixins/activated_user/dm_activated_user.rb
|
62
|
+
- lib/merb-auth-slice-activation/mixins/activated_user/sq_activated_user.rb
|
63
|
+
- public/javascripts/master.js
|
64
|
+
- public/stylesheets/master.css
|
65
|
+
- stubs/app/controllers/activations.rb
|
66
|
+
- stubs/app/mailers/views/activation_mailer/activation.text.erb
|
67
|
+
- stubs/app/mailers/views/activation_mailer/signup.text.erb
|
68
|
+
has_rdoc: false
|
69
|
+
homepage: http://github.com/jsmestad/merb-auth-slice-activation
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --main
|
73
|
+
- README.textile
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.2.0
|
92
|
+
signing_key:
|
93
|
+
specification_version: 2
|
94
|
+
summary: Adding Activation to merb-auth
|
95
|
+
test_files:
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/controllers/activations_spec.rb
|
98
|
+
- spec/mailers/activation_mailer_spec.rb
|
99
|
+
- spec/mixins/activated_user_spec.rb
|