merbful_authentication 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +25 -0
  2. data/README +69 -0
  3. data/Rakefile +35 -0
  4. data/TODO +5 -0
  5. data/activerecord_generators/merbful_authentication_model/merbful_authentication_model_generator.rb +65 -0
  6. data/activerecord_generators/merbful_authentication_model/templates/authenticated_system_orm_map.rb +34 -0
  7. data/activerecord_generators/merbful_authentication_model/templates/migration.rb +20 -0
  8. data/activerecord_generators/merbful_authentication_model/templates/model.rb +63 -0
  9. data/datamapper_generators/merbful_authentication_model/merbful_authentication_model_generator.rb +60 -0
  10. data/datamapper_generators/merbful_authentication_model/templates/authenticated_system_orm_map.rb +34 -0
  11. data/datamapper_generators/merbful_authentication_model/templates/model.rb +78 -0
  12. data/lib/merbful_authentication.rb +10 -0
  13. data/lib/merbful_authentication/merbtasks.rb +6 -0
  14. data/merb_generators/authentication/USAGE +5 -0
  15. data/merb_generators/authentication/authentication_generator.rb +256 -0
  16. data/merb_generators/authentication/templates/activation.html.erb +1 -0
  17. data/merb_generators/authentication/templates/activation.text.erb +1 -0
  18. data/merb_generators/authentication/templates/authenticated_system_controller.rb +132 -0
  19. data/merb_generators/authentication/templates/authenticated_system_model.rb +97 -0
  20. data/merb_generators/authentication/templates/login.html.erb +14 -0
  21. data/merb_generators/authentication/templates/mail_controller.rb +13 -0
  22. data/merb_generators/authentication/templates/model_controller.rb +33 -0
  23. data/merb_generators/authentication/templates/new_model.html.erb +18 -0
  24. data/merb_generators/authentication/templates/session_controller.rb +33 -0
  25. data/merb_generators/authentication/templates/signup.html.erb +8 -0
  26. data/merb_generators/authentication/templates/signup.text.erb +8 -0
  27. data/rspec_generators/merbful_authentication_tests/merbful_authentication_tests_generator.rb +83 -0
  28. data/rspec_generators/merbful_authentication_tests/templates/authenticated_system_spec_helper.rb +22 -0
  29. data/rspec_generators/merbful_authentication_tests/templates/model_controller_spec.rb +78 -0
  30. data/rspec_generators/merbful_authentication_tests/templates/model_spec.rb +357 -0
  31. data/rspec_generators/merbful_authentication_tests/templates/model_spec_helper.rb +8 -0
  32. data/rspec_generators/merbful_authentication_tests/templates/session_controller_spec.rb +101 -0
  33. data/rspec_generators/merbful_authentication_tests/templates/user_mailer_spec.rb +70 -0
  34. data/test_unit_generators/merbful_authentication_tests/USAGE +5 -0
  35. data/test_unit_generators/merbful_authentication_tests/merbful_authentication_tests_generator.rb +84 -0
  36. data/test_unit_generators/merbful_authentication_tests/templates/authenticated_system_test_helper.rb +50 -0
  37. data/test_unit_generators/merbful_authentication_tests/templates/functional_test.rb +92 -0
  38. data/test_unit_generators/merbful_authentication_tests/templates/mailer_test.rb +66 -0
  39. data/test_unit_generators/merbful_authentication_tests/templates/model_functional_test.rb +92 -0
  40. data/test_unit_generators/merbful_authentication_tests/templates/model_test_helper.rb +8 -0
  41. data/test_unit_generators/merbful_authentication_tests/templates/unit_test.rb +142 -0
  42. metadata +114 -0
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require (File.dirname(__FILE__) / '../authenticated_system_test_helper')
3
+ require (File.dirname(__FILE__) / ".." / "<%= singular_name %>_test_helper")
4
+ include <%= class_name %>TestHelper
5
+
6
+ # Re-raise errors caught by the controller.
7
+ class <%= model_controller_class_name %>; def rescue_action(e) raise e end; end
8
+
9
+ class <%= model_controller_class_name %>Test < Test::Unit::TestCase
10
+
11
+ def setup
12
+ <%= class_name %>.clear_database_table
13
+ @controller = <%= model_controller_class_name %>.build(fake_request)
14
+ @request = @controller.request
15
+ @response = @controller.response
16
+ end
17
+
18
+ def test_should_allow_signup
19
+ assert_difference '<%= class_name %>.count', 1 do
20
+ create_<%= file_name %>
21
+ assert_equal 302, controller.status
22
+ end
23
+ end
24
+
25
+ def test_should_require_login_on_signup
26
+ assert_no_difference '<%= class_name %>.count' do
27
+ create_<%= file_name %>(:login => nil)
28
+ assert controller.assigns(:<%= file_name %>).errors.on(:login)
29
+ assert_response :success
30
+ end
31
+ end
32
+
33
+ def test_should_require_password_on_signup
34
+ assert_no_difference '<%= class_name %>.count' do
35
+ create_<%= file_name %>(:password => nil)
36
+ assert controller.assigns(:<%= file_name %>).errors.on(:password)
37
+ assert_response :success
38
+ end
39
+ end
40
+
41
+ def test_should_require_password_confirmation_on_signup
42
+ assert_no_difference '<%= class_name %>.count' do
43
+ create_<%= file_name %>(:password_confirmation => nil)
44
+ assert controller.assigns(:<%= file_name %>).errors.on(:password_confirmation)
45
+ assert_response :success
46
+ end
47
+ end
48
+
49
+ def test_should_require_email_on_signup
50
+ assert_no_difference '<%= class_name %>.count' do
51
+ create_<%= file_name %>(:email => nil)
52
+ assert controller.assigns(:<%= file_name %>).errors.on(:email)
53
+ assert_response :success
54
+ end
55
+ end
56
+ <% if options[:include_activation] %>
57
+ def test_should_activate_user
58
+ create_<%= singular_name %>( :login => 'aaron', :password => "test", :password_confirmation => "test")
59
+ @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
60
+ assert_not_nil @<%= singular_name %>
61
+ 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']
64
+ assert_response :redirect
65
+ end
66
+
67
+ def test_should_not_activate_user_without_key
68
+ create_<%= singular_name %>( :login => 'aaron', :password => "test", :password_confirmation => "test")
69
+ @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
70
+ assert_not_nil @<%= singular_name %>
71
+ 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
+ assert_nil User.authenticate('aaron', 'test')
77
+ end
78
+
79
+ def test_should_not_activate_user_with_blank_key
80
+ create_<%= singular_name %>( :login => 'aaron', :password => "test", :password_confirmation => "test")
81
+ @<%= singular_name %> = <%= class_name %>.find_with_conditions( :login => 'aaron' )
82
+ assert_not_nil @<%= singular_name %>
83
+ assert_nil <%= class_name %>.authenticate('aaron', 'test')
84
+ get url(:user_activation, :activation_code => "")
85
+ assert_nil <%= class_name %>.authenticate('aaron', 'test')
86
+ end<% end %>
87
+
88
+ protected
89
+ def create_<%= singular_name %>(options = {})
90
+ post "/<%= model_controller_plural_name %>", :<%= singular_name %> => valid_<%= singular_name %>_hash.merge(options)
91
+ end
92
+ end
@@ -0,0 +1,8 @@
1
+ module <%= class_name %>TestHelper
2
+ def valid_<%= singular_name %>_hash
3
+ { :login => "daniel",
4
+ :email => "daniel@example.com",
5
+ :password => "sekret",
6
+ :password_confirmation => "sekret"}
7
+ end
8
+ end
@@ -0,0 +1,142 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require (File.dirname(__FILE__) / '../authenticated_system_test_helper')
3
+ require (File.dirname(__FILE__) / ".." / "<%= singular_name %>_test_helper")
4
+ include <%= class_name %>TestHelper
5
+
6
+ class <%= class_name %>Test < Test::Unit::TestCase
7
+ # # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.
8
+ # # Then, you can remove it from this and the functional test.
9
+ # include AuthenticatedTestHelper
10
+ # fixtures :<%= plural_name %>
11
+ def setup
12
+ <%= class_name %>.clear_database_table
13
+ @<%= singular_name %>_1 = <%= class_name %>.new(valid_<%= singular_name %>_hash.with(
14
+ :login => 'quentin',
15
+ :email => 'quentin@example.com',
16
+ :password => 'test',
17
+ :password_confirmation => 'test',
18
+ :created_at => Time.now - (5 * Merb::Const::DAY)
19
+ ))
20
+ @<%= singular_name %>_2 = User.new(valid_user_hash.with(
21
+ :login => 'aaron',
22
+ :email => 'aaron@example.com',
23
+ :password => 'test',
24
+ :password_confirmation => 'test',
25
+ :created_at => Time.now - (1 * Merb::Const::DAY)
26
+ ))
27
+ @<%= singular_name %>_1.save
28
+ @<%= singular_name %>_2.save
29
+
30
+ @<%= singular_name %>_1.created_at = Time.now - (5 * Merb::Const::DAY)
31
+ @<%= singular_name %>_2.created_at = Time.now - (1 * Merb::Const::DAY)
32
+
33
+ <% if options[:include_activation] -%>
34
+ @<%= singular_name %>_1.activate
35
+ @<%= singular_name %>_2.activate
36
+ <% end -%>
37
+ # Reload from the db to get the right object
38
+ @<%= singular_name %>_1 = <%= class_name %>.find_with_conditions(:login => 'quentin')
39
+ @<%= singular_name %>_2 = <%= class_name %>.find_with_conditions(:login => 'aaron')
40
+
41
+ end
42
+
43
+ def test_should_create_<%= singular_name %>
44
+ assert_difference '<%= class_name %>.count' do
45
+ <%= singular_name %> = create_<%= singular_name %>
46
+ assert !<%= singular_name %>.new_record?, "#{<%= singular_name %>.errors.to_yaml}"
47
+ end
48
+ end
49
+
50
+ def test_should_require_login
51
+ assert_no_difference '<%= class_name %>.count' do
52
+ u = create_<%= singular_name %>(:login => nil)
53
+ assert u.errors.on(:login)
54
+ end
55
+ end
56
+
57
+ def test_should_require_password
58
+ assert_no_difference '<%= class_name %>.count' do
59
+ u = create_<%= singular_name %>(:password => nil)
60
+ assert u.errors.on(:password)
61
+ end
62
+ end
63
+
64
+ def test_should_require_password_confirmation
65
+ assert_no_difference '<%= class_name %>.count' do
66
+ u = create_<%= singular_name %>(:password_confirmation => nil)
67
+ assert u.errors.on(:password_confirmation)
68
+ end
69
+ end
70
+
71
+ def test_should_require_email
72
+ assert_no_difference '<%= class_name %>.count' do
73
+ u = create_<%= singular_name %>(:email => nil)
74
+ assert u.errors.on(:email)
75
+ end
76
+ end
77
+
78
+ def test_should_reset_password
79
+ @<%= singular_name %>_1.password = 'new password'
80
+ @<%= singular_name %>_1.password_confirmation = 'new password'
81
+ @<%= singular_name %>_1.save
82
+ @<%= singular_name %>_1 = <%= class_name %>.find_with_conditions(:login => @<%= singular_name %>_1.login)
83
+ assert_equal @<%= singular_name %>_1, <%= class_name %>.authenticate('quentin', 'new password')
84
+ end
85
+
86
+ def test_should_not_rehash_password
87
+ @<%= singular_name %>_1.login = 'quentin2'
88
+ @<%= singular_name %>_1.save
89
+ @<%= singular_name %>_1 = <%= class_name %>.find_with_conditions(:login => 'quentin2')
90
+ assert_equal @<%= singular_name %>_1, <%= class_name %>.authenticate('quentin2', 'test')
91
+ end
92
+
93
+ def test_should_authenticate_<%= singular_name %>
94
+ assert_equal @<%= singular_name %>_1, <%= class_name %>.authenticate('quentin', 'test')
95
+ end
96
+
97
+ def test_should_set_remember_token
98
+ @<%= singular_name %>_1.remember_me
99
+ assert_not_nil @<%= singular_name %>_1.remember_token
100
+ assert_not_nil @<%= singular_name %>_1.remember_token_expires_at
101
+ end
102
+
103
+ def test_should_unset_remember_token
104
+ @<%= singular_name %>_1.remember_me
105
+ assert_not_nil @<%= singular_name %>_1.remember_token
106
+ @<%= singular_name %>_1.forget_me
107
+ assert_nil @<%= singular_name %>_1.remember_token
108
+ end
109
+
110
+ def test_should_remember_me_for_one_week
111
+ before = (Time.now + 1 * Merb::Const::WEEK).utc
112
+ @<%= singular_name %>_1.remember_me_for Merb::Const::WEEK
113
+ after = (Time.now + 1 * Merb::Const::WEEK).utc
114
+ assert_not_nil @<%= singular_name %>_1.remember_token
115
+ assert_not_nil @<%= singular_name %>_1.remember_token_expires_at
116
+ assert @<%= singular_name %>_1.remember_token_expires_at.between?(before, after)
117
+ end
118
+
119
+ def test_should_remember_me_until_one_week
120
+ time = (Time.now + 1 * Merb::Const::WEEK).utc
121
+ @<%= singular_name %>_1.remember_me_until time
122
+ assert_not_nil @<%= singular_name %>_1.remember_token
123
+ assert_not_nil @<%= singular_name %>_1.remember_token_expires_at
124
+ assert_equal @<%= singular_name %>_1.remember_token_expires_at, time
125
+ end
126
+
127
+ def test_should_remember_me_default_two_weeks
128
+ before = (Time.now + 2 * Merb::Const::WEEK).utc
129
+ @<%= singular_name %>_1.remember_me
130
+ after = (Time.now + 2 * Merb::Const::WEEK).utc
131
+ assert_not_nil @<%= singular_name %>_1.remember_token
132
+ assert_not_nil @<%= singular_name %>_1.remember_token_expires_at
133
+ assert @<%= singular_name %>_1.remember_token_expires_at.between?(before, after)
134
+ end
135
+
136
+ protected
137
+ def create_<%= singular_name %>(options = {})
138
+ u = <%= class_name %>.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
139
+ u.save
140
+ u
141
+ end
142
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merbful_authentication
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Neighman
8
+ autorequire: merbful_authentication
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-05 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.0
23
+ version:
24
+ description: A Merb plugin that is essentially a port of Rick Olsons restful_authentication plugin for rails
25
+ email: has.sox@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - LICENSE
33
+ - TODO
34
+ files:
35
+ - LICENSE
36
+ - README
37
+ - Rakefile
38
+ - TODO
39
+ - lib/merbful_authentication
40
+ - lib/merbful_authentication/merbtasks.rb
41
+ - lib/merbful_authentication.rb
42
+ - merb_generators/authentication
43
+ - merb_generators/authentication/authentication_generator.rb
44
+ - merb_generators/authentication/templates
45
+ - merb_generators/authentication/templates/activation.html.erb
46
+ - merb_generators/authentication/templates/activation.text.erb
47
+ - merb_generators/authentication/templates/authenticated_system_controller.rb
48
+ - merb_generators/authentication/templates/authenticated_system_model.rb
49
+ - merb_generators/authentication/templates/login.html.erb
50
+ - merb_generators/authentication/templates/mail_controller.rb
51
+ - merb_generators/authentication/templates/model_controller.rb
52
+ - merb_generators/authentication/templates/new_model.html.erb
53
+ - merb_generators/authentication/templates/session_controller.rb
54
+ - merb_generators/authentication/templates/signup.html.erb
55
+ - merb_generators/authentication/templates/signup.text.erb
56
+ - merb_generators/authentication/USAGE
57
+ - datamapper_generators/merbful_authentication_model
58
+ - datamapper_generators/merbful_authentication_model/merbful_authentication_model_generator.rb
59
+ - datamapper_generators/merbful_authentication_model/templates
60
+ - datamapper_generators/merbful_authentication_model/templates/authenticated_system_orm_map.rb
61
+ - datamapper_generators/merbful_authentication_model/templates/model.rb
62
+ - activerecord_generators/merbful_authentication_model
63
+ - activerecord_generators/merbful_authentication_model/merbful_authentication_model_generator.rb
64
+ - activerecord_generators/merbful_authentication_model/templates
65
+ - activerecord_generators/merbful_authentication_model/templates/authenticated_system_orm_map.rb
66
+ - activerecord_generators/merbful_authentication_model/templates/migration.rb
67
+ - activerecord_generators/merbful_authentication_model/templates/model.rb
68
+ - rspec_generators/merbful_authentication_tests
69
+ - rspec_generators/merbful_authentication_tests/merbful_authentication_tests_generator.rb
70
+ - rspec_generators/merbful_authentication_tests/templates
71
+ - rspec_generators/merbful_authentication_tests/templates/authenticated_system_spec_helper.rb
72
+ - rspec_generators/merbful_authentication_tests/templates/model_controller_spec.rb
73
+ - rspec_generators/merbful_authentication_tests/templates/model_spec.rb
74
+ - rspec_generators/merbful_authentication_tests/templates/model_spec_helper.rb
75
+ - rspec_generators/merbful_authentication_tests/templates/session_controller_spec.rb
76
+ - rspec_generators/merbful_authentication_tests/templates/user_mailer_spec.rb
77
+ - test_unit_generators/merbful_authentication_tests
78
+ - test_unit_generators/merbful_authentication_tests/merbful_authentication_tests_generator.rb
79
+ - test_unit_generators/merbful_authentication_tests/templates
80
+ - test_unit_generators/merbful_authentication_tests/templates/authenticated_system_test_helper.rb
81
+ - test_unit_generators/merbful_authentication_tests/templates/functional_test.rb
82
+ - test_unit_generators/merbful_authentication_tests/templates/mailer_test.rb
83
+ - test_unit_generators/merbful_authentication_tests/templates/model_functional_test.rb
84
+ - test_unit_generators/merbful_authentication_tests/templates/model_test_helper.rb
85
+ - test_unit_generators/merbful_authentication_tests/templates/unit_test.rb
86
+ - test_unit_generators/merbful_authentication_tests/USAGE
87
+ has_rdoc: true
88
+ homepage: http://rubyforge.org/projects/merbful-auth/
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.0.1
110
+ signing_key:
111
+ specification_version: 2
112
+ summary: A Merb plugin that is essentially a port of Rick Olsons restful_authentication plugin for rails
113
+ test_files: []
114
+