fetty-generators 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/Gemfile +2 -0
  2. data/README.rdoc +42 -36
  3. data/Rakefile +1 -3
  4. data/lib/generators/fetty.rb +160 -10
  5. data/lib/generators/fetty/authentication/USAGE +4 -0
  6. data/lib/generators/fetty/authentication/authentication_generator.rb +171 -0
  7. data/lib/generators/fetty/authentication/templates/controllers/reset_passwords_controller.rb +45 -0
  8. data/lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb +30 -0
  9. data/lib/generators/fetty/authentication/templates/controllers/users_controller.rb +78 -0
  10. data/lib/generators/fetty/authentication/templates/helpers/reset_passwords_helper.rb +2 -0
  11. data/lib/generators/fetty/authentication/templates/helpers/sessions_helper.rb +2 -0
  12. data/lib/generators/fetty/authentication/templates/helpers/users_helper.rb +2 -0
  13. data/lib/generators/fetty/authentication/templates/lib/sessions_authentication.rb +53 -0
  14. data/lib/generators/fetty/authentication/templates/lib/users_authentication.rb +110 -0
  15. data/lib/generators/fetty/authentication/templates/mailers/setup_mail.rb +11 -0
  16. data/lib/generators/fetty/authentication/templates/mailers/user_mailer.rb +14 -0
  17. data/lib/generators/fetty/authentication/templates/models/active_record/create_users.rb +17 -0
  18. data/lib/generators/fetty/authentication/templates/models/active_record/user.rb +15 -0
  19. data/lib/generators/fetty/authentication/templates/models/mongoid/user.rb +23 -0
  20. data/lib/generators/fetty/authentication/templates/spec/controllers/reset_passwords_controller_spec.rb +93 -0
  21. data/lib/generators/fetty/authentication/templates/spec/controllers/sessions_controller_spec.rb +61 -0
  22. data/lib/generators/fetty/authentication/templates/spec/controllers/users_controller_spec.rb +158 -0
  23. data/lib/generators/fetty/authentication/templates/spec/models/user_spec.rb +108 -0
  24. data/lib/generators/fetty/authentication/templates/spec/routing/reset_passwords_routing_spec.rb +21 -0
  25. data/lib/generators/fetty/authentication/templates/spec/routing/sessions_routing_spec.rb +17 -0
  26. data/lib/generators/fetty/authentication/templates/spec/routing/users_routing_spec.rb +37 -0
  27. data/lib/generators/fetty/authentication/templates/spec/support/user_factories.rb +6 -0
  28. data/lib/generators/fetty/authentication/templates/views/layouts/application.html.erb +33 -0
  29. data/lib/generators/fetty/authentication/templates/views/reset_passwords/edit.html.erb +19 -0
  30. data/lib/generators/fetty/authentication/templates/views/reset_passwords/new.html.erb +14 -0
  31. data/lib/generators/fetty/authentication/templates/views/sessions/new.html.erb +22 -0
  32. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_activation.text.erb +4 -0
  33. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_forgot_password.text.erb +7 -0
  34. data/lib/generators/fetty/authentication/templates/views/users/_table.html.erb +23 -0
  35. data/lib/generators/fetty/authentication/templates/views/users/edit.html.erb +21 -0
  36. data/lib/generators/fetty/authentication/templates/views/users/index.html.erb +7 -0
  37. data/lib/generators/fetty/authentication/templates/views/users/index.js.erb +1 -0
  38. data/lib/generators/fetty/authentication/templates/views/users/new.html.erb +23 -0
  39. data/lib/generators/fetty/authentication/templates/views/users/show.html.erb +19 -0
  40. data/lib/generators/fetty/messages/USAGE +4 -0
  41. data/lib/generators/fetty/messages/messages_generator.rb +136 -0
  42. data/lib/generators/fetty/messages/templates/assets/javascripts/jquery.tokeninput.js +718 -0
  43. data/lib/generators/fetty/messages/templates/assets/javascripts/messages.js +19 -0
  44. data/lib/generators/fetty/messages/templates/assets/stylesheets/messages.css +87 -0
  45. data/lib/generators/fetty/messages/templates/assets/stylesheets/token-input-facebook.css +122 -0
  46. data/lib/generators/fetty/messages/templates/controllers/messages_controller.rb +109 -0
  47. data/lib/generators/fetty/messages/templates/helpers/messages_helper.rb +2 -0
  48. data/lib/generators/fetty/messages/templates/lib/users_messages.rb +67 -0
  49. data/lib/generators/fetty/messages/templates/models/active_record/create_messages.rb +24 -0
  50. data/lib/generators/fetty/messages/templates/models/active_record/message.rb +67 -0
  51. data/lib/generators/fetty/messages/templates/models/mongoid/message.rb +81 -0
  52. data/lib/generators/fetty/messages/templates/spec/controllers/messages_controller_spec.rb +78 -0
  53. data/lib/generators/fetty/messages/templates/spec/models/message_spec.rb +53 -0
  54. data/lib/generators/fetty/messages/templates/spec/routing/messages_routing_spec.rb +61 -0
  55. data/lib/generators/fetty/messages/templates/spec/support/message_factories.rb +8 -0
  56. data/lib/generators/fetty/messages/templates/views/_head.html.erb +20 -0
  57. data/lib/generators/fetty/messages/templates/views/_messages.html.erb +56 -0
  58. data/lib/generators/fetty/messages/templates/views/_tabs_panel.html.erb +11 -0
  59. data/lib/generators/fetty/messages/templates/views/index.html.erb +10 -0
  60. data/lib/generators/fetty/messages/templates/views/index.js.erb +1 -0
  61. data/lib/generators/fetty/messages/templates/views/new.html.erb +26 -0
  62. data/lib/generators/fetty/messages/templates/views/show.html.erb +35 -0
  63. data/lib/generators/fetty/scaffold/USAGE +2 -52
  64. data/lib/generators/fetty/scaffold/scaffold_generator.rb +96 -329
  65. data/lib/generators/fetty/scaffold/templates/controllers/active_record/controller.rb +60 -0
  66. data/lib/generators/fetty/scaffold/templates/controllers/mongoid/controller.rb +60 -0
  67. data/lib/generators/fetty/scaffold/templates/helpers/helper.rb +2 -0
  68. data/lib/generators/fetty/scaffold/templates/models/active_record/migration.rb +16 -0
  69. data/lib/generators/fetty/scaffold/templates/models/active_record/model.rb +10 -0
  70. data/lib/generators/fetty/scaffold/templates/models/mongoid/model.rb +16 -0
  71. data/lib/generators/fetty/scaffold/templates/test/rspec/controller.rb +98 -0
  72. data/lib/generators/fetty/scaffold/templates/test/rspec/factories.rb +26 -0
  73. data/lib/generators/fetty/scaffold/templates/test/rspec/helper.rb +15 -0
  74. data/lib/generators/fetty/scaffold/templates/test/rspec/model.rb +9 -0
  75. data/lib/generators/fetty/scaffold/templates/test/rspec/request.rb +11 -0
  76. data/lib/generators/fetty/scaffold/templates/test/rspec/routing.rb +41 -0
  77. data/lib/generators/fetty/scaffold/templates/test/test_unit/controller.rb +62 -0
  78. data/lib/generators/fetty/scaffold/templates/{fixtures.yml → test/test_unit/fixtures.yml} +2 -0
  79. data/lib/generators/fetty/scaffold/templates/test/test_unit/helper.rb +4 -0
  80. data/lib/generators/fetty/scaffold/templates/test/test_unit/model.rb +7 -0
  81. data/lib/generators/fetty/scaffold/templates/views/_form.html.erb +20 -0
  82. data/lib/generators/fetty/scaffold/templates/views/_table.html.erb +48 -0
  83. data/lib/generators/fetty/scaffold/templates/views/edit.html.erb +13 -0
  84. data/lib/generators/fetty/scaffold/templates/views/index.html.erb +15 -0
  85. data/lib/generators/fetty/scaffold/templates/views/{erb/index.js.erb → index.js.erb} +0 -0
  86. data/lib/generators/fetty/scaffold/templates/views/new.html.erb +9 -0
  87. data/lib/generators/fetty/scaffold/templates/views/show.html.erb +28 -0
  88. data/lib/generators/fetty/setup/USAGE +3 -20
  89. data/lib/generators/fetty/setup/setup_generator.rb +122 -61
  90. data/lib/generators/fetty/setup/templates/ability.rb +0 -0
  91. data/lib/generators/fetty/setup/templates/ckeditor.rb +54 -0
  92. data/lib/generators/fetty/setup/templates/ckeditor.tar.gz +0 -0
  93. data/lib/generators/fetty/setup/templates/escape_utils.rb +7 -0
  94. data/lib/generators/fetty/setup/templates/file_uploader.rb +15 -0
  95. data/lib/generators/fetty/setup/templates/image_uploader.rb +48 -0
  96. data/lib/generators/fetty/setup/templates/spec_helper.rb +44 -0
  97. data/lib/generators/fetty/views/USAGE +5 -0
  98. data/lib/generators/fetty/{layout/templates/stylesheet.css → views/templates/application.css} +184 -166
  99. data/lib/generators/fetty/views/templates/application.html.erb +23 -0
  100. data/lib/generators/fetty/{layout → views}/templates/application.js +0 -0
  101. data/lib/generators/fetty/views/templates/application_helper.rb +10 -0
  102. data/lib/generators/fetty/views/templates/down_arrow.gif +0 -0
  103. data/lib/generators/fetty/{layout → views}/templates/error_messages_helper.rb +0 -0
  104. data/lib/generators/fetty/{layout → views}/templates/layout_helper.rb +0 -0
  105. data/lib/generators/fetty/views/templates/up_arrow.gif +0 -0
  106. data/lib/generators/fetty/views/views_generator.rb +51 -0
  107. data/lib/generators/scaffold.rb +204 -0
  108. metadata +126 -111
  109. data/LICENSE +0 -20
  110. data/lib/generators/fetty/layout/USAGE +0 -26
  111. data/lib/generators/fetty/layout/layout_generator.rb +0 -44
  112. data/lib/generators/fetty/layout/templates/layout.html.erb +0 -32
  113. data/lib/generators/fetty/layout/templates/layout.html.haml +0 -34
  114. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +0 -23
  115. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +0 -23
  116. data/lib/generators/fetty/layout/templates/stylesheet.sass +0 -163
  117. data/lib/generators/fetty/scaffold/templates/actions/create.rb +0 -8
  118. data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +0 -5
  119. data/lib/generators/fetty/scaffold/templates/actions/edit.rb +0 -3
  120. data/lib/generators/fetty/scaffold/templates/actions/index.rb +0 -10
  121. data/lib/generators/fetty/scaffold/templates/actions/new.rb +0 -3
  122. data/lib/generators/fetty/scaffold/templates/actions/show.rb +0 -3
  123. data/lib/generators/fetty/scaffold/templates/actions/update.rb +0 -8
  124. data/lib/generators/fetty/scaffold/templates/controller.rb +0 -7
  125. data/lib/generators/fetty/scaffold/templates/helper.rb +0 -2
  126. data/lib/generators/fetty/scaffold/templates/migration.rb +0 -16
  127. data/lib/generators/fetty/scaffold/templates/model.rb +0 -7
  128. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +0 -11
  129. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  130. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  131. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +0 -4
  132. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +0 -4
  133. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +0 -4
  134. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +0 -11
  135. data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +0 -8
  136. data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +0 -7
  137. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  138. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  139. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  140. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  141. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  142. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  143. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  144. data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +0 -5
  145. data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +0 -7
  146. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +0 -11
  147. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  148. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  149. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +0 -4
  150. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +0 -4
  151. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +0 -4
  152. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +0 -11
  153. data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +0 -5
  154. data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +0 -7
  155. data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +0 -22
  156. data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +0 -50
  157. data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +0 -12
  158. data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +0 -13
  159. data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +0 -9
  160. data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +0 -26
  161. data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +0 -8
  162. data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +0 -33
  163. data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +0 -14
  164. data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +0 -12
  165. data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +0 -1
  166. data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +0 -8
  167. data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +0 -23
@@ -0,0 +1,60 @@
1
+ class <%= controller_name %> < ApplicationController
2
+
3
+ <%- if action? :index -%>
4
+ def index
5
+ search = <%= class_name %>.where('<%= model_attributes[0].name %> LIKE ?', "%#{params[:search]}%")
6
+ search = search.order(params[:sort] + " " + params[:direction]) unless params[:sort].blank? && params[:direction].blank?
7
+
8
+ <%= instances_name('@') %> = search.page(params[:page]).per(10)
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.xml { render :xml => <%= instances_name('@') %> }
13
+ format.js
14
+ end
15
+ end
16
+ <%- end -%>
17
+ <%- if action? :show -%>
18
+ def show
19
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
20
+ end
21
+ <%- end -%>
22
+ <%- if action? :new -%>
23
+ def new
24
+ <%= instance_name('@') %> = <%= class_name %>.new
25
+ end
26
+ <%- end -%>
27
+ <%- if action? :create -%>
28
+ def create
29
+ <%= instance_name('@') %> = <%= class_name %>.new(params[<%= instance_name(':') %>])
30
+ if <%= instance_name('@') %>.save
31
+ redirect_to <%= generate_route_link(:action => :show, :suffix => 'path', :object => instance_name('@')) %>, :notice => "Successfully created <%= simple_name %>."
32
+ else
33
+ render :action => 'new'
34
+ end
35
+ end
36
+ <%- end -%>
37
+ <%- if action? :edit -%>
38
+ def edit
39
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
40
+ end
41
+ <%- end -%>
42
+ <%- if action? :update -%>
43
+ def update
44
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
45
+ if <%= instance_name('@') %>.update_attributes(params[<%= instance_name(':') %>])
46
+ redirect_to <%= generate_route_link(:action => :show, :suffix => 'path', :object => instance_name('@')) %>, :notice => "Successfully updated <%= simple_name %>."
47
+ else
48
+ render :action => 'edit'
49
+ end
50
+ end
51
+ <%- end -%>
52
+ <%- if action? :destroy -%>
53
+ def destroy
54
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
55
+ <%= instance_name('@') %>.destroy
56
+ redirect_to <%= generate_route_link(:action => :index, :suffix => 'url') %>, :notice => "Successfully destroyed <%= simple_name %>."
57
+ end
58
+ <%- end -%>
59
+
60
+ end
@@ -0,0 +1,60 @@
1
+ class <%= controller_name %> < ApplicationController
2
+
3
+ <%- if action? :index -%>
4
+ def index
5
+ criteria = <%= class_name %>.where("<%= model_attributes[0].name %>" => /#{params[:search]}/i)
6
+ criteria = criteria.order_by([params[:sort], params[:direction]]) unless params[:sort].blank? && params[:direction].blank?
7
+
8
+ <%= instances_name('@') %> = criteria.page(params[:page]).per(10)
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.xml { render :xml => <%= instances_name('@') %> }
13
+ format.js
14
+ end
15
+ end
16
+ <%- end -%>
17
+ <%- if action? :show -%>
18
+ def show
19
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
20
+ end
21
+ <%- end -%>
22
+ <%- if action? :new -%>
23
+ def new
24
+ <%= instance_name('@') %> = <%= class_name %>.new
25
+ end
26
+ <%- end -%>
27
+ <%- if action? :create -%>
28
+ def create
29
+ <%= instance_name('@') %> = <%= class_name %>.new(params[<%= instance_name(':') %>])
30
+ if <%= instance_name('@') %>.save
31
+ redirect_to <%= generate_route_link(:action => :show, :suffix => 'path', :object => instance_name('@')) %>, :notice => "Successfully created <%= simple_name %>."
32
+ else
33
+ render :action => 'new'
34
+ end
35
+ end
36
+ <%- end -%>
37
+ <%- if action? :edit -%>
38
+ def edit
39
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
40
+ end
41
+ <%- end -%>
42
+ <%- if action? :update -%>
43
+ def update
44
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
45
+ if <%= instance_name('@') %>.update_attributes(params[<%= instance_name(':') %>])
46
+ redirect_to <%= generate_route_link(:action => :show, :suffix => 'path', :object => instance_name('@')) %>, :notice => "Successfully updated <%= simple_name %>."
47
+ else
48
+ render :action => 'edit'
49
+ end
50
+ end
51
+ <%- end -%>
52
+ <%- if action? :destroy -%>
53
+ def destroy
54
+ <%= instance_name('@') %> = <%= class_name %>.find(params[:id])
55
+ <%= instance_name('@') %>.destroy
56
+ redirect_to <%= generate_route_link(:action => :index, :suffix => 'url') %>, :notice => "Successfully destroyed <%= simple_name %>."
57
+ end
58
+ <%- end -%>
59
+
60
+ end
@@ -0,0 +1,2 @@
1
+ module <%= helper_name %>
2
+ end
@@ -0,0 +1,16 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <%- for attribute in model_attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ <%- if options.timestamps -%>
8
+ t.timestamps
9
+ <%- end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= table_name %>
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class <%= model_name %> < ActiveRecord::Base
2
+ attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
+ <%- if has_type? :image -%>
4
+ mount_uploader <%= special_select(:image).map { |name| ":#{name}" }.join(", ") %>, ImageUploader
5
+ <%- end -%>
6
+ <%- if has_type? :file -%>
7
+ mount_uploader <%= special_select(:file).map { |name| ":#{name}" }.join(", ") %>, FileUploader
8
+ <%- end -%>
9
+
10
+ end
@@ -0,0 +1,16 @@
1
+ class <%= model_name %>
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ <%- model_attributes.map do |a| -%>
6
+ <%= "field :#{a.name}" %>
7
+ <%- end -%>
8
+
9
+ attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
10
+ <%- if has_type? :image -%>
11
+ mount_uploader <%= special_select(:image).map { |name| ":#{name}" }.join(", ") %>, ImageUploader
12
+ <%- end -%>
13
+ <%- if has_type? :file -%>
14
+ mount_uploader <%= special_select(:file).map { |name| ":#{name}" }.join(", ") %>, FileUploader
15
+ <%- end -%>
16
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_name %> do
4
+ <% if action? :index %>
5
+ describe "GET index" do
6
+ it "should render index template" do
7
+ stub_authenticate_user
8
+ get :index
9
+ response.should render_template(:index)
10
+ end
11
+ end
12
+ <% end %>
13
+ <% if action? :show %>
14
+ describe "GET show" do
15
+ it "should render show template" do
16
+ stub_authenticate_user
17
+ <%= instance_name %> = Factory(<%= instance_name(':') %>)
18
+ get :show, :id => <%= instance_name %>.id.to_s
19
+ response.should render_template(:show)
20
+ end
21
+ end
22
+ <% end %>
23
+ <% if action? :new %>
24
+ describe "GET new" do
25
+ it "should render new template" do
26
+ stub_authenticate_user
27
+ get :new
28
+ response.should render_template(:new)
29
+ end
30
+ end
31
+ <% end %>
32
+ <% if action? :create %>
33
+ describe "POST create" do
34
+ describe "with valid params" do
35
+ it "should redirect to show template" do
36
+ stub_authenticate_user
37
+ <%= class_name %>.any_instance.stub(:valid?).and_return(true)
38
+ post :create, <%= instance_name(':') %> => Factory.attributes_for(<%= instance_name(':') %>)
39
+ response.should redirect_to(<%= generate_route_link(:action => :show, :suffix => 'path', :object => "assigns(#{instance_name(':')})") %>)
40
+ end
41
+ end
42
+
43
+ describe "with invalid params" do
44
+ it "should re-render new template" do
45
+ stub_authenticate_user
46
+ <%= class_name %>.any_instance.stub(:valid?).and_return(false)
47
+ post :create, <%= instance_name(':') %> => nil
48
+ response.should render_template(:new)
49
+ end
50
+ end
51
+ end
52
+ <% end %>
53
+ <% if action? :edit %>
54
+ describe "GET edit" do
55
+ it "should render edit template" do
56
+ stub_authenticate_user
57
+ <%= instance_name %> = Factory(<%= instance_name(':') %>)
58
+ get :edit, :id => <%= instance_name %>.id.to_s
59
+ response.should render_template(:edit)
60
+ end
61
+ end
62
+ <% end %>
63
+ <% if action? :update %>
64
+ describe "PUT update" do
65
+ describe "with valid params" do
66
+ it "should redirect to show template" do
67
+ stub_authenticate_user
68
+ <%= instance_name %> = Factory(<%= instance_name(':') %>)
69
+ <%= class_name %>.stub(:find).with(<%= instance_name %>.id.to_s).and_return(<%= instance_name %>)
70
+ <%= class_name %>.any_instance.stub(:valid?).and_return(true)
71
+ put :update, :id => <%= instance_name %>.id.to_s
72
+ response.should redirect_to(<%= generate_route_link(:action => :show, :suffix => 'path', :object => "assigns(#{instance_name(':')})") %>)
73
+ end
74
+ end
75
+
76
+ describe "with invalid params" do
77
+ it "should re-render edit template" do
78
+ stub_authenticate_user
79
+ <%= instance_name %> = Factory(<%= instance_name(':') %>)
80
+ <%= class_name %>.stub(:find).with(<%= instance_name %>.id.to_s).and_return(<%= instance_name %>)
81
+ <%= class_name %>.any_instance.stub(:valid?).and_return(false)
82
+ put :update, :id => <%= instance_name %>.id.to_s
83
+ response.should render_template(:edit)
84
+ end
85
+ end
86
+ end
87
+ <% end %>
88
+ <% if action? :destroy %>
89
+ describe "DELETE destroy" do
90
+ it "should redirect to index template" do
91
+ stub_authenticate_user
92
+ <%= instance_name %> = Factory(<%= instance_name(':') %>)
93
+ delete :destroy, :id => <%= instance_name %>.id.to_s
94
+ response.should redirect_to(<%= generate_route_link(:action => :index, :suffix => 'path') %>)
95
+ end
96
+ end
97
+ <% end %>
98
+ end
@@ -0,0 +1,26 @@
1
+ # => This is for fixtures replacement
2
+ # => using factory_girl_rails (https://github.com/thoughtbot/factory_girl_rails)
3
+
4
+ # => Let's define a sequence that factories can use. This sequence defines a
5
+ # => unique e-mail address. The first address will be "somebody1@example.com",
6
+ # => and the second will be "somebody2@example.com."
7
+ # Factory.sequence :email do |n|
8
+ # "somebody#{n}@example.com"
9
+ # end
10
+
11
+ # => Let's define a factory for the User model. The class name is guessed from the factory name.
12
+ # => These properties are set statically, and are evaluated when the factory is defined.
13
+ # => This property is set "lazily." The block will be called whenever an
14
+ # => instance is generated, and the return value of the block is used as the value for the attribute.
15
+ # Factory.define :user do |f|
16
+ # f.first_name 'John'
17
+ # f.last_name 'Doe'
18
+ # f.admin false
19
+ # f.email { Factory.next(:email) }
20
+ # end
21
+
22
+ Factory.define <%= instance_name(':') %> do |f|
23
+ <%- for attribute in model_attributes -%>
24
+ f.<%= attribute.name %> '<%= attribute.default %>'
25
+ <%- end -%>
26
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the <%= helper_name %>. For example:
5
+ #
6
+ # describe <%= helper_name %> do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe <%= helper_name %> do
14
+ pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= model_name %> do
4
+ it "should be valid" do
5
+ <%= instance_name('@') %> = <%= class_name %>.new
6
+ <%= instance_name('@') %>.attributes = Factory.attributes_for(<%= instance_name(':') %>)
7
+ <%= instance_name('@') %>.should be_valid
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "<%= model_name %>" do
4
+ describe "GET /<%= model_name %>" do
5
+ it "works! (now write some real specs)" do
6
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
7
+ get <%= generate_route_link(:action => :index, :suffix => 'path') %>
8
+ response.should be_success
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_name %> do
4
+ describe 'routing' do
5
+ <%- if action? :index -%>
6
+ it 'routes to #index' do
7
+ get('/<%= plural_name %>').should route_to('<%= plural_name %>#index')
8
+ end
9
+ <%- end -%>
10
+ <%- if action? :show -%>
11
+ it 'routes to #show' do
12
+ get('/<%= plural_name %>/1').should route_to('<%= plural_name %>#show', :id => '1')
13
+ end
14
+ <%- end -%>
15
+ <%- if action? :new -%>
16
+ it 'routes to #new' do
17
+ get('/<%= plural_name %>/new').should route_to('<%= plural_name %>#new')
18
+ end
19
+ <%- end -%>
20
+ <%- if action? :create -%>
21
+ it 'routes to #create' do
22
+ post('/<%= plural_name %>').should route_to('<%= plural_name %>#create')
23
+ end
24
+ <%- end -%>
25
+ <%- if action? :edit -%>
26
+ it 'routes to #edit' do
27
+ get('/<%= plural_name %>/1/edit').should route_to('<%= plural_name %>#edit', :id => '1')
28
+ end
29
+ <%- end -%>
30
+ <%- if action? :update -%>
31
+ it 'routes to #update' do
32
+ put('/<%= plural_name %>/1').should route_to('<%= plural_name %>#update', :id => '1')
33
+ end
34
+ <%- end -%>
35
+ <%- if action? :destroy -%>
36
+ it 'routes to #destroy' do
37
+ delete('/<%= plural_name %>/1').should route_to('<%= plural_name %>#destroy', :id => '1')
38
+ end
39
+ <%- end -%>
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_name %>Test < ActionController::TestCase
4
+ <%- if action? :index -%>
5
+ def test_index
6
+ get :index
7
+ assert_template 'index'
8
+ end
9
+ <%- end -%>
10
+ <%- if action? :show -%>
11
+ def test_show
12
+ get :show, :id => <%= class_name %>.first
13
+ assert_template 'show'
14
+ end
15
+ <%- end -%>
16
+ <%- if action? :new -%>
17
+ def test_new
18
+ get :new
19
+ assert_template 'new'
20
+ end
21
+ <%- end -%>
22
+ <%- if action? :create -%>
23
+ def test_create_invalid
24
+ <%= class_name %>.any_instance.stub(:valid?).and_return(false)
25
+ post :create
26
+ assert_template 'new'
27
+ end
28
+
29
+ def test_create_valid
30
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
31
+ post :create
32
+ assert_redirected_to <%= generate_route_link(:action => :show, :suffix => 'url', :object => "assigns(:#{singular_name})" ) %>
33
+ end
34
+ <%- end -%>
35
+ <%- if action? :edit -%>
36
+ def test_edit
37
+ get :edit, :id => <%= class_name %>.first
38
+ assert_template 'edit'
39
+ end
40
+ <%- end -%>
41
+ <%- if action? :update -%>
42
+ def test_update_invalid
43
+ <%= class_name %>.any_instance.stub(:valid?).and_return(false)
44
+ put :update, :id => <%= class_name %>.first
45
+ assert_template 'edit'
46
+ end
47
+
48
+ def test_update_valid
49
+ <%= class_name %>.any_instance.stub(:valid?).and_return(true)
50
+ put :update, :id => <%= class_name %>.first
51
+ assert_redirected_to <%= generate_route_link(:action => :show, :suffix => 'url', :object => "assigns(:#{singular_name})" ) %>
52
+ end
53
+ <%- end -%>
54
+ <%- if action? :destroy -%>
55
+ def test_destroy
56
+ <%= instance_name %> = <%= class_name %>.first
57
+ delete :destroy, :id => <%= instance_name %>
58
+ assert_redirected_to <%= generate_route_link(:action => :index, :suffix => 'url') %>
59
+ assert !<%= class_name %>.exists?(<%= instance_name %>.id)
60
+ end
61
+ <%- end -%>
62
+ end