Commit 223b8e80ba32a305b14b86520a7eae5b4abc85fa

Authored by Dan Croak
1 parent 5306b580

updating blitz

vendor/plugins/blitz/features/step_definitions/view_steps.rb
... ... @@ -45,3 +45,21 @@ Then /^an empty "(.*)" view for "posts" should be generated$/ do |view|
45 45 assert_generated_empty_file("app/views/posts/#{view}.html.erb")
46 46 end
47 47  
  48 +Then /^a model\-reflected "index" view for "posts" should be generated$/ do
  49 + assert_generated_file("app/views/posts/index.html.erb") do
  50 + "<h1>Posts</h1>\n\n" <<
  51 + "<ul>\n" <<
  52 + " <% @posts.each do |post| -%>\n" <<
  53 + " <li><%= link_to post.to_s, post_path(post) %></li>\n" <<
  54 + " <% end -%>\n" <<
  55 + "</ul>\n"
  56 + end
  57 +end
  58 +
  59 +Then /^a non\-model\-reflected "index" view for "posts" should be generated$/ do
  60 + assert_generated_file("app/views/posts/index.html.erb") do
  61 + "<h1>Posts</h1>"
  62 + end
  63 +end
  64 +
  65 +
... ...
vendor/plugins/blitz/features/view_generator.feature
... ... @@ -20,18 +20,19 @@ Feature: Rails view generator
20 20 Given a Rails app
21 21 And the blitz plugin is installed
22 22 When I generate a Post model with title, body, and User
23   - When I generate a "new" view for "Posts" with the empty option
  23 + And I generate a "new" view for "Posts" with the empty option
24 24 Then an empty "new" view for "posts" should be generated
25 25  
26   - Scenario: View generator for show action
  26 + Scenario: View generator for index action
27 27 Given a Rails app
28 28 And the blitz plugin is installed
29   - When I generate a "show" view for "Posts" with the empty option
30   - Then an empty "show" view for "posts" should be generated
  29 + When I generate a "index" view for "Posts"
  30 + Then a non-model-reflected "index" view for "posts" should be generated
31 31  
32 32 Scenario: View generator for index action
33 33 Given a Rails app
34 34 And the blitz plugin is installed
35   - When I generate a "index" view for "Posts" with the empty option
36   - Then an empty "index" view for "posts" should be generated
  35 + When I generate a Post model with title, body, and User
  36 + And I generate a "index" view for "Posts"
  37 + Then a model-reflected "index" view for "posts" should be generated
37 38  
... ...
vendor/plugins/blitz/generators/view/templates/index.html.erb
1   -<h1><%= resource %></h1>
2   -
3   -<%%= link_to 'Edit', edit_<%= resource %>_path(@<%= resource %>) %>
  1 +<h1><%= resource_class.pluralize %></h1>
  2 +<% if active_record_defined? -%>
4 3  
  4 +<ul>
  5 + <%% @<%= resources %>.each do |<%= resource %>| -%>
  6 + <li><%%= link_to <%= resource %>.to_s, <%= resource %>_path(<%= resource %>) %></li>
  7 + <%% end -%>
  8 +</ul>
  9 +<% end -%>
... ...
vendor/plugins/blitz/generators/view/view_generator.rb
... ... @@ -14,12 +14,10 @@ class ViewGenerator &lt; Rails::Generator::NamedBase
14 14 else
15 15 m.template 'new.html.erb', path
16 16 end
17   - elsif %w(index show).any? { |action| actions.include?(action) }
18   - actions.each do |action|
19   - path = File.join('app/views', class_path, file_name,
20   - "#{action}.html.erb")
21   - m.file 'empty.html.erb', path
22   - end
  17 + elsif actions.include?("index")
  18 + path = File.join('app/views', class_path, file_name,
  19 + "index.html.erb")
  20 + m.template "index.html.erb", path
23 21 end
24 22 end
25 23 end
... ...