nifty-generators 0.4.3 → 0.4.4
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/CHANGELOG +7 -0
- data/Gemfile.lock +59 -57
- data/README.rdoc +7 -0
- data/features/nifty_scaffold.feature +30 -0
- data/features/step_definitions/common_steps.rb +6 -0
- data/lib/generators/nifty/scaffold/scaffold_generator.rb +93 -23
- data/lib/generators/nifty/scaffold/templates/actions/create.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/actions/destroy.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/actions/edit.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/actions/index.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/actions/new.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/actions/show.rb +1 -1
- data/lib/generators/nifty/scaffold/templates/actions/update.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/migration.rb +3 -3
- data/lib/generators/nifty/scaffold/templates/model.rb +1 -0
- data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/destroy.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/destroy.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/destroy.rb +4 -4
- data/lib/generators/nifty/scaffold/templates/views/erb/_form.html.erb +1 -1
- data/lib/generators/nifty/scaffold/templates/views/erb/edit.html.erb +2 -2
- data/lib/generators/nifty/scaffold/templates/views/erb/index.html.erb +6 -6
- data/lib/generators/nifty/scaffold/templates/views/erb/new.html.erb +1 -1
- data/lib/generators/nifty/scaffold/templates/views/erb/show.html.erb +4 -4
- data/lib/generators/nifty/scaffold/templates/views/haml/_form.html.haml +1 -1
- data/lib/generators/nifty/scaffold/templates/views/haml/edit.html.haml +2 -2
- data/lib/generators/nifty/scaffold/templates/views/haml/index.html.haml +6 -6
- data/lib/generators/nifty/scaffold/templates/views/haml/new.html.haml +1 -1
- data/lib/generators/nifty/scaffold/templates/views/haml/show.html.haml +4 -4
- metadata +3 -3
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,40 +7,39 @@ GEM
|
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
abstract (1.0.0)
|
10
|
-
actionmailer (3.0.
|
11
|
-
actionpack (= 3.0.
|
12
|
-
mail (~> 2.2.
|
13
|
-
actionpack (3.0.
|
14
|
-
activemodel (= 3.0.
|
15
|
-
activesupport (= 3.0.
|
10
|
+
actionmailer (3.0.3)
|
11
|
+
actionpack (= 3.0.3)
|
12
|
+
mail (~> 2.2.9)
|
13
|
+
actionpack (3.0.3)
|
14
|
+
activemodel (= 3.0.3)
|
15
|
+
activesupport (= 3.0.3)
|
16
16
|
builder (~> 2.1.2)
|
17
17
|
erubis (~> 2.6.6)
|
18
|
-
i18n (~> 0.4
|
18
|
+
i18n (~> 0.4)
|
19
19
|
rack (~> 1.2.1)
|
20
|
-
rack-mount (~> 0.6.
|
21
|
-
rack-test (~> 0.5.
|
20
|
+
rack-mount (~> 0.6.13)
|
21
|
+
rack-test (~> 0.5.6)
|
22
22
|
tzinfo (~> 0.3.23)
|
23
|
-
activemodel (3.0.
|
24
|
-
activesupport (= 3.0.
|
23
|
+
activemodel (3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
25
|
builder (~> 2.1.2)
|
26
|
-
i18n (~> 0.4
|
27
|
-
activerecord (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
30
|
-
arel (~>
|
26
|
+
i18n (~> 0.4)
|
27
|
+
activerecord (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
arel (~> 2.0.2)
|
31
31
|
tzinfo (~> 0.3.23)
|
32
|
-
activeresource (3.0.
|
33
|
-
activemodel (= 3.0.
|
34
|
-
activesupport (= 3.0.
|
35
|
-
activesupport (3.0.
|
36
|
-
arel (
|
37
|
-
|
38
|
-
bcrypt-ruby (2.1.2)
|
32
|
+
activeresource (3.0.3)
|
33
|
+
activemodel (= 3.0.3)
|
34
|
+
activesupport (= 3.0.3)
|
35
|
+
activesupport (3.0.3)
|
36
|
+
arel (2.0.7)
|
37
|
+
bcrypt-ruby (2.1.4)
|
39
38
|
builder (2.1.2)
|
40
|
-
cucumber (0.9.
|
39
|
+
cucumber (0.9.4)
|
41
40
|
builder (~> 2.1.2)
|
42
41
|
diff-lcs (~> 1.1.2)
|
43
|
-
gherkin (~> 2.2.
|
42
|
+
gherkin (~> 2.2.9)
|
44
43
|
json (~> 1.4.6)
|
45
44
|
term-ansicolor (~> 1.0.5)
|
46
45
|
diff-lcs (1.1.2)
|
@@ -49,53 +48,56 @@ GEM
|
|
49
48
|
gherkin (2.2.9)
|
50
49
|
json (~> 1.4.6)
|
51
50
|
term-ansicolor (~> 1.0.5)
|
52
|
-
i18n (0.
|
51
|
+
i18n (0.5.0)
|
53
52
|
json (1.4.6)
|
54
|
-
mail (2.2.
|
53
|
+
mail (2.2.14)
|
55
54
|
activesupport (>= 2.3.6)
|
56
|
-
|
57
|
-
|
55
|
+
i18n (>= 0.4.0)
|
56
|
+
mime-types (~> 1.16)
|
57
|
+
treetop (~> 1.4.8)
|
58
58
|
mime-types (1.16)
|
59
|
-
mocha (0.9.
|
59
|
+
mocha (0.9.10)
|
60
60
|
rake
|
61
61
|
polyglot (0.3.1)
|
62
62
|
rack (1.2.1)
|
63
63
|
rack-mount (0.6.13)
|
64
64
|
rack (>= 1.0.0)
|
65
|
-
rack-test (0.5.
|
65
|
+
rack-test (0.5.7)
|
66
66
|
rack (>= 1.0)
|
67
|
-
rails (3.0.
|
68
|
-
actionmailer (= 3.0.
|
69
|
-
actionpack (= 3.0.
|
70
|
-
activerecord (= 3.0.
|
71
|
-
activeresource (= 3.0.
|
72
|
-
activesupport (= 3.0.
|
73
|
-
bundler (~> 1.0
|
74
|
-
railties (= 3.0.
|
75
|
-
railties (3.0.
|
76
|
-
actionpack (= 3.0.
|
77
|
-
activesupport (= 3.0.
|
78
|
-
rake (>= 0.8.
|
79
|
-
thor (~> 0.14.
|
67
|
+
rails (3.0.3)
|
68
|
+
actionmailer (= 3.0.3)
|
69
|
+
actionpack (= 3.0.3)
|
70
|
+
activerecord (= 3.0.3)
|
71
|
+
activeresource (= 3.0.3)
|
72
|
+
activesupport (= 3.0.3)
|
73
|
+
bundler (~> 1.0)
|
74
|
+
railties (= 3.0.3)
|
75
|
+
railties (3.0.3)
|
76
|
+
actionpack (= 3.0.3)
|
77
|
+
activesupport (= 3.0.3)
|
78
|
+
rake (>= 0.8.7)
|
79
|
+
thor (~> 0.14.4)
|
80
80
|
rake (0.8.7)
|
81
|
-
rspec (2.0.
|
82
|
-
rspec-core (
|
83
|
-
rspec-expectations (
|
84
|
-
rspec-mocks (
|
85
|
-
rspec-core (2.0.
|
86
|
-
rspec-expectations (2.0.
|
81
|
+
rspec (2.0.1)
|
82
|
+
rspec-core (~> 2.0.1)
|
83
|
+
rspec-expectations (~> 2.0.1)
|
84
|
+
rspec-mocks (~> 2.0.1)
|
85
|
+
rspec-core (2.0.1)
|
86
|
+
rspec-expectations (2.0.1)
|
87
87
|
diff-lcs (>= 1.1.2)
|
88
|
-
rspec-mocks (2.0.
|
89
|
-
rspec-core (
|
90
|
-
rspec-expectations (
|
88
|
+
rspec-mocks (2.0.1)
|
89
|
+
rspec-core (~> 2.0.1)
|
90
|
+
rspec-expectations (~> 2.0.1)
|
91
91
|
rspec-rails (2.0.1)
|
92
92
|
rspec (~> 2.0.0)
|
93
|
-
sqlite3
|
93
|
+
sqlite3 (1.3.3)
|
94
|
+
sqlite3-ruby (1.3.3)
|
95
|
+
sqlite3 (>= 1.3.3)
|
94
96
|
term-ansicolor (1.0.5)
|
95
|
-
thor (0.14.
|
96
|
-
treetop (1.4.
|
97
|
+
thor (0.14.6)
|
98
|
+
treetop (1.4.9)
|
97
99
|
polyglot (>= 0.3.1)
|
98
|
-
tzinfo (0.3.
|
100
|
+
tzinfo (0.3.24)
|
99
101
|
|
100
102
|
PLATFORMS
|
101
103
|
ruby
|
data/README.rdoc
CHANGED
@@ -100,3 +100,10 @@ Also, make sure you're using Rails 2.1 or greater.
|
|
100
100
|
If you are having a problem with Nifty Generators, first look at the FAQs above. If you still cannot resolve it, please submit an issue here.
|
101
101
|
|
102
102
|
http://github.com/ryanb/nifty-generators/issues
|
103
|
+
|
104
|
+
|
105
|
+
== Development
|
106
|
+
|
107
|
+
If you want to contribute to this project, you can download the Git repository and get the Cucumber features running by calling +bundle+ then +rake+. I normally develop this using Ruby 1.9.2 however it should work with 1.8.7 as well.
|
108
|
+
|
109
|
+
The Rails 3 generators are located under <tt>lib/generators</tt> and are tested with Cucumber. The older Rails 2 generators are under <tt>rails_generators</tt> and are tested with Shoulda under the <tt>test</tt> directory.
|
@@ -42,3 +42,33 @@ Feature: Nifty Scaffold Generator
|
|
42
42
|
Scenario: Report error when invalid model name
|
43
43
|
Given a new Rails app
|
44
44
|
Then I should see "Usage:" when running "rails g nifty:scaffold name:string parent_id:integer"
|
45
|
+
|
46
|
+
Scenario: Generate scaffold for namespaced resource
|
47
|
+
Given a new Rails app
|
48
|
+
When I run "rails g nifty:scaffold Admin::User name:string"
|
49
|
+
Then I should see the following files
|
50
|
+
| app/models/user.rb |
|
51
|
+
| app/controllers/admin/users_controller.rb |
|
52
|
+
| app/helpers/admin/users_helper.rb |
|
53
|
+
| app/views/admin/users/index.html.erb |
|
54
|
+
| app/views/admin/users/show.html.erb |
|
55
|
+
| app/views/admin/users/new.html.erb |
|
56
|
+
| app/views/admin/users/edit.html.erb |
|
57
|
+
| db/migrate |
|
58
|
+
And I should see "class User" in file "app/models/user.rb"
|
59
|
+
And I should not see "set_table_name :" in file "app/models/user.rb"
|
60
|
+
And I should see "namespace(:admin){ resources :users }" in file "config/routes.rb"
|
61
|
+
When I run "rails g nifty:layout -f"
|
62
|
+
And I run "rake db:migrate"
|
63
|
+
And I should successfully run "rails g nifty:scaffold Admin::User -f"
|
64
|
+
Then I should successfully run "rake test"
|
65
|
+
|
66
|
+
Scenario: Generate scaffold with a namespaced model
|
67
|
+
Given a new Rails app
|
68
|
+
When I run "rails g nifty:scaffold Admin::User name:string --namespace_model"
|
69
|
+
Then I should see "class Admin::User" in file "app/models/admin/user.rb"
|
70
|
+
And I should see "set_table_name :admin_users" in file "app/models/admin/user.rb"
|
71
|
+
When I run "rails g nifty:layout -f"
|
72
|
+
And I run "rake db:migrate"
|
73
|
+
And I should successfully run "rails g nifty:scaffold Admin::User -f --namespace_model"
|
74
|
+
Then I should successfully run "rake test"
|
@@ -25,6 +25,12 @@ Then /^I should see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
|
|
25
25
|
File.readlines(path).join.should include(content)
|
26
26
|
end
|
27
27
|
|
28
|
+
Then /^I should not see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
|
29
|
+
path = File.join(@current_directory, short_path)
|
30
|
+
File.should exist(path)
|
31
|
+
File.readlines(path).join.should_not include(content)
|
32
|
+
end
|
33
|
+
|
28
34
|
Then /^I should see the following files$/ do |table|
|
29
35
|
table.raw.flatten.each do |path|
|
30
36
|
File.should exist(File.join(@current_directory, path))
|
@@ -6,9 +6,9 @@ module Nifty
|
|
6
6
|
module Generators
|
7
7
|
class ScaffoldGenerator < Base
|
8
8
|
include Rails::Generators::Migration
|
9
|
-
no_tasks { attr_accessor :
|
9
|
+
no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
|
10
10
|
|
11
|
-
argument :
|
11
|
+
argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
|
12
12
|
argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
|
13
13
|
|
14
14
|
class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
|
@@ -16,6 +16,7 @@ module Nifty
|
|
16
16
|
class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
|
17
17
|
class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
|
18
18
|
class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
|
19
|
+
class_option :namespace_model, :desc => 'If the resource is namespaced, include the model in the namespace.', :type => :boolean
|
19
20
|
class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
|
20
21
|
|
21
22
|
class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
|
@@ -25,11 +26,12 @@ module Nifty
|
|
25
26
|
def initialize(*args, &block)
|
26
27
|
super
|
27
28
|
|
28
|
-
print_usage unless
|
29
|
+
print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/
|
29
30
|
|
30
31
|
@controller_actions = []
|
31
32
|
@model_attributes = []
|
32
33
|
@skip_model = options.skip_model?
|
34
|
+
@namespace_model = options.namespace_model?
|
33
35
|
@invert_actions = options.invert?
|
34
36
|
|
35
37
|
args_for_c_m.each do |arg|
|
@@ -69,20 +71,20 @@ module Nifty
|
|
69
71
|
|
70
72
|
def create_model
|
71
73
|
unless @skip_model
|
72
|
-
template 'model.rb', "app/models/#{
|
74
|
+
template 'model.rb', "app/models/#{model_path}.rb"
|
73
75
|
if test_framework == :rspec
|
74
|
-
template "tests/rspec/model.rb", "spec/models/#{
|
75
|
-
template 'fixtures.yml', "spec/fixtures/#{
|
76
|
+
template "tests/rspec/model.rb", "spec/models/#{model_path}_spec.rb"
|
77
|
+
template 'fixtures.yml', "spec/fixtures/#{model_path.pluralize}.yml"
|
76
78
|
else
|
77
|
-
template "tests/#{test_framework}/model.rb", "test/unit/#{
|
78
|
-
template 'fixtures.yml', "test/fixtures/#{
|
79
|
+
template "tests/#{test_framework}/model.rb", "test/unit/#{model_path}_test.rb"
|
80
|
+
template 'fixtures.yml', "test/fixtures/#{model_path.pluralize}.yml"
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
85
|
def create_migration
|
84
86
|
unless @skip_model || options.skip_migration?
|
85
|
-
migration_template 'migration.rb', "db/migrate/create_#{
|
87
|
+
migration_template 'migration.rb', "db/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -102,7 +104,11 @@ module Nifty
|
|
102
104
|
template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
|
103
105
|
end
|
104
106
|
|
105
|
-
|
107
|
+
namespaces = plural_name.split('/')
|
108
|
+
resource = namespaces.pop
|
109
|
+
route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace|
|
110
|
+
"namespace(:#{namespace}){ #{acc} }"
|
111
|
+
}
|
106
112
|
|
107
113
|
if test_framework == :rspec
|
108
114
|
template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
|
@@ -131,21 +137,47 @@ module Nifty
|
|
131
137
|
end
|
132
138
|
|
133
139
|
def singular_name
|
134
|
-
|
140
|
+
scaffold_name.underscore
|
135
141
|
end
|
136
142
|
|
137
143
|
def plural_name
|
138
|
-
|
144
|
+
scaffold_name.underscore.pluralize
|
145
|
+
end
|
146
|
+
|
147
|
+
def table_name
|
148
|
+
if scaffold_name.include?('::') && @namespace_model
|
149
|
+
plural_name.gsub('/', '_')
|
150
|
+
end
|
139
151
|
end
|
140
152
|
|
141
153
|
def class_name
|
142
|
-
|
154
|
+
if @namespace_model
|
155
|
+
scaffold_name.camelize
|
156
|
+
else
|
157
|
+
scaffold_name.split('::').last.camelize
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def model_path
|
162
|
+
class_name.underscore
|
143
163
|
end
|
144
164
|
|
145
165
|
def plural_class_name
|
146
166
|
plural_name.camelize
|
147
167
|
end
|
148
168
|
|
169
|
+
def instance_name
|
170
|
+
if @namespace_model
|
171
|
+
singular_name.gsub('/','_')
|
172
|
+
else
|
173
|
+
singular_name.split('/').last
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def instances_name
|
178
|
+
instance_name.pluralize
|
179
|
+
end
|
180
|
+
|
149
181
|
def controller_methods(dir_name)
|
150
182
|
controller_actions.map do |action|
|
151
183
|
read_template("#{dir_name}/#{action}.rb")
|
@@ -164,35 +196,73 @@ module Nifty
|
|
164
196
|
end
|
165
197
|
end
|
166
198
|
|
167
|
-
def
|
199
|
+
def item_resource
|
200
|
+
scaffold_name.underscore.gsub('/','_')
|
201
|
+
end
|
202
|
+
|
203
|
+
def items_path
|
168
204
|
if action? :index
|
169
|
-
"#{
|
205
|
+
"#{item_resource.pluralize}_path"
|
206
|
+
else
|
207
|
+
"root_path"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def item_path(options = {})
|
212
|
+
if action? :show
|
213
|
+
name = options[:instance_variable] ? "@#{instance_name}" : instance_name
|
214
|
+
if %w(new edit).include? options[:action].to_s
|
215
|
+
"#{options[:action].to_s}_#{item_resource}_path(#{name})"
|
216
|
+
else
|
217
|
+
if scaffold_name.include?('::') && !@namespace_model
|
218
|
+
namespace = singular_name.split('/')[0..-2]
|
219
|
+
"[ :#{namespace.join(', :')}, #{name} ]"
|
220
|
+
else
|
221
|
+
name
|
222
|
+
end
|
223
|
+
end
|
170
224
|
else
|
171
|
-
|
225
|
+
items_path
|
172
226
|
end
|
173
227
|
end
|
174
228
|
|
175
|
-
def
|
229
|
+
def item_url
|
176
230
|
if action? :show
|
177
|
-
|
231
|
+
item_resource + '_url'
|
232
|
+
else
|
233
|
+
items_url
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def items_url
|
238
|
+
if action? :index
|
239
|
+
item_resource.pluralize + '_url'
|
178
240
|
else
|
179
|
-
|
241
|
+
"root_url"
|
180
242
|
end
|
181
243
|
end
|
182
244
|
|
183
245
|
def item_path_for_spec(suffix = 'path')
|
184
246
|
if action? :show
|
185
|
-
"#{
|
247
|
+
"#{item_resource}_#{suffix}(assigns[:#{instance_name}])"
|
186
248
|
else
|
187
|
-
|
249
|
+
if suffix == 'path'
|
250
|
+
items_path
|
251
|
+
else
|
252
|
+
items_url
|
253
|
+
end
|
188
254
|
end
|
189
255
|
end
|
190
256
|
|
191
257
|
def item_path_for_test(suffix = 'path')
|
192
258
|
if action? :show
|
193
|
-
"#{
|
259
|
+
"#{item_resource}_#{suffix}(assigns(:#{instance_name}))"
|
194
260
|
else
|
195
|
-
|
261
|
+
if suffix == 'path'
|
262
|
+
items_path
|
263
|
+
else
|
264
|
+
items_url
|
265
|
+
end
|
196
266
|
end
|
197
267
|
end
|
198
268
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
def create
|
2
|
-
@<%=
|
3
|
-
if @<%=
|
4
|
-
flash[:notice] = "Successfully created <%=
|
5
|
-
redirect_to <%= item_path
|
2
|
+
@<%= instance_name %> = <%= class_name %>.new(params[:<%= instance_name %>])
|
3
|
+
if @<%= instance_name %>.save
|
4
|
+
flash[:notice] = "Successfully created <%= class_name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_path :instance_variable => true %>
|
6
6
|
else
|
7
7
|
render :action => 'new'
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
def destroy
|
2
|
-
@<%=
|
3
|
-
@<%=
|
4
|
-
flash[:notice] = "Successfully destroyed <%=
|
5
|
-
redirect_to <%=
|
2
|
+
@<%= instance_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
@<%= instance_name %>.destroy
|
4
|
+
flash[:notice] = "Successfully destroyed <%= class_name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= items_url %>
|
6
6
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
def update
|
2
|
-
@<%=
|
3
|
-
if @<%=
|
4
|
-
flash[:notice] = "Successfully updated <%=
|
5
|
-
redirect_to <%=
|
2
|
+
@<%= instance_name %> = <%= class_name %>.find(params[:id])
|
3
|
+
if @<%= instance_name %>.update_attributes(params[:<%= instance_name %>])
|
4
|
+
flash[:notice] = "Successfully updated <%= class_name.underscore.humanize.downcase %>."
|
5
|
+
redirect_to <%= item_url %>
|
6
6
|
else
|
7
7
|
render :action => 'edit'
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class Create<%=
|
1
|
+
class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table :<%= plural_name %> do |t|
|
3
|
+
create_table :<%= table_name || plural_name.split('/').last %> do |t|
|
4
4
|
<%- for attribute in model_attributes -%>
|
5
5
|
t.<%= attribute.type %> :<%= attribute.name %>
|
6
6
|
<%- end -%>
|
@@ -11,6 +11,6 @@ class Create<%= plural_class_name %> < ActiveRecord::Migration
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.down
|
14
|
-
drop_table :<%= plural_name %>
|
14
|
+
drop_table :<%= table_name || plural_name.split('/').last %>
|
15
15
|
end
|
16
16
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
it "destroy action should destroy model and redirect to index action" do
|
2
|
-
<%=
|
3
|
-
delete :destroy, :id => <%=
|
4
|
-
response.should redirect_to(<%=
|
5
|
-
<%= class_name %>.exists?(<%=
|
2
|
+
<%= instance_name %> = <%= class_name %>.first
|
3
|
+
delete :destroy, :id => <%= instance_name %>
|
4
|
+
response.should redirect_to(<%= items_url %>)
|
5
|
+
<%= class_name %>.exists?(<%= instance_name %>.id).should be_false
|
6
6
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
context "destroy action" do
|
2
2
|
should "destroy model and redirect to index action" do
|
3
|
-
<%=
|
4
|
-
delete :destroy, :id => <%=
|
5
|
-
assert_redirected_to <%=
|
6
|
-
assert !<%= class_name %>.exists?(<%=
|
3
|
+
<%= instance_name %> = <%= class_name %>.first
|
4
|
+
delete :destroy, :id => <%= instance_name %>
|
5
|
+
assert_redirected_to <%= items_url %>
|
6
|
+
assert !<%= class_name %>.exists?(<%= instance_name %>.id)
|
7
7
|
end
|
8
8
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
def test_destroy
|
2
|
-
<%=
|
3
|
-
delete :destroy, :id => <%=
|
4
|
-
assert_redirected_to <%=
|
5
|
-
assert !<%= class_name %>.exists?(<%=
|
2
|
+
<%= instance_name %> = <%= class_name %>.first
|
3
|
+
delete :destroy, :id => <%= instance_name %>
|
4
|
+
assert_redirected_to <%= items_url %>
|
5
|
+
assert !<%= class_name %>.exists?(<%= instance_name %>.id)
|
6
6
|
end
|
@@ -5,10 +5,10 @@
|
|
5
5
|
<%- if actions? :show, :index -%>
|
6
6
|
<p>
|
7
7
|
<%- if action? :show -%>
|
8
|
-
<%%= link_to "Show",
|
8
|
+
<%%= link_to "Show", <%= item_path :instance_variable => true %> %> |
|
9
9
|
<%- end -%>
|
10
10
|
<%- if action? :index -%>
|
11
|
-
<%%= link_to "View All", <%=
|
11
|
+
<%%= link_to "View All", <%= items_path %> %>
|
12
12
|
<%- end -%>
|
13
13
|
</p>
|
14
14
|
<%- end -%>
|
@@ -6,24 +6,24 @@
|
|
6
6
|
<th><%= attribute.human_name.titleize %></th>
|
7
7
|
<%- end -%>
|
8
8
|
</tr>
|
9
|
-
<%% for <%=
|
9
|
+
<%% for <%= instance_name %> in @<%= instances_name %> %>
|
10
10
|
<tr>
|
11
11
|
<%- for attribute in model_attributes -%>
|
12
|
-
<td><%%= <%=
|
12
|
+
<td><%%= <%= instance_name %>.<%= attribute.name %> %></td>
|
13
13
|
<%- end -%>
|
14
14
|
<%- if action? :show -%>
|
15
|
-
<td><%%= link_to "Show", <%=
|
15
|
+
<td><%%= link_to "Show", <%= item_path %> %></td>
|
16
16
|
<%- end -%>
|
17
17
|
<%- if action? :edit -%>
|
18
|
-
<td><%%= link_to "Edit",
|
18
|
+
<td><%%= link_to "Edit", <%= item_path :action => :edit %> %></td>
|
19
19
|
<%- end -%>
|
20
20
|
<%- if action? :destroy -%>
|
21
|
-
<td><%%= link_to "Destroy", <%=
|
21
|
+
<td><%%= link_to "Destroy", <%= item_path %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
22
22
|
<%- end -%>
|
23
23
|
</tr>
|
24
24
|
<%% end %>
|
25
25
|
</table>
|
26
26
|
|
27
27
|
<%- if action? :new -%>
|
28
|
-
<p><%%= link_to "New <%= singular_name.titleize %>",
|
28
|
+
<p><%%= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %> %></p>
|
29
29
|
<%- end -%>
|
@@ -3,18 +3,18 @@
|
|
3
3
|
<%- for attribute in model_attributes -%>
|
4
4
|
<p>
|
5
5
|
<strong><%= attribute.human_name.titleize %>:</strong>
|
6
|
-
<%%= @<%=
|
6
|
+
<%%= @<%= instance_name %>.<%= attribute.name %> %>
|
7
7
|
</p>
|
8
8
|
<%- end -%>
|
9
9
|
|
10
10
|
<p>
|
11
11
|
<%- if action? :edit -%>
|
12
|
-
<%%= link_to "Edit",
|
12
|
+
<%%= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %> %> |
|
13
13
|
<%- end -%>
|
14
14
|
<%- if action? :destroy -%>
|
15
|
-
<%%= link_to "Destroy",
|
15
|
+
<%%= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete %> |
|
16
16
|
<%- end -%>
|
17
17
|
<%- if action? :index -%>
|
18
|
-
<%%= link_to "View All", <%=
|
18
|
+
<%%= link_to "View All", <%= items_path %> %>
|
19
19
|
<%- end -%>
|
20
20
|
</p>
|
@@ -5,10 +5,10 @@
|
|
5
5
|
<%- if actions? :show, :index -%>
|
6
6
|
%p
|
7
7
|
<%- if action? :show -%>
|
8
|
-
= link_to "Show", <%=
|
8
|
+
= link_to "Show", <%= item_path %>
|
9
9
|
|
|
10
10
|
<%- end -%>
|
11
11
|
<%- if action? :index -%>
|
12
|
-
= link_to "View All", <%=
|
12
|
+
= link_to "View All", <%= items_path %>
|
13
13
|
<%- end -%>
|
14
14
|
<%- end -%>
|
@@ -5,21 +5,21 @@
|
|
5
5
|
<%- for attribute in model_attributes -%>
|
6
6
|
%th <%= attribute.human_name %>
|
7
7
|
<%- end -%>
|
8
|
-
- for <%=
|
8
|
+
- for <%= instance_name %> in @<%= instances_name %>
|
9
9
|
%tr
|
10
10
|
<%- for attribute in model_attributes -%>
|
11
|
-
%td= <%=
|
11
|
+
%td= <%= instance_name %>.<%= attribute.name %>
|
12
12
|
<%- end -%>
|
13
13
|
<%- if action? :show -%>
|
14
|
-
%td= link_to 'Show', <%=
|
14
|
+
%td= link_to 'Show', <%= item_path %>
|
15
15
|
<%- end -%>
|
16
16
|
<%- if action? :edit -%>
|
17
|
-
%td= link_to 'Edit',
|
17
|
+
%td= link_to 'Edit', <%= item_path :action => :edit %>
|
18
18
|
<%- end -%>
|
19
19
|
<%- if action? :destroy -%>
|
20
|
-
%td= link_to 'Destroy', <%=
|
20
|
+
%td= link_to 'Destroy', <%= item_path %>, :confirm => 'Are you sure?', :method => :delete
|
21
21
|
<%- end -%>
|
22
22
|
|
23
23
|
<%- if actions? :new -%>
|
24
|
-
%p= link_to "New <%= singular_name.titleize %>",
|
24
|
+
%p= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %>
|
25
25
|
<%- end -%>
|
@@ -3,18 +3,18 @@
|
|
3
3
|
<%- for attribute in model_attributes -%>
|
4
4
|
%p
|
5
5
|
%strong <%= attribute.human_name.titleize %>:
|
6
|
-
= @<%=
|
6
|
+
= @<%= instance_name %>.<%= attribute.name %>
|
7
7
|
<%- end -%>
|
8
8
|
|
9
9
|
%p
|
10
10
|
<%- if action? :edit -%>
|
11
|
-
= link_to "Edit",
|
11
|
+
= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %>
|
12
12
|
|
|
13
13
|
<%- end -%>
|
14
14
|
<%- if action? :destroy -%>
|
15
|
-
= link_to "Destroy",
|
15
|
+
= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete
|
16
16
|
|
|
17
17
|
<%- end -%>
|
18
18
|
<%- if action? :index -%>
|
19
|
-
= link_to "View All", <%=
|
19
|
+
= link_to "View All", <%= items_path %>
|
20
20
|
<%- end -%>
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 4
|
9
|
+
version: 0.4.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ryan Bates
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-17 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|