rspec_rails3_gen 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/LICENSE +20 -0
  2. data/README +14 -0
  3. data/README.rdoc +13 -0
  4. data/bin/rspec_controller +19 -0
  5. data/bin/rspec_integration_spec +21 -0
  6. data/bin/rspec_model +19 -0
  7. data/bin/rspec_scaffold +21 -0
  8. data/bin/rspec_skeleton +19 -0
  9. data/lib/generators/rspec/controller/USAGE +33 -0
  10. data/lib/generators/rspec/controller/controller_generator.rb +125 -0
  11. data/lib/generators/rspec/controller/templates/actions/create.rb +4 -0
  12. data/lib/generators/rspec/controller/templates/actions/destroy.rb +4 -0
  13. data/lib/generators/rspec/controller/templates/actions/edit.rb +3 -0
  14. data/lib/generators/rspec/controller/templates/actions/index.rb +3 -0
  15. data/lib/generators/rspec/controller/templates/actions/new.rb +3 -0
  16. data/lib/generators/rspec/controller/templates/actions/show.rb +3 -0
  17. data/lib/generators/rspec/controller/templates/actions/update.rb +5 -0
  18. data/lib/generators/rspec/controller/templates/controller.rb +4 -0
  19. data/lib/generators/rspec/controller/templates/controller_spec.rb +25 -0
  20. data/lib/generators/rspec/controller/templates/helper.rb +2 -0
  21. data/lib/generators/rspec/controller/templates/helper_spec.erb +11 -0
  22. data/lib/generators/rspec/controller/templates/view_spec.rb +12 -0
  23. data/lib/generators/rspec/controller/templates/views/erb/_form.html.erb +4 -0
  24. data/lib/generators/rspec/controller/templates/views/erb/edit.html.erb +14 -0
  25. data/lib/generators/rspec/controller/templates/views/erb/index.html.erb +10 -0
  26. data/lib/generators/rspec/controller/templates/views/erb/new.html.erb +7 -0
  27. data/lib/generators/rspec/controller/templates/views/erb/show.html.erb +13 -0
  28. data/lib/generators/rspec/controller/templates/views/haml/_form.html.haml +4 -0
  29. data/lib/generators/rspec/controller/templates/views/haml/edit.html.haml +14 -0
  30. data/lib/generators/rspec/controller/templates/views/haml/index.html.haml +8 -0
  31. data/lib/generators/rspec/controller/templates/views/haml/new.html.haml +7 -0
  32. data/lib/generators/rspec/controller/templates/views/haml/show.html.haml +14 -0
  33. data/lib/generators/rspec/default_values.rb +28 -0
  34. data/lib/generators/rspec/integration_spec/USAGE +19 -0
  35. data/lib/generators/rspec/integration_spec/integration_spec_generator.rb +13 -0
  36. data/lib/generators/rspec/integration_spec/templates/integration_spec.rb +4 -0
  37. data/lib/generators/rspec/model/USAGE +18 -0
  38. data/lib/generators/rspec/model/model_generator.rb +53 -0
  39. data/lib/generators/rspec/model/templates/model.rb +1 -0
  40. data/lib/generators/rspec/model/templates/model_spec.rb +13 -0
  41. data/lib/generators/rspec/scaffold/USAGE +1 -0
  42. data/lib/generators/rspec/scaffold/scaffold_generator.rb +198 -0
  43. data/lib/generators/rspec/scaffold/templates/actions/create.rb +4 -0
  44. data/lib/generators/rspec/scaffold/templates/actions/destroy.rb +4 -0
  45. data/lib/generators/rspec/scaffold/templates/actions/edit.rb +3 -0
  46. data/lib/generators/rspec/scaffold/templates/actions/index.rb +3 -0
  47. data/lib/generators/rspec/scaffold/templates/actions/new.rb +3 -0
  48. data/lib/generators/rspec/scaffold/templates/actions/show.rb +3 -0
  49. data/lib/generators/rspec/scaffold/templates/actions/update.rb +5 -0
  50. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +131 -0
  51. data/lib/generators/rspec/scaffold/templates/edit_erb_spec.rb +25 -0
  52. data/lib/generators/rspec/scaffold/templates/helper_spec.erb +11 -0
  53. data/lib/generators/rspec/scaffold/templates/index_erb_spec.rb +27 -0
  54. data/lib/generators/rspec/scaffold/templates/new_erb_spec.rb +25 -0
  55. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +33 -0
  56. data/lib/generators/rspec/scaffold/templates/show_erb_spec.rb +22 -0
  57. data/lib/generators/rspec/scaffold/templates/views/erb/_form.html.erb +10 -0
  58. data/lib/generators/rspec/scaffold/templates/views/erb/edit.html.erb +14 -0
  59. data/lib/generators/rspec/scaffold/templates/views/erb/index.html.erb +29 -0
  60. data/lib/generators/rspec/scaffold/templates/views/erb/new.html.erb +7 -0
  61. data/lib/generators/rspec/scaffold/templates/views/erb/show.html.erb +20 -0
  62. data/lib/generators/rspec/scaffold/templates/views/haml/_form.html.haml +10 -0
  63. data/lib/generators/rspec/scaffold/templates/views/haml/edit.html.haml +14 -0
  64. data/lib/generators/rspec/scaffold/templates/views/haml/index.html.haml +25 -0
  65. data/lib/generators/rspec/scaffold/templates/views/haml/new.html.haml +7 -0
  66. data/lib/generators/rspec/scaffold/templates/views/haml/show.html.haml +20 -0
  67. data/lib/generators/rspec/skeleton/USAGE +19 -0
  68. data/lib/generators/rspec/skeleton/skeleton_generator.rb +29 -0
  69. data/lib/generators/rspec/skeleton/templates/previous_failures.txt +0 -0
  70. data/lib/generators/rspec/skeleton/templates/rcov.opts +2 -0
  71. data/lib/generators/rspec/skeleton/templates/rspec.rake +144 -0
  72. data/lib/generators/rspec/skeleton/templates/script/autospec +6 -0
  73. data/lib/generators/rspec/skeleton/templates/script/spec +10 -0
  74. data/lib/generators/rspec/skeleton/templates/spec.opts +4 -0
  75. data/lib/generators/rspec/skeleton/templates/spec_helper.rb +54 -0
  76. data/lib/generators/rspec_rails3_gen_base.rb +27 -0
  77. data/spec/rspec_rails3_spec.rb +7 -0
  78. data/spec/spec_helper.rb +9 -0
  79. metadata +146 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,14 @@
1
+ Description:
2
+ The Rspec Rails 3 generators includes the following generators:
3
+
4
+ rspec:skeleton - generates an Rspec skeleton directory structure
5
+ rspec:integration_spec - generates an Rspec integration test specification for a controller
6
+ rspec:controller - generates an Rspec controller specification
7
+ rspec:model - generates an Rspec model specification
8
+ rspec:scaffold - scaffolds multiple Rspec artifacts for a controller
9
+
10
+ NOTE:
11
+ This is currently a work in progress. Please feel free to join in the effort and fork this project and fix whatever bugs etc.
12
+ This has not yet been tested... haha! I will continue when I get time, and add tests!
13
+
14
+
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = Description:
2
+
3
+ The Rspec Rails 3 generators includes the following generators:
4
+
5
+ * rspec:skeleton - generates an Rspec skeleton directory structure
6
+ * rspec:integration_spec - generates an Rspec integration test specification for a controller
7
+ * rspec:controller - generates an Rspec controller specification
8
+ * rspec:model - generates an Rspec model specification
9
+ * rspec:scaffold - scaffolds multiple Rspec artifacts for a controller
10
+
11
+ == Important
12
+ This is currently a work in progress. Please feel free to join in the effort and fork this project and fix whatever bugs etc.
13
+ This has not yet been tested... haha! I will continue when I get time, and add tests!
@@ -0,0 +1,19 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ require 'rails/generators'
17
+ require 'generators/rspec/controller/controller_generator'
18
+
19
+ RSpec::Generators::ControllerGenerator.start
@@ -0,0 +1,21 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ require 'rails/generators'
19
+ require 'generators/rspec/integration_spec/integration_spec_generator'
20
+
21
+ RSpec::Generators::IntegrationSpecGenerator.start
data/bin/rspec_model ADDED
@@ -0,0 +1,19 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ require 'rails/generators'
17
+ require 'generators/rspec/model/model_generator'
18
+
19
+ RSpec::Generators::ModelGenerator.start
@@ -0,0 +1,21 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ require 'rails/ruby_version_check'
13
+ end
14
+
15
+ Signal.trap("INT") { puts; exit }
16
+
17
+ require 'rails/version'
18
+ require 'rails/generators'
19
+ require 'generators/rspec/scaffold/scaffold_generator'
20
+
21
+ RSpec::Generators::ScaffoldGenerator.start
@@ -0,0 +1,19 @@
1
+ #!/user/local/bin/ruby
2
+
3
+ begin
4
+ require 'rails/ruby_version_check'
5
+ rescue LoadError
6
+ # If people are not using gems, the load path must still
7
+ # be correct.
8
+ # TODO: Remove the begin / rescue block somehow
9
+ $:.unshift File.expand_path('../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
11
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
12
+ end
13
+
14
+ Signal.trap("INT") { puts; exit }
15
+
16
+ require 'rails/generators'
17
+ require 'generators/rspec/skeleton/skeleton_generator'
18
+
19
+ RSpec::Generators::SkeletonGenerator.start
@@ -0,0 +1,33 @@
1
+ Description:
2
+ The rspec_controller generator creates stub specs and files for a new
3
+ controller and its views.
4
+
5
+ The generator takes a controller name and a list of views as arguments.
6
+ The controller name may be given in CamelCase or under_score and should
7
+ not be suffixed with 'Controller'. To create a controller within a
8
+ module, specify the controller name as 'module/controller'.
9
+
10
+ The generator creates stubs for a controller (and spec), a view (and spec)
11
+ for each view in the argument list, plus a helper.
12
+
13
+ Example:
14
+ ./script/generate rspec_controller dog bark fetch
15
+ ...
16
+ create spec/controllers/dog_controller_spec.rb
17
+ create app/controllers/dog_controller.rb
18
+ create app/helpers/dog_helper.rb
19
+ create spec/views/dog/bark_view_spec.rb
20
+ create app/views/dog/bark.rhtml
21
+ create spec/views/dog/fetch_view_spec.rb
22
+ create app/views/dog/fetch.rhtml
23
+
24
+ Modules Example:
25
+ ./script/generate rspec_controller 'pets/dog' bark fetch
26
+ ...
27
+ create spec/controllers/pets/dog_controller_spec.rb
28
+ create app/controllers/pets/dog_controller.rb
29
+ create app/helpers/pets/dog_helper.rb
30
+ create spec/views/pets/dog/bark_view_spec.rb
31
+ create app/views/pets/dog/bark.rhtml
32
+ create spec/views/pets/dog/fetch_view_spec.rb
33
+ create app/views/pets/dog/fetch.rhtml
@@ -0,0 +1,125 @@
1
+ require 'generators/rspec_rails3_gen_base'
2
+
3
+ # ==================
4
+ # TODO: Make hooks for other generators work!!!
5
+ # see 'hook_for'
6
+ # ==================
7
+
8
+ module RSpec
9
+ module Generators
10
+ class ControllerGenerator < NamedBase
11
+
12
+ argument :controller_actions, :type => :array, :default => [], :required => false, :banner => 'controller_actions'
13
+ check_class_collision :suffix => "Controller"
14
+
15
+ # attr_accessor :actions
16
+
17
+ no_tasks { attr_accessor :actions }
18
+
19
+ class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
20
+
21
+ def self.source_root
22
+ @source_root ||= File.expand_path('../templates', __FILE__)
23
+ end
24
+
25
+ def initialize(*args, &block)
26
+ super
27
+ @actions = []
28
+
29
+ controller_actions.each do |arg|
30
+ @actions << arg
31
+ @actions << 'create' if arg == 'new'
32
+ @actions << 'update' if arg == 'edit'
33
+ end
34
+
35
+ @actions.uniq!
36
+
37
+ if @actions.empty?
38
+ @actions = all_actions - @actions
39
+ end
40
+ end
41
+
42
+ def create_files
43
+ # Check for class naming collisions.
44
+ class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
45
+
46
+ @default_file_extension = "erb"
47
+
48
+ # Controller, helper, views, and spec directories.
49
+ inside 'app' do
50
+ empty_directory 'controllers'
51
+ empty_directory 'helpers'
52
+ empty_directory 'views'
53
+ end
54
+
55
+ # use hooks instead!
56
+
57
+ # template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
58
+ # template 'helper.rb', File.join('app/helpers', class_path, "#{file_name}_helper.rb")
59
+
60
+ html_actions = actions.reject{|a| %w{create update}.include?(a)}
61
+ #
62
+ # html_actions.each do |action|
63
+ # @action = action
64
+ # template "views/#{@default_file_extension}/#{action}.html.#{@default_file_extension}", "app/views/#{action}.html.#{@default_file_extension}"
65
+ #
66
+ # # add '_form' view for new or update action
67
+ # if %w{edit new}.include?(action)
68
+ # template "views/#{@default_file_extension}/_form.html.#{@default_file_extension}", "app/views/_form.html.#{@default_file_extension}"
69
+ # end
70
+ # end
71
+
72
+ # spec
73
+ inside 'spec' do
74
+ empty_directory 'controllers'
75
+ empty_directory 'helpers'
76
+ empty_directory 'views'
77
+ end
78
+
79
+ # Controller spec, class, and helper.
80
+ template 'controller_spec.rb', File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
81
+ template 'helper_spec.rb.t', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
82
+
83
+ # Spec and view template for each action.
84
+ html_actions.each do |action|
85
+ @action = action
86
+ target_file = "spec/views/#{file_name}/actions/#{action}_html_#{@default_file_extension}_spec.rb"
87
+ puts target_file
88
+ template 'view_spec.rb', target_file
89
+ end
90
+ end
91
+
92
+ # hook into controller and helper generators to have them execute using same arguments!
93
+ # hook_for :controller, :helper
94
+
95
+ no_tasks do
96
+ def all_actions
97
+ %w[index show new create edit update destroy]
98
+ end
99
+
100
+ def current_action
101
+ @action || 'unknown'
102
+ end
103
+
104
+
105
+ def action?(name)
106
+ actions.include? name.to_s
107
+ end
108
+
109
+ def actions?(*names)
110
+ names.all? { |name| action? name }
111
+ end
112
+
113
+ def class_name
114
+ name.camelize
115
+ end
116
+
117
+
118
+ def plural_class_name
119
+ plural_name.camelize
120
+ end
121
+ end
122
+
123
+ end # class
124
+ end # generators
125
+ end # rspec
@@ -0,0 +1,4 @@
1
+ def create
2
+ respond_with(@<%= singular_name %> = <%= class_name %>.create(params[:<%= singular_name %>]))
3
+ end
4
+
@@ -0,0 +1,4 @@
1
+ def destroy
2
+ respond_with(@<%= singular_name %> = <%= class_name %>.find(params[:id]))
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ def edit
2
+ respond_with(@<%= singular_name %> = <%= class_name %>.find(params[:id]))
3
+ end
@@ -0,0 +1,3 @@
1
+ def index
2
+ respond_with(@<%= plural_name %> = <%= class_name %>.all)
3
+ end
@@ -0,0 +1,3 @@
1
+ def new
2
+ respond_with(@<%= singular_name %> = <%= class_name %>.new)
3
+ end
@@ -0,0 +1,3 @@
1
+ def show
2
+ respond_with(@<%= singular_name %> = <%= class_name %>.find(params[:id]))
3
+ end
@@ -0,0 +1,5 @@
1
+ def update
2
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
+ @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
4
+ respond_with(@<%= singular_name %>)
5
+ end
@@ -0,0 +1,4 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController::Base
2
+ respond_to :html, :xml, :json
3
+ <%#= controller_methods :actions %>
4
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Controller do
4
+
5
+ <% if actions.empty? -%>
6
+ #Delete this example and add some real ones
7
+ <% else -%>
8
+ #Delete these examples and add some real ones
9
+ <% end -%>
10
+ it "should use <%= class_name %>Controller" do
11
+ controller.should be_an_instance_of(<%= class_name %>Controller)
12
+ end
13
+
14
+ <% unless actions.empty? -%>
15
+ <% for action in actions -%>
16
+
17
+ describe "GET '<%= action %>'" do
18
+ it "should be successful" do
19
+ get '<%= action %>'
20
+ response.should be_success
21
+ end
22
+ end
23
+ <% end -%>
24
+ <% end -%>
25
+ end
@@ -0,0 +1,2 @@
1
+ module <%= plural_class_name %>Helper
2
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %>Helper do
4
+
5
+ # Delete this example and add some real ones or delete this file
6
+ it "should be included in the object returned by #helper" do
7
+ included_modules = (class << helper; self; end).send :included_modules
8
+ included_modules.should include(<%= class_name %>Helper)
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "/<%= class_name.underscore %>/<%= current_action %>" do
4
+ before(:each) do
5
+ render '<%= class_name.underscore %>/<%= current_action %>'
6
+ end
7
+
8
+ #Delete this example and add some real ones or delete this file
9
+ it "should tell you where to find the file" do
10
+ response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= current_action %>])
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ <%% form_for @<%= singular_name %> do |f| %>
2
+ <%%= f.error_messages %>
3
+ <p><%%= f.submit "Submit" %></p>
4
+ <%% end %>
@@ -0,0 +1,14 @@
1
+ <%% title "Edit <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if actions? :show, :index -%>
6
+ <p>
7
+ <%- if action? :show -%>
8
+ <%%= link_to "Show", @<%= singular_name %> %> |
9
+ <%- end -%>
10
+ <%- if action? :index -%>
11
+ <%%= link_to "View All", <%= plural_name %>_path %>
12
+ <%- end -%>
13
+ </p>
14
+ <%- end -%>
@@ -0,0 +1,10 @@
1
+ <%% title "<%= plural_name.titleize %>" %>
2
+
3
+ <table>
4
+ <tr>
5
+ </tr>
6
+ </table>
7
+
8
+ <%- if action? :new -%>
9
+ <p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
10
+ <%- end -%>
@@ -0,0 +1,7 @@
1
+ <%% title "New <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ <p><%%= link_to "Back to List", <%= plural_name %>_path %></p>
7
+ <%- end -%>
@@ -0,0 +1,13 @@
1
+ <%% title "<%= singular_name.titleize %>" %>
2
+
3
+ <p>
4
+ <%- if action? :edit -%>
5
+ <%%= link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
6
+ <%- end -%>
7
+ <%- if action? :destroy -%>
8
+ <%%= link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %> |
9
+ <%- end -%>
10
+ <%- if action? :index -%>
11
+ <%%= link_to "View All", <%= plural_name %>_path %>
12
+ <%- end -%>
13
+ </p>
@@ -0,0 +1,4 @@
1
+ - form_for @<%= singular_name %> do |f|
2
+ = f.error_messages
3
+ %p
4
+ = f.submit "Submit"
@@ -0,0 +1,14 @@
1
+ - title "Edit <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if actions? :show, :index -%>
6
+ %p
7
+ <%- if action? :show -%>
8
+ = link_to "Show", <%= singular_name %>_path(@<%= singular_name %>)
9
+ |
10
+ <%- end -%>
11
+ <%- if action? :index -%>
12
+ = link_to "View All", <%= plural_name %>_path
13
+ <%- end -%>
14
+ <%- end -%>
@@ -0,0 +1,8 @@
1
+ - title "<%= plural_name.titleize %>"
2
+
3
+ %table
4
+ %tr
5
+
6
+ <%- if actions? :new -%>
7
+ %p= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path
8
+ <%- end -%>
@@ -0,0 +1,7 @@
1
+ - title "New <%= singular_name.titleize %>"
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ %p= link_to "Back to List", <%= plural_name %>_path
7
+ <%- end -%>
@@ -0,0 +1,14 @@
1
+ - title "<%= singular_name.titleize %>"
2
+
3
+ %p
4
+ <%- if action? :edit -%>
5
+ = link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>)
6
+ |
7
+ <%- end -%>
8
+ <%- if action? :destroy -%>
9
+ = link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
10
+ |
11
+ <%- end -%>
12
+ <%- if action? :index -%>
13
+ = link_to "View All", <%= plural_name %>_path
14
+ <%- end -%>
@@ -0,0 +1,28 @@
1
+ module Rails
2
+ module Generators
3
+ class GeneratedAttribute
4
+ def default_value
5
+ @default_value ||= case type
6
+ when :int, :integer then "1"
7
+ when :float then "1.5"
8
+ when :decimal then "9.99"
9
+ when :datetime, :timestamp, :time then "Time.now"
10
+ when :date then "Date.today"
11
+ when :string, :text then "\"value for #{@name}\""
12
+ when :boolean then "false"
13
+ when :belongs_to, :references then "1"
14
+ else
15
+ ""
16
+ end
17
+ end
18
+
19
+ def name_or_reference
20
+ if ::Rails::VERSION::STRING >= '2.2'
21
+ reference? ? :"#{name}_id" : name
22
+ else
23
+ name
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ Description:
2
+ This is the rspec:integration_spec generator. It is also available as a global executable rspec_integration_spec.
3
+ This generator creates an integration specification for a Rails application.
4
+
5
+ The generator creates an integration specification in spec/integration with the name of the controller postfixed with _spec.
6
+ Like any other RSpec specification, the spec is a ruby file with a standard .rb extension.
7
+
8
+ Example: Generator
9
+ ./script/generate rspec:integration_spec person
10
+
11
+ This will create an integration specification for person:
12
+ Spec: spec/integration/people_spec.rb
13
+
14
+ Example: Executable
15
+ rspec_integration_spec person
16
+
17
+ This will create an integration specification for person:
18
+ Spec: spec/integration/people_spec.rb
19
+
@@ -0,0 +1,13 @@
1
+ # Author: Kristian Mandrup
2
+ # email: kmandrup@gmail.com
3
+ require 'generators/rspec_rails3_gen_base'
4
+ module RSpec
5
+ module Generators
6
+ class IntegrationSpecGenerator < NamedBase
7
+
8
+ def create_files
9
+ template "integration_spec.rb" , File.join('spec/integration', class_path, "#{class_name.tableize}_spec.rb")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe "<%= class_name.pluralize %>" do
4
+ end
@@ -0,0 +1,18 @@
1
+ Description:
2
+ The rspec_model generator creates stubs for a new model.
3
+
4
+ The generator takes a model name as its argument. The model name may be
5
+ given in CamelCase or under_score and should not be suffixed with 'Model'.
6
+
7
+ The generator creates a model class in app/models, an RSpec spec in
8
+ spec/models, database fixtures in spec/fixtures/plural_name.yml, and a migration
9
+ in db/migrate.
10
+
11
+ Example:
12
+ ./script/generate rspec_model Account
13
+
14
+ This will create an Account model:
15
+ Model: app/models/account.rb
16
+ Spec: spec/models/account_spec.rb
17
+ Fixtures: spec/fixtures/accounts.yml
18
+ Migration: db/migrate/XXX_add_accounts.rb