jeffkreeftmeijer-awesome_scaffold 0.0.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeff Kreeftmeijer
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.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = awesome_scaffold
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Jeff Kreeftmeijer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "awesome_scaffold"
8
+ gem.summary = "A rails scaffold generator that uses RSpec, Cucumber and HAML"
9
+ gem.email = "jeff@kreeftmeijer.nl"
10
+ gem.homepage = "http://github.com/jeffkreeftmeijer/awesome_scaffold"
11
+ gem.authors = ["Jeff Kreeftmeijer"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "awesome_scaffold #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,312 @@
1
+ #config.gem "thoughtbot-factory_girl", :lib => 'factory_girl', :source => 'http://gems.github.com'
2
+ class AwesomeScaffoldGenerator < Rails::Generator::NamedBase
3
+ default_options :skip_migration => false
4
+
5
+ attr_reader :controller_name,
6
+ :controller_class_path,
7
+ :controller_file_path,
8
+ :controller_class_nesting,
9
+ :controller_class_nesting_depth,
10
+ :controller_class_name,
11
+ :controller_singular_name,
12
+ :controller_plural_name,
13
+ :resource_edit_path,
14
+ :default_file_extension
15
+ alias_method :controller_file_name, :controller_singular_name
16
+ alias_method :controller_table_name, :controller_plural_name
17
+
18
+ def initialize(runtime_args, runtime_options = {})
19
+ super
20
+
21
+ @controller_name = @name.pluralize
22
+
23
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
24
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
25
+
26
+ if @controller_class_nesting.empty?
27
+ @controller_class_name = @controller_class_name_without_nesting
28
+ else
29
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
30
+ end
31
+
32
+ @resource_generator = "awesome_scaffold"
33
+ @default_file_extension = "html.haml"
34
+ @resource_edit_path = "/edit"
35
+
36
+ end
37
+
38
+ def manifest
39
+ record do |m|
40
+ #just so you can see what the variables are
41
+ # => "yoda/bob"
42
+ #p @name # yoda/bob
43
+ #p @controller_name # yoda/bobs
44
+ #p @controller_class_name_without_nesting # Bobs
45
+ #p @controller_class_nesting # yoda
46
+ #p @controller_plural_name #bobs
47
+ #p @controller_singular_name #bobs
48
+ #p @controller_file_path #yoda/bobs
49
+ #p @controller_class_path # ["yoda"]
50
+
51
+ # Check for class naming collisions.
52
+ m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
53
+ m.class_collisions(class_path, "#{class_name}")
54
+
55
+
56
+ # Controller, helper, views, spec and cucumber directories.
57
+ m.directory(File.join('app/models'))
58
+ m.directory(File.join('app/controllers', controller_class_path))
59
+ m.directory(File.join('app/helpers', controller_class_path))
60
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
61
+ m.directory(File.join('spec/controllers', controller_class_path))
62
+ m.directory(File.join('spec/models'))
63
+ m.directory(File.join('spec/helpers', class_path))
64
+ m.directory File.join('spec/fixtures')
65
+ m.directory File.join('spec/views', controller_class_path, controller_file_name)
66
+
67
+ # Controller spec, class, and helper.
68
+ m.template 'awesome_scaffold:controller_spec.rb',
69
+ File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
70
+
71
+ m.template "awesome_scaffold:controller.rb",
72
+ File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
73
+
74
+ m.template 'awesome_scaffold:helper_spec.rb',
75
+ File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
76
+
77
+ m.template "#{@resource_generator}:helper.rb",
78
+ File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")
79
+
80
+ for action in scaffold_views
81
+ m.template(
82
+ "awesome_scaffold:view_#{action}_haml.erb",
83
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
84
+ )
85
+ end
86
+
87
+ # Model class, unit test, and fixtures.
88
+ m.template 'awesome_scaffold:model.rb', File.join('app/models', "#{@controller_singular_name.singularize}.rb")
89
+ m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{@controller_singular_name}.yml")
90
+ m.template 'awesome_scaffold:model_spec.rb', File.join('spec/models', "#{@controller_singular_name.singularize}_spec.rb")
91
+
92
+ # View specs
93
+ m.template "awesome_scaffold:edit_haml_spec.rb",
94
+ File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
95
+ m.template "awesome_scaffold:index_haml_spec.rb",
96
+ File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
97
+ m.template "awesome_scaffold:new_haml_spec.rb",
98
+ File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
99
+ m.template "awesome_scaffold:show_haml_spec.rb",
100
+ File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
101
+
102
+ # Cucumber features
103
+ m.template 'awesome_scaffold:controller.feature', File.join('features', "#{@controller_singular_name}.feature")
104
+
105
+ # Factories.rb
106
+ m.factories
107
+
108
+ m.route_resources(name)
109
+
110
+ # done
111
+ m.puts "\n\e[32m" # green
112
+ m.puts "AWESOME! everything worked."
113
+ m.puts "\e[0m" # clear
114
+ m.puts "Now put this in your paths.rb file (if you haven't already):\n"
115
+
116
+ paths = "when /the (.+) list/\n" <<
117
+ " eval(\"\#{$1.pluralize}_path\")\n\n" <<
118
+
119
+ "when /show page for the (.+) named (.+)/\n" <<
120
+ " item = $1.singularize.capitalize.constantize.find_by_name($2)\n" <<
121
+ " eval(\"\#{$1.singularize}_path(\#{item.id})\")\n\n" <<
122
+
123
+ "when /new (.+) page/\n" <<
124
+ " eval(\"new_\#{$1.singularize}_path\")\n\n" <<
125
+
126
+ "when /edit page for the (.+) named (.+)/\n" <<
127
+ " item = $1.singularize.capitalize.constantize.find_by_name($2)\n" <<
128
+ " eval(\"edit_\#{$1.singularize}_path(\#{item.id})\")\n\n"
129
+
130
+ m.puts "\e[33m" # yellow
131
+ m.puts(paths)
132
+ m.puts "\e[0m" # clear
133
+ m.puts "Press [ENTER] to continue"
134
+ m.pause
135
+
136
+ m.puts "And put this in your global_steps.rb file (if you haven't already):\n\n"
137
+
138
+ steps = "Given /^I have ?a? (.+) named (.+)$/ do |model_name, names|\n"
139
+ steps << " names.split(', ').each do |n|\n"
140
+ steps << " Factory(model_name.singularize, :name => n)\n"
141
+ steps << " end\n"
142
+ steps << "end\n\n"
143
+
144
+ steps << "Given /^I have no (.+)$/ do |model_name|\n"
145
+ steps << " model_name.singularize.capitalize.constantize.delete_all\n"
146
+ steps << "end\n\n"
147
+
148
+ steps << "Then /^I should have ([0-9]+|no) (.+) records?$/ do |count, model_name|\n"
149
+ steps << " model_name.singularize.capitalize.constantize.count.should == count.to_i\n"
150
+ steps << "end\n\n"
151
+
152
+ steps << "Then /^I should have ([0-9]+|no) (.+) records? named (.+)$/ do |count, model_name, name|\n"
153
+ steps << " model_name.singularize.capitalize.constantize.count(:conditions => \"name = '\#{name.gsub('\"', '')}'\").should == count.to_i\n"
154
+ steps << "end\n\n"
155
+
156
+ m.puts "\e[33m" # yellow
157
+ m.puts(steps)
158
+ m.puts "\e[0m" # clear
159
+ m.puts "Press [ENTER] to continue"
160
+ m.pause
161
+
162
+ m.puts "And put this in your application_helper.rb file (if you haven't already):\n\n"
163
+
164
+ st = "def st(arg)\n"
165
+ st << " return t(arg)unless(RAILS_ENV == 'test')\n"
166
+ st << " arg\n"
167
+ st << "end\n\n"
168
+
169
+ m.puts "\e[33m" # yellow
170
+ m.puts(st)
171
+ m.puts "\e[0m" # clear
172
+ m.puts "Press [ENTER] to continue"
173
+ m.pause
174
+
175
+ m.puts "And don't forget to put this in your cucumber.rb file\n"
176
+ m.puts "\e[33m" # yellow
177
+ m.puts "config.gem \"thoughtbot-factory_girl\", :lib => 'factory_girl', :source => 'http://gems.github.com'\n\n"
178
+ m.puts "\e[0m" # clear
179
+
180
+ # run the say command (OSX only, I guess)
181
+ #m.system("say -v zarvox The #{singular_name} scaffold was created, my master")
182
+
183
+ unless options[:skip_migration]
184
+ m.migration_template(
185
+ 'awesome_scaffold:migration.rb', 'db/migrate',
186
+ :assigns => {
187
+ :migration_name => "Create#{singular_name.pluralize.capitalize}",
188
+ :attributes => attributes
189
+ },
190
+ :migration_file_name => "create_#{controller_singular_name.gsub(/\//, '_').pluralize}"
191
+ )
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ protected
198
+ def form_link_for(table_name, singular_name)
199
+ if !@controller_name.split("/")[1].nil?
200
+ return "[:#{@controller_class_nesting.downcase}, @#{singular_name.singularize}]"
201
+ else
202
+ return "@#{singular_name.singularize}"
203
+ end
204
+ end
205
+
206
+ def path_for(singular, plural, txt)
207
+ case txt
208
+ when "show"
209
+ return "#{table_name.singularize}_path(@#{singular_name.singularize})"
210
+ when "edit"
211
+ return "edit_#{table_name.singularize}_path(@#{singular_name.singularize})"
212
+ when "destroy"
213
+ return "#{table_name.singularize}_path(@#{singular_name.singularize}), :confirm => 'Are you sure?', :method => :delete"
214
+ when "index"
215
+ return "#{table_name}_path"
216
+ end
217
+ end
218
+
219
+ # Override with your own usage banner.
220
+ def banner
221
+ "Usage: #{$0} awesome_scaffold ModelName [field:type field:type]"
222
+ end
223
+
224
+ def add_options!(opt)
225
+ opt.separator ''
226
+ opt.separator 'Options:'
227
+ opt.on("--skip-migration",
228
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
229
+ end
230
+
231
+ def scaffold_views
232
+ %w[ index show new edit ]
233
+ end
234
+
235
+ def model_name
236
+ class_name.demodulize
237
+ end
238
+
239
+ def route_resources(resource)
240
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
241
+ logger.route "map.resources #{resource.pluralize}"
242
+ unless options[:pretend]
243
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
244
+
245
+ if !resource.split('/')[1].nil?
246
+ one = resource.split('/')[0]
247
+ two = resource.split('/')[1]
248
+ "#{match}\n map.namespace(:#{one}) do |#{one}|\n #{one}.resources :#{two.pluralize}\n end"
249
+ else
250
+ "#{match}\n map.resources :#{resource.pluralize}\n"
251
+ end
252
+
253
+ end
254
+ end
255
+ end
256
+
257
+ def factories
258
+ logger.factory "Factory.define :#{plural_name}"
259
+ #record { |m| template('awesome_scaffold:empty.rb', File.join('spec', "factories.rb")) unless(File.exists?('spec/factories.rb'))}
260
+
261
+ File.open('spec/factories.rb', "a+") do |f|
262
+ content = f.read
263
+ if(!content.include?("Factory.define :#{plural_name}"))
264
+ factory = "Factory.define :#{singular_name} do |f|\n"
265
+ attributes.each do |a|
266
+ factory << " f.#{a.name} #{a.default_value}\n"
267
+ end
268
+ factory << "end\n\n"
269
+ f.write(factory)
270
+ end
271
+ end
272
+ end
273
+
274
+ def gsub_file(relative_destination, regexp, *args, &block)
275
+ path = destination_path(relative_destination)
276
+ content = File.read(path).gsub(regexp, *args, &block)
277
+ File.open(path, 'wb') { |file| file.write(content) }
278
+ end
279
+
280
+ def pause
281
+ STDIN.gets
282
+ end
283
+ end
284
+
285
+ module Rails
286
+ module Generator
287
+ class GeneratedAttribute
288
+ def default_value
289
+ @default_value ||= case type
290
+ when :int, :integer then "\"1\""
291
+ when :float then "\"1.5\""
292
+ when :decimal then "\"9.99\""
293
+ when :datetime, :timestamp, :time then "Time.now"
294
+ when :date then "Date.today"
295
+ when :string then "\"MyString\""
296
+ when :text then "\"MyText\""
297
+ when :boolean then "false"
298
+ else
299
+ ""
300
+ end
301
+ end
302
+
303
+ def input_type
304
+ @input_type ||= case type
305
+ when :text then "textarea"
306
+ else
307
+ "input"
308
+ end
309
+ end
310
+ end
311
+ end
312
+ end
@@ -0,0 +1,48 @@
1
+ Feature: <%= plural_name.capitalize %>
2
+ In order to manage <%= plural_name %>
3
+ I want to be able to view, create, update and destroy <%= plural_name %>
4
+
5
+ Scenario: Show the list of <%= plural_name %>
6
+ Given I have <%= plural_name %> named bob, henry
7
+ And I am on the <%= plural_name %> list
8
+ Then I should see "bob"
9
+ And I should see "henry"
10
+
11
+ Scenario: Show a specific <%= singular_name.singularize %>
12
+ Given I have a <%= singular_name.singularize %> named bob
13
+ And I am on the show page for the <%= singular_name.singularize %> named bob
14
+ Then I should see "bob"
15
+
16
+ Scenario: Successfully create a new <%= singular_name.singularize %>
17
+ Given I have no <%= plural_name %>
18
+ And I am on the new <%= singular_name.singularize %> page
19
+ <% for attribute in attributes -%>
20
+ When I fill in "<%= singular_name.singularize %>.field.<%= attribute.name %>.name" with <%= attribute.default_value %>
21
+ <% end -%>
22
+ And I press "<%= singular_name.singularize %>.action.create.name"
23
+ # Then I should see "<%= singular_name.singularize %>.action.create.notice" # You should show flash messages in your layout file ;)
24
+ Then I should have 1 <%= singular_name.singularize %> record
25
+
26
+ Scenario: Fail to create a new <%= singular_name.singularize %>
27
+ # Use this scenario for the validations on your model!
28
+
29
+ Scenario: Successfully update a <%= singular_name.singularize %>
30
+ Given I have a <%= singular_name.singularize %> named bob
31
+ And I am on the edit page for the <%= singular_name.singularize %> named bob
32
+ <% for attribute in attributes -%>
33
+ When I fill in "<%= singular_name.singularize %>.field.<%= attribute.name %>.name" with <%= attribute.default_value %>
34
+ <% end -%>
35
+ And I press "<%= singular_name.singularize %>.action.update.name"
36
+ # Then I should see "<%= singular_name.singularize %>.action.create.notice" # You should show flash messages in your layout file ;)
37
+ Then I should have 1 <%= singular_name.singularize %> record named <%= attribute.default_value %>
38
+ And I should have no <%= singular_name.singularize %> records named bob
39
+
40
+ Scenario: Fail to update a <%= singular_name.singularize %>
41
+ # Use this scenario for the validations on your model!
42
+
43
+ Scenario: Successfully destroy a <%= singular_name.singularize %>
44
+ Given I have a <%= singular_name.singularize %> named bob
45
+ And I am on the <%= plural_name %> list
46
+ When I follow "<%= singular_name.singularize %>.action.destroy.name"
47
+ # Then I should see "<%= singular_name.singularize %>.action.destroy.notice" # You should show flash messages in your layout file ;)
48
+ Then I should have no <%= singular_name.singularize %> records
@@ -0,0 +1,85 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+ # GET /<%= name %>
3
+ # GET /<%= name %>.xml
4
+ def index
5
+ @<%= plural_name %> = <%= singular_name.capitalize %>.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.haml
9
+ format.xml { render :xml => @<%= plural_name %> }
10
+ end
11
+ end
12
+
13
+ # GET /<%= name %>/1
14
+ # GET /<%= name %>/1.xml
15
+ def show
16
+ @<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.haml
20
+ format.xml { render :xml => @<%= singular_name %> }
21
+ end
22
+ end
23
+
24
+ # GET /<%= name %>/new
25
+ # GET /<%= name %>/new.xml
26
+ def new
27
+ @<%= singular_name %> = <%= singular_name.capitalize %>.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.haml
31
+ format.xml { render :xml => @<%= singular_name %> }
32
+ end
33
+ end
34
+
35
+ # POST /<%= name %>
36
+ # POST /<%= name %>.xml
37
+ def create
38
+ @<%= file_name %> = <%= singular_name.capitalize %>.new(params[:<%= singular_name %>])
39
+
40
+ respond_to do |format|
41
+ if @<%= file_name %>.save
42
+ flash[:notice] = t("<%= singular_name %>.action.create.notice")
43
+ format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
44
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
45
+ else
46
+ format.html { render :action => "new" }
47
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
48
+ end
49
+ end
50
+ end
51
+
52
+ # GET /<%= name %>/1/edit
53
+ def edit
54
+ @<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
55
+ end
56
+
57
+ # PUT /<%= name %>/1
58
+ # PUT /<%= name %>/1.xml
59
+ def update
60
+ @<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
64
+ flash[:notice] = t("<%= singular_name %>.action.update.notice")
65
+ format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /<%= name %>/1
75
+ # DELETE /<%= name %>/1.xml
76
+ def destroy
77
+ @<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
78
+ @<%= file_name %>.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(<%= table_name %>_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,131 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../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,23 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
2
+
3
+ describe "/<%= name %>/edit.<%= default_file_extension %>" do
4
+ include <%= controller_class_name %>Helper
5
+
6
+ before do
7
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
8
+ <% for attribute in attributes -%>
9
+ @<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
10
+ <% end -%>
11
+ assigns[:<%= file_name %>] = @<%= file_name %>
12
+ end
13
+
14
+ it "should render edit form" do
15
+ render "/<%= name.pluralize %>/edit.<%= default_file_extension %>"
16
+
17
+ response.should have_tag("form[action=#{<%= table_name.singularize %>_path(@<%= file_name %>)}][method=post]") do
18
+ <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
19
+ with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
20
+ <% end -%><% end -%>
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module <%= controller_class_name %>Helper
2
+
3
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../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,21 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
2
+
3
+ describe "/<%= name.pluralize %>/index.<%= default_file_extension %>" do
4
+ include <%= controller_class_name %>Helper
5
+
6
+ before do
7
+ <% [98,99].each do |id| -%>
8
+ <%= file_name %>_<%= id %> = mock_model(<%= singular_name.capitalize %>)
9
+ <% for attribute in attributes -%>
10
+ <%= file_name %>_<%= id %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
11
+ <% end -%><% end %>
12
+ assigns[:<%= file_name.pluralize %>] = [<%= file_name %>_98, <%= file_name %>_99]
13
+ end
14
+
15
+ it "should render list of <%= table_name %>" do
16
+ render "/<%= name.pluralize %>/index.<%= default_file_extension %>"
17
+ <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
18
+ response.should have_tag("tr>td", <%= attribute.default_value %>, 2)
19
+ <% end -%><% end -%>
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ class <%= migration_name.classify.pluralize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= singular_name.pluralize %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end %>
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :<%= singular_name.pluralize %>
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ class <%= singular_name.capitalize %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= singular_name.capitalize %> do
4
+ before(:each) do
5
+ @<%= file_name %> = <%= singular_name.capitalize %>.new
6
+ end
7
+
8
+ it "should be valid" do
9
+ @<%= file_name %>.should be_valid
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
2
+
3
+ describe "/<%= name.pluralize %>/new.<%= default_file_extension %>" do
4
+ include <%= controller_class_name %>Helper
5
+
6
+ before do
7
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
8
+ @<%= file_name %>.stub!(:new_record?).and_return(true)
9
+ <% for attribute in attributes -%>
10
+ @<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
11
+ <% end -%>
12
+ assigns[:<%= file_name %>] = @<%= file_name %>
13
+ end
14
+
15
+ it "should render new form" do
16
+ render "/<%= name.pluralize %>/new.<%= default_file_extension %>"
17
+
18
+ response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
19
+ <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
20
+ with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
21
+ <% end -%><% end -%>
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
2
+
3
+ describe "/<%= name.pluralize %>/show.<%= default_file_extension %>" do
4
+ include <%= controller_class_name %>Helper
5
+
6
+ before do
7
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
8
+ <% for attribute in attributes -%>
9
+ @<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
10
+ <% end -%>
11
+
12
+ assigns[:<%= file_name %>] = @<%= file_name %>
13
+ end
14
+
15
+ it "should render attributes in <p>" do
16
+ render "/<%= name.pluralize %>/show.<%= default_file_extension %>"
17
+ <% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
18
+ response.should have_text(/<%= Regexp.escape(attribute.default_value)[1..-2]%>/)
19
+ <% end -%><% end -%>
20
+ end
21
+ end
22
+
@@ -0,0 +1,10 @@
1
+ = error_messages_for :<%= singular_name %>
2
+
3
+ - form_for <%= form_link_for(table_name, singular_name) %> do |f|
4
+ <% for attribute in attributes -%>
5
+ %div.field
6
+ = f.label(:<%= attribute.name %>, st("<%= singular_name %>.field.<%= attribute.name %>.name"))
7
+ = f.<%= attribute.field_type %>(:<%= attribute.name %> )
8
+ <% end %>
9
+ %div.submit
10
+ = f.submit st("<%= singular_name %>.action.update.name")
@@ -0,0 +1,16 @@
1
+ %table
2
+ %tr
3
+ <% for attribute in attributes -%>
4
+ %th= st("<%= singular_name %>.field.<%=attribute.name%>.name")
5
+ <% end -%>
6
+
7
+ - for <%= singular_name %> in @<%= plural_name %>
8
+ %tr
9
+ <% for attribute in attributes -%>
10
+ %td= h(<%= singular_name %>.<%= attribute.name %>)
11
+ <% end -%>
12
+ %td= link_to(st("<%= singular_name %>.action.show.name"), <%= path_for(table_name, singular_name, "show").gsub(/@/, "")%>)
13
+ %td= link_to(st("<%= singular_name %>.action.update.name"), <%= path_for(table_name, singular_name, "edit").gsub(/@/, "")%>)
14
+ %td= link_to(st("<%= singular_name %>.action.destroy.name"), <%= path_for(table_name, singular_name, "show").gsub(/@/, "")%>, :confirm => st("<%= singular_name %>.action.destroy.sure"), :method => :delete, :title => "#{st('<%= singular_name %>.action.destroy.name')}")
15
+
16
+ = link_to(st("<%= singular_name %>.action.create.name"), new_<%= table_name.singularize %>_path)
@@ -0,0 +1,10 @@
1
+ = error_messages_for :<%= singular_name %>
2
+
3
+ - form_for <%= form_link_for(table_name, singular_name) %> do |f|
4
+ <% for attribute in attributes -%>
5
+ %div.field
6
+ = f.label(:<%= attribute.name %>, st("<%= singular_name %>.field.<%= attribute.name %>.name"))
7
+ = f.<%= attribute.field_type %>(:<%= attribute.name %> )
8
+ <% end %>
9
+ %div.submit
10
+ = f.submit st("<%= singular_name %>.action.create.name")
@@ -0,0 +1,5 @@
1
+ <% for attribute in attributes -%>
2
+ %p
3
+ %strong <%= attribute.column.human_name %>:
4
+ =h(@<%= singular_name %>.<%= attribute.name %>)
5
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AwesomeScaffoldTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'awesome_scaffold'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeffkreeftmeijer-awesome_scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Kreeftmeijer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jeff@kreeftmeijer.nl
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/awesome_scaffold_generator.rb
33
+ - lib/templates/controller.feature
34
+ - lib/templates/controller.rb
35
+ - lib/templates/controller_spec.rb
36
+ - lib/templates/edit_haml_spec.rb
37
+ - lib/templates/helper.rb
38
+ - lib/templates/helper_spec.rb
39
+ - lib/templates/index_haml_spec.rb
40
+ - lib/templates/migration.rb
41
+ - lib/templates/model.rb
42
+ - lib/templates/model_spec.rb
43
+ - lib/templates/new_haml_spec.rb
44
+ - lib/templates/show_haml_spec.rb
45
+ - lib/templates/view_edit_haml.erb
46
+ - lib/templates/view_index_haml.erb
47
+ - lib/templates/view_new_haml.erb
48
+ - lib/templates/view_show_haml.erb
49
+ - rails_generators/awesome_scaffold/aewesome_scaffold.rb
50
+ - test/awesome_scaffold_test.rb
51
+ - test/test_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/jeffkreeftmeijer/awesome_scaffold
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: A rails scaffold generator that uses RSpec, Cucumber and HAML
78
+ test_files:
79
+ - test/awesome_scaffold_test.rb
80
+ - test/test_helper.rb