chendo-rspec-haml-scaffold-generator 1.0.1

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.
@@ -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 Zach Inglis
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.
@@ -0,0 +1,20 @@
1
+ RSpec Haml Scaffold Generator
2
+ ====
3
+
4
+ This is an uber version of the RSpec Scaffold Generator, the following things have been added:
5
+
6
+ Support for Haml instead of erb
7
+ Nested routes (nested tests/migrations)
8
+
9
+ Installation:
10
+ sudo gem install zachinglis-rspec-haml-scaffold
11
+
12
+ Examples:
13
+
14
+ ./script/generate rspec_haml_scaffold post # no attributes, view will be anemic
15
+ ./script/generate rspec_haml_scaffold post attribute:string attribute:boolean # this is actually broken at the moment, don't do this !!! Feel free to patch it
16
+
17
+ Credits
18
+
19
+ * Daniel Fischer - http://danielfischer.com
20
+ * Zach Inglis - http://zachinglis.com
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rspec-haml-scaffold-generator"
8
+ gem.summary = "Generate RSpec/HAML scaffolds."
9
+ gem.email = "zach@lt3media.com"
10
+ gem.homepage = "http://github.com/zachinglis/rspec-haml-scaffold-generator"
11
+ gem.authors = ["Zach Inglis", "Daniel Fischer"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
16
+ end
17
+
18
+ require 'rake/testtask'
19
+ Rake::TestTask.new(:test) do |test|
20
+ test.libs << 'lib' << 'test'
21
+ test.pattern = 'test/**/*_test.rb'
22
+ test.verbose = true
23
+ end
24
+
25
+ begin
26
+ require 'rcov/rcovtask'
27
+ Rcov::RcovTask.new do |test|
28
+ test.libs << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+ rescue LoadError
33
+ task :rcov do
34
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
35
+ end
36
+ end
37
+
38
+
39
+ task :default => :test
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ if File.exist?('VERSION.yml')
44
+ config = YAML.load(File.read('VERSION.yml'))
45
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
46
+ else
47
+ version = ""
48
+ end
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "rspec-haml-scaffold-generator #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
55
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 1
@@ -0,0 +1 @@
1
+ ./script/generate rspec_haml_scaffold
@@ -0,0 +1,214 @@
1
+ class RspecHamlScaffoldGenerator < Rails::Generator::NamedBase
2
+ default_options :skip_migration => false
3
+
4
+ attr_reader :controller_name,
5
+ :controller_class_path,
6
+ :controller_file_path,
7
+ :controller_class_nesting,
8
+ :controller_class_nesting_depth,
9
+ :controller_class_name,
10
+ :controller_singular_name,
11
+ :controller_plural_name,
12
+ :resource_edit_path,
13
+ :default_file_extension
14
+ alias_method :controller_file_name, :controller_singular_name
15
+ alias_method :controller_table_name, :controller_plural_name
16
+
17
+ def initialize(runtime_args, runtime_options = {})
18
+ super
19
+
20
+ @controller_name = @name.pluralize
21
+
22
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
23
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
24
+
25
+ if @controller_class_nesting.empty?
26
+ @controller_class_name = @controller_class_name_without_nesting
27
+ else
28
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
29
+ end
30
+
31
+ @resource_generator = "rspec_haml_scaffold"
32
+ @default_file_extension = "html.haml"
33
+ @resource_edit_path = "/edit"
34
+
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
+ # Controller, helper, views, and spec directories.
56
+ m.directory(File.join('app/models'))
57
+ m.directory(File.join('app/controllers', controller_class_path))
58
+ m.directory(File.join('app/helpers', controller_class_path))
59
+ m.directory(File.join('app/views', controller_class_path, controller_file_name))
60
+ m.directory(File.join('spec/controllers', controller_class_path))
61
+ m.directory(File.join('spec/models'))
62
+ m.directory(File.join('spec/helpers', class_path))
63
+ m.directory File.join('spec/fixtures')
64
+ m.directory File.join('spec/views', controller_class_path, controller_file_name)
65
+
66
+ # Controller spec, class, and helper.
67
+ m.template 'rspec_haml_scaffold:controller_spec.rb',
68
+ File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
69
+
70
+ m.template "rspec_haml_scaffold:controller.rb",
71
+ File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
72
+
73
+ m.template 'rspec_haml_scaffold:helper_spec.rb',
74
+ File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
75
+
76
+ m.template "#{@resource_generator}:helper.rb",
77
+ File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")
78
+
79
+ for action in scaffold_views
80
+ m.template(
81
+ "rspec_haml_scaffold:view_#{action}_haml.erb",
82
+ File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
83
+ )
84
+ end
85
+
86
+ # Model class, unit test, and fixtures.
87
+ m.template 'rspec_haml_scaffold:model.rb', File.join('app/models', "#{@controller_singular_name.singularize}.rb")
88
+ m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{@controller_singular_name}.yml")
89
+ m.template 'rspec_haml_scaffold:model_spec.rb', File.join('spec/models', "#{@controller_singular_name.singularize}_spec.rb")
90
+
91
+ # View specs
92
+ m.template "rspec_haml_scaffold:edit_haml_spec.rb",
93
+ File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
94
+ m.template "rspec_haml_scaffold:index_haml_spec.rb",
95
+ File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
96
+ m.template "rspec_haml_scaffold:new_haml_spec.rb",
97
+ File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
98
+ m.template "rspec_haml_scaffold:show_haml_spec.rb",
99
+ File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
100
+
101
+ unless options[:skip_migration]
102
+ m.migration_template(
103
+ 'rspec_haml_scaffold:migration.rb', 'db/migrate',
104
+ :assigns => {
105
+ :migration_name => "Create#{singular_name.pluralize.capitalize}",
106
+ :attributes => attributes
107
+ },
108
+ :migration_file_name => "create_#{controller_singular_name.gsub(/\//, '_').pluralize}"
109
+ )
110
+ end
111
+
112
+ #m.route_resources controller_file_name
113
+ route_resources name
114
+
115
+ end
116
+ end
117
+
118
+ protected
119
+ def form_link_for(table_name, singular_name)
120
+ if !@controller_name.split("/")[1].nil?
121
+ return "[:#{@controller_class_nesting.downcase}, @#{singular_name.singularize}]"
122
+ else
123
+ return "@#{singular_name.singularize}"
124
+ end
125
+ end
126
+
127
+ def path_for(singular, plural, txt)
128
+ case txt
129
+ when "show"
130
+ return "#{table_name.singularize}_path(@#{singular_name.singularize})"
131
+ when "edit"
132
+ return "edit_#{table_name.singularize}_path(@#{singular_name.singularize})"
133
+ when "destroy"
134
+ return "#{table_name.singularize}_path(@#{singular_name.singularize}), :confirm => 'Are you sure?', :method => :delete"
135
+ when "index"
136
+ return "#{table_name}_path"
137
+ end
138
+ end
139
+
140
+ # Override with your own usage banner.
141
+ def banner
142
+ "Usage: #{$0} rspec_haml_scaffold ModelName [field:type field:type]"
143
+ end
144
+
145
+ def add_options!(opt)
146
+ opt.separator ''
147
+ opt.separator 'Options:'
148
+ opt.on("--skip-migration",
149
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
150
+ end
151
+
152
+ def scaffold_views
153
+ %w[ index show new edit ]
154
+ end
155
+
156
+ def model_name
157
+ class_name.demodulize
158
+ end
159
+
160
+ def route_resources(resource)
161
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
162
+ logger.route "map.resources #{resource}"
163
+ unless options[:pretend]
164
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
165
+
166
+ if !resource.split('/')[1].nil?
167
+ one = resource.split('/')[0]
168
+ two = resource.split('/')[1]
169
+ "#{match}\n map.namespace(:#{one}) do |#{one}|\n #{one}.resources :#{two.pluralize}\n end"
170
+ else
171
+ "#{match}\n map.resources :#{resource.pluralize}\n"
172
+ end
173
+
174
+ end
175
+ end
176
+ end
177
+
178
+
179
+ def gsub_file(relative_destination, regexp, *args, &block)
180
+ path = destination_path(relative_destination)
181
+ content = File.read(path).gsub(regexp, *args, &block)
182
+ File.open(path, 'wb') { |file| file.write(content) }
183
+ end
184
+
185
+ end
186
+
187
+ module Rails
188
+ module Generator
189
+ class GeneratedAttribute
190
+ def default_value
191
+ @default_value ||= case type
192
+ when :int, :integer then "\"1\""
193
+ when :float then "\"1.5\""
194
+ when :decimal then "\"9.99\""
195
+ when :datetime, :timestamp, :time then "Time.now"
196
+ when :date then "Date.today"
197
+ when :string then "\"MyString\""
198
+ when :text then "\"MyText\""
199
+ when :boolean then "false"
200
+ else
201
+ ""
202
+ end
203
+ end
204
+
205
+ def input_type
206
+ @input_type ||= case type
207
+ when :text then "textarea"
208
+ else
209
+ "input"
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,12 @@
1
+ RSpec Haml Scaffold Generator
2
+ ====
3
+
4
+ This is an uber version of the RSpec Scaffold Generator, the following things have been added:
5
+
6
+ Support for Haml instead of erb
7
+ Nested routes (nested tests/migrations)
8
+
9
+ Examples:
10
+
11
+ ./script generate rspec_haml_scaffold post # no attributes, view will be anemic
12
+ ./script generate rspec_haml_scaffold post attribute:string attribute:boolean # this is actually broken at the moment, don't do this !!! Feel free to patch it
@@ -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 %>.find(: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
+ # GET /<%= name %>/1/edit
36
+ def edit
37
+ @<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
38
+ end
39
+
40
+ # POST /<%= name %>
41
+ # POST /<%= name %>.xml
42
+ def create
43
+ @<%= file_name %> = <%= singular_name.capitalize %>.new(params[:<%= singular_name %>])
44
+
45
+ respond_to do |format|
46
+ if @<%= file_name %>.save
47
+ flash[:notice] = '<%= singular_name.capitalize %> was successfully created.'
48
+ format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
49
+ format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
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] = '<%= singular_name.capitalize %> was successfully updated.'
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,323 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
2
+
3
+ describe <%= controller_class_name %>Controller, "#route_for" do
4
+
5
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'index' } to /<%= name.pluralize %>" do
6
+ route_for(:controller => "<%= name.pluralize %>", :action => "index").should == "/<%= name.pluralize %>"
7
+ end
8
+
9
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'new' } to /<%= name.pluralize %>/new" do
10
+ route_for(:controller => "<%= name.pluralize %>", :action => "new").should == "/<%= name.pluralize %>/new"
11
+ end
12
+
13
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'show', :id => 1 } to /<%= name.pluralize %>/1" do
14
+ route_for(:controller => "<%= name.pluralize %>", :action => "show", :id => 1).should == "/<%= name.pluralize %>/1"
15
+ end
16
+
17
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'edit', :id => 1 } to /<%= name.pluralize %>/1<%= resource_edit_path %>" do
18
+ route_for(:controller => "<%= name.pluralize %>", :action => "edit", :id => 1).should == "/<%= name.pluralize %>/1<%= resource_edit_path %>"
19
+ end
20
+
21
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'update', :id => 1} to /<%= name.pluralize %>/1" do
22
+ route_for(:controller => "<%= name.pluralize %>", :action => "update", :id => 1).should == "/<%= name.pluralize %>/1"
23
+ end
24
+
25
+ it "should map { :controller => '<%= name.pluralize %>', :action => 'destroy', :id => 1} to /<%= name.pluralize %>/1" do
26
+ route_for(:controller => "<%= name.pluralize %>", :action => "destroy", :id => 1).should == "/<%= name.pluralize %>/1"
27
+ end
28
+
29
+ end
30
+
31
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>" do
32
+
33
+ before do
34
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
35
+ <%= singular_name.capitalize %>.stub!(:find).and_return([@<%= file_name %>])
36
+ end
37
+
38
+ def do_get
39
+ get :index
40
+ end
41
+
42
+ it "should be successful" do
43
+ do_get
44
+ response.should be_success
45
+ end
46
+
47
+ it "should render index template" do
48
+ do_get
49
+ response.should render_template('index')
50
+ end
51
+
52
+ it "should find all <%= name.pluralize %>" do
53
+ <%= singular_name.capitalize %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
54
+ do_get
55
+ end
56
+
57
+ it "should assign the found <%= name.pluralize %> for the view" do
58
+ do_get
59
+ assigns[:<%= singular_name.pluralize %>].should == [@<%= file_name %>]
60
+ end
61
+ end
62
+
63
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>.xml" do
64
+
65
+ before do
66
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_xml => "XML")
67
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
68
+ end
69
+
70
+ def do_get
71
+ @request.env["HTTP_ACCEPT"] = "application/xml"
72
+ get :index
73
+ end
74
+
75
+ it "should be successful" do
76
+ do_get
77
+ response.should be_success
78
+ end
79
+
80
+ it "should find all <%= name.pluralize %>" do
81
+ <%= singular_name.capitalize %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
82
+ do_get
83
+ end
84
+
85
+ it "should render the found <%= name %> as xml" do
86
+ @<%= file_name %>.should_receive(:to_xml).and_return("XML")
87
+ do_get
88
+ response.body.should == "XML"
89
+ end
90
+ end
91
+
92
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1" do
93
+
94
+ before do
95
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
96
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
97
+ end
98
+
99
+ def do_get
100
+ get :show, :id => "1"
101
+ end
102
+
103
+ it "should be successful" do
104
+ do_get
105
+ response.should be_success
106
+ end
107
+
108
+ it "should render show template" do
109
+ do_get
110
+ response.should render_template('show')
111
+ end
112
+
113
+ it "should find the <%= file_name %> requested" do
114
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
115
+ do_get
116
+ end
117
+
118
+ it "should assign the found <%= file_name %> for the view" do
119
+ do_get
120
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
121
+ end
122
+ end
123
+
124
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1.xml" do
125
+
126
+ before do
127
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_xml => "XML")
128
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
129
+ end
130
+
131
+ def do_get
132
+ @request.env["HTTP_ACCEPT"] = "application/xml"
133
+ get :show, :id => "1"
134
+ end
135
+
136
+ it "should be successful" do
137
+ do_get
138
+ response.should be_success
139
+ end
140
+
141
+ it "should find the <%= file_name %> requested" do
142
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
143
+ do_get
144
+ end
145
+
146
+ it "should render the found <%= file_name %> as xml" do
147
+ @<%= singular_name %>.should_receive(:to_xml).and_return("XML")
148
+ do_get
149
+ response.body.should == "XML"
150
+ end
151
+ end
152
+
153
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/new" do
154
+
155
+ before do
156
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
157
+ <%= singular_name.capitalize %>.stub!(:new).and_return(@<%= file_name %>)
158
+ end
159
+
160
+ def do_get
161
+ get :new
162
+ end
163
+
164
+ it "should be successful" do
165
+ do_get
166
+ response.should be_success
167
+ end
168
+
169
+ it "should render new template" do
170
+ do_get
171
+ response.should render_template('new')
172
+ end
173
+
174
+ it "should create an new <%= file_name %>" do
175
+ <%= singular_name.capitalize %>.should_receive(:new).and_return(@<%= file_name %>)
176
+ do_get
177
+ end
178
+
179
+ it "should not save the new <%= file_name %>" do
180
+ @<%= file_name %>.should_not_receive(:save)
181
+ do_get
182
+ end
183
+
184
+ it "should assign the new <%= file_name %> for the view" do
185
+ do_get
186
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
187
+ end
188
+ end
189
+
190
+ describe <%= controller_class_name %>Controller, "handling GET /<%= name.pluralize %>/1/edit" do
191
+
192
+ before do
193
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
194
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
195
+ end
196
+
197
+ def do_get
198
+ get :edit, :id => "1"
199
+ end
200
+
201
+ it "should be successful" do
202
+ do_get
203
+ response.should be_success
204
+ end
205
+
206
+ it "should render edit template" do
207
+ do_get
208
+ response.should render_template('edit')
209
+ end
210
+
211
+ it "should find the <%= file_name %> requested" do
212
+ <%= singular_name.capitalize %>.should_receive(:find).and_return(@<%= file_name %>)
213
+ do_get
214
+ end
215
+
216
+ it "should assign the found <%= file_name %> for the view" do
217
+ do_get
218
+ assigns[:<%= file_name %>].should equal(@<%= file_name %>)
219
+ end
220
+ end
221
+
222
+ describe <%= controller_class_name %>Controller, "handling POST /<%= name.pluralize %>" do
223
+
224
+ before do
225
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_param => "1")
226
+ <%= singular_name.capitalize %>.stub!(:new).and_return(@<%= file_name %>)
227
+ end
228
+
229
+ def post_with_successful_save
230
+ @<%= file_name %>.should_receive(:save).and_return(true)
231
+ post :create, :<%= file_name %> => {}
232
+ end
233
+
234
+ def post_with_failed_save
235
+ @<%= file_name %>.should_receive(:save).and_return(false)
236
+ post :create, :<%= file_name %> => {}
237
+ end
238
+
239
+ it "should create a new <%= file_name %>" do
240
+ <%= singular_name.capitalize %>.should_receive(:new).with({}).and_return(@<%= file_name %>)
241
+ post_with_successful_save
242
+ end
243
+
244
+ it "should redirect to the new <%= file_name %> on successful save" do
245
+ post_with_successful_save
246
+ response.should redirect_to(<%= table_name.singularize %>_url("1"))
247
+ end
248
+
249
+ it "should re-render 'new' on failed save" do
250
+ post_with_failed_save
251
+ response.should render_template('new')
252
+ end
253
+ end
254
+
255
+ describe <%= controller_class_name %>Controller, "handling PUT /<%= name.pluralize %>/1" do
256
+
257
+ before do
258
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :to_param => "1")
259
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
260
+ end
261
+
262
+ def put_with_successful_update
263
+ @<%= file_name %>.should_receive(:update_attributes).and_return(true)
264
+ put :update, :id => "1"
265
+ end
266
+
267
+ def put_with_failed_update
268
+ @<%= file_name %>.should_receive(:update_attributes).and_return(false)
269
+ put :update, :id => "1"
270
+ end
271
+
272
+ it "should find the <%= file_name %> requested" do
273
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
274
+ put_with_successful_update
275
+ end
276
+
277
+ it "should update the found <%= file_name %>" do
278
+ put_with_successful_update
279
+ assigns(:<%= file_name %>).should equal(@<%= file_name %>)
280
+ end
281
+
282
+ it "should assign the found <%= file_name %> for the view" do
283
+ put_with_successful_update
284
+ assigns(:<%= file_name %>).should equal(@<%= file_name %>)
285
+ end
286
+
287
+ it "should redirect to the <%= file_name %> on successful update" do
288
+ put_with_successful_update
289
+ response.should redirect_to(<%= table_name.singularize %>_url("1"))
290
+ end
291
+
292
+ it "should re-render 'edit' on failed update" do
293
+ put_with_failed_update
294
+ response.should render_template('edit')
295
+ end
296
+ end
297
+
298
+ describe <%= controller_class_name %>Controller, "handling DELETE /<%= name %>/1" do
299
+
300
+ before do
301
+ @<%= file_name %> = mock_model(<%= singular_name.capitalize %>, :destroy => true)
302
+ <%= singular_name.capitalize %>.stub!(:find).and_return(@<%= file_name %>)
303
+ end
304
+
305
+ def do_delete
306
+ delete :destroy, :id => "1"
307
+ end
308
+
309
+ it "should find the <%= file_name %> requested" do
310
+ <%= singular_name.capitalize %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
311
+ do_delete
312
+ end
313
+
314
+ it "should call destroy on the found <%= file_name %>" do
315
+ @<%= file_name %>.should_receive(:destroy)
316
+ do_delete
317
+ end
318
+
319
+ it "should redirect to the <%= name.pluralize %> list" do
320
+ do_delete
321
+ response.should redirect_to(<%= table_name.pluralize %>_url)
322
+ end
323
+ 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,4 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
2
+
3
+ describe <%= controller_class_name %>Helper do # Helper methods can be called directly in the examples (it blocks)
4
+ 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,15 @@
1
+ %h1 Editing <%= singular_name %>
2
+
3
+ = error_messages_for :<%= singular_name %>
4
+
5
+ - form_for(<%= form_link_for(table_name, singular_name) %>) do |f|
6
+ <% for attribute in attributes -%>
7
+ %p
8
+ %b <%= attribute.column.human_name %>
9
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
10
+ <% end %>
11
+ %p= f.submit "Update"
12
+
13
+ = link_to 'Show', <%= path_for(table_name, singular_name, "show") %>
14
+ = link_to 'Back', <%= path_for(table_name, singular_name, "index") %>
15
+
@@ -0,0 +1,18 @@
1
+ %h1 Listing <%= plural_name %>
2
+
3
+ %table
4
+ %tr
5
+ <% for attribute in attributes -%>
6
+ %th <%=attribute.column.human_name%>
7
+ <% end -%>
8
+
9
+ - for <%= singular_name %> in @<%= plural_name %>
10
+ %tr
11
+ <% for attribute in attributes -%>
12
+ %td=h <%= singular_name %>.<%= attribute.name %>
13
+ <% end %>
14
+ %td= link_to 'Show', <%= path_for(table_name, singular_name, "show").gsub(/@/, "") %>
15
+ %td= link_to 'Edit', <%= path_for(table_name, singular_name, "edit").gsub(/@/, "") %>
16
+ %td= link_to 'Destroy', <%= path_for(table_name, singular_name, "destroy").gsub(/@/, "") %>, :confirm => "Are you sure?", :method => :delete
17
+
18
+ = link_to 'New <%= singular_name.singularize %>', new_<%= table_name.singularize %>_path
@@ -0,0 +1,15 @@
1
+ %h1 New <%= singular_name %>
2
+
3
+ = error_messages_for :<%= singular_name %>
4
+
5
+ - form_for(<%= form_link_for(table_name, singular_name) %>) do |f|
6
+ <% for attribute in attributes -%>
7
+ %p
8
+ %b <%= attribute.column.human_name %>
9
+ %br
10
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
11
+ <% end %>
12
+ %p
13
+ = f.submit "Create"
14
+
15
+ = link_to 'Back', <%= path_for(table_name, singular_name, "index") %>
@@ -0,0 +1,9 @@
1
+ <% for attribute in attributes -%>
2
+ %p
3
+ %b <%= attribute.column.human_name %>:
4
+ =h @<%= singular_name %>.<%= attribute.name %>
5
+
6
+ <% end -%>
7
+
8
+ = link_to 'Edit', <%= path_for(table_name, singular_name, "edit") %>
9
+ = link_to 'Back', <%= path_for(table_name, singular_name, "index") %>
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README'))
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rspec-haml-scaffold-generator}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Zach Inglis", "Daniel Fischer"]
12
+ s.date = %q{2009-09-22}
13
+ s.email = %q{zach@lt3media.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION.yml",
24
+ "generators/.DS_Store",
25
+ "generators/USAGE",
26
+ "generators/rspec_haml_scaffold/.DS_Store",
27
+ "generators/rspec_haml_scaffold/rspec_haml_scaffold_generator.rb",
28
+ "generators/rspec_haml_scaffold/templates/INSTALL",
29
+ "generators/rspec_haml_scaffold/templates/controller.rb",
30
+ "generators/rspec_haml_scaffold/templates/controller_spec.rb",
31
+ "generators/rspec_haml_scaffold/templates/edit_haml_spec.rb",
32
+ "generators/rspec_haml_scaffold/templates/helper.rb",
33
+ "generators/rspec_haml_scaffold/templates/helper_spec.rb",
34
+ "generators/rspec_haml_scaffold/templates/index_haml_spec.rb",
35
+ "generators/rspec_haml_scaffold/templates/migration.rb",
36
+ "generators/rspec_haml_scaffold/templates/model.rb",
37
+ "generators/rspec_haml_scaffold/templates/model_spec.rb",
38
+ "generators/rspec_haml_scaffold/templates/new_haml_spec.rb",
39
+ "generators/rspec_haml_scaffold/templates/show_haml_spec.rb",
40
+ "generators/rspec_haml_scaffold/templates/view_edit_haml.erb",
41
+ "generators/rspec_haml_scaffold/templates/view_index_haml.erb",
42
+ "generators/rspec_haml_scaffold/templates/view_new_haml.erb",
43
+ "generators/rspec_haml_scaffold/templates/view_show_haml.erb",
44
+ "install.rb",
45
+ "rspec-haml-scaffold-generator.gemspec",
46
+ "rspec_haml_scaffold_generator_test.rb"
47
+ ]
48
+ s.homepage = %q{http://github.com/zachinglis/rspec-haml-scaffold-generator}
49
+ s.rdoc_options = ["--charset=UTF-8"]
50
+ s.require_paths = ["lib"]
51
+ s.rubygems_version = %q{1.3.4}
52
+ s.summary = %q{Generate RSpec/HAML scaffolds.}
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ else
60
+ end
61
+ else
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class RspecHamlScaffoldGeneratorTest < 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
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chendo-rspec-haml-scaffold-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zach Inglis
8
+ - Daniel Fischer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-09-22 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: zach@lt3media.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README.rdoc
26
+ files:
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION.yml
32
+ - generators/.DS_Store
33
+ - generators/USAGE
34
+ - generators/rspec_haml_scaffold/.DS_Store
35
+ - generators/rspec_haml_scaffold/rspec_haml_scaffold_generator.rb
36
+ - generators/rspec_haml_scaffold/templates/INSTALL
37
+ - generators/rspec_haml_scaffold/templates/controller.rb
38
+ - generators/rspec_haml_scaffold/templates/controller_spec.rb
39
+ - generators/rspec_haml_scaffold/templates/edit_haml_spec.rb
40
+ - generators/rspec_haml_scaffold/templates/helper.rb
41
+ - generators/rspec_haml_scaffold/templates/helper_spec.rb
42
+ - generators/rspec_haml_scaffold/templates/index_haml_spec.rb
43
+ - generators/rspec_haml_scaffold/templates/migration.rb
44
+ - generators/rspec_haml_scaffold/templates/model.rb
45
+ - generators/rspec_haml_scaffold/templates/model_spec.rb
46
+ - generators/rspec_haml_scaffold/templates/new_haml_spec.rb
47
+ - generators/rspec_haml_scaffold/templates/show_haml_spec.rb
48
+ - generators/rspec_haml_scaffold/templates/view_edit_haml.erb
49
+ - generators/rspec_haml_scaffold/templates/view_index_haml.erb
50
+ - generators/rspec_haml_scaffold/templates/view_new_haml.erb
51
+ - generators/rspec_haml_scaffold/templates/view_show_haml.erb
52
+ - install.rb
53
+ - rspec-haml-scaffold-generator.gemspec
54
+ - rspec_haml_scaffold_generator_test.rb
55
+ has_rdoc: false
56
+ homepage: http://github.com/zachinglis/rspec-haml-scaffold-generator
57
+ licenses:
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Generate RSpec/HAML scaffolds.
82
+ test_files: []
83
+