view_mapper 0.1.0 → 0.2.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/README.rdoc +44 -0
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/generators/view_for/view_for_generator.rb +6 -2
- data/lib/view_mapper/paperclip_templates/controller.rb +85 -0
- data/lib/view_mapper/paperclip_templates/fixtures.yml +19 -0
- data/lib/view_mapper/paperclip_templates/functional_test.rb +45 -0
- data/lib/view_mapper/paperclip_templates/helper.rb +2 -0
- data/lib/view_mapper/paperclip_templates/helper_test.rb +4 -0
- data/lib/view_mapper/paperclip_templates/layout.html.erb +17 -0
- data/lib/view_mapper/paperclip_templates/migration.rb +22 -0
- data/lib/view_mapper/paperclip_templates/model.rb +8 -0
- data/lib/view_mapper/paperclip_templates/style.css +54 -0
- data/lib/view_mapper/paperclip_templates/unit_test.rb +8 -0
- data/lib/view_mapper/paperclip_templates/view_edit.html.erb +23 -0
- data/lib/view_mapper/paperclip_templates/view_index.html.erb +24 -0
- data/lib/view_mapper/paperclip_templates/view_new.html.erb +22 -0
- data/lib/view_mapper/paperclip_templates/view_show.html.erb +17 -0
- data/lib/view_mapper/paperclip_view.rb +125 -0
- data/lib/view_mapper/view_mapper.rb +4 -0
- data/lib/view_mapper.rb +1 -0
- data/test/auto_complete_test.rb +0 -17
- data/test/expected_templates/paperclip/create_testies.rb +23 -0
- data/test/expected_templates/paperclip/edit.html.erb +31 -0
- data/test/expected_templates/paperclip/index.html.erb +24 -0
- data/test/expected_templates/paperclip/new.html.erb +30 -0
- data/test/expected_templates/paperclip/show.html.erb +28 -0
- data/test/expected_templates/paperclip/testy.rb +4 -0
- data/test/paperclip_view_test.rb +299 -0
- data/test/rails_generator/generators/components/model/model_generator.rb +45 -0
- data/test/test_helper.rb +55 -7
- data/test/view_for_generator_test.rb +2 -2
- data/view_mapper.gemspec +31 -4
- metadata +31 -4
- data/README +0 -116
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Listing testies</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>First name</th>
|
6
|
+
<th>Last name</th>
|
7
|
+
<th>Address</th>
|
8
|
+
</tr>
|
9
|
+
|
10
|
+
<% @testies.each do |testy| %>
|
11
|
+
<tr>
|
12
|
+
<td><%=h testy.first_name %></td>
|
13
|
+
<td><%=h testy.last_name %></td>
|
14
|
+
<td><%=h testy.address %></td>
|
15
|
+
<td><%= link_to 'Show', testy %></td>
|
16
|
+
<td><%= link_to 'Edit', edit_testy_path(testy) %></td>
|
17
|
+
<td><%= link_to 'Destroy', testy, :confirm => 'Are you sure?', :method => :delete %></td>
|
18
|
+
</tr>
|
19
|
+
<% end %>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<br />
|
23
|
+
|
24
|
+
<%= link_to 'New testy', new_testy_path %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<h1>New testy</h1>
|
2
|
+
|
3
|
+
<% form_for(@testy, :html => { :multipart => true }) do |f| %>
|
4
|
+
<%= f.error_messages %>
|
5
|
+
<p>
|
6
|
+
<%= f.label :first_name %><br />
|
7
|
+
<%= f.text_field :first_name %>
|
8
|
+
</p>
|
9
|
+
<p>
|
10
|
+
<%= f.label :last_name %><br />
|
11
|
+
<%= f.text_field :last_name %>
|
12
|
+
</p>
|
13
|
+
<p>
|
14
|
+
<%= f.label :address %><br />
|
15
|
+
<%= f.text_field :address %>
|
16
|
+
</p>
|
17
|
+
<p>
|
18
|
+
<%= f.label :avatar %><br />
|
19
|
+
<%= f.file_field :avatar %>
|
20
|
+
</p>
|
21
|
+
<p>
|
22
|
+
<%= f.label :avatar2 %><br />
|
23
|
+
<%= f.file_field :avatar2 %>
|
24
|
+
</p>
|
25
|
+
<p>
|
26
|
+
<%= f.submit 'Create' %>
|
27
|
+
</p>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<%= link_to 'Back', testies_path %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<p>
|
2
|
+
<b>First name:</b>
|
3
|
+
<%=h @testy.first_name %>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<b>Last name:</b>
|
8
|
+
<%=h @testy.last_name %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Address:</b>
|
13
|
+
<%=h @testy.address %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<b>Avatar:</b>
|
18
|
+
<%= link_to @testy.avatar_file_name, @testy.avatar.url %><br>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<b>Avatar2:</b>
|
23
|
+
<%= link_to @testy.avatar2_file_name, @testy.avatar2.url %><br>
|
24
|
+
</p>
|
25
|
+
|
26
|
+
|
27
|
+
<%= link_to 'Edit', edit_testy_path(@testy) %> |
|
28
|
+
<%= link_to 'Back', testies_path %>
|
@@ -0,0 +1,299 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PaperclipViewTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
attr_reader :singular_name
|
6
|
+
attr_reader :attributes
|
7
|
+
attr_reader :plural_name
|
8
|
+
attr_reader :attachments
|
9
|
+
attr_reader :class_name
|
10
|
+
attr_reader :migration_name
|
11
|
+
attr_reader :table_name
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
context "A view_for generator instantiated for a test model" do
|
15
|
+
setup do
|
16
|
+
setup_test_model(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "detect the existing attachments when no attachment is specified" do
|
20
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'paperclip'])
|
21
|
+
assert_contains gen.attachments, 'avatar'
|
22
|
+
assert_contains gen.attachments, 'avatar2'
|
23
|
+
end
|
24
|
+
|
25
|
+
should "use the specified attachments if provided" do
|
26
|
+
gen = new_generator_for_test_model('view_for', ['--view', 'paperclip:avatar'])
|
27
|
+
assert_equal [ 'avatar' ], gen.attachments
|
28
|
+
end
|
29
|
+
|
30
|
+
should "return an error message with a bad paperclip param" do
|
31
|
+
Rails::Generator::Base.logger.expects('error').with('Attachment \'blah\' does not exist.')
|
32
|
+
new_generator_for_test_model('view_for', ['--view', 'paperclip:blah'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "A view_for generator instantiated for a test model" do
|
37
|
+
setup do
|
38
|
+
setup_test_model(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with missing paperclip columns" do
|
42
|
+
setup do
|
43
|
+
Struct.new("FakeColumn", :name)
|
44
|
+
@fake_cols = [ Struct::FakeColumn.new("first_name"), Struct::FakeColumn.new("last_name"), Struct::FakeColumn.new("address") ]
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return an error message with a bad paperclip param" do
|
48
|
+
Rails::Generator::Base.logger.expects('error').with('Column \'avatar_file_name\' does not exist. First run script/generate paperclip testy avatar.')
|
49
|
+
new_generator_for_test_model('view_for', ['--view', 'paperclip:avatar'])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "A test model with no attachments" do
|
55
|
+
setup do
|
56
|
+
setup_test_model(true)
|
57
|
+
Testy.class_eval do
|
58
|
+
def self.attachment_definitions
|
59
|
+
{}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
teardown do
|
65
|
+
Testy.class_eval do
|
66
|
+
def self.attachment_definitions
|
67
|
+
{ :avatar => {:validations => []}, :avatar2 => {:validations => []} }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
should "return a warning when run with view_for when no attachment exists and not run any actions" do
|
73
|
+
Rails::Generator::Base.logger.expects('warning').with('No paperclip attachments exist on the specified class.')
|
74
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
75
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
76
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
77
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
78
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
79
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
80
|
+
Rails::Generator::Base.logger.stubs(:error)
|
81
|
+
Rails::Generator::Base.logger.stubs(:route)
|
82
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
83
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'paperclip']))
|
84
|
+
end
|
85
|
+
|
86
|
+
should "return a warning when run with scaffold_for_view when no attachment exists and not run any actions" do
|
87
|
+
Rails::Generator::Base.logger.expects('warning').with('No paperclip attachments specified.')
|
88
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
89
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
90
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
91
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
92
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
93
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
94
|
+
Rails::Generator::Base.logger.stubs(:error)
|
95
|
+
Rails::Generator::Base.logger.stubs(:route)
|
96
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
97
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'paperclip']))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "A scaffold_for_view generator with no model" do
|
102
|
+
setup do
|
103
|
+
ActiveRecord::Base.send(:include, MockPaperclip)
|
104
|
+
end
|
105
|
+
|
106
|
+
should "use the specified attachments if provided" do
|
107
|
+
gen = new_generator_for_test_model('scaffold_for_view', ['--view', 'paperclip:avatar3,avatar4'])
|
108
|
+
assert_contains gen.attachments, 'avatar3'
|
109
|
+
assert_contains gen.attachments, 'avatar4'
|
110
|
+
end
|
111
|
+
|
112
|
+
should "not detect the existing attachments when no attachment is specified" do
|
113
|
+
Rails::Generator::Base.logger.expects('warning').with('No paperclip attachments specified.')
|
114
|
+
gen = new_generator_for_test_model('scaffold_for_view', ['--view', 'paperclip'])
|
115
|
+
assert_equal [], gen.attachments
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "A view_for gen with no model" do
|
120
|
+
should "not return an error message when paperclip is installed" do
|
121
|
+
Rails::Generator::Base.logger.expects('error').never
|
122
|
+
ActiveRecord::Base.send(:include, MockPaperclip)
|
123
|
+
new_generator_for_test_model('view_for', ['--view', 'paperclip:avatar'])
|
124
|
+
end
|
125
|
+
|
126
|
+
should "return an error message when paperclip is not installed" do
|
127
|
+
Rails::Generator::Base.logger.expects('error').with('The Paperclip plugin does not appear to be installed.')
|
128
|
+
ActiveRecord::Base.stubs(:methods).returns([])
|
129
|
+
new_generator_for_test_model('view_for', ['--view', 'paperclip:avatar'])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "A view_for generator instantiated for a test model with two attachments" do
|
134
|
+
setup do
|
135
|
+
setup_test_model(true)
|
136
|
+
@gen = new_generator_for_test_model('view_for', ['--view', 'paperclip'])
|
137
|
+
end
|
138
|
+
|
139
|
+
should "return the proper source root folder" do
|
140
|
+
assert_equal './test/../lib/view_mapper/paperclip_templates', @gen.source_root
|
141
|
+
end
|
142
|
+
|
143
|
+
should "have the proper built in columns" do
|
144
|
+
assert_equal [ 'id',
|
145
|
+
'created_at',
|
146
|
+
'updated_at',
|
147
|
+
'avatar_file_name',
|
148
|
+
'avatar_content_type',
|
149
|
+
'avatar_file_size',
|
150
|
+
'avatar_updated_at',
|
151
|
+
'avatar2_file_name',
|
152
|
+
'avatar2_content_type',
|
153
|
+
'avatar2_file_size',
|
154
|
+
'avatar2_updated_at'
|
155
|
+
].sort,
|
156
|
+
@gen.built_in_columns.sort
|
157
|
+
end
|
158
|
+
|
159
|
+
view_for_templates = %w{ new edit index show }
|
160
|
+
view_for_templates.each do | template |
|
161
|
+
should "render the #{template} template as expected" do
|
162
|
+
@attributes = @gen.attributes
|
163
|
+
@singular_name = @gen.singular_name
|
164
|
+
@plural_name = @gen.plural_name
|
165
|
+
@attachments = @gen.attachments
|
166
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/view_#{template}.html.erb"))
|
167
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
168
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/#{template}.html.erb"))
|
169
|
+
assert_equal expected_file.read, result
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "A Rails generator script run on a testy model" do
|
175
|
+
setup do
|
176
|
+
setup_test_model(true)
|
177
|
+
@generator_script = Rails::Generator::Scripts::Generate.new
|
178
|
+
end
|
179
|
+
|
180
|
+
should "not perform any actions when run on the view_for generator with an invalid paperclip field" do
|
181
|
+
Rails::Generator::Commands::Create.any_instance.expects(:directory).never
|
182
|
+
Rails::Generator::Commands::Create.any_instance.expects(:template).never
|
183
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).never
|
184
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
185
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route).never
|
186
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
187
|
+
Rails::Generator::Base.logger.stubs(:error)
|
188
|
+
Rails::Generator::Base.logger.stubs(:route)
|
189
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'paperclip:blah']))
|
190
|
+
end
|
191
|
+
|
192
|
+
should "create a normal view_for manifest when the view_for generator is run with a valid attachment" do
|
193
|
+
|
194
|
+
directories = [
|
195
|
+
'app/controllers/',
|
196
|
+
'app/helpers/',
|
197
|
+
'app/views/testies',
|
198
|
+
'app/views/layouts/',
|
199
|
+
'test/functional/',
|
200
|
+
'test/unit/',
|
201
|
+
'test/unit/helpers/',
|
202
|
+
'public/stylesheets/'
|
203
|
+
].each { |path| Rails::Generator::Commands::Create.any_instance.expects(:directory).with(path) }
|
204
|
+
|
205
|
+
templates = {
|
206
|
+
'view_index.html.erb' => 'app/views/testies/index.html.erb',
|
207
|
+
'view_show.html.erb' => 'app/views/testies/show.html.erb',
|
208
|
+
'view_new.html.erb' => 'app/views/testies/new.html.erb',
|
209
|
+
'view_edit.html.erb' => 'app/views/testies/edit.html.erb',
|
210
|
+
'layout.html.erb' => 'app/views/layouts/testies.html.erb',
|
211
|
+
'style.css' => 'public/stylesheets/scaffold.css',
|
212
|
+
'controller.rb' => 'app/controllers/testies_controller.rb',
|
213
|
+
'functional_test.rb' => 'test/functional/testies_controller_test.rb',
|
214
|
+
'helper.rb' => 'app/helpers/testies_helper.rb',
|
215
|
+
'helper_test.rb' => 'test/unit/helpers/testies_helper_test.rb'
|
216
|
+
}.each { |template, target| Rails::Generator::Commands::Create.any_instance.expects(:template).with(template, target) }
|
217
|
+
|
218
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).with('testies')
|
219
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
220
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
221
|
+
|
222
|
+
@generator_script.run(generator_script_cmd_line('view_for', ['--view', 'paperclip:avatar']))
|
223
|
+
end
|
224
|
+
|
225
|
+
should "create a manifest containing model actions when the scaffold_for_view generator is run with a valid attachment" do
|
226
|
+
|
227
|
+
directories = [
|
228
|
+
'app/models/',
|
229
|
+
'app/controllers/',
|
230
|
+
'app/helpers/',
|
231
|
+
'app/views/testies',
|
232
|
+
'app/views/layouts/',
|
233
|
+
'test/functional/',
|
234
|
+
'test/unit/',
|
235
|
+
'test/unit/helpers/',
|
236
|
+
'test/fixtures/',
|
237
|
+
'public/stylesheets/'
|
238
|
+
].each { |path| Rails::Generator::Commands::Create.any_instance.expects(:directory).with(path) }
|
239
|
+
|
240
|
+
templates = {
|
241
|
+
'view_index.html.erb' => 'app/views/testies/index.html.erb',
|
242
|
+
'view_show.html.erb' => 'app/views/testies/show.html.erb',
|
243
|
+
'view_new.html.erb' => 'app/views/testies/new.html.erb',
|
244
|
+
'view_edit.html.erb' => 'app/views/testies/edit.html.erb',
|
245
|
+
'layout.html.erb' => 'app/views/layouts/testies.html.erb',
|
246
|
+
'style.css' => 'public/stylesheets/scaffold.css',
|
247
|
+
'controller.rb' => 'app/controllers/testies_controller.rb',
|
248
|
+
'functional_test.rb' => 'test/functional/testies_controller_test.rb',
|
249
|
+
'helper.rb' => 'app/helpers/testies_helper.rb',
|
250
|
+
'helper_test.rb' => 'test/unit/helpers/testies_helper_test.rb',
|
251
|
+
'model.rb' => 'app/models/testy.rb',
|
252
|
+
'unit_test.rb' => 'test/unit/testy_test.rb',
|
253
|
+
'fixtures.yml' => 'test/fixtures/testies.yml'
|
254
|
+
}.each { |template, target| Rails::Generator::Commands::Create.any_instance.expects(:template).with(template, target) }
|
255
|
+
|
256
|
+
Rails::Generator::Commands::Create.any_instance.expects(:route_resources).with('testies')
|
257
|
+
Rails::Generator::Commands::Create.any_instance.expects(:file).never
|
258
|
+
Rails::Generator::Commands::Create.any_instance.expects(:dependency).never
|
259
|
+
|
260
|
+
Rails::Generator::Commands::Create.any_instance.expects(:migration_template).with(
|
261
|
+
'migration.rb',
|
262
|
+
'db/migrate',
|
263
|
+
:assigns => { :migration_name => "CreateTesties" },
|
264
|
+
:migration_file_name => "create_testies"
|
265
|
+
)
|
266
|
+
|
267
|
+
@generator_script.run(generator_script_cmd_line('scaffold_for_view', ['--view', 'paperclip:avatar']))
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context "A scaffold_for_view generator instantiated for a test model with an avatar attachment" do
|
272
|
+
setup do
|
273
|
+
@gen = new_generator_for_test_model('scaffold_for_view', ['--view', 'paperclip:avatar,avatar2'])
|
274
|
+
end
|
275
|
+
|
276
|
+
should "render the model template as expected" do
|
277
|
+
@class_name = @gen.class_name
|
278
|
+
@attributes = @gen.attributes
|
279
|
+
@attachments = @gen.attachments
|
280
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/model.rb"))
|
281
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
282
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/testy.rb"))
|
283
|
+
assert_equal expected_file.read, result
|
284
|
+
end
|
285
|
+
|
286
|
+
should "render the migration template as expected" do
|
287
|
+
@class_name = @gen.class_name
|
288
|
+
@attributes = @gen.attributes
|
289
|
+
@attachments = @gen.attachments
|
290
|
+
@migration_name = 'CreateTesties'
|
291
|
+
@table_name = @gen.table_name
|
292
|
+
@options = {}
|
293
|
+
template_file = File.open(File.join(File.dirname(__FILE__), "/../lib/view_mapper/paperclip_templates/migration.rb"))
|
294
|
+
result = ERB.new(template_file.read, nil, '-').result(binding)
|
295
|
+
expected_file = File.open(File.join(File.dirname(__FILE__), "expected_templates/paperclip/create_testies.rb"))
|
296
|
+
assert_equal expected_file.read, result
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class ModelGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false
|
3
|
+
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
# Check for class naming collisions.
|
7
|
+
m.class_collisions class_name, "#{class_name}Test"
|
8
|
+
|
9
|
+
# Model, test, and fixture directories.
|
10
|
+
m.directory File.join('app/models', class_path)
|
11
|
+
m.directory File.join('test/unit', class_path)
|
12
|
+
m.directory File.join('test/fixtures', class_path)
|
13
|
+
|
14
|
+
# Model class, unit test, and fixtures.
|
15
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
16
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
17
|
+
|
18
|
+
unless options[:skip_fixture]
|
19
|
+
m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
|
20
|
+
end
|
21
|
+
|
22
|
+
unless options[:skip_migration]
|
23
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
24
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
25
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def banner
|
32
|
+
"Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_options!(opt)
|
36
|
+
opt.separator ''
|
37
|
+
opt.separator 'Options:'
|
38
|
+
opt.on("--skip-timestamps",
|
39
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
40
|
+
opt.on("--skip-migration",
|
41
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
42
|
+
opt.on("--skip-fixture",
|
43
|
+
"Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
|
44
|
+
end
|
45
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -26,18 +26,66 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
26
26
|
require 'view_mapper'
|
27
27
|
require 'fake_view'
|
28
28
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
table.column :
|
29
|
+
def setup_test_table(paperclip_columns = false)
|
30
|
+
ActiveRecord::Base.connection.create_table :testies, :force => true do |table|
|
31
|
+
table.column :first_name, :string
|
32
|
+
table.column :last_name, :string
|
33
|
+
table.column :address, :string
|
34
|
+
if paperclip_columns
|
35
|
+
table.column :avatar_file_name, :string
|
36
|
+
table.column :avatar_content_type, :string
|
37
|
+
table.column :avatar_file_size, :integer
|
38
|
+
table.column :avatar_updated_at, :datetime
|
39
|
+
table.column :avatar2_file_name, :string
|
40
|
+
table.column :avatar2_content_type, :string
|
41
|
+
table.column :avatar2_file_size, :integer
|
42
|
+
table.column :avatar2_updated_at, :datetime
|
36
43
|
end
|
37
44
|
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_test_model(missing_columns = false)
|
48
|
+
setup_test_table(missing_columns)
|
49
|
+
Object.send(:remove_const, "Testy") rescue nil
|
50
|
+
Object.const_set("Testy", Class.new(ActiveRecord::Base))
|
51
|
+
Testy.class_eval do
|
52
|
+
def self.attachment_definitions
|
53
|
+
{ :avatar => {:validations => []}, :avatar2 => {:validations => []} }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ActiveRecord::Base.send(:include, MockPaperclip)
|
38
57
|
Object.const_get("Testy")
|
39
58
|
end
|
40
59
|
|
60
|
+
module MockPaperclip
|
61
|
+
class << self
|
62
|
+
def included(base)
|
63
|
+
base.extend(ClassMethods)
|
64
|
+
end
|
65
|
+
module ClassMethods
|
66
|
+
def has_attached_file
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
41
72
|
class Rails::Generator::NamedBase
|
42
73
|
public :attributes
|
43
74
|
end
|
75
|
+
|
76
|
+
def generator_cmd_line(gen, args)
|
77
|
+
if gen == 'view_for'
|
78
|
+
cmd_line = ['testy']
|
79
|
+
else
|
80
|
+
cmd_line = ['testy', 'first_name:string', 'last_name:string', 'address:string']
|
81
|
+
end
|
82
|
+
(cmd_line << args).flatten
|
83
|
+
end
|
84
|
+
|
85
|
+
def generator_script_cmd_line(gen, args)
|
86
|
+
([gen] << generator_cmd_line(gen, args)).flatten
|
87
|
+
end
|
88
|
+
|
89
|
+
def new_generator_for_test_model(gen, args)
|
90
|
+
Rails::Generator::Base.instance(gen, generator_cmd_line(gen, args))
|
91
|
+
end
|
@@ -20,7 +20,7 @@ class ViewForGeneratorTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
should "display error message with a bad model name when run on view_for" do
|
23
|
-
Rails::Generator::Base.logger.expects('error').with('Class \'blah\' does not exist.')
|
23
|
+
Rails::Generator::Base.logger.expects('error').with('Class \'blah\' does not exist or contains a syntax error and could not be loaded.')
|
24
24
|
@generator_script.run(['view_for', 'blah'])
|
25
25
|
end
|
26
26
|
|
@@ -79,7 +79,7 @@ class ViewForGeneratorTest < Test::Unit::TestCase
|
|
79
79
|
end
|
80
80
|
|
81
81
|
should "have the proper model name" do
|
82
|
-
assert_equal @model, @view_for_gen.model
|
82
|
+
assert_equal @model.name, @view_for_gen.model.name
|
83
83
|
end
|
84
84
|
|
85
85
|
should "have the proper attributes for ERB" do
|
data/view_mapper.gemspec
CHANGED
@@ -5,22 +5,22 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{view_mapper}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pat Shaughnessy"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-16}
|
13
13
|
s.description = %q{Generate complex view code for your models}
|
14
14
|
s.email = %q{pat@patshaughnessy.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README"
|
17
|
+
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
"LICENSE",
|
23
|
-
"README",
|
23
|
+
"README.rdoc",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"generators/scaffold_for_view/USAGE",
|
@@ -40,6 +40,21 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/view_mapper/auto_complete_templates/view_show.html.erb",
|
41
41
|
"lib/view_mapper/auto_complete_view.rb",
|
42
42
|
"lib/view_mapper/editable_manifest.rb",
|
43
|
+
"lib/view_mapper/paperclip_templates/controller.rb",
|
44
|
+
"lib/view_mapper/paperclip_templates/fixtures.yml",
|
45
|
+
"lib/view_mapper/paperclip_templates/functional_test.rb",
|
46
|
+
"lib/view_mapper/paperclip_templates/helper.rb",
|
47
|
+
"lib/view_mapper/paperclip_templates/helper_test.rb",
|
48
|
+
"lib/view_mapper/paperclip_templates/layout.html.erb",
|
49
|
+
"lib/view_mapper/paperclip_templates/migration.rb",
|
50
|
+
"lib/view_mapper/paperclip_templates/model.rb",
|
51
|
+
"lib/view_mapper/paperclip_templates/style.css",
|
52
|
+
"lib/view_mapper/paperclip_templates/unit_test.rb",
|
53
|
+
"lib/view_mapper/paperclip_templates/view_edit.html.erb",
|
54
|
+
"lib/view_mapper/paperclip_templates/view_index.html.erb",
|
55
|
+
"lib/view_mapper/paperclip_templates/view_new.html.erb",
|
56
|
+
"lib/view_mapper/paperclip_templates/view_show.html.erb",
|
57
|
+
"lib/view_mapper/paperclip_view.rb",
|
43
58
|
"lib/view_mapper/route_action.rb",
|
44
59
|
"lib/view_mapper/view_mapper.rb",
|
45
60
|
"test/auto_complete_test.rb",
|
@@ -53,12 +68,20 @@ Gem::Specification.new do |s|
|
|
53
68
|
"test/expected_templates/auto_complete/standard_routes.rb",
|
54
69
|
"test/expected_templates/auto_complete/testies.html.erb",
|
55
70
|
"test/expected_templates/auto_complete/testies_controller.rb",
|
71
|
+
"test/expected_templates/paperclip/create_testies.rb",
|
72
|
+
"test/expected_templates/paperclip/edit.html.erb",
|
73
|
+
"test/expected_templates/paperclip/index.html.erb",
|
74
|
+
"test/expected_templates/paperclip/new.html.erb",
|
75
|
+
"test/expected_templates/paperclip/show.html.erb",
|
76
|
+
"test/expected_templates/paperclip/testy.rb",
|
56
77
|
"test/fake/fake_generator.rb",
|
57
78
|
"test/fake_view.rb",
|
79
|
+
"test/paperclip_view_test.rb",
|
58
80
|
"test/rails_generator.rb",
|
59
81
|
"test/rails_generator/base.rb",
|
60
82
|
"test/rails_generator/commands.rb",
|
61
83
|
"test/rails_generator/generated_attribute.rb",
|
84
|
+
"test/rails_generator/generators/components/model/model_generator.rb",
|
62
85
|
"test/rails_generator/generators/components/scaffold/scaffold_generator.rb",
|
63
86
|
"test/rails_generator/lookup.rb",
|
64
87
|
"test/rails_generator/manifest.rb",
|
@@ -87,11 +110,15 @@ Gem::Specification.new do |s|
|
|
87
110
|
"test/expected_templates/auto_complete/expected_routes.rb",
|
88
111
|
"test/expected_templates/auto_complete/standard_routes.rb",
|
89
112
|
"test/expected_templates/auto_complete/testies_controller.rb",
|
113
|
+
"test/expected_templates/paperclip/create_testies.rb",
|
114
|
+
"test/expected_templates/paperclip/testy.rb",
|
90
115
|
"test/fake/fake_generator.rb",
|
91
116
|
"test/fake_view.rb",
|
117
|
+
"test/paperclip_view_test.rb",
|
92
118
|
"test/rails_generator/base.rb",
|
93
119
|
"test/rails_generator/commands.rb",
|
94
120
|
"test/rails_generator/generated_attribute.rb",
|
121
|
+
"test/rails_generator/generators/components/model/model_generator.rb",
|
95
122
|
"test/rails_generator/generators/components/scaffold/scaffold_generator.rb",
|
96
123
|
"test/rails_generator/lookup.rb",
|
97
124
|
"test/rails_generator/manifest.rb",
|