somatics3-generators 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Rakefile +9 -1
  2. data/VERSION +1 -1
  3. data/bin/somatics +0 -0
  4. data/bin/somatify +0 -0
  5. data/lib/generators/somatics/associated/associated_generator.rb +184 -0
  6. data/lib/generators/somatics/associated/templates/migration.rb +11 -0
  7. data/lib/generators/somatics/attributes/attributes_generator.rb +8 -5
  8. data/lib/generators/somatics/authenticated/authenticated_generator.rb +27 -195
  9. data/lib/generators/somatics/authenticated/templates/partial_form.html.erb +23 -0
  10. data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +14 -299
  11. data/lib/generators/somatics/authenticated_controller/templates/locales_en.yml +6 -0
  12. data/lib/generators/somatics/authenticated_controller/templates/locales_zh-TW.yml +6 -0
  13. data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +10 -8
  14. data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +11 -43
  15. data/lib/generators/somatics/install/install_generator.rb +26 -3
  16. data/lib/generators/somatics/install/templates/config/locales/devise_zh-TW.yml +39 -0
  17. data/lib/generators/somatics/install/templates/controller_admin.rb +8 -4
  18. data/lib/generators/somatics/install/templates/helper_admin.rb +39 -3
  19. data/lib/generators/somatics/install/templates/initializer_paper_trail.rb +2 -0
  20. data/lib/generators/somatics/install/templates/layout_admin.html.erb +4 -4
  21. data/lib/generators/somatics/install/templates/lib/active_record/diff.rb +61 -0
  22. data/lib/generators/somatics/install/templates/lib/tasks/heroku.rake +30 -0
  23. data/lib/generators/somatics/install/templates/lib/tasks/svn.rake +47 -0
  24. data/lib/generators/somatics/install/templates/partial_versions.html.erb +56 -0
  25. data/lib/generators/somatics/install/templates/public/stylesheets/application.css +863 -0
  26. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +3 -0
  27. data/lib/generators/somatics/install/templates/public/themes/default/stylesheets/application.css +951 -0
  28. data/lib/generators/somatics/install/templates/view_index.html.erb +46 -1
  29. data/lib/generators/somatics/scaffold/scaffold_generator.rb +0 -1
  30. data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +31 -60
  31. data/lib/generators/somatics/scaffold_controller/templates/controller.rb +4 -21
  32. data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +3 -4
  33. data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +2 -0
  34. data/lib/generators/somatics/settings/settings_generator.rb +7 -3
  35. data/lib/generators/somatics/settings_controller/templates/controller.rb +4 -20
  36. data/lib/generators/somatics/settings_controller/templates/partial_form.html.erb +1 -1
  37. data/lib/generators/somatics/settings_controller/templates/view_index.html.erb +2 -2
  38. data/somatics3-generators.gemspec +28 -37
  39. data/templates/somatics.rb +76 -121
  40. metadata +70 -64
  41. data/lib/generators/somatics/authenticated/templates/mailer.rb +0 -25
  42. data/lib/generators/somatics/authenticated/templates/migration.rb +0 -26
  43. data/lib/generators/somatics/authenticated/templates/model.rb +0 -83
  44. data/lib/generators/somatics/authenticated/templates/observer.rb +0 -11
  45. data/lib/generators/somatics/authenticated/templates/test/mailer_test.rb +0 -31
  46. data/lib/generators/somatics/authenticated/templates/test/model_functional_test.rb +0 -93
  47. data/lib/generators/somatics/authenticated/templates/test/sessions_functional_test.rb +0 -82
  48. data/lib/generators/somatics/authenticated/templates/test/unit_test.rb +0 -164
  49. data/lib/generators/somatics/authenticated/templates/test/users.yml +0 -60
  50. data/lib/generators/somatics/authenticated_controller/templates/_model_partial.html.erb +0 -8
  51. data/lib/generators/somatics/authenticated_controller/templates/activation.erb +0 -3
  52. data/lib/generators/somatics/authenticated_controller/templates/authenticated_system.rb +0 -189
  53. data/lib/generators/somatics/authenticated_controller/templates/authenticated_test_helper.rb +0 -10
  54. data/lib/generators/somatics/authenticated_controller/templates/config/initializers/site_keys.rb +0 -38
  55. data/lib/generators/somatics/authenticated_controller/templates/controller.rb +0 -55
  56. data/lib/generators/somatics/authenticated_controller/templates/helper.rb +0 -91
  57. data/lib/generators/somatics/authenticated_controller/templates/mailer.rb +0 -25
  58. data/lib/generators/somatics/authenticated_controller/templates/migration.rb +0 -26
  59. data/lib/generators/somatics/authenticated_controller/templates/model.rb +0 -83
  60. data/lib/generators/somatics/authenticated_controller/templates/observer.rb +0 -11
  61. data/lib/generators/somatics/authenticated_controller/templates/session_helper.rb +0 -2
  62. data/lib/generators/somatics/authenticated_controller/templates/signup.html.erb +0 -19
  63. data/lib/generators/somatics/authenticated_controller/templates/signup_notification.erb +0 -8
  64. data/lib/generators/somatics/authenticated_controller/templates/test/mailer_test.rb +0 -31
  65. data/lib/generators/somatics/authenticated_controller/templates/test/model_functional_test.rb +0 -93
  66. data/lib/generators/somatics/authenticated_controller/templates/test/sessions_functional_test.rb +0 -82
  67. data/lib/generators/somatics/authenticated_controller/templates/test/unit_test.rb +0 -164
  68. data/lib/generators/somatics/authenticated_controller/templates/test/users.yml +0 -60
  69. data/lib/generators/somatics/scaffold_controller/templates/builder_index.pdf.prawn +0 -25
  70. data/lib/generators/somatics/settings_controller/templates/builder_index.pdf.prawn +0 -25
  71. data/lib/generators/somatics/settings_controller/templates/model.rb +0 -54
@@ -1,25 +0,0 @@
1
- class <%= class_name %>Mailer < ActionMailer::Base
2
- def signup_notification(<%= file_name %>)
3
- setup_email(<%= file_name %>)
4
- @subject += 'Please activate your new account'
5
- <% if options[:include_activation] %>
6
- @body[:url] = "http://YOURSITE/activate/#{<%= file_name %>.activation_code}"
7
- <% else %>
8
- @body[:url] = "http://YOURSITE/login/" <% end %>
9
- end
10
-
11
- def activation(<%= file_name %>)
12
- setup_email(<%= file_name %>)
13
- @subject += 'Your account has been activated!'
14
- @body[:url] = "http://YOURSITE/"
15
- end
16
-
17
- protected
18
- def setup_email(<%= file_name %>)
19
- @recipients = "#{<%= file_name %>.email}"
20
- @from = "ADMINEMAIL"
21
- @subject = "[YOURSITE] "
22
- @sent_on = Time.now
23
- @body[:<%= file_name %>] = <%= file_name %>
24
- end
25
- end
@@ -1,26 +0,0 @@
1
- class <%= migration_name %> < ActiveRecord::Migration
2
- def self.up
3
- create_table "<%= table_name %>", :force => true do |t|
4
- t.column :login, :string, :limit => 40
5
- t.column :name, :string, :limit => 100, :default => '', :null => true
6
- t.column :email, :string, :limit => 100
7
- t.column :crypted_password, :string, :limit => 40
8
- t.column :salt, :string, :limit => 40
9
- t.column :created_at, :datetime
10
- t.column :updated_at, :datetime
11
- t.column :remember_token, :string, :limit => 40
12
- t.column :remember_token_expires_at, :datetime
13
- <% if options[:include_activation] -%>
14
- t.column :activation_code, :string, :limit => 40
15
- t.column :activated_at, :datetime<% end %>
16
- <% for attribute in attributes -%>
17
- t.<%= attribute.type %> :<%= attribute.name %>
18
- <% end -%>
19
- end
20
- add_index :<%= table_name %>, :login, :unique => true
21
- end
22
-
23
- def self.down
24
- drop_table "<%= table_name %>"
25
- end
26
- end
@@ -1,83 +0,0 @@
1
- require 'digest/sha1'
2
-
3
- class <%= class_name %> < ActiveRecord::Base
4
- include Authentication
5
- include Authentication::ByPassword
6
- include Authentication::ByCookieToken
7
- <% if options[:aasm] -%>
8
- include Authorization::AasmRoles
9
- <% elsif options[:stateful] -%>
10
- include Authorization::StatefulRoles<% end %>
11
- validates_presence_of :login
12
- validates_length_of :login, :within => 3..40
13
- validates_uniqueness_of :login
14
- validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message
15
-
16
- validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true
17
- validates_length_of :name, :maximum => 100
18
-
19
- validates_presence_of :email
20
- validates_length_of :email, :within => 6..100 #r@a.wk
21
- validates_uniqueness_of :email
22
- validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message
23
-
24
- <% if options[:include_activation] && !options[:stateful] %>before_create :make_activation_code <% end %>
25
-
26
- # HACK HACK HACK -- how to do attr_accessible from here?
27
- # prevents a user from submitting a crafted form that bypasses activation
28
- # anything else you want your user to change should be added here.
29
- attr_accessible :login, :email, :name, :password, :password_confirmation
30
-
31
- <% if options[:include_activation] && !options[:stateful] %>
32
- # Activates the user in the database.
33
- def activate!
34
- @activated = true
35
- self.activated_at = Time.now.utc
36
- self.activation_code = nil
37
- save(false)
38
- end
39
-
40
- # Returns true if the user has just been activated.
41
- def recently_activated?
42
- @activated
43
- end
44
-
45
- def active?
46
- # the existence of an activation code means they have not activated yet
47
- activation_code.nil?
48
- end<% end %>
49
-
50
- # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
51
- #
52
- # uff. this is really an authorization, not authentication routine.
53
- # We really need a Dispatch Chain here or something.
54
- # This will also let us return a human error message.
55
- #
56
- def self.authenticate(login, password)
57
- return nil if login.blank? || password.blank?
58
- u = <% if options[:stateful] %>find_in_state :first, :active, :conditions => {:login => login.downcase}<%
59
- elsif options[:include_activation] %>find :first, :conditions => ['login = ? and activated_at IS NOT NULL', login]<%
60
- else %>find_by_login(login.downcase)<% end %> # need to get the salt
61
- u && u.authenticated?(password) ? u : nil
62
- end
63
-
64
- def login=(value)
65
- write_attribute :login, (value ? value.downcase : nil)
66
- end
67
-
68
- def email=(value)
69
- write_attribute :email, (value ? value.downcase : nil)
70
- end
71
-
72
- protected
73
-
74
- <% if options[:include_activation] -%>
75
- def make_activation_code
76
- <% if options[:stateful] -%>
77
- self.deleted_at = nil
78
- <% end -%>
79
- self.activation_code = self.class.make_token
80
- end
81
- <% end %>
82
-
83
- end
@@ -1,11 +0,0 @@
1
- class <%= class_name %>Observer < ActiveRecord::Observer
2
- def after_create(<%= file_name %>)
3
- <%= class_name %>Mailer.deliver_signup_notification(<%= file_name %>)
4
- end
5
-
6
- def after_save(<%= file_name %>)
7
- <% if options[:include_activation] %>
8
- <%= class_name %>Mailer.deliver_activation(<%= file_name %>) if <%= file_name %>.recently_activated?
9
- <% end %>
10
- end
11
- end
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require '<%= file_name %>_mailer'
3
-
4
- class <%= class_name %>MailerTest < Test::Unit::TestCase
5
- FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
6
- CHARSET = "utf-8"
7
-
8
- include ActionMailer::Quoting
9
-
10
- def setup
11
- ActionMailer::Base.delivery_method = :test
12
- ActionMailer::Base.perform_deliveries = true
13
- ActionMailer::Base.deliveries = []
14
-
15
- @expected = TMail::Mail.new
16
- @expected.set_content_type "text", "plain", { "charset" => CHARSET }
17
- end
18
-
19
- def test_dummy_test
20
- #do nothing
21
- end
22
-
23
- private
24
- def read_fixture(action)
25
- IO.readlines("#{FIXTURES_PATH}/<%= file_name %>_mailer/#{action}")
26
- end
27
-
28
- def encode(subject)
29
- quoted_printable(subject, CHARSET)
30
- end
31
- end
@@ -1,93 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require '<%= model_controller_file_name %>_controller'
3
-
4
- # Re-raise errors caught by the controller.
5
- class <%= model_controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= model_controller_class_name %>ControllerTest < ActionController::TestCase
8
- # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9
- # Then, you can remove it from this and the units test.
10
- include <%= class_name %>AuthenticatedTestHelper
11
-
12
- fixtures :<%= table_name %>
13
-
14
- def test_should_allow_signup
15
- assert_difference '<%= class_name %>.count' do
16
- create_<%= file_name %>
17
- assert_response :redirect
18
- end
19
- end
20
-
21
- def test_should_require_login_on_signup
22
- assert_no_difference '<%= class_name %>.count' do
23
- create_<%= file_name %>(:login => nil)
24
- assert assigns(:<%= file_name %>).errors.on(:login)
25
- assert_response :success
26
- end
27
- end
28
-
29
- def test_should_require_password_on_signup
30
- assert_no_difference '<%= class_name %>.count' do
31
- create_<%= file_name %>(:password => nil)
32
- assert assigns(:<%= file_name %>).errors.on(:password)
33
- assert_response :success
34
- end
35
- end
36
-
37
- def test_should_require_password_confirmation_on_signup
38
- assert_no_difference '<%= class_name %>.count' do
39
- create_<%= file_name %>(:password_confirmation => nil)
40
- assert assigns(:<%= file_name %>).errors.on(:password_confirmation)
41
- assert_response :success
42
- end
43
- end
44
-
45
- def test_should_require_email_on_signup
46
- assert_no_difference '<%= class_name %>.count' do
47
- create_<%= file_name %>(:email => nil)
48
- assert assigns(:<%= file_name %>).errors.on(:email)
49
- assert_response :success
50
- end
51
- end
52
- <% if options[:stateful] %>
53
- def test_should_sign_up_user_in_pending_state
54
- create_<%= file_name %>
55
- assigns(:<%= file_name %>).reload
56
- assert assigns(:<%= file_name %>).pending?
57
- end<% end %>
58
-
59
- <% if options[:include_activation] %>
60
- def test_should_sign_up_user_with_activation_code
61
- create_<%= file_name %>
62
- assigns(:<%= file_name %>).reload
63
- assert_not_nil assigns(:<%= file_name %>).activation_code
64
- end
65
-
66
- def test_should_activate_user
67
- assert_nil <%= class_name %>.authenticate('aaron', 'test')
68
- get :activate, :activation_code => <%= table_name %>(:aaron).activation_code
69
- assert_redirected_to '/<%= controller_routing_path %>/new'
70
- assert_not_nil flash[:notice]
71
- assert_equal <%= table_name %>(:aaron), <%= class_name %>.authenticate('aaron', 'monkey')
72
- end
73
-
74
- def test_should_not_activate_user_without_key
75
- get :activate
76
- assert_nil flash[:notice]
77
- rescue ActionController::RoutingError
78
- # in the event your routes deny this, we'll just bow out gracefully.
79
- end
80
-
81
- def test_should_not_activate_user_with_blank_key
82
- get :activate, :activation_code => ''
83
- assert_nil flash[:notice]
84
- rescue ActionController::RoutingError
85
- # well played, sir
86
- end<% end %>
87
-
88
- protected
89
- def create_<%= file_name %>(options = {})
90
- post :create, :<%= file_name %> => { :login => 'quire', :email => 'quire@example.com',
91
- :password => 'quire69', :password_confirmation => 'quire69' }.merge(options)
92
- end
93
- end
@@ -1,82 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
- require '<%= sessions_controller_name %>_controller'
3
-
4
- # Re-raise errors caught by the controller.
5
- class <%= sessions_controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
-
7
- class <%= sessions_controller_class_name %>ControllerTest < ActionController::TestCase
8
- # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9
- # Then, you can remove it from this and the units test.
10
- include <%= class_name %>AuthenticatedTestHelper
11
-
12
- fixtures :<%= table_name %>
13
-
14
- def test_should_login_and_redirect
15
- post :create, :login => 'quentin', :password => 'monkey'
16
- assert session[:<%= file_name %>_id]
17
- assert_response :redirect
18
- end
19
-
20
- def test_should_fail_login_and_not_redirect
21
- post :create, :login => 'quentin', :password => 'bad password'
22
- assert_nil session[:<%= file_name %>_id]
23
- assert_response :success
24
- end
25
-
26
- def test_should_logout
27
- login_as :quentin
28
- get :destroy
29
- assert_nil session[:<%= file_name %>_id]
30
- assert_response :redirect
31
- end
32
-
33
- def test_should_remember_me
34
- @request.cookies["auth_token"] = nil
35
- post :create, :login => 'quentin', :password => 'monkey', :remember_me => "1"
36
- assert_not_nil @response.cookies["auth_token"]
37
- end
38
-
39
- def test_should_not_remember_me
40
- @request.cookies["auth_token"] = nil
41
- post :create, :login => 'quentin', :password => 'monkey', :remember_me => "0"
42
- puts @response.cookies["auth_token"]
43
- assert @response.cookies["auth_token"].blank?
44
- end
45
-
46
- def test_should_delete_token_on_logout
47
- login_as :quentin
48
- get :destroy
49
- assert @response.cookies["auth_token"].blank?
50
- end
51
-
52
- def test_should_login_with_cookie
53
- <%= table_name %>(:quentin).remember_me
54
- @request.cookies["auth_token"] = cookie_for(:quentin)
55
- get :new
56
- assert @controller.send(:logged_in?)
57
- end
58
-
59
- def test_should_fail_expired_cookie_login
60
- <%= table_name %>(:quentin).remember_me
61
- <%= table_name %>(:quentin).update_attribute :remember_token_expires_at, 5.minutes.ago
62
- @request.cookies["auth_token"] = cookie_for(:quentin)
63
- get :new
64
- assert !@controller.send(:logged_in?)
65
- end
66
-
67
- def test_should_fail_cookie_login
68
- <%= table_name %>(:quentin).remember_me
69
- @request.cookies["auth_token"] = auth_token('invalid_auth_token')
70
- get :new
71
- assert !@controller.send(:logged_in?)
72
- end
73
-
74
- protected
75
- def auth_token(token)
76
- CGI::Cookie.new('name' => 'auth_token', 'value' => token)
77
- end
78
-
79
- def cookie_for(<%= file_name %>)
80
- auth_token <%= table_name %>(<%= file_name %>).remember_token
81
- end
82
- end
@@ -1,164 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class <%= class_name %>Test < ActiveSupport::TestCase
4
- # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.
5
- # Then, you can remove it from this and the functional test.
6
- include <%= class_name %>AuthenticatedTestHelper
7
- fixtures :<%= table_name %>
8
-
9
- def test_should_create_<%= file_name %>
10
- assert_difference '<%= class_name %>.count' do
11
- <%= file_name %> = create_<%= file_name %>
12
- assert !<%= file_name %>.new_record?, "#{<%= file_name %>.errors.full_messages.to_sentence}"
13
- end
14
- end
15
- <% if options[:include_activation] %>
16
- def test_should_initialize_activation_code_upon_creation
17
- <%= file_name %> = create_<%= file_name %>
18
- <%= file_name %>.reload
19
- assert_not_nil <%= file_name %>.activation_code
20
- end
21
- <% end %><% if options[:stateful] %>
22
- def test_should_create_and_start_in_pending_state
23
- <%= file_name %> = create_<%= file_name %>
24
- <%= file_name %>.reload
25
- assert <%= file_name %>.pending?
26
- end
27
-
28
- <% end %>
29
- def test_should_require_login
30
- assert_no_difference '<%= class_name %>.count' do
31
- u = create_<%= file_name %>(:login => nil)
32
- assert u.errors.on(:login)
33
- end
34
- end
35
-
36
- def test_should_require_password
37
- assert_no_difference '<%= class_name %>.count' do
38
- u = create_<%= file_name %>(:password => nil)
39
- assert u.errors.on(:password)
40
- end
41
- end
42
-
43
- def test_should_require_password_confirmation
44
- assert_no_difference '<%= class_name %>.count' do
45
- u = create_<%= file_name %>(:password_confirmation => nil)
46
- assert u.errors.on(:password_confirmation)
47
- end
48
- end
49
-
50
- def test_should_require_email
51
- assert_no_difference '<%= class_name %>.count' do
52
- u = create_<%= file_name %>(:email => nil)
53
- assert u.errors.on(:email)
54
- end
55
- end
56
-
57
- def test_should_reset_password
58
- <%= table_name %>(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
59
- assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin', 'new password')
60
- end
61
-
62
- def test_should_not_rehash_password
63
- <%= table_name %>(:quentin).update_attributes(:login => 'quentin2')
64
- assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin2', 'monkey')
65
- end
66
-
67
- def test_should_authenticate_<%= file_name %>
68
- assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin', 'monkey')
69
- end
70
-
71
- def test_should_set_remember_token
72
- <%= table_name %>(:quentin).remember_me
73
- assert_not_nil <%= table_name %>(:quentin).remember_token
74
- assert_not_nil <%= table_name %>(:quentin).remember_token_expires_at
75
- end
76
-
77
- def test_should_unset_remember_token
78
- <%= table_name %>(:quentin).remember_me
79
- assert_not_nil <%= table_name %>(:quentin).remember_token
80
- <%= table_name %>(:quentin).forget_me
81
- assert_nil <%= table_name %>(:quentin).remember_token
82
- end
83
-
84
- def test_should_remember_me_for_one_week
85
- before = 1.week.from_now.utc
86
- <%= table_name %>(:quentin).remember_me_for 1.week
87
- after = 1.week.from_now.utc
88
- assert_not_nil <%= table_name %>(:quentin).remember_token
89
- assert_not_nil <%= table_name %>(:quentin).remember_token_expires_at
90
- assert <%= table_name %>(:quentin).remember_token_expires_at.between?(before, after)
91
- end
92
-
93
- def test_should_remember_me_until_one_week
94
- time = 1.week.from_now.utc
95
- <%= table_name %>(:quentin).remember_me_until time
96
- assert_not_nil <%= table_name %>(:quentin).remember_token
97
- assert_not_nil <%= table_name %>(:quentin).remember_token_expires_at
98
- assert_equal <%= table_name %>(:quentin).remember_token_expires_at, time
99
- end
100
-
101
- def test_should_remember_me_default_two_weeks
102
- before = 2.weeks.from_now.utc
103
- <%= table_name %>(:quentin).remember_me
104
- after = 2.weeks.from_now.utc
105
- assert_not_nil <%= table_name %>(:quentin).remember_token
106
- assert_not_nil <%= table_name %>(:quentin).remember_token_expires_at
107
- assert <%= table_name %>(:quentin).remember_token_expires_at.between?(before, after)
108
- end
109
- <% if options[:stateful] %>
110
- def test_should_register_passive_<%= file_name %>
111
- <%= file_name %> = create_<%= file_name %>(:password => nil, :password_confirmation => nil)
112
- assert <%= file_name %>.passive?
113
- <%= file_name %>.update_attributes(:password => 'new password', :password_confirmation => 'new password')
114
- <%= file_name %>.register!
115
- assert <%= file_name %>.pending?
116
- end
117
-
118
- def test_should_suspend_<%= file_name %>
119
- <%= table_name %>(:quentin).suspend!
120
- assert <%= table_name %>(:quentin).suspended?
121
- end
122
-
123
- def test_suspended_<%= file_name %>_should_not_authenticate
124
- <%= table_name %>(:quentin).suspend!
125
- assert_not_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin', 'test')
126
- end
127
-
128
- def test_should_unsuspend_<%= file_name %>_to_active_state
129
- <%= table_name %>(:quentin).suspend!
130
- assert <%= table_name %>(:quentin).suspended?
131
- <%= table_name %>(:quentin).unsuspend!
132
- assert <%= table_name %>(:quentin).active?
133
- end
134
-
135
- def test_should_unsuspend_<%= file_name %>_with_nil_activation_code_and_activated_at_to_passive_state
136
- <%= table_name %>(:quentin).suspend!
137
- <%= class_name %>.update_all :activation_code => nil, :activated_at => nil
138
- assert <%= table_name %>(:quentin).suspended?
139
- <%= table_name %>(:quentin).reload.unsuspend!
140
- assert <%= table_name %>(:quentin).passive?
141
- end
142
-
143
- def test_should_unsuspend_<%= file_name %>_with_activation_code_and_nil_activated_at_to_pending_state
144
- <%= table_name %>(:quentin).suspend!
145
- <%= class_name %>.update_all :activation_code => 'foo-bar', :activated_at => nil
146
- assert <%= table_name %>(:quentin).suspended?
147
- <%= table_name %>(:quentin).reload.unsuspend!
148
- assert <%= table_name %>(:quentin).pending?
149
- end
150
-
151
- def test_should_delete_<%= file_name %>
152
- assert_nil <%= table_name %>(:quentin).deleted_at
153
- <%= table_name %>(:quentin).delete!
154
- assert_not_nil <%= table_name %>(:quentin).deleted_at
155
- assert <%= table_name %>(:quentin).deleted?
156
- end
157
- <% end %>
158
- protected
159
- def create_<%= file_name %>(options = {})
160
- record = <%= class_name %>.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire69', :password_confirmation => 'quire69' }.merge(options))
161
- record.<% if options[:stateful] %>register! if record.valid?<% else %>save<% end %>
162
- record
163
- end
164
- end