grimen-dry_scaffold 0.2.6 → 0.3.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.
Files changed (56) hide show
  1. data/CHANGELOG.textile +6 -0
  2. data/README.textile +26 -17
  3. data/TODO.textile +43 -6
  4. data/config/scaffold.yml +14 -6
  5. data/generators/dry_model/USAGE +2 -5
  6. data/generators/dry_model/dry_model_generator.rb +68 -145
  7. data/generators/dry_model/prototypes/active_record_migration.rb +1 -1
  8. data/generators/dry_model/prototypes/active_record_model.rb +2 -2
  9. data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
  10. data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
  11. data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
  12. data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
  13. data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +8 -2
  14. data/generators/dry_model/templates/models/active_record_migration.rb +2 -2
  15. data/generators/dry_model/templates/models/{test_data → fixture_data}/active_record_fixtures.yml +1 -1
  16. data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
  17. data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
  18. data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
  19. data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +10 -2
  20. data/generators/dry_scaffold/USAGE +4 -5
  21. data/generators/dry_scaffold/dry_scaffold_generator.rb +145 -151
  22. data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +53 -52
  23. data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +5 -4
  24. data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +107 -0
  25. data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +76 -0
  26. data/generators/dry_scaffold/prototypes/helpers/helper.rb +1 -1
  27. data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
  28. data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +6 -2
  29. data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +9 -9
  30. data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +7 -7
  31. data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +6 -6
  32. data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +3 -3
  33. data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +5 -5
  34. data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +1 -2
  35. data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +3 -3
  36. data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +6 -6
  37. data/generators/dry_scaffold/templates/controllers/action_controller.rb +7 -6
  38. data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +2 -2
  39. data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
  40. data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +46 -37
  41. data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
  42. data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +4 -0
  43. data/generators/dry_scaffold/templates/views/haml/_item.html.haml +3 -3
  44. data/generators/dry_scaffold/templates/views/haml/edit.html.haml +1 -1
  45. data/generators/dry_scaffold/templates/views/haml/index.html.haml +1 -1
  46. data/generators/dry_scaffold/templates/views/haml/new.html.haml +1 -1
  47. data/generators/dry_scaffold/templates/views/haml/show.html.haml +2 -2
  48. data/lib/dry_generator.rb +176 -0
  49. data/tasks/dry_scaffold.rake +5 -1
  50. metadata +16 -9
  51. data/generators/dry_model/prototypes/test_data/active_record_fixtures.yml +0 -3
  52. data/generators/dry_model/prototypes/test_data/factory_girl_factories.rb +0 -4
  53. data/generators/dry_model/prototypes/test_data/machinist_factories.rb +0 -8
  54. data/generators/dry_model/templates/models/test_data/factory_girl_factories.rb +0 -5
  55. data/generators/dry_model/templates/models/test_data/machinist_factories.rb +0 -9
  56. data/generators/dry_scaffold/prototypes/controllers/tests/unit_test/functional_test.rb +0 -64
@@ -1,18 +1,18 @@
1
1
  xml.instruct! :xml, :version => '1.0'
2
2
  xml.rss(:version => '2.0') do
3
3
  xml.channel do
4
- xml.title 'Resources'
5
- xml.description 'Index of all resources.'
6
- xml.link resources_url(:rss)
7
- xml.lastBuildDate (@resources.first.created_at rescue Time.now.utc).to_s(:rfc822)
4
+ xml.title 'Ducks'
5
+ xml.description 'Index of all ducks.'
6
+ xml.link ducks_url(:rss)
7
+ xml.lastBuildDate (@ducks.first.created_at rescue Time.now.utc).to_s(:rfc822)
8
8
  xml.language I18n.locale
9
9
 
10
- @resources.each do |resource|
10
+ @ducks.each do |duck|
11
11
  xml.item do
12
12
  xml.title 'title'
13
13
  xml.description 'summary'
14
- xml.pubDate resource.try(:created_at).to_s(:rfc822)
15
- xml.link resource_url(resource, :rss)
14
+ xml.pubDate duck.try(:created_at).to_s(:rfc822)
15
+ xml.link duck_url(duck, :rss)
16
16
 
17
17
  xml.author 'author_name'
18
18
  end
@@ -1,9 +1,9 @@
1
- - content_tag_for(:tr, resource) do
2
- %td.title= h resource.try(:title)
3
- %td.description= h resource.try(:description)
1
+ - content_tag_for(:tr, duck) do
2
+ %td.title= h duck.try(:title)
3
+ %td.description= h duck.try(:description)
4
4
  %td.actions
5
- = link_to 'Show', resource_url(resource)
5
+ = link_to 'Show', duck_url(duck)
6
6
  |
7
- = link_to 'Edit', edit_resource_url(resource)
7
+ = link_to 'Edit', edit_duck_url(duck)
8
8
  |
9
- = link_to 'Destroy', resource_url(resource), :confirm => 'Are you sure?', :method => :delete
9
+ = link_to 'Destroy', duck_url(duck), :confirm => 'Are you sure?', :method => :delete
@@ -1,10 +1,10 @@
1
1
  %h1.heading
2
- = "Editing resource %s" % @resource.id
2
+ = "Editing duck %s" % @duck.id
3
3
 
4
- - semantic_form_for(@resource) do |form|
4
+ - semantic_form_for(@duck) do |form|
5
5
  = render 'form', :form => form
6
6
  - form.buttons do
7
7
  = form.commit_button 'Update'
8
8
 
9
9
  %p.actions
10
- = link_to 'Cancel', resources_url
10
+ = link_to 'Cancel', ducks_url
@@ -1,8 +1,8 @@
1
1
  %h1.heading
2
- = 'Sections'
2
+ = 'Ducks'
3
3
 
4
4
  %p.actions
5
- = link_to 'New resource', new_resource_url
5
+ = link_to 'New duck', new_duck_url
6
6
 
7
7
  %table
8
8
  %thead.header
@@ -11,7 +11,7 @@
11
11
  %th.description= 'Description'
12
12
  %th.actions= 'Actions'
13
13
  %tbody.items.resources
14
- - @collection.each do |resource|
15
- = render 'item', :resource => resource
14
+ - @ducks.each do |duck|
15
+ = render 'item', :duck => duck
16
16
 
17
- = will_paginate(@collection)
17
+ = will_paginate(@ducks)
@@ -1,6 +1,5 @@
1
1
  !!! 1.1
2
-
3
- %html{html_attrs(I18n.locale)}
2
+ %html{html_attrs(I18n.locale).update(:lang => nil)}
4
3
  %head
5
4
  %title= "#{controller_class_name}: #{controller.action_name}"
6
5
 
@@ -1,10 +1,10 @@
1
1
  %h1.heading
2
- = 'New resource'
2
+ = 'New duck'
3
3
 
4
- - semantic_form_for(@resource) do |form|
4
+ - semantic_form_for(@duck) do |form|
5
5
  = render 'form', :form => form
6
6
  - form.buttons do
7
7
  = form.commit_button 'Create'
8
8
 
9
9
  %p.actions
10
- = link_to 'Cancel', resources_url
10
+ = link_to 'Cancel', ducks_url
@@ -1,13 +1,13 @@
1
1
  %h1.heading
2
- = "Resource %s" % @resource.id
2
+ = "Duck %s" % @duck.id
3
3
 
4
- - content_tag_for(:dl, @resource) do
4
+ - content_tag_for(:dl, @duck) do
5
5
  %dt.label= 'Title'
6
- %dd.title= h @resource.try(:title)
6
+ %dd.title= h @duck.try(:title)
7
7
  %dt.label= 'Description'
8
- %dd.description= h @resource.try(:description)
8
+ %dd.description= h @duck.try(:description)
9
9
 
10
10
  %p.actions
11
- = link_to 'Edit', edit_resource_url(@resource)
11
+ = link_to 'Edit', edit_duck_url(@duck)
12
12
  |
13
- = link_to 'Index', resources_url
13
+ = link_to 'Index', ducks_url
@@ -105,7 +105,7 @@ class <%= controller_class_name %>Controller < ApplicationController
105
105
 
106
106
  respond_to do |format|
107
107
  if <%= resource_instance %>.save
108
- flash[:notice] = '<%= singular_name.humanize %> was successfully created.'
108
+ flash[:notice] = "<%= singular_name.humanize %> was successfully created."
109
109
  <% formats.each do |_format| -%>
110
110
  <% case _format when :html then -%>
111
111
  format.html { redirect_to(<%= resource_instance %>) }
@@ -122,7 +122,7 @@ class <%= controller_class_name %>Controller < ApplicationController
122
122
  <% end -%>
123
123
  <% end -%>
124
124
  else
125
- #flash[:error] = '<%= singular_name.humanize %> could not be created.'
125
+ flash[:error] = "<%= singular_name.humanize %> could not be created."
126
126
  <% formats.each do |_format| -%>
127
127
  <% case _format when :html then -%>
128
128
  format.html { render 'new' }
@@ -150,6 +150,7 @@ class <%= controller_class_name %>Controller < ApplicationController
150
150
  def update
151
151
  respond_to do |format|
152
152
  if <%= resource_instance %>.update_attributes(params[:<%= singular_name %>])
153
+ flash[:notice] = "<%= singular_name.humanize %> was successfully updated."
153
154
  <% formats.each do |_format| -%>
154
155
  <% case _format when :html then -%>
155
156
  format.html { redirect_to(<%= resource_instance %>) }
@@ -162,7 +163,7 @@ class <%= controller_class_name %>Controller < ApplicationController
162
163
  <% end -%>
163
164
  <% end -%>
164
165
  else
165
- #flash[:error] = '<%= singular_name.humanize %> could not be updated.'
166
+ flash[:error] = "<%= singular_name.humanize %> could not be updated."
166
167
  <% formats.each do |_format| -%>
167
168
  <% case _format when :html then -%>
168
169
  format.html { render 'edit' }
@@ -190,7 +191,7 @@ class <%= controller_class_name %>Controller < ApplicationController
190
191
  def destroy
191
192
  respond_to do |format|
192
193
  if <%= resource_instance %>.destroy
193
- flash[:notice] = '<%= singular_name.humanize %> was successfully destroyed.'
194
+ flash[:notice] = "<%= singular_name.humanize %> was successfully destroyed."
194
195
  <% formats.each do |_format| -%>
195
196
  <% case _format when :html then -%>
196
197
  format.html { redirect_to(<%= plural_name %>_url) }
@@ -203,7 +204,7 @@ class <%= controller_class_name %>Controller < ApplicationController
203
204
  <% end -%>
204
205
  <% end -%>
205
206
  else
206
- flash[:error] = '<%= singular_name.humanize %> could not be destroyed.'
207
+ flash[:error] = "<%= singular_name.humanize %> could not be destroyed."
207
208
  <% formats.each do |_format| -%>
208
209
  <% case _format when :html then -%>
209
210
  format.html { redirect_to(<%= singular_name %>_url(<%= resource_instance %>)) }
@@ -223,7 +224,7 @@ class <%= controller_class_name %>Controller < ApplicationController
223
224
  <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
224
225
  # GET /<%= plural_name %>/<%= action.to_s %>
225
226
  def <%= action.to_s %>
226
- # TODO: Implement action "<%= plural_name %>/<%= action.to_s %>"
227
+
227
228
  end
228
229
 
229
230
  <% end -%>
@@ -18,7 +18,7 @@ class <%= controller_class_name %>Controller < InheritedResources::Base
18
18
  <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
19
19
  # GET /<%= plural_name %>/<%= action.to_s %>
20
20
  def <%= action.to_s %>
21
- # TODO: Implement action "<%= plural_name %>/<%= action.to_s %>"
21
+
22
22
  end
23
23
 
24
24
  <% end -%>
@@ -29,7 +29,7 @@ class <%= controller_class_name %>Controller < InheritedResources::Base
29
29
  paginate_options ||= {}
30
30
  paginate_options[:page] ||= (params[:page] || 1)
31
31
  paginate_options[:per_page] ||= (params[:per_page] || 20)
32
- @<%= plural_name %> = @<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
32
+ @collection = @<%= model_plural_name %> ||= end_of_association_chain.paginate(paginate_options)
33
33
  <% else -%>
34
34
  @collection = @<%= model_plural_name %> ||= end_of_association_chain.all
35
35
  <% end -%>
@@ -0,0 +1,90 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
+
5
+ <% if actions.include?(:create) -%>
6
+ context 'create' do
7
+ setup do
8
+ <%= resource_instance %> = <%= build_object %>
9
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
10
+ <%= resource_instance %> = <%= class_name %>.find(:all).last
11
+ end
12
+ should_redirect_to '<%= show_path %>'
13
+ end
14
+
15
+ <% end -%>
16
+ <% if actions.include?(:update) -%>
17
+ context 'update' do
18
+ setup do
19
+ <%= resource_instance %> = <%= build_object %>
20
+ put :update, :id => <%= resource_instance %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
21
+ end
22
+ should_redirect_to '<%= show_path %>'
23
+ end
24
+
25
+ <% end -%>
26
+ <% if actions.include?(:destroy) -%>
27
+ context 'destroy' do
28
+ setup do
29
+ <%= resource_instance %> = <%= build_object %>
30
+ delete :destroy, :id => <%= resource_instance %>.to_param
31
+ end
32
+ should_redirect_to '<%= index_path %>'
33
+ end
34
+
35
+ <% end -%>
36
+ <% if actions.include?(:new) -%>
37
+ context 'new' do
38
+ setup do
39
+ get :new
40
+ end
41
+ should_respond_with :success
42
+ should_render_template :new
43
+ should_assign_to :<%= singular_name %>
44
+ end
45
+
46
+ <% end -%>
47
+ <% if actions.include?(:edit) -%>
48
+ context 'edit' do
49
+ setup do
50
+ <%= resource_instance %> = <%= build_object %>
51
+ get :edit, :id => <%= resource_instance %>.to_param
52
+ end
53
+ should_respond_with :success
54
+ should_render_template :edit
55
+ should_assign_to :<%= singular_name %>
56
+ end
57
+
58
+ <% end -%>
59
+ <% if actions.include?(:show) -%>
60
+ context 'show' do
61
+ setup do
62
+ <%= resource_instance %> = <%= build_object %>
63
+ get :show, :id => <%= resource_instance %>.to_param
64
+ end
65
+ should_respond_with :success
66
+ should_render_template :show
67
+ should_assign_to :<%= singular_name %>
68
+ end
69
+
70
+ <% end -%>
71
+ <% if actions.include?(:index) -%>
72
+ context 'index' do
73
+ setup do
74
+ get :index
75
+ end
76
+ should_respond_with :success
77
+ should_assign_to :<%= plural_name %>
78
+ end
79
+
80
+ <% end -%>
81
+ <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
82
+ context '<%= action.to_s %>' do
83
+ setup do
84
+ get :<%= action.to_s %>
85
+ end
86
+ should_respond_with :success
87
+ end
88
+
89
+ <% end -%>
90
+ end
@@ -3,81 +3,90 @@ require 'test_helper'
3
3
  class <%= controller_class_name %>ControllerTest < ActionController::TestCase
4
4
 
5
5
  <% if actions.include?(:create) -%>
6
- test "create" do
6
+ test 'create' do
7
7
  <%= class_name %>.any_instance.expects(:save).returns(true)
8
- post :create, :<%= file_name %> => { }
8
+ <%= resource_instance %> = <%= build_object %>
9
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
9
10
  assert_response :redirect
10
11
  end
11
12
 
12
- test "create_with_failure" do
13
+ test 'create with failure' do
13
14
  <%= class_name %>.any_instance.expects(:save).returns(false)
14
- post :create, :<%= file_name %> => { }
15
+ <%= resource_instance %> = <%= build_object %>
16
+ post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
15
17
  assert_template 'new'
16
18
  end
17
19
 
20
+ <% end -%>
21
+ <% if actions.include?(:update) -%>
22
+ test 'update' do
23
+ <%= class_name %>.any_instance.expects(:save).returns(true)
24
+ <%= resource_instance %> = <%= build_object %>
25
+ put :update, :id => <%= build_object %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
26
+ assert_response :redirect
27
+ end
28
+
29
+ test 'update with failure' do
30
+ <%= class_name %>.any_instance.expects(:save).returns(false)
31
+ <%= resource_instance %> = <%= build_object %>
32
+ put :update, :id => <%= build_object %>.to_param, :<%= singular_name %> => <%= resource_instance %>.attributes
33
+ assert_template 'edit'
34
+ end
35
+
18
36
  <% end -%>
19
37
  <% if actions.include?(:destroy) -%>
20
- test "destroy" do
38
+ test 'destroy' do
21
39
  <%= class_name %>.any_instance.expects(:destroy).returns(true)
22
- delete :destroy, :id => <%= table_name %>(:one).to_param
40
+ <%= resource_instance %> = <%= build_object %>
41
+ delete :destroy, :id => <%= resource_instance %>.to_param
23
42
  assert_not_nil flash[:notice]
24
43
  assert_response :redirect
25
44
  end
26
45
 
27
- test "destroy_with_failure" do
46
+ test 'destroy with failure' do
28
47
  <%= class_name %>.any_instance.expects(:destroy).returns(false)
29
- delete :destroy, :id => <%= table_name %>(:one).to_param
48
+ <%= resource_instance %> = <%= build_object %>
49
+ delete :destroy, :id => <%= resource_instance %>.to_param
30
50
  assert_not_nil flash[:error]
31
51
  assert_response :redirect
32
52
  end
33
53
 
34
54
  <% end -%>
35
- <% if actions.include?(:edit) -%>
36
- test "edit" do
37
- get :edit, :id => <%= table_name %>(:one).to_param
38
- assert_response :success
39
- end
40
-
41
- <% end -%>
42
- <% if actions.include?(:index) -%>
43
- test "index" do
44
- get :index
55
+ <% if actions.include?(:new) -%>
56
+ test 'new' do
57
+ get :new
45
58
  assert_response :success
46
- assert_not_nil assigns(:<%= table_name %>)
47
59
  end
48
60
 
49
61
  <% end -%>
50
- <% if actions.include?(:new) -%>
51
- test "new" do
52
- get :new
62
+ <% if actions.include?(:edit) -%>
63
+ test 'edit' do
64
+ <%= resource_instance %> = <%= build_object %>
65
+ get :edit, :id => <%= resource_instance %>.to_param
53
66
  assert_response :success
54
67
  end
55
68
 
56
69
  <% end -%>
57
70
  <% if actions.include?(:show) -%>
58
- test "show" do
59
- get :show, :id => <%= table_name %>(:one).to_param
71
+ test 'show' do
72
+ <%= resource_instance %> = <%= build_object %>
73
+ get :show, :id => <%= resource_instance %>.to_param
60
74
  assert_response :success
61
75
  end
62
76
 
63
77
  <% end -%>
64
- <% if actions.include?(:update) -%>
65
- test "update" do
66
- <%= class_name %>.any_instance.expects(:save).returns(true)
67
- put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
68
- assert_response :redirect
69
- end
70
-
71
- test "update_with_failure" do
72
- <%= class_name %>.any_instance.expects(:save).returns(false)
73
- put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
74
- assert_template 'edit'
78
+ <% if actions.include?(:index) -%>
79
+ test 'index' do
80
+ get :index
81
+ assert_response :success
82
+ assert_not_nil assigns(:<%= table_name %>)
75
83
  end
76
84
 
77
85
  <% end -%>
78
86
  <% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
79
- test "<%= action.to_s %>" do
80
- assert true
87
+ test '<%= action.to_s %>' do
88
+ get :<%= action.to_s %>
89
+ assert_response :success
81
90
  end
82
91
 
83
92
  <% end -%>
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
+
5
+ should 'test something' do
6
+ assert true
7
+ end
8
+
9
+ end
@@ -2,4 +2,8 @@ require 'test_helper'
2
2
 
3
3
  class <%= controller_class_name %>HelperTest < ActionView::TestCase
4
4
 
5
+ test 'something' do
6
+ assert true
7
+ end
8
+
5
9
  end
@@ -3,8 +3,8 @@
3
3
  %td.<%= attribute.name %>= h <%= singular_name %>.try(:<%= attribute.name %>)
4
4
  <% end -%>
5
5
  %td.actions
6
- = link_to 'Show', <%= show_link(singular_name) %>
6
+ = link_to 'Show', <%= show_path(singular_name) %>
7
7
  |
8
- = link_to 'Edit', <%= edit_link(singular_name) %>
8
+ = link_to 'Edit', <%= edit_path(singular_name) %>
9
9
  |
10
- = link_to 'Destroy', <%= destroy_link(singular_name) %>, :confirm => 'Are you sure?', :method => :delete
10
+ = link_to 'Destroy', <%= destroy_path(singular_name) %>, :confirm => 'Are you sure?', :method => :delete