shoulda_machinist_generator 0.3.4 → 0.4.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/Rakefile +1 -0
- data/VERSION +1 -1
- data/rails_generators/shoulda_machinist_admin_scaffold/shoulda_machinist_admin_scaffold_generator.rb +251 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/controller.rb +85 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/functional_test.rb +108 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/helper.rb +2 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/layout.html.erb +17 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view__form.html.erb +6 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_edit.html.erb +14 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_index.html.erb +29 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_new.html.erb +13 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_show.html.erb +13 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/controller.rb +24 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/functional_test.rb +31 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/helper.rb +2 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/init.rb +4 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/layout.html.erb +17 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/routes.rb +0 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/test_helper.rb +24 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/view_index.html.erb +19 -0
- data/rails_generators/shoulda_machinist_admin_scaffold/templates/view_show.html.erb +9 -0
- data/rails_generators/shoulda_machinist_model/templates/unit_test.rb +1 -0
- metadata +47 -16
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/rails_generators/shoulda_machinist_admin_scaffold/shoulda_machinist_admin_scaffold_generator.rb
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
#--
|
2
|
+
# ShouldaMachinistScaffoldGeneratorConfig based on rubygems code.
|
3
|
+
# Thank you Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
4
|
+
#++
|
5
|
+
class ShouldaMachinistAdminScaffoldGeneratorConfig
|
6
|
+
|
7
|
+
DEFAULT_TEMPLATING = 'erb'
|
8
|
+
DEFAULT_FUNCTIONAL_TEST_STYLE = 'basic'
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@config = load_file(config_file)
|
12
|
+
|
13
|
+
@templating = @config[:templating] || DEFAULT_TEMPLATING
|
14
|
+
@functional_test_style = @config[:functional_test_style] || DEFAULT_FUNCTIONAL_TEST_STYLE
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :templating, :functional_test_style
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def load_file(filename)
|
22
|
+
begin
|
23
|
+
YAML.load(File.read(filename)) if filename and File.exist?(filename)
|
24
|
+
rescue ArgumentError
|
25
|
+
warn "Failed to load #{config_file_name}"
|
26
|
+
rescue Errno::EACCES
|
27
|
+
warn "Failed to load #{config_file_name} due to permissions problem."
|
28
|
+
end or {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def config_file
|
32
|
+
File.join(find_home, '.shoulda_generator')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Finds the user's home directory.
|
37
|
+
|
38
|
+
def find_home
|
39
|
+
['HOME', 'USERPROFILE'].each do |homekey|
|
40
|
+
return ENV[homekey] if ENV[homekey]
|
41
|
+
end
|
42
|
+
|
43
|
+
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
|
44
|
+
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
|
45
|
+
end
|
46
|
+
|
47
|
+
begin
|
48
|
+
File.expand_path("~")
|
49
|
+
rescue
|
50
|
+
if File::ALT_SEPARATOR then
|
51
|
+
"C:/"
|
52
|
+
else
|
53
|
+
"/"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class ShouldaMachinistAdminScaffoldGenerator < Rails::Generator::NamedBase
|
60
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_layout => true
|
61
|
+
|
62
|
+
attr_reader :controller_name,
|
63
|
+
:controller_class_path,
|
64
|
+
:controller_file_path,
|
65
|
+
:controller_class_nesting,
|
66
|
+
:controller_class_nesting_depth,
|
67
|
+
:controller_class_name,
|
68
|
+
:controller_underscore_name,
|
69
|
+
:controller_singular_name,
|
70
|
+
:controller_plural_name
|
71
|
+
alias_method :controller_file_name, :controller_underscore_name
|
72
|
+
alias_method :controller_table_name, :controller_plural_name
|
73
|
+
|
74
|
+
def initialize(runtime_args, runtime_options = {})
|
75
|
+
super
|
76
|
+
|
77
|
+
@configuration = ShouldaMachinistAdminScaffoldGeneratorConfig.new
|
78
|
+
|
79
|
+
@controller_name = @name.pluralize
|
80
|
+
|
81
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
82
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
83
|
+
@controller_singular_name=base_name.singularize
|
84
|
+
if @controller_class_nesting.empty?
|
85
|
+
@controller_class_name = @controller_class_name_without_nesting
|
86
|
+
else
|
87
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def manifest
|
92
|
+
record do |m|
|
93
|
+
# Check for class naming collisions.
|
94
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
95
|
+
m.class_collisions(class_path, "#{class_name}")
|
96
|
+
|
97
|
+
# Controller, helper, views, test and stylesheets directories.
|
98
|
+
#
|
99
|
+
# Common directories:
|
100
|
+
#
|
101
|
+
m.directory(File.join('app/models', class_path))
|
102
|
+
m.directory(File.join('test/unit', class_path))
|
103
|
+
#
|
104
|
+
# Admin directories:
|
105
|
+
#
|
106
|
+
m.directory(File.join('app/controllers/admin', controller_class_path))
|
107
|
+
m.directory(File.join('app/helpers/admin', controller_class_path))
|
108
|
+
m.directory(File.join('app/views/admin', controller_class_path, controller_file_name))
|
109
|
+
m.directory(File.join('app/views/layouts/admin', controller_class_path))
|
110
|
+
m.directory(File.join('test/functional/admin', controller_class_path))
|
111
|
+
#
|
112
|
+
# Public directories:
|
113
|
+
#
|
114
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
115
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
116
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
117
|
+
m.directory(File.join('app/views/layouts', controller_class_path))
|
118
|
+
m.directory(File.join('test/functional', controller_class_path))
|
119
|
+
|
120
|
+
for action in scaffold_views
|
121
|
+
m.template(
|
122
|
+
"view_#{action}.html.erb",
|
123
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
for action in scaffold_admin_views
|
128
|
+
m.template(
|
129
|
+
"admin/view_#{action}.html.erb",
|
130
|
+
File.join('app/views/admin', controller_class_path, controller_file_name, "#{action}.html.erb")
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Layout and stylesheet for public site.
|
135
|
+
m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
|
136
|
+
|
137
|
+
|
138
|
+
# Layout and stylesheet for admin site.
|
139
|
+
m.template('admin/layout.html.erb', File.join('app/views/layouts/admin', controller_class_path, "#{controller_file_name}.html.erb"))
|
140
|
+
|
141
|
+
|
142
|
+
# Controller for public site
|
143
|
+
m.template(
|
144
|
+
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
145
|
+
)
|
146
|
+
|
147
|
+
# Controller for admin
|
148
|
+
m.template(
|
149
|
+
'admin/controller.rb', File.join('app/controllers/admin',
|
150
|
+
controller_class_path, "#{controller_file_name}_controller.rb")
|
151
|
+
)
|
152
|
+
|
153
|
+
# Tests and helpers for public site
|
154
|
+
m.template('functional_test.rb', File.join('test/functional',
|
155
|
+
controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
156
|
+
|
157
|
+
m.template('helper.rb', File.join('app/helpers',
|
158
|
+
controller_class_path, "#{controller_file_name}_helper.rb"))
|
159
|
+
|
160
|
+
# Tests and helpers for admin
|
161
|
+
m.template('admin/functional_test.rb',
|
162
|
+
File.join('test/functional/admin', controller_class_path,
|
163
|
+
"#{controller_file_name}_controller_test.rb"))
|
164
|
+
|
165
|
+
m.template('admin/helper.rb', File.join('app/helpers/admin',
|
166
|
+
controller_class_path, "#{controller_file_name}_helper.rb"))
|
167
|
+
|
168
|
+
m.route_resources controller_file_name
|
169
|
+
m.route_admin_resources controller_file_name
|
170
|
+
|
171
|
+
m.dependency 'shoulda_model', [name] + @args, :collision => :skip
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
protected
|
176
|
+
# Override with your own usage banner.
|
177
|
+
def banner
|
178
|
+
"Usage: #{$0} shoulda_machinist_admin_scaffold ModelName [field:type, field:type]"
|
179
|
+
end
|
180
|
+
|
181
|
+
def add_options!(opt)
|
182
|
+
opt.separator ''
|
183
|
+
opt.separator 'Options:'
|
184
|
+
opt.on("--skip-timestamps",
|
185
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
186
|
+
opt.on("--skip-migration",
|
187
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
def scaffold_admin_views
|
192
|
+
%w[ index show new edit _form ]
|
193
|
+
end
|
194
|
+
|
195
|
+
def scaffold_views
|
196
|
+
%w[ index show ]
|
197
|
+
end
|
198
|
+
|
199
|
+
def model_name
|
200
|
+
class_name.demodulize
|
201
|
+
end
|
202
|
+
|
203
|
+
# This inserts the routing declarations into the engine's routes file.
|
204
|
+
# Copied from Rails::Generator::Commands and modified to make it do what we want.
|
205
|
+
#
|
206
|
+
def route_admin_resources(*resources)
|
207
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
208
|
+
|
209
|
+
# Add the map.namespace(:admin) macro into the routes file unless it's already there.
|
210
|
+
#
|
211
|
+
unless exists_in_file? 'config/routes.rb', /#{Regexp.escape("map.namespace(:admin) do |admin|")}/mi
|
212
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
213
|
+
logger.route "inserting map.namespace(:admin)"
|
214
|
+
unless options[:pretend]
|
215
|
+
gsub_file File.join('config/routes.rb'), /(#{Regexp.escape(sentinel)})/mi do |match|
|
216
|
+
"#{match}\n map.namespace(:admin) do |admin|\n end\n\n # Minuet routes go here\n"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
# Add the map.namespace resources macro into the admin namespace
|
223
|
+
# in the routes file.
|
224
|
+
#
|
225
|
+
sentinel = 'map.namespace(:admin) do |admin|'
|
226
|
+
logger.route "map.namespace resources #{resource_list}"
|
227
|
+
unless options[:pretend]
|
228
|
+
gsub_file File.join('config/routes.rb'), /(#{Regexp.escape(sentinel)})/mi do |match|
|
229
|
+
"#{match}\n admin.resources #{resource_list}"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
# It's quite crude to copy and paste this in here, but it's working for the moment. It actually comes
|
236
|
+
# from Rails::Generator::Commands. This should be fixed.
|
237
|
+
#
|
238
|
+
def gsub_file(relative_destination, regexp, *args, &block)
|
239
|
+
path = destination_path(relative_destination)
|
240
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
241
|
+
File.open(path, File::RDWR|File::CREAT) { |file| file.write(content) }
|
242
|
+
end
|
243
|
+
|
244
|
+
def exists_in_file?(relative_destination, regexp)
|
245
|
+
path = destination_path(relative_destination)
|
246
|
+
content = File.read(path)
|
247
|
+
!regexp.match(content).nil?
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class Admin::<%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= table_name %>
|
3
|
+
# GET /<%= table_name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= table_name %> = <%= class_name %>.find(:all)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= table_name %>/1
|
14
|
+
# GET /<%= table_name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @<%= file_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= table_name %>/new
|
25
|
+
# GET /<%= table_name %>/new.xml
|
26
|
+
def new
|
27
|
+
@<%= file_name %> = <%= class_name %>.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @<%= file_name %> }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /<%= table_name %>/1/edit
|
36
|
+
def edit
|
37
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /<%= table_name %>
|
41
|
+
# POST /<%= table_name %>.xml
|
42
|
+
def create
|
43
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @<%= file_name %>.save
|
47
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
48
|
+
format.html { redirect_to(admin_<%= singular_name %>_url(@<%= singular_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 /<%= table_name %>/1
|
58
|
+
# PUT /<%= table_name %>/1.xml
|
59
|
+
def update
|
60
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
65
|
+
format.html { redirect_to(admin_<%= singular_name %>_url(@<%= singular_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 /<%= table_name %>/1
|
75
|
+
# DELETE /<%= table_name %>/1.xml
|
76
|
+
def destroy
|
77
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
78
|
+
@<%= file_name %>.destroy
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
format.html { redirect_to(admin_<%= table_name %>_url) }
|
82
|
+
format.xml { head :ok }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class Admin::<%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
context "The Admin::<%= controller_class_name %>Controller" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@<%= file_name %> = <%= class_name %>.make
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'GET to index' do
|
12
|
+
setup do
|
13
|
+
get :index
|
14
|
+
end
|
15
|
+
should_respond_with :success
|
16
|
+
should_assign_to :<%= table_name %>
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'GET to new' do
|
20
|
+
setup do
|
21
|
+
get :new
|
22
|
+
end
|
23
|
+
|
24
|
+
should_respond_with :success
|
25
|
+
should_render_template :new
|
26
|
+
should_assign_to :<%= file_name %>
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'POST to create' do
|
30
|
+
context "with valid parameters" do
|
31
|
+
setup do
|
32
|
+
assert_difference('<%= class_name %>.count') do
|
33
|
+
post :create, :<%= file_name %> => { }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should_redirect_to("the show page") { admin_<%= file_name %>_path(assigns(:<%= file_name %>))}
|
38
|
+
should_assign_to :<%= file_name %>
|
39
|
+
end
|
40
|
+
|
41
|
+
# context "with invalid parameters" do
|
42
|
+
# setup do
|
43
|
+
# assert_no_difference('<%= class_name %>.count') do
|
44
|
+
# post :create, :<%= file_name %> => {}
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
# should_respond_with :success
|
49
|
+
# should_render_template :new
|
50
|
+
# should_assign_to :<%= file_name %>
|
51
|
+
# end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'GET to show' do
|
55
|
+
setup do
|
56
|
+
get :show, :id => @<%= file_name %>.to_param
|
57
|
+
end
|
58
|
+
should_respond_with :success
|
59
|
+
should_render_template :show
|
60
|
+
should_assign_to :<%= file_name %>
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'GET to edit' do
|
64
|
+
setup do
|
65
|
+
get :edit, :id => @<%= file_name %>.to_param
|
66
|
+
end
|
67
|
+
should_respond_with :success
|
68
|
+
should_render_template :edit
|
69
|
+
should_assign_to :<%= file_name %>
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'PUT to update' do
|
73
|
+
context "with valid parameters" do
|
74
|
+
setup do
|
75
|
+
assert_no_difference("<%= class_name %>.count") do
|
76
|
+
put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => {}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
should_redirect_to("the show page") { admin_<%= file_name %>_path(assigns(:<%= file_name %>))}
|
81
|
+
should_assign_to :<%= file_name %>
|
82
|
+
end
|
83
|
+
|
84
|
+
# context "with invalid parameters" do
|
85
|
+
# setup do
|
86
|
+
# assert_no_difference("<%= class_name %>.count") do
|
87
|
+
# put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => { }
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
|
91
|
+
# should_respond_with :success
|
92
|
+
# should_render_template :edit
|
93
|
+
# should_assign_to :<%= file_name %>
|
94
|
+
# end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'DELETE to destroy' do
|
98
|
+
setup do
|
99
|
+
assert_difference('<%= class_name %>.count', -1) do
|
100
|
+
delete :destroy, :id => @<%= file_name %>.to_param
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
should_redirect_to ("the index page") { admin_<%= table_name %>_path }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
8
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%% @page_title = "Edit <%= singular_name.humanize.downcase %>" %>
|
2
|
+
<h2>Edit <%= singular_name.humanize.downcase %> - <%%= link_to 'Show <%= singular_name.humanize.downcase %>', admin_<%= singular_name %>_path(@<%= singular_name %>) %></h2>
|
3
|
+
|
4
|
+
<%% form_for(:<%= singular_name %>, :url => admin_<%= singular_name %>_path(@<%= singular_name %>), :html => { :method => :put }) do |f| %>
|
5
|
+
<%%= f.error_messages %>
|
6
|
+
|
7
|
+
<p>Please complete all fields marked <span class="required">*</span></p>
|
8
|
+
|
9
|
+
<%%= render :partial => 'form', :locals => {:f => f} %>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%%= f.submit "Update <%= singular_name.humanize.downcase %>", :class => "create" %>
|
13
|
+
</p>
|
14
|
+
<%% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%% @page_title = "Manage <%= plural_name.humanize %>" %>
|
2
|
+
<h2>Manage <%= plural_name.humanize %> - <%%= link_to 'Create <%= singular_name.humanize %>', new_admin_<%= singular_name %>_path %></h2>
|
3
|
+
<!-- <p class="create-button"><%%= link_to '<span class="left"></span><span class="middle">Create CV</span><span class="right"></span>', new_admin_<%= singular_name %>_path %></p> -->
|
4
|
+
|
5
|
+
<table class="grid" cellpadding="0" cellspacing="0">
|
6
|
+
<tr>
|
7
|
+
<% for attribute in attributes -%>
|
8
|
+
<th><%= attribute.column.human_name %></th>
|
9
|
+
<% end -%>
|
10
|
+
<th>Created on</th>
|
11
|
+
<th>Update on</th>
|
12
|
+
<th> </th>
|
13
|
+
<th> </th>
|
14
|
+
<th> </th>
|
15
|
+
</tr>
|
16
|
+
|
17
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
18
|
+
<tr class="<%%= cycle("row", "alt-row") %>">
|
19
|
+
<% for attribute in attributes -%>
|
20
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
21
|
+
<% end -%>
|
22
|
+
<td><%%=h long_date_with_time(<%= singular_name %>.created_at) %></td>
|
23
|
+
<td><%%=h long_date_with_time(<%= singular_name %>.updated_at) %></td>
|
24
|
+
<td class="show"><%%= link_to 'View', admin_<%= singular_name %>_path(<%= singular_name %>), :title => "View <%= singular_name %>" %></td>
|
25
|
+
<td class="edit"><%%= link_to 'Edit', edit_admin_<%= singular_name %>_path(<%= singular_name %>), :title => "Edit <%= singular_name %>" %></td>
|
26
|
+
<td class="delete"><%%= link_to 'Delete', admin_<%= singular_name %>_path(<%= singular_name %>), :title => "Delete <%= singular_name %>", :confirm => 'Are you sure you want to delete this <%= singular_name %>?', :method => :delete %></td>
|
27
|
+
</tr>
|
28
|
+
<%% end %>
|
29
|
+
</table>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%% @page_title = "Create <%= singular_name.humanize.downcase %>" %>
|
2
|
+
<h2>Create <%= singular_name.humanize.downcase %></h2>
|
3
|
+
|
4
|
+
<%% form_for(:<%= singular_name %>, :url => admin_<%= plural_name %>_path) do |f| %>
|
5
|
+
<%%= f.error_messages %>
|
6
|
+
|
7
|
+
<p>Please complete all fields marked <span class="required">*</span></p>
|
8
|
+
|
9
|
+
<%%= render :partial => 'form', :locals => {:f => f} %>
|
10
|
+
<p>
|
11
|
+
<%%= f.submit "Create <%= singular_name.humanize.downcase%>", :class => "create" %>
|
12
|
+
</p>
|
13
|
+
<%% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%% @page_title = "Show <%= singular_name.humanize.downcase %>" %>
|
2
|
+
<h2>Show <%= singular_name %> - <%%= link_to 'Edit <%= singular_name.humanize.downcase %>', edit_admin_<%= singular_name %>_path(@<%= singular_name %>) %></h2>
|
3
|
+
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
<p>
|
6
|
+
<strong><%= attribute.column.human_name %>:</strong>
|
7
|
+
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
8
|
+
</p>
|
9
|
+
<% end -%>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<%%= link_to 'Back to <%= plural_name %>', admin_<%= plural_name %>_url %>
|
13
|
+
</p>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= table_name %>
|
3
|
+
# GET /<%= table_name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= table_name %> = <%= class_name %>.find(:all)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @<%= table_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= table_name %>/1
|
14
|
+
# GET /<%= table_name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @<%= file_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
context "The <%= controller_class_name %>Controller" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@<%= file_name %> = <%= class_name %>.make
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'GET to index' do
|
12
|
+
setup do
|
13
|
+
get :index
|
14
|
+
end
|
15
|
+
should_respond_with :success
|
16
|
+
should_assign_to :<%= table_name %>
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
context 'GET to show' do
|
21
|
+
setup do
|
22
|
+
get :show, :id => @<%= file_name %>.to_param
|
23
|
+
end
|
24
|
+
should_respond_with :success
|
25
|
+
should_render_template :show
|
26
|
+
should_assign_to :<%= file_name %>
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
|
8
|
+
<%%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<p style="color: green"><%%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%%= yield %>
|
15
|
+
|
16
|
+
</body>
|
17
|
+
</html>
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Load the normal Rails helper. This ensures the environment is loaded.
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
|
3
|
+
|
4
|
+
# Load the schema - if migrations have been performed, this will be up to date.
|
5
|
+
#load(File.dirname(__FILE__) + "/../db/schema.rb")
|
6
|
+
#Rake::Task['db:test:prepare']
|
7
|
+
|
8
|
+
# Set up the fixtures location manually, we don't want to move them to a
|
9
|
+
# temporary path using Engines::Testing.set_fixture_path.
|
10
|
+
Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
11
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
|
12
|
+
|
13
|
+
# The only drawback to using transactional fixtures is when you actually
|
14
|
+
# need to test transactions. Since your test is bracketed by a transaction,
|
15
|
+
# any transactions started in your code will be automatically rolled back.
|
16
|
+
Test::Unit::TestCase.use_transactional_fixtures = false
|
17
|
+
|
18
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
19
|
+
# would need people(:david). If you don't want to migrate your existing
|
20
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
21
|
+
# instantiated fixtures translates to a database query per test method),
|
22
|
+
# then set this back to true.
|
23
|
+
Test::Unit::TestCase.use_instantiated_fixtures = false
|
24
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h1>Listing <%= plural_name.humanize.downcase %></h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<th><%= attribute.column.human_name %></th>
|
7
|
+
<% end -%>
|
8
|
+
<th> </th>
|
9
|
+
</tr>
|
10
|
+
|
11
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
12
|
+
<tr>
|
13
|
+
<% for attribute in attributes -%>
|
14
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
15
|
+
<% end -%>
|
16
|
+
<td><%%= link_to 'Show <%= singular_name.humanize.downcase %>', <%= singular_name %>_url(<%= singular_name %>) %></td>
|
17
|
+
</tr>
|
18
|
+
<%% end %>
|
19
|
+
</table>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Show <%= singular_name.humanize.downcase %></h1>
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
<p>
|
4
|
+
<strong><%= attribute.column.human_name %>:</strong>
|
5
|
+
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
6
|
+
</p>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
<p><%%= link_to 'Back to <%= plural_name.humanize.downcase %>', <%= plural_name %>_url %></p>
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda_machinist_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Dave Hrycyszyn
|
@@ -10,7 +16,7 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
19
|
+
date: 2011-02-24 00:00:00 +00:00
|
14
20
|
default_executable:
|
15
21
|
dependencies: []
|
16
22
|
|
@@ -28,6 +34,25 @@ files:
|
|
28
34
|
- README.rdoc
|
29
35
|
- Rakefile
|
30
36
|
- VERSION
|
37
|
+
- rails_generators/shoulda_machinist_admin_scaffold/shoulda_machinist_admin_scaffold_generator.rb
|
38
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/controller.rb
|
39
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/functional_test.rb
|
40
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/helper.rb
|
41
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/layout.html.erb
|
42
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view__form.html.erb
|
43
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_edit.html.erb
|
44
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_index.html.erb
|
45
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_new.html.erb
|
46
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/admin/view_show.html.erb
|
47
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/controller.rb
|
48
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/functional_test.rb
|
49
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/helper.rb
|
50
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/init.rb
|
51
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/layout.html.erb
|
52
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/routes.rb
|
53
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/test_helper.rb
|
54
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/view_index.html.erb
|
55
|
+
- rails_generators/shoulda_machinist_admin_scaffold/templates/view_show.html.erb
|
31
56
|
- rails_generators/shoulda_machinist_model/USAGE
|
32
57
|
- rails_generators/shoulda_machinist_model/shoulda_machinist_model_generator.rb
|
33
58
|
- rails_generators/shoulda_machinist_model/templates/blueprints.rb
|
@@ -75,46 +100,52 @@ homepage: http://github.com/futurechimp/shoulda_machinist_generator
|
|
75
100
|
licenses: []
|
76
101
|
|
77
102
|
post_install_message:
|
78
|
-
rdoc_options:
|
79
|
-
|
103
|
+
rdoc_options: []
|
104
|
+
|
80
105
|
require_paths:
|
81
106
|
- lib
|
82
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
83
109
|
requirements:
|
84
110
|
- - ">="
|
85
111
|
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
86
115
|
version: "0"
|
87
|
-
version:
|
88
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
89
118
|
requirements:
|
90
119
|
- - ">="
|
91
120
|
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
92
124
|
version: "0"
|
93
|
-
version:
|
94
125
|
requirements: []
|
95
126
|
|
96
127
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.3.
|
128
|
+
rubygems_version: 1.3.7
|
98
129
|
signing_key:
|
99
130
|
specification_version: 3
|
100
131
|
summary: Generators which create tests using shoulda and machinist
|
101
132
|
test_files:
|
102
|
-
- test/test_helper.rb
|
103
|
-
- test/fixtures/environment_with_constant.rb
|
104
|
-
- test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb
|
105
133
|
- test/fixtures/about_yml_plugins/bad_about_yml/init.rb
|
134
|
+
- test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb
|
135
|
+
- test/fixtures/eager/zoo.rb
|
136
|
+
- test/fixtures/eager/zoo/reptile_house.rb
|
137
|
+
- test/fixtures/environment_with_constant.rb
|
106
138
|
- test/fixtures/lib/generators/missing_class/missing_class_generator.rb
|
107
139
|
- test/fixtures/lib/generators/working/working_generator.rb
|
108
|
-
- test/fixtures/plugins/
|
109
|
-
- test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb
|
110
|
-
- test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb
|
140
|
+
- test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb
|
111
141
|
- test/fixtures/plugins/default/gemlike/init.rb
|
112
142
|
- test/fixtures/plugins/default/gemlike/lib/gemlike.rb
|
113
143
|
- test/fixtures/plugins/default/gemlike/rails/init.rb
|
114
144
|
- test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb
|
115
|
-
- test/fixtures/plugins/
|
116
|
-
- test/fixtures/
|
117
|
-
- test/fixtures/
|
145
|
+
- test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb
|
146
|
+
- test/fixtures/plugins/default/stubby/init.rb
|
147
|
+
- test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb
|
118
148
|
- test/rails_generators/shoulda_model_generator_test.rb
|
119
149
|
- test/shoulda_macros/generator_macros.rb
|
120
150
|
- test/stolen_from_railties.rb
|
151
|
+
- test/test_helper.rb
|