merbful_authentication 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -3,7 +3,7 @@ merbful_authentication
3
3
 
4
4
  This is a port of the rails plugin "restful_authentication" by Rick Olson to the Merb Web Framework.
5
5
 
6
- It is currently very freshly ported. Please report any bugs / patches to
6
+ Please report any bugs / patches to
7
7
  has.sox /at/ gmail /dot/ com
8
8
 
9
9
  You can find the original at http://svn.techno-weenie.net/projects/plugins/restful_authentication/
@@ -30,19 +30,24 @@ Datamapper
30
30
 
31
31
  === Required Routes
32
32
 
33
- At the moment this version of the plugin requires some named routes. These are included in
34
- lib/authenticated_system/authenticated_routes.rb
35
-
36
- In config/router.rb
37
-
38
- r.resources :users
39
- r.match("/login").to(:controller => "Sessions", :action => "create").name(:login)
40
- r.match("/logout").to(:controller => "Sessions", :action => "destroy").name(:logout)
41
- r.match("/users/activate/:activation_code").to(:controller => "Users", :action => "activate").name(:user_activation)
33
+ There are some routes required to use this plugin. The actual path is unimportant but the _NAME_ of the route is.
42
34
 
35
+ These are located in
36
+ lib/authenticated_system/authenticated_system_routes.rb
37
+
38
+ A method is appended to routes.rb to call Authenticated.add_routes
43
39
 
44
40
  Note:
45
41
  When using activation don't forget to setup your mailer.
42
+
43
+ === Dependencies
44
+
45
+ There is a list of dependencies for merbful_authentication and these are loaded automatically.
46
+
47
+ the dependencies are required in
48
+ lib/authentication_system/authentication_system_dependencies.rb
49
+
50
+ Some requiring code is appended to init.rb if it is not already required.
46
51
 
47
52
 
48
53
  Copyright of original project
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  PLUGIN = "merbful_authentication"
5
5
  NAME = "merbful_authentication"
6
- VERSION = "0.9.0"
6
+ VERSION = "0.9.1"
7
7
  AUTHOR = "Daniel Neighman"
8
8
  EMAIL = "has.sox@gmail.com"
9
9
  HOMEPAGE = "http://rubyforge.org/projects/merbful-auth/"
@@ -131,6 +131,29 @@ class AuthenticatedGenerator < Merb::GeneratorBase
131
131
  copy_files
132
132
 
133
133
 
134
+ # Add the call to include authenticated_dependencies in init.rb
135
+ dr = @destination_root
136
+ init_path = File.join(dr,"config","init.rb")
137
+ if File.open(init_path){ |f| f.read !~ /authenticated_dependencies/ }
138
+ File.open(init_path, "a") do |f|
139
+ o =<<-END
140
+
141
+ begin
142
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'authenticated_system/authenticated_dependencies')
143
+ rescue LoadError
144
+ end
145
+ END
146
+ f << o
147
+ end
148
+ end
149
+
150
+ # Add the routes to routes.rb
151
+ rp = File.join(dr,"config","router.rb")
152
+ if File.open(rp){|f| f.read !~ /AuthenticatedSystem/ }
153
+ File.open(rp, 'a') do |f|
154
+ f << "\n\nAuthenticatedSystem.add_routes rescue nil\n"
155
+ end
156
+ end
134
157
 
135
158
  end
136
159
 
@@ -1,4 +1,3 @@
1
- dependency "merb-mailer", ">= 0.9"
2
1
  class <%= class_name %>Mailer < Merb::MailController
3
2
 
4
3
  def signup_notification
@@ -1,4 +1,7 @@
1
- dependency 'merb_helpers', '>= 0.9' rescue NoMethodError
1
+ require 'merb_helpers'
2
+ <% if include_activation -%>
3
+ require 'merb-mailer'
4
+ <% end -%>
2
5
 
3
6
  base = File.dirname(__FILE__)
4
7
 
@@ -1,9 +1,13 @@
1
1
  # Put the correct routes in place
2
- Merb::BootLoader.after_app_loads do
3
- Merb::Router.prepend do |r|
4
- r.match("/login").to(:controller => "<%= controller_class_name %>", :action => "create").name(:login)
5
- r.match("/logout").to(:controller => "<%= controller_class_name %>", :action => "destroy").name(:logout)
6
- r.match("/<%= plural_name %>/activate/:activation_code").to(:controller => "<%= model_controller_class_name %>", :action => "activate").name(:<%= singular_name %>_activation)
7
- r.resources :users
2
+ module AuthenticatedSystem
3
+ def self.add_routes
4
+ Merb::BootLoader.after_app_loads do
5
+ Merb::Router.prepend do |r|
6
+ r.match("/login").to(:controller => "<%= controller_class_name %>", :action => "create").name(:login)
7
+ r.match("/logout").to(:controller => "<%= controller_class_name %>", :action => "destroy").name(:logout)
8
+ r.match("/<%= plural_name %>/activate/:activation_code").to(:controller => "<%= model_controller_class_name %>", :action => "activate").name(:<%= singular_name %>_activation)
9
+ r.resources :users
10
+ end
11
+ end
8
12
  end
9
13
  end
@@ -2,10 +2,6 @@ Merb::Config.use do |c|
2
2
  c[:session_store] = "memory"
3
3
  end
4
4
 
5
- [Merb::Test::ControllerHelper, Merb::Test::ViewHelper, Merb::Test::RouteHelper].each do |m|
6
- Merb::Test::Helpers.send(:include, m)
7
- end
8
-
9
5
  <% if include_activation -%>
10
6
  class Merb::Mailer
11
7
  self.delivery_method = :test_send
@@ -42,8 +42,14 @@ class MerbfulAuthenticationTestsGenerator < Merb::GeneratorBase
42
42
  @m = m
43
43
 
44
44
  @choices = []
45
- @choices << relative(File.join(@base, "test", "mailers"))
46
- @choices << relative(File.join(@base, "test", "mailers", "%singular_name%_mailer_test.rb"))
45
+ @choices << "test/mailers"
46
+ Dir[File.join(@base, "test", "mailers", "**", "*")].each do |f|
47
+ @choices << relative(f)
48
+ end
49
+
50
+ @choices.each do |f|
51
+ options[f] = include_activation ? true : false
52
+ end
47
53
 
48
54
  @assigns = {
49
55
  :name => name,
@@ -2,10 +2,6 @@ Merb::Config.use do |c|
2
2
  c[:session_store] = "memory"
3
3
  end
4
4
 
5
- [Merb::Test::ControllerHelper, Merb::Test::ViewHelper, Merb::Test::RouteHelper].each do |m|
6
- Merb::Test::Helpers.send(:include, m)
7
- end
8
-
9
5
  <% if include_activation -%>
10
6
  class Merb::Mailer
11
7
  self.delivery_method = :test_send
@@ -40,7 +36,7 @@ def assert_no_difference(expressions, message = nil, &block)
40
36
  end
41
37
 
42
38
 
43
- def assert_response(code = :success)
39
+ def assert_response(code = :success, controller = (@controller || nil))
44
40
  case code
45
41
  when :success
46
42
  assert_equal 200, controller.status
@@ -10,9 +10,8 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
10
10
 
11
11
  def setup
12
12
  <%= class_name %>.clear_database_table
13
- @controller = <%= controller_class_name %>.build(fake_request)
14
- @request = @controller.request
15
- @response = @controller.response
13
+ @controller = <%= controller_class_name %>.new(fake_request)
14
+ @controller.setup_session
16
15
 
17
16
  @<%= singular_name %> = <%= class_name %>.new(valid_<%= singular_name %>_hash.with(:login => 'quentin', :password => 'test', :password_confirmation => 'test'))
18
17
  @<%= singular_name %>.save
@@ -20,67 +19,72 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
20
19
  @<%= singular_name %>.activate
21
20
  <% end -%>
22
21
  end
22
+
23
+ def test_helper_login_as_method
24
+ login_as :quentin
25
+ assert @controller.send(:logged_in?)
26
+ end
23
27
 
24
28
  def test_should_login_and_redirect
25
- controller.params.merge!(:login => 'quentin', :password => 'test')
26
- controller.dispatch(:create)
27
- assert controller.session[:<%= singular_name %>]
29
+ @controller.params.merge!(:login => 'quentin', :password => 'test')
30
+ @controller._dispatch(:create)
31
+ assert @controller.session[:<%= singular_name %>]
28
32
  assert_response :redirect
29
33
  end
30
34
 
31
35
  def test_should_fail_login_and_not_redirect
32
- controller.params.merge!(:login => 'quentin', :password => 'bad password')
33
- controller.dispatch(:create)
34
- assert_nil controller.session[:<%= file_name %>]
36
+ @controller.params.merge!(:login => 'quentin', :password => 'bad password')
37
+ @controller._dispatch(:create)
38
+ assert_nil @controller.session[:<%= file_name %>]
35
39
  assert_response :success
36
40
  end
37
41
 
38
42
  def test_should_logout
39
43
  login_as :quentin
40
- controller.dispatch(:destroy)
41
- assert_nil controller.session[:<%= file_name %>]
44
+ @controller._dispatch(:destroy)
45
+ assert_nil @controller.session[:<%= file_name %>]
42
46
  assert_response :redirect
43
47
  end
44
48
 
45
49
  def test_should_remember_me
46
- controller.params.merge!(:login => 'quentin', :password => 'test', :remember_me => '1')
47
- controller.dispatch(:create)
48
- assert_not_nil controller.cookies["auth_token"]
50
+ @controller.params.merge!(:login => 'quentin', :password => 'test', :remember_me => '1')
51
+ @controller._dispatch(:create)
52
+ assert_not_nil @controller.cookies["auth_token"]
49
53
  end
50
54
 
51
55
  def test_should_not_remember_me
52
- controller.params.merge!(:login => 'quentin', :password => 'test', :remember_me => '0')
53
- controller.dispatch(:create)
54
- assert_nil controller.cookies["auth_token"]
56
+ @controller.params.merge!(:login => 'quentin', :password => 'test', :remember_me => '0')
57
+ @controller._dispatch(:create)
58
+ assert_nil @controller.cookies["auth_token"]
55
59
  end
56
60
 
57
61
  def test_should_delete_token_on_logout
58
62
  login_as :quentin
59
- controller.dispatch(:destroy)
60
- assert_nil controller.cookies["auth_token"]
63
+ @controller._dispatch(:destroy)
64
+ assert_nil @controller.cookies["auth_token"]
61
65
  end
62
66
 
63
67
  def test_should_login_with_cookie
64
68
  @user.remember_me
65
- controller.cookies["auth_token"] = @<%= singular_name %>.remember_token
66
- controller.dispatch(:new)
67
- assert controller.send(:logged_in?)
69
+ @controller.cookies["auth_token"] = @<%= singular_name %>.remember_token
70
+ @controller._dispatch(:new)
71
+ assert @controller.send(:logged_in?)
68
72
  end
69
73
 
70
74
  def test_should_fail_expired_cookie_login
71
75
  @<%= singular_name %>.remember_me
72
76
  @<%= singular_name %>.remember_token_expires_at = (Time.now - (5 * 60))
73
77
  @<%= singular_name %>.save
74
- controller.cookies["auth_token"] = @<%= singular_name %>.remember_token
75
- controller.dispatch(:new)
76
- assert !(controller.send(:logged_in?))
78
+ @controller.cookies["auth_token"] = @<%= singular_name %>.remember_token
79
+ @controller._dispatch(:new)
80
+ assert !(@controller.send(:logged_in?))
77
81
  end
78
82
 
79
83
  def test_should_fail_cookie_login
80
84
  @<%= singular_name %>.remember_me
81
- controller.cookies["auth_token"] = 'invalid_auth_token'
82
- controller.dispatch(:new)
83
- assert !controller.send(:logged_in?)
85
+ @controller.cookies["auth_token"] = 'invalid_auth_token'
86
+ @controller._dispatch(:new)
87
+ assert !@controller.send(:logged_in?)
84
88
  end
85
89
 
86
90
  protected
@@ -10,22 +10,20 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
10
10
 
11
11
  def setup
12
12
  <%= class_name %>.clear_database_table
13
- @controller = <%= model_controller_class_name %>.build(fake_request)
14
- @request = @controller.request
15
- @response = @controller.response
13
+ @controller = <%= model_controller_class_name %>.new(fake_request)
16
14
  end
17
15
 
18
16
  def test_should_allow_signup
19
17
  assert_difference '<%= class_name %>.count', 1 do
20
18
  create_<%= file_name %>
21
- assert_equal 302, controller.status
19
+ assert_equal 302, @controller.status
22
20
  end
23
21
  end
24
22
 
25
23
  def test_should_require_login_on_signup
26
24
  assert_no_difference '<%= class_name %>.count' do
27
25
  create_<%= file_name %>(:login => nil)
28
- assert controller.assigns(:<%= file_name %>).errors.on(:login)
26
+ assert @controller.assigns(:<%= file_name %>).errors.on(:login)
29
27
  assert_response :success
30
28
  end
31
29
  end
@@ -33,7 +31,7 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
33
31
  def test_should_require_password_on_signup
34
32
  assert_no_difference '<%= class_name %>.count' do
35
33
  create_<%= file_name %>(:password => nil)
36
- assert controller.assigns(:<%= file_name %>).errors.on(:password)
34
+ assert @controller.assigns(:<%= file_name %>).errors.on(:password)
37
35
  assert_response :success
38
36
  end
39
37
  end
@@ -41,7 +39,7 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
41
39
  def test_should_require_password_confirmation_on_signup
42
40
  assert_no_difference '<%= class_name %>.count' do
43
41
  create_<%= file_name %>(:password_confirmation => nil)
44
- assert controller.assigns(:<%= file_name %>).errors.on(:password_confirmation)
42
+ assert @controller.assigns(:<%= file_name %>).errors.on(:password_confirmation)
45
43
  assert_response :success
46
44
  end
47
45
  end
@@ -49,7 +47,7 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
49
47
  def test_should_require_email_on_signup
50
48
  assert_no_difference '<%= class_name %>.count' do
51
49
  create_<%= file_name %>(:email => nil)
52
- assert controller.assigns(:<%= file_name %>).errors.on(:email)
50
+ assert @controller.assigns(:<%= file_name %>).errors.on(:email)
53
51
  assert_response :success
54
52
  end
55
53
  end
@@ -59,8 +57,8 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
59
57
  @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
60
58
  assert_not_nil @<%= singular_name %>
61
59
  assert_nil <%= class_name %>.authenticate('aaron', 'test')
62
- get url(:<%= singular_name %>_activation, :activation_code => @<%= singular_name %>.activation_code )
63
- assert_equal '/', controller.headers['Location']
60
+ @controller = get @controller.url(:<%= singular_name %>_activation, :activation_code => @<%= singular_name %>.activation_code )
61
+ assert_equal '/', @controller.headers['Location']
64
62
  assert_response :redirect
65
63
  end
66
64
 
@@ -69,10 +67,6 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
69
67
  @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
70
68
  assert_not_nil @<%= singular_name %>
71
69
  assert_nil <%= class_name %>.authenticate('aaron', 'test')
72
- assert_raise ArgumentError do
73
- @controller = <%= model_controller_class_name %>.build(fake_request)
74
- controller.dispatch(:activate)
75
- end
76
70
  assert_nil User.authenticate('aaron', 'test')
77
71
  end
78
72
 
@@ -81,12 +75,12 @@ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
81
75
  @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
82
76
  assert_not_nil @<%= singular_name %>
83
77
  assert_nil <%= class_name %>.authenticate('aaron', 'test')
84
- get url(:user_activation, :activation_code => "")
78
+ @controller = get @controller.url(:user_activation, :activation_code => " ")
85
79
  assert_nil <%= class_name %>.authenticate('aaron', 'test')
86
80
  end<% end %>
87
81
 
88
82
  protected
89
83
  def create_<%= singular_name %>(options = {})
90
- post "/<%= model_controller_plural_name %>", :<%= singular_name %> => valid_<%= singular_name %>_hash.merge(options)
84
+ @controller = post "/<%= model_controller_singular_name %>", :<%= singular_name %> => valid_<%= singular_name %>_hash.merge(options)
91
85
  end
92
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merbful_authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Neighman
@@ -9,7 +9,7 @@ autorequire: merbful_authentication
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-27 00:00:00 +11:00
12
+ date: 2008-03-05 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency