somatics3-generators 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +60 -0
  6. data/VERSION +1 -0
  7. data/bin/somatics +21 -0
  8. data/bin/somatify +21 -0
  9. data/lib/generators/somatics/authenticated/authenticated_generator.rb +220 -0
  10. data/lib/generators/somatics/authenticated/templates/mailer.rb +25 -0
  11. data/lib/generators/somatics/authenticated/templates/migration.rb +26 -0
  12. data/lib/generators/somatics/authenticated/templates/model.rb +83 -0
  13. data/lib/generators/somatics/authenticated/templates/observer.rb +11 -0
  14. data/lib/generators/somatics/authenticated/templates/test/mailer_test.rb +31 -0
  15. data/lib/generators/somatics/authenticated/templates/test/model_functional_test.rb +93 -0
  16. data/lib/generators/somatics/authenticated/templates/test/sessions_functional_test.rb +82 -0
  17. data/lib/generators/somatics/authenticated/templates/test/unit_test.rb +164 -0
  18. data/lib/generators/somatics/authenticated/templates/test/users.yml +60 -0
  19. data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +323 -0
  20. data/lib/generators/somatics/authenticated_controller/templates/_model_partial.html.erb +8 -0
  21. data/lib/generators/somatics/authenticated_controller/templates/activation.erb +3 -0
  22. data/lib/generators/somatics/authenticated_controller/templates/authenticated_system.rb +189 -0
  23. data/lib/generators/somatics/authenticated_controller/templates/authenticated_test_helper.rb +10 -0
  24. data/lib/generators/somatics/authenticated_controller/templates/config/initializers/site_keys.rb +38 -0
  25. data/lib/generators/somatics/authenticated_controller/templates/controller.rb +55 -0
  26. data/lib/generators/somatics/authenticated_controller/templates/helper.rb +91 -0
  27. data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +29 -0
  28. data/lib/generators/somatics/authenticated_controller/templates/mailer.rb +25 -0
  29. data/lib/generators/somatics/authenticated_controller/templates/migration.rb +26 -0
  30. data/lib/generators/somatics/authenticated_controller/templates/model.rb +83 -0
  31. data/lib/generators/somatics/authenticated_controller/templates/observer.rb +11 -0
  32. data/lib/generators/somatics/authenticated_controller/templates/session_helper.rb +2 -0
  33. data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +43 -0
  34. data/lib/generators/somatics/authenticated_controller/templates/signup.html.erb +19 -0
  35. data/lib/generators/somatics/authenticated_controller/templates/signup_notification.erb +8 -0
  36. data/lib/generators/somatics/authenticated_controller/templates/test/mailer_test.rb +31 -0
  37. data/lib/generators/somatics/authenticated_controller/templates/test/model_functional_test.rb +93 -0
  38. data/lib/generators/somatics/authenticated_controller/templates/test/sessions_functional_test.rb +82 -0
  39. data/lib/generators/somatics/authenticated_controller/templates/test/unit_test.rb +164 -0
  40. data/lib/generators/somatics/authenticated_controller/templates/test/users.yml +60 -0
  41. data/lib/generators/somatics/helper/helper_generator.rb +16 -0
  42. data/lib/generators/somatics/install/install_generator.rb +65 -0
  43. data/lib/generators/somatics/install/templates/config/locales/somatics_en.yml +33 -0
  44. data/lib/generators/somatics/install/templates/config/locales/somatics_zh-TW.yml +33 -0
  45. data/lib/generators/somatics/install/templates/controller_admin.rb +16 -0
  46. data/lib/generators/somatics/install/templates/controller_home.rb +4 -0
  47. data/lib/generators/somatics/install/templates/helper_admin.rb +68 -0
  48. data/lib/generators/somatics/install/templates/layout_admin.html.erb +88 -0
  49. data/lib/generators/somatics/install/templates/lib/somatic_link_renderer.rb +42 -0
  50. data/lib/generators/somatics/install/templates/partial_menu.html.erb +1 -0
  51. data/lib/generators/somatics/install/templates/public/images/somatics/add.png +0 -0
  52. data/lib/generators/somatics/install/templates/public/images/somatics/arrow_collapsed.png +0 -0
  53. data/lib/generators/somatics/install/templates/public/images/somatics/arrow_expanded.png +0 -0
  54. data/lib/generators/somatics/install/templates/public/images/somatics/attachment.png +0 -0
  55. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_left.png +0 -0
  56. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_arrow_right.png +0 -0
  57. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_diamond.png +0 -0
  58. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_end.png +0 -0
  59. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_go.png +0 -0
  60. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_minus.png +0 -0
  61. data/lib/generators/somatics/install/templates/public/images/somatics/bullet_toggle_plus.png +0 -0
  62. data/lib/generators/somatics/install/templates/public/images/somatics/c.png +0 -0
  63. data/lib/generators/somatics/install/templates/public/images/somatics/cancel.png +0 -0
  64. data/lib/generators/somatics/install/templates/public/images/somatics/changeset.png +0 -0
  65. data/lib/generators/somatics/install/templates/public/images/somatics/comment.png +0 -0
  66. data/lib/generators/somatics/install/templates/public/images/somatics/comments.png +0 -0
  67. data/lib/generators/somatics/install/templates/public/images/somatics/content-left.png +0 -0
  68. data/lib/generators/somatics/install/templates/public/images/somatics/content-right.png +0 -0
  69. data/lib/generators/somatics/install/templates/public/images/somatics/copy.png +0 -0
  70. data/lib/generators/somatics/install/templates/public/images/somatics/csharp.png +0 -0
  71. data/lib/generators/somatics/install/templates/public/images/somatics/database_key.png +0 -0
  72. data/lib/generators/somatics/install/templates/public/images/somatics/default.png +0 -0
  73. data/lib/generators/somatics/install/templates/public/images/somatics/delete.png +0 -0
  74. data/lib/generators/somatics/install/templates/public/images/somatics/document.png +0 -0
  75. data/lib/generators/somatics/install/templates/public/images/somatics/draft.png +0 -0
  76. data/lib/generators/somatics/install/templates/public/images/somatics/duplicate.png +0 -0
  77. data/lib/generators/somatics/install/templates/public/images/somatics/edit.png +0 -0
  78. data/lib/generators/somatics/install/templates/public/images/somatics/exclamation.png +0 -0
  79. data/lib/generators/somatics/install/templates/public/images/somatics/external.png +0 -0
  80. data/lib/generators/somatics/install/templates/public/images/somatics/fav.png +0 -0
  81. data/lib/generators/somatics/install/templates/public/images/somatics/fav_off.png +0 -0
  82. data/lib/generators/somatics/install/templates/public/images/somatics/feed.png +0 -0
  83. data/lib/generators/somatics/install/templates/public/images/somatics/folder.png +0 -0
  84. data/lib/generators/somatics/install/templates/public/images/somatics/folder_open.png +0 -0
  85. data/lib/generators/somatics/install/templates/public/images/somatics/footer-bg.png +0 -0
  86. data/lib/generators/somatics/install/templates/public/images/somatics/footer-left.png +0 -0
  87. data/lib/generators/somatics/install/templates/public/images/somatics/footer-right.png +0 -0
  88. data/lib/generators/somatics/install/templates/public/images/somatics/group.png +0 -0
  89. data/lib/generators/somatics/install/templates/public/images/somatics/help.png +0 -0
  90. data/lib/generators/somatics/install/templates/public/images/somatics/history.png +0 -0
  91. data/lib/generators/somatics/install/templates/public/images/somatics/image.png +0 -0
  92. data/lib/generators/somatics/install/templates/public/images/somatics/lightning.png +0 -0
  93. data/lib/generators/somatics/install/templates/public/images/somatics/link.png +0 -0
  94. data/lib/generators/somatics/install/templates/public/images/somatics/loading.gif +0 -0
  95. data/lib/generators/somatics/install/templates/public/images/somatics/locked.png +0 -0
  96. data/lib/generators/somatics/install/templates/public/images/somatics/message.png +0 -0
  97. data/lib/generators/somatics/install/templates/public/images/somatics/milestone.png +0 -0
  98. data/lib/generators/somatics/install/templates/public/images/somatics/move.png +0 -0
  99. data/lib/generators/somatics/install/templates/public/images/somatics/news.png +0 -0
  100. data/lib/generators/somatics/install/templates/public/images/somatics/openid-bg.gif +0 -0
  101. data/lib/generators/somatics/install/templates/public/images/somatics/package.png +0 -0
  102. data/lib/generators/somatics/install/templates/public/images/somatics/pdf.png +0 -0
  103. data/lib/generators/somatics/install/templates/public/images/somatics/php.png +0 -0
  104. data/lib/generators/somatics/install/templates/public/images/somatics/plugin.png +0 -0
  105. data/lib/generators/somatics/install/templates/public/images/somatics/projects.png +0 -0
  106. data/lib/generators/somatics/install/templates/public/images/somatics/rails.png +0 -0
  107. data/lib/generators/somatics/install/templates/public/images/somatics/reload.png +0 -0
  108. data/lib/generators/somatics/install/templates/public/images/somatics/report.png +0 -0
  109. data/lib/generators/somatics/install/templates/public/images/somatics/ruby.png +0 -0
  110. data/lib/generators/somatics/install/templates/public/images/somatics/save.png +0 -0
  111. data/lib/generators/somatics/install/templates/public/images/somatics/sort_asc.png +0 -0
  112. data/lib/generators/somatics/install/templates/public/images/somatics/sort_desc.png +0 -0
  113. data/lib/generators/somatics/install/templates/public/images/somatics/stats.png +0 -0
  114. data/lib/generators/somatics/install/templates/public/images/somatics/table_multiple.png +0 -0
  115. data/lib/generators/somatics/install/templates/public/images/somatics/task_done.png +0 -0
  116. data/lib/generators/somatics/install/templates/public/images/somatics/task_late.png +0 -0
  117. data/lib/generators/somatics/install/templates/public/images/somatics/task_parent_end.png +0 -0
  118. data/lib/generators/somatics/install/templates/public/images/somatics/task_todo.png +0 -0
  119. data/lib/generators/somatics/install/templates/public/images/somatics/text.png +0 -0
  120. data/lib/generators/somatics/install/templates/public/images/somatics/text_list_bullets.png +0 -0
  121. data/lib/generators/somatics/install/templates/public/images/somatics/textfield.png +0 -0
  122. data/lib/generators/somatics/install/templates/public/images/somatics/ticket.png +0 -0
  123. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_checked.png +0 -0
  124. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_edit.png +0 -0
  125. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_go.png +0 -0
  126. data/lib/generators/somatics/install/templates/public/images/somatics/ticket_note.png +0 -0
  127. data/lib/generators/somatics/install/templates/public/images/somatics/time.png +0 -0
  128. data/lib/generators/somatics/install/templates/public/images/somatics/time_add.png +0 -0
  129. data/lib/generators/somatics/install/templates/public/images/somatics/toggle_check.png +0 -0
  130. data/lib/generators/somatics/install/templates/public/images/somatics/true.png +0 -0
  131. data/lib/generators/somatics/install/templates/public/images/somatics/unlock.png +0 -0
  132. data/lib/generators/somatics/install/templates/public/images/somatics/user.png +0 -0
  133. data/lib/generators/somatics/install/templates/public/images/somatics/warning.png +0 -0
  134. data/lib/generators/somatics/install/templates/public/images/somatics/wiki_edit.png +0 -0
  135. data/lib/generators/somatics/install/templates/public/images/somatics/xml.png +0 -0
  136. data/lib/generators/somatics/install/templates/public/images/somatics/zip.png +0 -0
  137. data/lib/generators/somatics/install/templates/public/images/somatics/zoom_in.png +0 -0
  138. data/lib/generators/somatics/install/templates/public/javascripts/somatics/base.js +231 -0
  139. data/lib/generators/somatics/install/templates/public/javascripts/somatics/context_menu.js +237 -0
  140. data/lib/generators/somatics/install/templates/public/javascripts/somatics/controls.js +965 -0
  141. data/lib/generators/somatics/install/templates/public/javascripts/somatics/dragdrop.js +974 -0
  142. data/lib/generators/somatics/install/templates/public/javascripts/somatics/effects.js +1123 -0
  143. data/lib/generators/somatics/install/templates/public/javascripts/somatics/prototype.js +6001 -0
  144. data/lib/generators/somatics/install/templates/public/javascripts/somatics/rails.js +175 -0
  145. data/lib/generators/somatics/install/templates/public/javascripts/somatics/select_list_move.js +82 -0
  146. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +948 -0
  147. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/context_menu.css +52 -0
  148. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/csshover.htc +122 -0
  149. data/lib/generators/somatics/install/templates/public/stylesheets/somatics/jstoolbar.css +95 -0
  150. data/lib/generators/somatics/install/templates/view_index.html.erb +1 -0
  151. data/lib/generators/somatics/scaffold/scaffold_generator.rb +25 -0
  152. data/lib/generators/somatics/scaffold/templates/_form.html.erb +23 -0
  153. data/lib/generators/somatics/scaffold/templates/edit.html.erb +6 -0
  154. data/lib/generators/somatics/scaffold/templates/index.html.erb +27 -0
  155. data/lib/generators/somatics/scaffold/templates/new.html.erb +5 -0
  156. data/lib/generators/somatics/scaffold/templates/show.html.erb +12 -0
  157. data/lib/generators/somatics/scaffold_controller/USAGE +20 -0
  158. data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +137 -0
  159. data/lib/generators/somatics/scaffold_controller/templates/builder_index.pdf.prawn +25 -0
  160. data/lib/generators/somatics/scaffold_controller/templates/builder_index.xls.builder +24 -0
  161. data/lib/generators/somatics/scaffold_controller/templates/builder_index.xml.builder +10 -0
  162. data/lib/generators/somatics/scaffold_controller/templates/controller.rb +140 -0
  163. data/lib/generators/somatics/scaffold_controller/templates/locales_en.yml +17 -0
  164. data/lib/generators/somatics/scaffold_controller/templates/locales_zh-TW.yml +20 -0
  165. data/lib/generators/somatics/scaffold_controller/templates/partial_bulk.html.erb +12 -0
  166. data/lib/generators/somatics/scaffold_controller/templates/partial_edit.html.erb +7 -0
  167. data/lib/generators/somatics/scaffold_controller/templates/partial_form.html.erb +13 -0
  168. data/lib/generators/somatics/scaffold_controller/templates/partial_list.html.erb +42 -0
  169. data/lib/generators/somatics/scaffold_controller/templates/partial_menu.html.erb +1 -0
  170. data/lib/generators/somatics/scaffold_controller/templates/partial_show.html.erb +31 -0
  171. data/lib/generators/somatics/scaffold_controller/templates/view_edit.html.erb +24 -0
  172. data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +28 -0
  173. data/lib/generators/somatics/scaffold_controller/templates/view_new.html.erb +14 -0
  174. data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +24 -0
  175. data/lib/generators/somatics.rb +95 -0
  176. data/lib/somatics3-generators.rb +19 -0
  177. data/somatics3-generators.gemspec +223 -0
  178. data/templates/somatics.rb +128 -0
  179. data/test/helper.rb +10 -0
  180. data/test/test_somatics3-generators.rb +7 -0
  181. metadata +301 -0
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,93 @@
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
@@ -0,0 +1,82 @@
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
@@ -0,0 +1,164 @@
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
@@ -0,0 +1,60 @@
1
+ <%
2
+ ## this code must match that in templates/model.rb
3
+ require 'digest/sha1'
4
+ def make_fake_token
5
+ @fake_token_counter ||= 0
6
+ @fake_token_counter += 1
7
+ Digest::SHA1.hexdigest(@fake_token_counter.to_s)
8
+ end
9
+ salts = (1..2).map{ make_fake_token }
10
+ passwds = salts.map{ |salt| password_digest('monkey', salt) }
11
+ -%>
12
+
13
+ quentin:
14
+ id: 1
15
+ login: quentin
16
+ email: quentin@example.com
17
+ salt: <%= salts[0] %> # SHA1('0')
18
+ crypted_password: <%= passwds[0] %> # 'monkey'
19
+ created_at: <%%= 5.days.ago.to_s :db %>
20
+ remember_token_expires_at: <%%= 1.days.from_now.to_s %>
21
+ remember_token: <%= make_fake_token %>
22
+ <% if options[:include_activation] -%>
23
+ activation_code:
24
+ activated_at: <%%= 5.days.ago.to_s :db %>
25
+ <% end -%>
26
+ <% if options[:stateful] -%>
27
+ state: active
28
+ <% end -%>
29
+
30
+ aaron:
31
+ id: 2
32
+ login: aaron
33
+ email: aaron@example.com
34
+ salt: <%= salts[1] %> # SHA1('1')
35
+ crypted_password: <%= passwds[1] %> # 'monkey'
36
+ created_at: <%%= 1.days.ago.to_s :db %>
37
+ remember_token_expires_at:
38
+ remember_token:
39
+ <% if options[:include_activation] -%>
40
+ activation_code: <%= make_fake_token %>
41
+ activated_at:
42
+ <% end -%>
43
+ <% if options[:stateful] %>
44
+ state: pending
45
+ <% end -%>
46
+
47
+
48
+ old_password_holder:
49
+ id: 3
50
+ login: old_password_holder
51
+ email: salty_dog@example.com
52
+ salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
53
+ crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
54
+ created_at: <%%= 1.days.ago.to_s :db %>
55
+ <% if options[:include_activation] %>
56
+ activation_code:
57
+ activated_at: <%%= 5.days.ago.to_s :db %>
58
+ <% end %>
59
+ <% if options[:stateful] %>
60
+ state: active<% end %>
@@ -0,0 +1,16 @@
1
+ require 'generators/somatics'
2
+ # require 'rails/generators/scaffold_controller_generator'
3
+ require 'rails/generators/rails/helper/helper_generator'
4
+
5
+ module Somatics
6
+ module Generators
7
+ class HelperGenerator < Rails::Generators::HelperGenerator
8
+
9
+ protected
10
+ # def class_path
11
+ # puts options[:namespace]
12
+ # @class_path.unshift(options[:namespace]) if options[:namespace].present?
13
+ # end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,65 @@
1
+ require 'generators/somatics'
2
+ require 'rails/generators/named_base'
3
+
4
+ module Somatics
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ extend TemplatePath
8
+ class_option :namespace, :banner => "NAME", :type => :string, :required => false, :default => "admin", :desc => "namespace to generate the controller for"
9
+
10
+ def public_directory
11
+ directory "public", "public", :recursive => false
12
+ end
13
+
14
+ def images
15
+ directory "public/images"
16
+ end
17
+
18
+ def stylesheets
19
+ directory "public/stylesheets"
20
+ end
21
+
22
+ def javascripts
23
+ directory "public/javascripts"
24
+ end
25
+
26
+ def base
27
+ template 'controller_admin.rb', File.join('app/controllers/admin', 'admin_controller.rb')
28
+ template 'helper_admin.rb', File.join('app/helpers/admin', 'admin_helper.rb')
29
+ end
30
+
31
+ def home
32
+ template 'controller_home.rb', File.join('app/controllers/admin', 'home_controller.rb')
33
+ template 'view_index.html.erb', File.join('app/views/admin', 'home', 'index.html.erb')
34
+ end
35
+
36
+ def layouts
37
+ template 'layout_admin.html.erb', File.join('app/views/layouts', "admin.html.erb")
38
+ template 'partial_menu.html.erb', File.join('app/views/admin/shared', "_menu.html.erb")
39
+ end
40
+
41
+ def mime_type
42
+ gsub_file File.join('config','initializers', 'mime_types.rb'), "Mime::Type.register 'application/vnd.ms-excel', :xls", ""
43
+ append_file File.join('config','initializers', 'mime_types.rb'), "Mime::Type.register 'application/vnd.ms-excel', :xls"
44
+ end
45
+
46
+ def locales
47
+ directory "config/locales"
48
+ end
49
+
50
+ def add_route
51
+ route_config = ""
52
+ route_config << "\tnamespace :#{options[:namespace]} do \n" if options[:namespace].present?
53
+ route_config << "\t\troot :to => 'home#index'\n"
54
+ route_config << "\t\tmatch 'home' => 'home#index'\n"
55
+ route_config << "\tend\n" if options[:namespace].present?
56
+ route route_config
57
+ end
58
+
59
+ def libs
60
+ directory "lib"
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,33 @@
1
+ en:
2
+ Overview: Overview
3
+ new: new
4
+ New: New
5
+ create: create
6
+ Create: Create
7
+ update: update
8
+ Update: Update
9
+ delete: delete
10
+ Delete: Delete
11
+ back: back
12
+ Back: Back
13
+ back_to: back to
14
+ Back_to: Back to
15
+ information: information
16
+ Information: Information
17
+ bulk: bulk
18
+ Bulk: Bulk
19
+ ID: ID
20
+ Logged_in_as: Logged in as
21
+ Logout: Logout
22
+ Home: Home
23
+ Admin_Panel: Admin Panel
24
+ Support: Support
25
+ Loading: Loading
26
+ Search: Search
27
+ Also_available_in: Also available in
28
+ Log_in: Log in
29
+ previous: Previous
30
+ next: Next
31
+ no_data_available: No Data Available
32
+ Add: Add
33
+ Cancel: Cancel
@@ -0,0 +1,33 @@
1
+ "zh-TW":
2
+ Overview: 概覽
3
+ new: 新增
4
+ New: 新增
5
+ create: 新增
6
+ Create: 新增
7
+ update: 更新
8
+ Update: 更新
9
+ delete: 刪除
10
+ Delete: 刪除
11
+ back: 返回
12
+ Back: 返回
13
+ back_to: 返回
14
+ Back_to: 返回
15
+ information: 資料
16
+ Information: 資料
17
+ bulk: 批量
18
+ Bulk: 批量
19
+ ID: 編號
20
+ Logged_in_as: 登入為
21
+ Logout: 登出
22
+ Home: 首頁
23
+ Admin_Panel: 管理面板
24
+ Support: 支援
25
+ Loading: 載入中
26
+ Search: 搜尋
27
+ Also_available_in: 匯出為
28
+ Log_in: 登入
29
+ previous: 上一頁
30
+ next: 下一頁
31
+ no_data_available: 未有可用的資料
32
+ Add: 加入
33
+ Cancel: 取消
@@ -0,0 +1,16 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class Admin::AdminController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ filter_parameter_logging :password
10
+
11
+ include RedmineFilter
12
+ include UserAuthenticatedSystem
13
+ before_filter :user_login_required
14
+
15
+ layout Proc.new { |c| c.request.format.js? ? false : 'admin' }
16
+ end
@@ -0,0 +1,4 @@
1
+ class Admin::HomeController < Admin::AdminController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,68 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module Admin::AdminHelper
3
+ def content_for(name, content = nil, &block)
4
+ @has_content ||= {}
5
+ @has_content[name] = true
6
+ super(name, content, &block)
7
+ end
8
+
9
+ def has_content?(name)
10
+ (@has_content && @has_content[name]) || false
11
+ end
12
+
13
+ def match_controller?(name)
14
+ controller.controller_name == name
15
+ end
16
+
17
+ def match_action?(name)
18
+ controller.action_name == name
19
+ end
20
+
21
+ def sort_asc_desc_helper(model_name, param)
22
+ result = image_tag('admin/sort_asc.png') if params[:"#{model_name}_sort"] == param
23
+ result = image_tag('admin/sort_desc.png') if params[:"#{model_name}_sort"] == param + "_reverse"
24
+ return result || ''
25
+ end
26
+
27
+ def sort_link_helper(text, model_name ,param)
28
+ key = param
29
+ key += "_reverse" if params[:"#{model_name}_sort"] == param
30
+ options = {
31
+ :url => {:action => 'list', :params => params.merge({:"#{model_name}_sort" => key, :page => nil})},
32
+ :update => 'content',
33
+ :method => :get
34
+ }
35
+ html_options = {
36
+ :title => "Sort by this field",
37
+ :href => url_for(:action => 'list', :params => params.merge({:"#{model_name}_sort" => key, :page => nil}))
38
+ }
39
+ link_to_remote(text + sort_asc_desc_helper(model_name,param), options, html_options)
40
+ end
41
+
42
+ def operators_for_select(filter_type)
43
+ Query.operators_by_filter_type[filter_type].collect {|o| [(Query.operators[o].to_s.humanize), o]}
44
+ end
45
+
46
+ def excel_document(xml, &block)
47
+ xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
48
+ xml.Workbook({
49
+ 'xmlns' => "urn:schemas-microsoft-com:office:spreadsheet",
50
+ 'xmlns:o' => "urn:schemas-microsoft-com:office:office",
51
+ 'xmlns:x' => "urn:schemas-microsoft-com:office:excel",
52
+ 'xmlns:html' => "http://www.w3.org/TR/REC-html40",
53
+ 'xmlns:ss' => "urn:schemas-microsoft-com:office:spreadsheet"
54
+ }) do
55
+ xml.Styles do
56
+ xml.Style 'ss:ID' => 'Default', 'ss:Name' => 'Normal' do
57
+ xml.Alignment 'ss:Vertical' => 'Bottom'
58
+ xml.Borders
59
+ xml.Font 'ss:FontName' => 'Arial'
60
+ xml.Interior
61
+ xml.NumberFormat
62
+ xml.Protection
63
+ end
64
+ end
65
+ yield block
66
+ end
67
+ end
68
+ end