dust-generators 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +0 -18
- data/Rakefile +1 -1
- data/lib/dust/version.rb +1 -1
- data/rails_generators/dust_albums/USAGE +8 -0
- data/rails_generators/dust_albums/dust_albums_generator.rb +127 -0
- data/rails_generators/dust_albums/templates/README +11 -0
- data/rails_generators/dust_albums/templates/app/controllers/albums_controller.rb +56 -0
- data/rails_generators/dust_albums/templates/app/controllers/photos_controller.rb +89 -0
- data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +17 -0
- data/rails_generators/dust_albums/templates/app/helpers/albums_helper.rb +2 -0
- data/rails_generators/dust_albums/templates/app/helpers/photos_helper.rb +2 -0
- data/rails_generators/dust_albums/templates/app/helpers/view_albums_helper.rb +2 -0
- data/rails_generators/dust_albums/templates/app/models/album.rb +42 -0
- data/rails_generators/dust_albums/templates/app/models/photo.rb +18 -0
- data/rails_generators/dust_albums/templates/app/views/albums/_form.html.erb +52 -0
- data/rails_generators/dust_albums/templates/app/views/albums/_search.html.erb +6 -0
- data/rails_generators/dust_albums/templates/app/views/albums/_upload_script.html.erb +37 -0
- data/rails_generators/dust_albums/templates/app/views/albums/edit.html.erb +5 -0
- data/rails_generators/dust_albums/templates/app/views/albums/index.html.erb +61 -0
- data/rails_generators/dust_albums/templates/app/views/albums/manage.html.erb +65 -0
- data/rails_generators/dust_albums/templates/app/views/albums/new.html.erb +6 -0
- data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +51 -0
- data/rails_generators/dust_albums/templates/app/views/albums/show.js.erb +1 -0
- data/rails_generators/dust_albums/templates/app/views/photos/_form.html.erb +23 -0
- data/rails_generators/dust_albums/templates/app/views/photos/_photo.html.erb +25 -0
- data/rails_generators/dust_albums/templates/app/views/photos/_search.html.erb +6 -0
- data/rails_generators/dust_albums/templates/app/views/photos/array.js.erb +3 -0
- data/rails_generators/dust_albums/templates/app/views/photos/edit.html.erb +28 -0
- data/rails_generators/dust_albums/templates/app/views/photos/index.html.erb +85 -0
- data/rails_generators/dust_albums/templates/app/views/photos/new.html.erb +7 -0
- data/rails_generators/dust_albums/templates/app/views/photos/show.html.erb +26 -0
- data/rails_generators/dust_albums/templates/app/views/photos/show.js.erb +9 -0
- data/rails_generators/dust_albums/templates/app/views/view_albums/index.html.erb +27 -0
- data/rails_generators/dust_albums/templates/app/views/view_albums/show.html.erb +31 -0
- data/rails_generators/dust_albums/templates/images/browse.png +0 -0
- data/rails_generators/dust_albums/templates/images/cancel.png +0 -0
- data/rails_generators/dust_albums/templates/images/save_position.png +0 -0
- data/rails_generators/dust_albums/templates/images/upload.png +0 -0
- data/rails_generators/dust_albums/templates/initializers/flash_session_cookie_middleware.rb +17 -0
- data/rails_generators/dust_albums/templates/initializers/session_store_middleware.rb +1 -0
- data/rails_generators/dust_albums/templates/javascript/dragsort.js +288 -0
- data/rails_generators/dust_albums/templates/javascript/dust_album.js +19 -0
- data/rails_generators/dust_albums/templates/javascript/uploadify/jquery.uploadify.v2.1.0.js +258 -0
- data/rails_generators/dust_albums/templates/javascript/uploadify/swfobject.js +4 -0
- data/rails_generators/dust_albums/templates/javascript/uploadify/uploadify.swf +0 -0
- data/rails_generators/dust_albums/templates/migration/albums_migration.rb +38 -0
- data/rails_generators/dust_albums/templates/stylesheets/dust_album.css +16 -0
- data/rails_generators/dust_albums/templates/stylesheets/dust_album_app.css +15 -0
- data/rails_generators/dust_albums/templates/stylesheets/uploadify.css +84 -0
- data/rails_generators/dust_config/USAGE +23 -0
- data/rails_generators/dust_config/dust_config_generator.rb +32 -0
- data/rails_generators/dust_config/templates/config.yml +8 -0
- data/rails_generators/dust_config/templates/load_config.rb +2 -0
- data/rails_generators/dust_scaffold/USAGE +51 -0
- data/rails_generators/dust_scaffold/dust_scaffold_generator.rb +232 -0
- data/rails_generators/dust_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/dust_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/dust_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/dust_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/dust_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/dust_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/dust_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/dust_scaffold/templates/controller.rb +3 -0
- data/rails_generators/dust_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/dust_scaffold/templates/helper.rb +2 -0
- data/rails_generators/dust_scaffold/templates/migration.rb +16 -0
- data/rails_generators/dust_scaffold/templates/model.rb +3 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/dust_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/controller.rb +5 -0
- data/rails_generators/dust_scaffold/templates/tests/shoulda/model.rb +7 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/create.rb +11 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/index.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/new.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/show.rb +4 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/actions/update.rb +11 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/controller.rb +5 -0
- data/rails_generators/dust_scaffold/templates/tests/testunit/model.rb +7 -0
- data/rails_generators/dust_scaffold/templates/views/erb/_form.html.erb +10 -0
- data/rails_generators/dust_scaffold/templates/views/erb/edit.html.erb +14 -0
- data/rails_generators/dust_scaffold/templates/views/erb/index.html.erb +29 -0
- data/rails_generators/dust_scaffold/templates/views/erb/new.html.erb +7 -0
- data/rails_generators/dust_scaffold/templates/views/erb/show.html.erb +20 -0
- data/rails_generators/dust_scaffold/templates/views/haml/_form.html.haml +10 -0
- data/rails_generators/dust_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/dust_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/dust_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/dust_scaffold/templates/views/haml/show.html.haml +20 -0
- metadata +127 -33
@@ -0,0 +1,232 @@
|
|
1
|
+
class DustScaffoldGenerator < Rails::Generator::Base
|
2
|
+
attr_accessor :name, :attributes, :controller_actions
|
3
|
+
|
4
|
+
def initialize(runtime_args, runtime_options = {})
|
5
|
+
super
|
6
|
+
usage if @args.empty?
|
7
|
+
|
8
|
+
@name = @args.first
|
9
|
+
@controller_actions = []
|
10
|
+
@attributes = []
|
11
|
+
|
12
|
+
@args[1..-1].each do |arg|
|
13
|
+
if arg == '!'
|
14
|
+
options[:invert] = true
|
15
|
+
elsif arg.include? ':'
|
16
|
+
@attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(":"))
|
17
|
+
else
|
18
|
+
@controller_actions << arg
|
19
|
+
@controller_actions << 'create' if arg == 'new'
|
20
|
+
@controller_actions << 'update' if arg == 'edit'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@controller_actions.uniq!
|
25
|
+
@attributes.uniq!
|
26
|
+
|
27
|
+
if options[:invert] || @controller_actions.empty?
|
28
|
+
@controller_actions = all_actions - @controller_actions
|
29
|
+
end
|
30
|
+
|
31
|
+
if @attributes.empty?
|
32
|
+
options[:skip_model] = true # default to skipping model if no attributes passed
|
33
|
+
if model_exists?
|
34
|
+
model_columns_for_attributes.each do |column|
|
35
|
+
@attributes << Rails::Generator::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
@attributes << Rails::Generator::GeneratedAttribute.new('name', 'string')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def manifest
|
44
|
+
record do |m|
|
45
|
+
unless options[:skip_model]
|
46
|
+
m.directory "app/models"
|
47
|
+
m.template "model.rb", "app/models/#{singular_name}.rb"
|
48
|
+
unless options[:skip_migration]
|
49
|
+
m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{plural_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
if rspec?
|
53
|
+
m.directory "spec/models"
|
54
|
+
m.template "tests/#{test_framework}/model.rb", "spec/models/#{singular_name}_spec.rb"
|
55
|
+
m.directory "spec/fixtures"
|
56
|
+
m.template "fixtures.yml", "spec/fixtures/#{plural_name}.yml"
|
57
|
+
else
|
58
|
+
m.directory "test/unit"
|
59
|
+
m.template "tests/#{test_framework}/model.rb", "test/unit/#{singular_name}_test.rb"
|
60
|
+
m.directory "test/fixtures"
|
61
|
+
m.template "fixtures.yml", "test/fixtures/#{plural_name}.yml"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
unless options[:skip_controller]
|
66
|
+
m.directory "app/controllers"
|
67
|
+
m.template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
|
68
|
+
|
69
|
+
m.directory "app/helpers"
|
70
|
+
m.template "helper.rb", "app/helpers/#{plural_name}_helper.rb"
|
71
|
+
|
72
|
+
m.directory "app/views/#{plural_name}"
|
73
|
+
controller_actions.each do |action|
|
74
|
+
if File.exist? source_path("views/#{view_language}/#{action}.html.#{view_language}")
|
75
|
+
m.template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if form_partial?
|
80
|
+
m.template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
81
|
+
end
|
82
|
+
|
83
|
+
m.route_resources plural_name
|
84
|
+
|
85
|
+
if rspec?
|
86
|
+
m.directory "spec/controllers"
|
87
|
+
m.template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
88
|
+
else
|
89
|
+
m.directory "test/functional"
|
90
|
+
m.template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def form_partial?
|
97
|
+
actions? :new, :edit
|
98
|
+
end
|
99
|
+
|
100
|
+
def all_actions
|
101
|
+
%w[index show new create edit update destroy]
|
102
|
+
end
|
103
|
+
|
104
|
+
def action?(name)
|
105
|
+
controller_actions.include? name.to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def actions?(*names)
|
109
|
+
names.all? { |n| action? n.to_s }
|
110
|
+
end
|
111
|
+
|
112
|
+
def singular_name
|
113
|
+
name.underscore
|
114
|
+
end
|
115
|
+
|
116
|
+
def plural_name
|
117
|
+
name.underscore.pluralize
|
118
|
+
end
|
119
|
+
|
120
|
+
def class_name
|
121
|
+
name.camelize
|
122
|
+
end
|
123
|
+
|
124
|
+
def plural_class_name
|
125
|
+
plural_name.camelize
|
126
|
+
end
|
127
|
+
|
128
|
+
def controller_methods(dir_name)
|
129
|
+
controller_actions.map do |action|
|
130
|
+
read_template("#{dir_name}/#{action}.rb")
|
131
|
+
end.join(" \n").strip
|
132
|
+
end
|
133
|
+
|
134
|
+
def render_form
|
135
|
+
if form_partial?
|
136
|
+
if options[:haml]
|
137
|
+
"= render :partial => 'form'"
|
138
|
+
else
|
139
|
+
"<%= render :partial => 'form' %>"
|
140
|
+
end
|
141
|
+
else
|
142
|
+
read_template("views/#{view_language}/_form.html.#{view_language}")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def items_path(suffix = 'path')
|
147
|
+
if action? :index
|
148
|
+
"#{plural_name}_#{suffix}"
|
149
|
+
else
|
150
|
+
"root_#{suffix}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def item_path(suffix = 'path')
|
155
|
+
if action? :show
|
156
|
+
"@#{singular_name}"
|
157
|
+
else
|
158
|
+
items_path(suffix)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def item_path_for_spec(suffix = 'path')
|
163
|
+
if action? :show
|
164
|
+
"#{singular_name}_#{suffix}(assigns[:#{singular_name}])"
|
165
|
+
else
|
166
|
+
items_path(suffix)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def item_path_for_test(suffix = 'path')
|
171
|
+
if action? :show
|
172
|
+
"#{singular_name}_#{suffix}(assigns(:#{singular_name}))"
|
173
|
+
else
|
174
|
+
items_path(suffix)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def model_columns_for_attributes
|
179
|
+
class_name.constantize.columns.reject do |column|
|
180
|
+
column.name.to_s =~ /^(id|created_at|updated_at)$/
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def rspec?
|
185
|
+
test_framework == :rspec
|
186
|
+
end
|
187
|
+
|
188
|
+
protected
|
189
|
+
|
190
|
+
def view_language
|
191
|
+
options[:haml] ? 'haml' : 'erb'
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_framework
|
195
|
+
options[:test_framework] ||= default_test_framework
|
196
|
+
end
|
197
|
+
|
198
|
+
def default_test_framework
|
199
|
+
File.exist?(destination_path("spec")) ? :rspec : :testunit
|
200
|
+
end
|
201
|
+
|
202
|
+
def add_options!(opt)
|
203
|
+
opt.separator ''
|
204
|
+
opt.separator 'Options:'
|
205
|
+
opt.on("--skip-model", "Don't generate a model or migration file.") { |v| options[:skip_model] = v }
|
206
|
+
opt.on("--skip-migration", "Don't generate migration file for model.") { |v| options[:skip_migration] = v }
|
207
|
+
opt.on("--skip-timestamps", "Don't add timestamps to migration file.") { |v| options[:skip_timestamps] = v }
|
208
|
+
opt.on("--skip-controller", "Don't generate controller, helper, or views.") { |v| options[:skip_controller] = v }
|
209
|
+
opt.on("--invert", "Generate all controller actions except these mentioned.") { |v| options[:invert] = v }
|
210
|
+
opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = v }
|
211
|
+
opt.on("--testunit", "Use test/unit for test files.") { options[:test_framework] = :testunit }
|
212
|
+
opt.on("--rspec", "Use RSpec for test files.") { options[:test_framework] = :rspec }
|
213
|
+
opt.on("--shoulda", "Use Shoulda for test files.") { options[:test_framework] = :shoulda }
|
214
|
+
end
|
215
|
+
|
216
|
+
# is there a better way to do this? Perhaps with const_defined?
|
217
|
+
def model_exists?
|
218
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
219
|
+
end
|
220
|
+
|
221
|
+
def read_template(relative_path)
|
222
|
+
ERB.new(File.read(source_path(relative_path)), nil, '-').result(binding)
|
223
|
+
end
|
224
|
+
|
225
|
+
def banner
|
226
|
+
<<-EOS
|
227
|
+
Creates a controller and optional model given the name, actions, and attributes.
|
228
|
+
|
229
|
+
USAGE: #{$0} #{spec.name} ModelName [controller_actions and model:attributes] [options]
|
230
|
+
EOS
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def create
|
2
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
|
3
|
+
if @<%= singular_name %>.save
|
4
|
+
flash[:notice] = "Successfully created <%= name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'new'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def update
|
2
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
|
4
|
+
flash[:notice] = "Successfully updated <%= name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_path('url') %>
|
6
|
+
else
|
7
|
+
render :action => 'edit'
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= plural_name %> do |t|
|
4
|
+
<%- for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- unless options[:skip_timestamps] -%>
|
8
|
+
t.timestamps
|
9
|
+
<%- end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= plural_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
it "create action should render new template when model is invalid" do
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
post :create
|
4
|
+
response.should render_template(:new)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "create action should redirect when model is valid" do
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
post :create
|
10
|
+
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
it "destroy action should destroy model and redirect to index action" do
|
2
|
+
<%= singular_name %> = <%= class_name %>.first
|
3
|
+
delete :destroy, :id => <%= singular_name %>
|
4
|
+
response.should redirect_to(<%= items_path('url') %>)
|
5
|
+
<%= class_name %>.exists?(<%= singular_name %>.id).should be_false
|
6
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
it "update action should render edit template when model is invalid" do
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
put :update, :id => <%= class_name %>.first
|
4
|
+
response.should render_template(:edit)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "update action should redirect when model is valid" do
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
put :update, :id => <%= class_name %>.first
|
10
|
+
response.should redirect_to(<%= item_path_for_spec('url') %>)
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
context "create action" do
|
2
|
+
should "render new template when model is invalid" do
|
3
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
+
post :create
|
5
|
+
assert_template 'new'
|
6
|
+
end
|
7
|
+
|
8
|
+
should "redirect when model is valid" do
|
9
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
+
post :create
|
11
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
context "destroy action" do
|
2
|
+
should "destroy model and redirect to index action" do
|
3
|
+
<%= singular_name %> = <%= class_name %>.first
|
4
|
+
delete :destroy, :id => <%= singular_name %>
|
5
|
+
assert_redirected_to <%= items_path('url') %>
|
6
|
+
assert !<%= class_name %>.exists?(<%= singular_name %>.id)
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
context "update action" do
|
2
|
+
should "render edit template when model is invalid" do
|
3
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
4
|
+
put :update, :id => <%= class_name %>.first
|
5
|
+
assert_template 'edit'
|
6
|
+
end
|
7
|
+
|
8
|
+
should "redirect when model is valid" do
|
9
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
10
|
+
put :update, :id => <%= class_name %>.first
|
11
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def test_create_invalid
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
post :create
|
4
|
+
assert_template 'new'
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_create_valid
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
post :create
|
10
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def test_update_invalid
|
2
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
3
|
+
put :update, :id => <%= class_name %>.first
|
4
|
+
assert_template 'edit'
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_update_valid
|
8
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
9
|
+
put :update, :id => <%= class_name %>.first
|
10
|
+
assert_redirected_to <%= item_path_for_test('url') %>
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%% form_for @<%= singular_name %> do |f| %>
|
2
|
+
<%%= f.error_messages %>
|
3
|
+
<%- for attribute in attributes -%>
|
4
|
+
<p>
|
5
|
+
<%%= f.label :<%= attribute.name %> %><br />
|
6
|
+
<%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<%- end -%>
|
9
|
+
<p><%%= f.submit %></p>
|
10
|
+
<%% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%% title "Edit <%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%= render_form %>
|
4
|
+
|
5
|
+
<%- if actions? :show, :index -%>
|
6
|
+
<p>
|
7
|
+
<%- if action? :show -%>
|
8
|
+
<%%= link_to "Show", @<%= singular_name %> %> |
|
9
|
+
<%- end -%>
|
10
|
+
<%- if action? :index -%>
|
11
|
+
<%%= link_to "View All", <%= plural_name %>_path %>
|
12
|
+
<%- end -%>
|
13
|
+
</p>
|
14
|
+
<%- end -%>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%% title "<%= plural_name.titleize %>" %>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<%- for attribute in attributes -%>
|
6
|
+
<th><%= attribute.column.human_name.titleize %></th>
|
7
|
+
<%- end -%>
|
8
|
+
</tr>
|
9
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
10
|
+
<tr>
|
11
|
+
<%- for attribute in attributes -%>
|
12
|
+
<td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :show -%>
|
15
|
+
<td><%%= link_to "Show", <%= singular_name %> %></td>
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :edit -%>
|
18
|
+
<td><%%= link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
19
|
+
<%- end -%>
|
20
|
+
<%- if action? :destroy -%>
|
21
|
+
<td><%%= link_to "Destroy", <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
22
|
+
<%- end -%>
|
23
|
+
</tr>
|
24
|
+
<%% end %>
|
25
|
+
</table>
|
26
|
+
|
27
|
+
<%- if action? :new -%>
|
28
|
+
<p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
|
29
|
+
<%- end -%>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%% title "<%= singular_name.titleize %>" %>
|
2
|
+
|
3
|
+
<%- for attribute in attributes -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.column.human_name.titleize %>:</strong>
|
6
|
+
<%%=h @<%= singular_name %>.<%= attribute.name %> %>
|
7
|
+
</p>
|
8
|
+
<%- end -%>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<%- if action? :edit -%>
|
12
|
+
<%%= link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
|
13
|
+
<%- end -%>
|
14
|
+
<%- if action? :destroy -%>
|
15
|
+
<%%= link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %> |
|
16
|
+
<%- end -%>
|
17
|
+
<%- if action? :index -%>
|
18
|
+
<%%= link_to "View All", <%= plural_name %>_path %>
|
19
|
+
<%- end -%>
|
20
|
+
</p>
|