rspec_rails3_gen 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,53 @@
1
+ require 'rails/version'
2
+ require File.dirname(__FILE__) + '/../default_values'
3
+ require 'generators/rspec_rails3_gen_base'
4
+
5
+ module RSpec
6
+ module Generators
7
+ class ModelGenerator < NamedBase
8
+ # argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
9
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
10
+
11
+ class_option :skip_fixture, :type => :boolean, :aliases => "-F", :default => false,
12
+ :desc => "Skip Fixture creation"
13
+
14
+ class_option :skip_migration, :type => :boolean, :aliases => "-M", :default => false,
15
+ :desc => "Skip Migration creation"
16
+
17
+
18
+ def self.source_root
19
+ @source_root ||= File.expand_path('../templates', __FILE__)
20
+ end
21
+
22
+ def create_files
23
+ empty_directory 'app/models'
24
+ empty_directory 'spec/models'
25
+ unless options[:skip_fixture]
26
+ empty_directory 'spec/fixtures'
27
+ end
28
+
29
+ end
30
+
31
+ def create_model
32
+ # use hook to execute model generator
33
+
34
+ # create spec for model
35
+ template 'model_spec.rb', "spec/models/#{file_name}_spec.rb"
36
+
37
+ # unless options[:skip_fixture]
38
+ # template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
39
+ # end
40
+ #
41
+ # unless options[:skip_migration]
42
+ # migration_template 'model:migration.rb', 'db/migrate', :assigns => {
43
+ # :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
44
+ # }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
45
+ # end
46
+ end
47
+
48
+ # hook into generators for model, migration and fixture and have them execute with same arguments
49
+ hook_for :model, :migration, :fixture
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ # model
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ before(:each) do
5
+ @valid_attributes = {
6
+ <%= attributes.map{|a| ":#{a.name_or_reference} => #{a.default_value}" }.join(",\n ") %>
7
+ }
8
+ end
9
+
10
+ it "should create a new instance given valid attributes" do
11
+ <%= class_name %>.create!(@valid_attributes)
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1,198 @@
1
+ require File.dirname(__FILE__) + '/../default_values'
2
+
3
+ # Author: Kristian Mandrup
4
+ # email: kmandrup@gmail.com
5
+ require 'generators/rspec_rails3_gen_base'
6
+
7
+ # ==================
8
+ # TODO: Make hooks for other generators work!!!
9
+ # see 'hook_for'
10
+ # ==================
11
+ module RSpec
12
+ module Generators
13
+ class ScaffoldGenerator < NamedBase
14
+
15
+ class_option :default_file_extension, :type => :string, :aliases => "-fe", :default => 'html.erb',
16
+ :desc => "Default file extension for views"
17
+
18
+ no_tasks do
19
+ attr_accessor :model_name
20
+ attr_accessor :model_attributes
21
+ attr_accessor :controller_actions
22
+
23
+ alias :attributes :model_attributes
24
+ alias :attributes= :model_attributes=
25
+ end
26
+
27
+ argument :model_name, :type => :string, :required => true, :banner => 'ModelName'
28
+ argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
29
+
30
+ def initialize(*args, &block)
31
+ super
32
+
33
+ @my_options ||= {}
34
+ @controller_actions = []
35
+ @model_attributes = []
36
+
37
+ args_for_c_m.each do |arg|
38
+ if arg == '!'
39
+ @my_options[:invert] = true
40
+ elsif arg.include?(':')
41
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
42
+ else
43
+ @controller_actions << arg
44
+ @controller_actions << 'create' if arg == 'new'
45
+ @controller_actions << 'update' if arg == 'edit'
46
+ end
47
+ end
48
+
49
+ @controller_actions.uniq!
50
+ @model_attributes.uniq!
51
+
52
+ if options.do_invert? || @controller_actions.empty?
53
+ @controller_actions = all_actions - @controller_actions
54
+ end
55
+
56
+ if @model_attributes.empty?
57
+ @my_options[:skip_model] = true # default to skipping model if no attributes passed
58
+ if model_exists?
59
+ model_columns_for_attributes.each do |column|
60
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
61
+ end
62
+ else
63
+ @model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
64
+ end
65
+ end
66
+ end
67
+
68
+ def create_files
69
+ # Controller, helper, views, and spec directories.
70
+
71
+ empty_directory 'spec/controllers'
72
+ empty_directory 'spec/routing'
73
+ empty_directory 'spec/models'
74
+ empty_directory 'spec/helpers'
75
+ empty_directory 'spec/fixtures'
76
+ empty_directory 'spec/views'
77
+ empty_directory 'spec/integration'
78
+
79
+ # Controller spec, class, and helper.
80
+ template 'routing_spec.rb',
81
+ File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
82
+
83
+ template 'controller_spec.rb',
84
+ File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
85
+
86
+
87
+ template 'helper_spec.rb',
88
+ File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
89
+
90
+ # View specs
91
+ template "edit_erb_spec.rb",
92
+ File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
93
+ template "index_erb_spec.rb",
94
+ File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
95
+ template "new_erb_spec.rb",
96
+ File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
97
+ template "show_erb_spec.rb",
98
+ File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
99
+
100
+ # route_resources controller_file_name
101
+
102
+ end
103
+
104
+ # tries to find generator within rspec first, then in rails
105
+ # use :in, fx :in => :rails to be more specific!
106
+
107
+ # TODO: Make hooks work!!!
108
+ # hook_for :integration_spec, :model, :migration, :scaffold, :layout
109
+
110
+ no_tasks do
111
+
112
+ def default_file_extension
113
+ options[:default_file_extension]
114
+ end
115
+
116
+ def controller_class_name
117
+ "#{class_name}Controller"
118
+ end
119
+
120
+ def controller_class_path
121
+ class_path || "controller/#{name}"
122
+ end
123
+
124
+ def controller_file_name
125
+ name
126
+ end
127
+
128
+ def model_exists?
129
+ File.exist? destination_path("app/models/#{singular_name}.rb")
130
+ end
131
+
132
+ def destination_path(path)
133
+ File.join(destination_root, path)
134
+ end
135
+
136
+
137
+ def scaffold_views
138
+ %w[ index show new edit ]
139
+ end
140
+
141
+ def actions
142
+ @controller_actions
143
+ end
144
+
145
+ def all_actions
146
+ %w[index show new create edit update destroy]
147
+ end
148
+
149
+ def action?(name)
150
+ controller_actions.include? name.to_s
151
+ end
152
+
153
+ def actions?(*names)
154
+ names.all? { |name| action? name }
155
+ end
156
+
157
+ def singular_name
158
+ model_name.underscore
159
+ end
160
+
161
+ def plural_name
162
+ model_name.underscore.pluralize
163
+ end
164
+
165
+ def class_name
166
+ model_name.camelize
167
+ end
168
+
169
+ def plural_class_name
170
+ plural_name.camelize
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ # What is this for???
178
+ module Rails
179
+ module Generators
180
+ class GeneratedAttribute
181
+ def input_type
182
+ @input_type ||= map_to_input_type
183
+ end
184
+
185
+ protected
186
+
187
+ def map_to_input_type
188
+ case type
189
+ when :text
190
+ "textarea"
191
+ else
192
+ "input"
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+
@@ -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,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_class_name %>Controller do
4
+
5
+ def mock_<%= file_name %>(stubs={})
6
+ @mock_<%= file_name %> ||= mock_model(<%= class_name %>, stubs)
7
+ end
8
+
9
+ describe "GET index" do
10
+ it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
11
+ <%= class_name %>.stub(:find).with(:all).and_return([mock_<%= file_name %>])
12
+ get :index
13
+ assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
14
+ end
15
+ end
16
+
17
+ describe "GET show" do
18
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
19
+ <%= class_name %>.stub(:find).with("37").and_return(mock_<%= file_name %>)
20
+ get :show, :id => "37"
21
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
22
+ end
23
+ end
24
+
25
+ describe "GET new" do
26
+ it "assigns a new <%= file_name %> as @<%= file_name %>" do
27
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>)
28
+ get :new
29
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
30
+ end
31
+ end
32
+
33
+ describe "GET edit" do
34
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
35
+ <%= class_name %>.stub(:find).with("37").and_return(mock_<%= file_name %>)
36
+ get :edit, :id => "37"
37
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
38
+ end
39
+ end
40
+
41
+ describe "POST create" do
42
+
43
+ describe "with valid params" do
44
+ it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
45
+ <%= class_name %>.stub(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
46
+ post :create, :<%= file_name %> => {:these => 'params'}
47
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
48
+ end
49
+
50
+ it "redirects to the created <%= file_name %>" do
51
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>(:save => true))
52
+ post :create, :<%= file_name %> => {}
53
+ response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
54
+ end
55
+ end
56
+
57
+ describe "with invalid params" do
58
+ it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
59
+ <%= class_name %>.stub(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
60
+ post :create, :<%= file_name %> => {:these => 'params'}
61
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
62
+ end
63
+
64
+ it "re-renders the 'new' template" do
65
+ <%= class_name %>.stub(:new).and_return(mock_<%= file_name %>(:save => false))
66
+ post :create, :<%= file_name %> => {}
67
+ response.should render_template('new')
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe "PUT update" do
74
+
75
+ describe "with valid params" do
76
+ it "updates the requested <%= file_name %>" do
77
+ <%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
78
+ mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
79
+ put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
80
+ end
81
+
82
+ it "assigns the requested <%= file_name %> as @<%= file_name %>" do
83
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
84
+ put :update, :id => "1"
85
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
86
+ end
87
+
88
+ it "redirects to the <%= file_name %>" do
89
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
90
+ put :update, :id => "1"
91
+ response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
92
+ end
93
+ end
94
+
95
+ describe "with invalid params" do
96
+ it "updates the requested <%= file_name %>" do
97
+ <%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
98
+ mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
99
+ put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
100
+ end
101
+
102
+ it "assigns the <%= file_name %> as @<%= file_name %>" do
103
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
104
+ put :update, :id => "1"
105
+ assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
106
+ end
107
+
108
+ it "re-renders the 'edit' template" do
109
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
110
+ put :update, :id => "1"
111
+ response.should render_template('edit')
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ describe "DELETE destroy" do
118
+ it "destroys the requested <%= file_name %>" do
119
+ <%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
120
+ mock_<%= file_name %>.should_receive(:destroy)
121
+ delete :destroy, :id => "37"
122
+ end
123
+
124
+ it "redirects to the <%= table_name %> list" do
125
+ <%= class_name %>.stub(:find).and_return(mock_<%= file_name %>(:destroy => true))
126
+ delete :destroy, :id => "1"
127
+ response.should redirect_to(<%= table_name %>_url)
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
5
+ include <%= controller_class_name %>Helper
6
+
7
+ before(:each) do
8
+ assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
9
+ :new_record? => false<%= output_attributes.empty? ? '' : ',' %>
10
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
+ <% end -%>
13
+ )
14
+ end
15
+
16
+ it "renders the edit <%= file_name %> form" do
17
+ render
18
+
19
+ response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
20
+ <% for attribute in output_attributes -%>
21
+ with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
22
+ <% end -%>
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_class_name %>Helper do
4
+
5
+ #Delete this example and add some real ones or delete this file
6
+ it "is included in the helper object" do
7
+ included_modules = (class << helper; self; end).send :included_modules
8
+ included_modules.should include(<%= controller_class_name %>Helper)
9
+ end
10
+
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
5
+ include <%= controller_class_name %>Helper
6
+
7
+ before(:each) do
8
+ assigns[:<%= table_name %>] = [
9
+ <% [1,2].each_with_index do |id, model_index| -%>
10
+ stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
11
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
12
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
13
+ <% end -%>
14
+ <% if !output_attributes.empty? -%>
15
+ <%= model_index == 1 ? ')' : '),' %>
16
+ <% end -%>
17
+ <% end -%>
18
+ ]
19
+ end
20
+
21
+ it "renders a list of <%= table_name %>" do
22
+ render
23
+ <% for attribute in output_attributes -%>
24
+ response.should have_tag("tr>td", <%= attribute.default_value %>.to_s, 2)
25
+ <% end -%>
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
5
+ include <%= controller_class_name %>Helper
6
+
7
+ before(:each) do
8
+ assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
9
+ :new_record? => true<%= output_attributes.empty? ? '' : ',' %>
10
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
11
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
12
+ <% end -%>
13
+ )
14
+ end
15
+
16
+ it "renders new <%= file_name %> form" do
17
+ render
18
+
19
+ response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
20
+ <% for attribute in output_attributes -%>
21
+ with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
22
+ <% end -%>
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= controller_class_name %>Controller do
4
+ describe "routing" do
5
+ it "recognizes and generates #index" do
6
+ { :get => "/<%= table_name %>" }.should route_to(:controller => "<%= table_name %>", :action => "index")
7
+ end
8
+
9
+ it "recognizes and generates #new" do
10
+ { :get => "/<%= table_name %>/new" }.should route_to(:controller => "<%= table_name %>", :action => "new")
11
+ end
12
+
13
+ it "recognizes and generates #show" do
14
+ { :get => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "show", :id => "1")
15
+ end
16
+
17
+ it "recognizes and generates #edit" do
18
+ { :get => "/<%= table_name %>/1/edit" }.should route_to(:controller => "<%= table_name %>", :action => "edit", :id => "1")
19
+ end
20
+
21
+ it "recognizes and generates #create" do
22
+ { :post => "/<%= table_name %>" }.should route_to(:controller => "<%= table_name %>", :action => "create")
23
+ end
24
+
25
+ it "recognizes and generates #update" do
26
+ { :put => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "update", :id => "1")
27
+ end
28
+
29
+ it "recognizes and generates #destroy" do
30
+ { :delete => "/<%= table_name %>/1" }.should route_to(:controller => "<%= table_name %>", :action => "destroy", :id => "1")
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
+ describe "/<%= table_name %>/show.<%= default_file_extension %>" do
5
+ include <%= controller_class_name %>Helper
6
+ before(:each) do
7
+ assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
8
+ <% output_attributes.each_with_index do |attribute, attribute_index| -%>
9
+ :<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
10
+ <% end -%>
11
+ <% if !output_attributes.empty? -%>
12
+ )
13
+ <% end -%>
14
+ end
15
+
16
+ it "renders attributes in <p>" do
17
+ render
18
+ <% for attribute in output_attributes -%>
19
+ response.should have_text(/<%= Regexp.escape(attribute.default_value).gsub(/^"|"$/, '')%>/)
20
+ <% end -%>
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ <%% form_for @<%= singular_name %> do |f| %>
2
+ <%%= f.error_messages %>
3
+ <%- for attribute in model_attributes -%>
4
+ <p>
5
+ <%%= f.label :<%= attribute.name %> %><br />
6
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
7
+ </p>
8
+ <%- end -%>
9
+ <p><%%= f.submit "Submit" %></p>
10
+ <%% 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,29 @@
1
+ <%% title "<%= plural_name.titleize %>" %>
2
+
3
+ <table>
4
+ <tr>
5
+ <%- for attribute in model_attributes -%>
6
+ <th><%= attribute.human_name.titleize %></th>
7
+ <%- end -%>
8
+ </tr>
9
+ <%% for <%= singular_name %> in @<%= plural_name %> %>
10
+ <tr>
11
+ <%- for attribute in model_attributes -%>
12
+ <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
13
+ <%- end -%>
14
+ <%- if action? :show -%>
15
+ <td><%%= link_to "Show", <%= singular_name %> %></td>
16
+ <%- end -%>
17
+ <%- if action? :edit -%>
18
+ <td><%%= link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
19
+ <%- end -%>
20
+ <%- if action? :destroy -%>
21
+ <td><%%= link_to "Destroy", <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
22
+ <%- end -%>
23
+ </tr>
24
+ <%% end %>
25
+ </table>
26
+
27
+ <%- if action? :new -%>
28
+ <p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
29
+ <%- 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 -%>