michel-dry_scaffold 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +51 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +461 -0
- data/Rakefile +48 -0
- data/TODO.textile +40 -0
- data/bin/dmodel +3 -0
- data/bin/dry_model +3 -0
- data/bin/dry_scaffold +3 -0
- data/bin/dscaffold +3 -0
- data/config/scaffold.yml +34 -0
- data/generators/dmodel/dmodel_generator.rb +15 -0
- data/generators/dry_model/USAGE +9 -0
- data/generators/dry_model/dry_model_generator.rb +134 -0
- data/generators/dry_model/prototypes/active_record_migration.rb +17 -0
- data/generators/dry_model/prototypes/active_record_model.rb +9 -0
- data/generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml +3 -0
- data/generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb +4 -0
- data/generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb +8 -0
- data/generators/dry_model/prototypes/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_model/prototypes/tests/shoulda/unit_test.rb +20 -0
- data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +15 -0
- data/generators/dry_model/templates/models/active_record_migration.rb +23 -0
- data/generators/dry_model/templates/models/active_record_model.rb +15 -0
- data/generators/dry_model/templates/models/fixture_data/active_record_fixtures.yml +6 -0
- data/generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb +5 -0
- data/generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb +9 -0
- data/generators/dry_model/templates/models/tests/rspec/unit_test.rb +11 -0
- data/generators/dry_model/templates/models/tests/shoulda/unit_test.rb +23 -0
- data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +17 -0
- data/generators/dry_scaffold/USAGE +11 -0
- data/generators/dry_scaffold/dry_scaffold_generator.rb +415 -0
- data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +135 -0
- data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +25 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/rspec/functional_test.rb +57 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +99 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +70 -0
- data/generators/dry_scaffold/prototypes/helpers/helper.rb +3 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb +9 -0
- data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +20 -0
- data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +21 -0
- data/generators/dry_scaffold/prototypes/views/haml/_form.html.haml +3 -0
- data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +9 -0
- data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +10 -0
- data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +17 -0
- data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +18 -0
- data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +10 -0
- data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +13 -0
- data/generators/dry_scaffold/templates/controllers/action_controller.rb +250 -0
- data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +36 -0
- data/generators/dry_scaffold/templates/controllers/tests/rspec/functional_test.rb +85 -0
- data/generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb +90 -0
- data/generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb +87 -0
- data/generators/dry_scaffold/templates/helpers/helper.rb +3 -0
- data/generators/dry_scaffold/templates/helpers/tests/rspec/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb +9 -0
- data/generators/dry_scaffold/templates/views/builder/index.atom.builder +20 -0
- data/generators/dry_scaffold/templates/views/builder/index.rss.builder +21 -0
- data/generators/dry_scaffold/templates/views/haml/_form.html.haml +13 -0
- data/generators/dry_scaffold/templates/views/haml/_item.html.haml +10 -0
- data/generators/dry_scaffold/templates/views/haml/edit.html.haml +18 -0
- data/generators/dry_scaffold/templates/views/haml/index.html.haml +38 -0
- data/generators/dry_scaffold/templates/views/haml/layout.html.haml +19 -0
- data/generators/dry_scaffold/templates/views/haml/new.html.haml +18 -0
- data/generators/dry_scaffold/templates/views/haml/show.html.haml +13 -0
- data/generators/dscaffold/dscaffold_generator.rb +15 -0
- data/lib/dry_generator.rb +197 -0
- data/lib/dry_scaffold/tasks.rb +5 -0
- data/lib/setup_helper.rb +36 -0
- data/rails/init.rb +3 -0
- data/tasks/dry_scaffold.rake +95 -0
- metadata +132 -0
@@ -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
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
<% if actions.include?(:create) -%>
|
6
|
+
test 'create' do
|
7
|
+
<%= class_name %>.any_instance.expects(:save).returns(true)
|
8
|
+
<%= resource_instance %> = <%= build_object %>
|
9
|
+
post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
|
10
|
+
assert_response :redirect
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'create with failure' do
|
14
|
+
<%= class_name %>.any_instance.expects(:save).returns(false)
|
15
|
+
<%= resource_instance %> = <%= build_object %>
|
16
|
+
post :create, :<%= singular_name %> => <%= resource_instance %>.attributes
|
17
|
+
assert_template 'new'
|
18
|
+
end
|
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
|
+
|
36
|
+
<% end -%>
|
37
|
+
<% if actions.include?(:destroy) -%>
|
38
|
+
test 'destroy' do
|
39
|
+
<%= class_name %>.any_instance.expects(:destroy).returns(true)
|
40
|
+
<%= resource_instance %> = <%= build_object %>
|
41
|
+
delete :destroy, :id => <%= resource_instance %>.to_param
|
42
|
+
assert_not_nil flash[:notice]
|
43
|
+
assert_response :redirect
|
44
|
+
end
|
45
|
+
|
46
|
+
# Not possible: destroy with failure
|
47
|
+
|
48
|
+
<% end -%>
|
49
|
+
<% if actions.include?(:new) -%>
|
50
|
+
test 'new' do
|
51
|
+
get :new
|
52
|
+
assert_response :success
|
53
|
+
end
|
54
|
+
|
55
|
+
<% end -%>
|
56
|
+
<% if actions.include?(:edit) -%>
|
57
|
+
test 'edit' do
|
58
|
+
<%= resource_instance %> = <%= build_object %>
|
59
|
+
get :edit, :id => <%= resource_instance %>.to_param
|
60
|
+
assert_response :success
|
61
|
+
end
|
62
|
+
|
63
|
+
<% end -%>
|
64
|
+
<% if actions.include?(:show) -%>
|
65
|
+
test 'show' do
|
66
|
+
<%= resource_instance %> = <%= build_object %>
|
67
|
+
get :show, :id => <%= resource_instance %>.to_param
|
68
|
+
assert_response :success
|
69
|
+
end
|
70
|
+
|
71
|
+
<% end -%>
|
72
|
+
<% if actions.include?(:index) -%>
|
73
|
+
test 'index' do
|
74
|
+
get :index
|
75
|
+
assert_response :success
|
76
|
+
assert_not_nil assigns(:<%= table_name %>)
|
77
|
+
end
|
78
|
+
|
79
|
+
<% end -%>
|
80
|
+
<% (actions - DryScaffoldGenerator::DEFAULT_CONTROLLER_ACTIONS).each do |action| -%>
|
81
|
+
test '<%= action.to_s %>' do
|
82
|
+
get :<%= action.to_s %>
|
83
|
+
assert_response :success
|
84
|
+
end
|
85
|
+
|
86
|
+
<% end -%>
|
87
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
atom_feed(:language => I18n.locale) do |feed|
|
2
|
+
feed.title '<%= class_name.pluralize %>'
|
3
|
+
feed.subtitle 'Index of all <%= plural_name %>.'
|
4
|
+
# Optional: feed.link <%= feed_link(:atom) %>
|
5
|
+
feed.updated <%= feed_date(:atom) %>
|
6
|
+
|
7
|
+
<%= collection_instance %>.each do |<%= singular_name %>|
|
8
|
+
feed.entry(<%= singular_name %>) do |entry|
|
9
|
+
entry.title 'title'
|
10
|
+
entry.summary 'summary'
|
11
|
+
# Optional: entry.content 'content', :type => 'html'
|
12
|
+
# Optional: entry.updated <%= feed_entry_date(:atom) %>
|
13
|
+
# Optional: entry.link <%= feed_entry_link(:atom) %>
|
14
|
+
|
15
|
+
<%= singular_name %>.author do |author|
|
16
|
+
author.name 'author_name'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
xml.instruct! :xml, :version => '1.0'
|
2
|
+
xml.rss(:version => '2.0') do
|
3
|
+
xml.channel do
|
4
|
+
xml.title '<%= class_name.pluralize %>'
|
5
|
+
xml.description 'Index of all <%= plural_name %>.'
|
6
|
+
xml.link <%= feed_link(:rss) %>
|
7
|
+
xml.lastBuildDate <%= feed_date(:rss) %>
|
8
|
+
xml.language I18n.locale
|
9
|
+
|
10
|
+
<%= collection_instance %>.each do |<%= singular_name %>|
|
11
|
+
xml.item do
|
12
|
+
xml.title 'title'
|
13
|
+
xml.description 'summary'
|
14
|
+
xml.pubDate <%= feed_entry_date(:rss) %>
|
15
|
+
xml.link <%= feed_entry_link(:rss) %>
|
16
|
+
|
17
|
+
xml.author 'author_name'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% if options[:formtastic] -%>
|
2
|
+
- form.inputs do
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
= form.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>'
|
5
|
+
<% end -%>
|
6
|
+
<% else -%>
|
7
|
+
%fieldset
|
8
|
+
%dl
|
9
|
+
<% attributes.each do |attribute| -%>
|
10
|
+
%dt.label= form.label :<%= attribute.name %>, '<%= attribute.name.humanize %>'
|
11
|
+
%dd.<%= attribute.name %>= form.<%= attribute.field_type %> :<%= attribute.name %>
|
12
|
+
<% end -%>
|
13
|
+
<% end -%>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- content_tag_for(:tr, <%= singular_name -%>, :class => cycle(:odd, :even)) do
|
2
|
+
<% attributes.each do |attribute| -%>
|
3
|
+
%td.<%= attribute.name %>= h <%= singular_name %>.try(:<%= attribute.name %>)
|
4
|
+
<% end -%>
|
5
|
+
%td.actions
|
6
|
+
= link_to 'Show', <%= show_path(singular_name) %>
|
7
|
+
|
|
8
|
+
= link_to 'Edit', <%= edit_path(singular_name) %>
|
9
|
+
|
|
10
|
+
= link_to 'Destroy', <%= destroy_path(singular_name) %>, :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= "Editing <%= singular_name %> %s" % <%= resource_instance %>.id
|
3
|
+
|
4
|
+
<% if options[:formtastic] -%>
|
5
|
+
- semantic_form_for(<%= resource_instance %>) do |form|
|
6
|
+
= render 'form', :form => form
|
7
|
+
- form.buttons do
|
8
|
+
= form.commit_button 'Update'
|
9
|
+
<% else -%>
|
10
|
+
- form_for(<%= resource_instance %>) do |form|
|
11
|
+
= form.error_messages
|
12
|
+
= render 'form', :form => form
|
13
|
+
%p.buttons
|
14
|
+
= form.submit 'Update'
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
%p.actions
|
18
|
+
= link_to 'Cancel', <%= index_path %>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= "<%= plural_name.humanize %>"
|
3
|
+
|
4
|
+
<% if options[:search] -%>
|
5
|
+
.actions-bar
|
6
|
+
%div{:class => "left search"}
|
7
|
+
- form_for @search do |f|
|
8
|
+
= f.label "Find:"
|
9
|
+
= f.text_field :<%= attributes.first.name %>
|
10
|
+
= f.submit("Search")
|
11
|
+
<% if options[:pagination] -%>
|
12
|
+
.right
|
13
|
+
= will_paginate @collection, :prev_label => "« Back", :next_label => "Next »"
|
14
|
+
.clear
|
15
|
+
<% end %>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
%p.actions
|
19
|
+
= link_to 'New <%= singular_name.humanize %>', <%= new_path %>
|
20
|
+
|
21
|
+
%table
|
22
|
+
%thead.header
|
23
|
+
%tr
|
24
|
+
<% attributes.each do |attribute| -%>
|
25
|
+
%th.<%= attribute.name %>= '<%= attribute.name.humanize %>'
|
26
|
+
<% end -%>
|
27
|
+
%th.actions= 'Actions'
|
28
|
+
%tbody.items.<%= plural_name %>
|
29
|
+
- <%= collection_instance %>.each do |<%= singular_name %>|
|
30
|
+
= render 'item', :<%= singular_name %> => <%= singular_name %>
|
31
|
+
|
32
|
+
<% if options[:pagination] && !options[:search] -%>
|
33
|
+
= will_paginate(<%= collection_instance %>)
|
34
|
+
<% end -%>
|
35
|
+
<% if options[:pagination] && options[:search] -%>
|
36
|
+
= will_paginate @collection, :prev_label => "« Back", :next_label => "Next »"
|
37
|
+
<% end -%>
|
38
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!! 1.1
|
2
|
+
|
3
|
+
%html{html_attrs(I18n.locale)}
|
4
|
+
%head
|
5
|
+
%title= "#{controller.controller_name.humanize}: #{controller.action_name}"
|
6
|
+
|
7
|
+
= stylesheet_link_tag 'screen', :media => 'screen, projection'
|
8
|
+
= stylesheet_link_tag 'print', :media => 'print'
|
9
|
+
/[if IE]
|
10
|
+
= stylesheet_link_tag 'ie', :media => 'screen, projection'
|
11
|
+
= stylesheet_link_tag 'scaffold' if File.exist?(stylesheet_path('scaffold').gsub(/\?.+/, ''))
|
12
|
+
|
13
|
+
= javascript_include_tag :defaults
|
14
|
+
|
15
|
+
%body{:id => "#{controller.controller_name}_#{controller.action_name}", :class => "#{controller.controller_name}_controller #{controller.action_name}_action"}
|
16
|
+
|
17
|
+
%p.flash{:style => 'color: green'}= flash[:notice]
|
18
|
+
|
19
|
+
= yield
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= 'New <%= singular_name.humanize %>'
|
3
|
+
|
4
|
+
<% if options[:formtastic] -%>
|
5
|
+
- semantic_form_for(<%= resource_instance %>) do |form|
|
6
|
+
= render 'form', :form => form
|
7
|
+
- form.buttons do
|
8
|
+
= form.commit_button 'Create'
|
9
|
+
<% else -%>
|
10
|
+
- form_for(<%= resource_instance %>) do |form|
|
11
|
+
= form.error_messages
|
12
|
+
= render 'form', :form => form
|
13
|
+
%p.buttons
|
14
|
+
= form.submit 'Create'
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
%p.actions
|
18
|
+
= link_to 'Cancel', <%= index_path %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h1.heading
|
2
|
+
= "<%= singular_name.humanize %> %s" % <%= resource_instance %>.id
|
3
|
+
|
4
|
+
- content_tag_for(:dl, <%= resource_instance %>) do
|
5
|
+
<% attributes.each do |attribute| -%>
|
6
|
+
%dt.label= '<%= attribute.name.humanize %>'
|
7
|
+
%dd.<%= attribute.name -%>= h <%= resource_instance %>.try(:<%= attribute.name %>)
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
%p.actions
|
11
|
+
= link_to 'Edit', <%= edit_path %>
|
12
|
+
|
|
13
|
+
= link_to 'Index', <%= index_path %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'dry_scaffold', 'dry_scaffold_generator')
|
2
|
+
|
3
|
+
class DscaffoldGenerator < DryScaffoldGenerator
|
4
|
+
|
5
|
+
def initialize(runtime_args, runtime_options = {})
|
6
|
+
super
|
7
|
+
# Make Rails look for templates within generator "dry_scaffold" path
|
8
|
+
@source_root = options[:source] || File.join(spec.path, '..', 'dry_scaffold', 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def usage_message
|
12
|
+
File.read(File.join(spec.path, '..', 'dry_scaffold', 'USAGE')) rescue ''
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
class DryGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
HAS_WILL_PAGINATE = defined?(WillPaginate)
|
4
|
+
HAS_FORMTASTIC = defined?(Formtastic)
|
5
|
+
HAS_INHERITED_RESOURCES = defined?(InheritedResources)
|
6
|
+
HAS_SHOULDA = defined?(Shoulda)
|
7
|
+
HAS_RSPEC = defined?(Rspec)
|
8
|
+
HAS_WILL_SEARCHLOGIC = defined?(Searchlogic)
|
9
|
+
|
10
|
+
|
11
|
+
# Load defaults from config file - default or custom.
|
12
|
+
begin
|
13
|
+
default_config_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'scaffold.yml'))
|
14
|
+
custom_config_file = File.expand_path(File.join(Rails.root, 'config', 'scaffold.yml'))
|
15
|
+
config_file = File.join(File.exist?(custom_config_file) ? custom_config_file : default_config_file)
|
16
|
+
config = YAML::load(File.open(config_file))
|
17
|
+
CONFIG_ARGS = config['dry_scaffold']['args'] rescue nil
|
18
|
+
CONFIG_OPTIONS = config['dry_scaffold']['options'] rescue nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# Banner: Generator arguments and options.
|
22
|
+
BANNER_ARGS = [
|
23
|
+
"[field:type field:type ...]"
|
24
|
+
].freeze
|
25
|
+
BANNER_OPTIONS = [
|
26
|
+
"[--skip-tests]",
|
27
|
+
"[--shoulda]",
|
28
|
+
"[--rspec]",
|
29
|
+
"[--fixtures]",
|
30
|
+
"[--fgirl]",
|
31
|
+
"[--machinist]",
|
32
|
+
"[--odaddy]"
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
DEFAULT_ARGS = {
|
36
|
+
:actions => (CONFIG_ARGS['actions'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil),
|
37
|
+
:formats => (CONFIG_ARGS['formats'].split(',').compact.uniq.collect { |v| v.downcase.to_sym } rescue nil)
|
38
|
+
}.freeze
|
39
|
+
|
40
|
+
DEFAULT_OPTIONS = {
|
41
|
+
:resourceful => CONFIG_OPTIONS['resourceful'] || HAS_INHERITED_RESOURCES,
|
42
|
+
:formtastic => CONFIG_OPTIONS['formtastic'] || HAS_FORMTASTIC,
|
43
|
+
:pagination => CONFIG_OPTIONS['pagination'] || HAS_WILL_PAGINATE,
|
44
|
+
:search => CONFIG_OPTIONS['search'] || HAS_WILL_SEARCHLOGIC,
|
45
|
+
:skip_tests => !CONFIG_OPTIONS['tests'] || false,
|
46
|
+
:skip_controller_tests => !CONFIG_OPTIONS['controller_tests'] || false,
|
47
|
+
:skip_helpers => !CONFIG_OPTIONS['helpers'] || false,
|
48
|
+
:skip_views => !CONFIG_OPTIONS['views'] || false,
|
49
|
+
:layout => CONFIG_OPTIONS['layout'] || false,
|
50
|
+
:fixtures => CONFIG_OPTIONS['fixtures'] || false,
|
51
|
+
:factory_girl => CONFIG_OPTIONS['factory_girl'] || CONFIG_OPTIONS['fgirl'] || false,
|
52
|
+
:machinist => CONFIG_OPTIONS['machinist'] || false,
|
53
|
+
:object_daddy => CONFIG_OPTIONS['object_daddy'] || CONFIG_OPTIONS['odaddy'] || false,
|
54
|
+
:test_unit => CONFIG_OPTIONS['test_unit'] || CONFIG_OPTIONS['tunit'] || false,
|
55
|
+
:shoulda => CONFIG_OPTIONS['shoulda'] || false,
|
56
|
+
:rspec => CONFIG_OPTIONS['rspec'] || false
|
57
|
+
}.freeze
|
58
|
+
|
59
|
+
TEST_PATHS = {
|
60
|
+
:test_unit => 'test',
|
61
|
+
:shoulda => 'test',
|
62
|
+
:rspec => 'spec'
|
63
|
+
}.freeze
|
64
|
+
|
65
|
+
TEST_POST_FIX = {
|
66
|
+
:test_unit => 'test',
|
67
|
+
:shoulda => 'test',
|
68
|
+
:rspec => 'spec'
|
69
|
+
}.freeze
|
70
|
+
|
71
|
+
DEFAULT_TEST_FRAMEWORK = :test_unit
|
72
|
+
DEFAULT_FACTORY_FRAMEWORK = :fixtures
|
73
|
+
|
74
|
+
TESTS_PATH = File.join('test').freeze
|
75
|
+
FUNCTIONAL_TESTS_PATH = {
|
76
|
+
:test_unit => 'functional',
|
77
|
+
:shoulda => 'functional',
|
78
|
+
:rspec => 'controllers'
|
79
|
+
}
|
80
|
+
UNIT_TESTS_PATH = {
|
81
|
+
:test_unit => 'unit',
|
82
|
+
:shoulda => 'unit',
|
83
|
+
:rspec => 'models',
|
84
|
+
}
|
85
|
+
|
86
|
+
NON_ATTR_ARG_KEY_PREFIX = '_'.freeze
|
87
|
+
|
88
|
+
attr_accessor :view_template_format,
|
89
|
+
:test_framework,
|
90
|
+
:factory_framework
|
91
|
+
|
92
|
+
def initialize(runtime_args, runtime_options = {})
|
93
|
+
super(runtime_args, runtime_options)
|
94
|
+
|
95
|
+
@test_framework = ( options[:test_framework] && options[:test_framework].to_sym ) ||
|
96
|
+
[:rspec,:test_unit,:shoulda].detect{|t|options[t]} ||
|
97
|
+
DEFAULT_TEST_FRAMEWORK
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
def symbol_array_to_expression(array)
|
103
|
+
":#{array.compact.join(', :')}" if array.present?
|
104
|
+
end
|
105
|
+
|
106
|
+
def banner_args
|
107
|
+
BANNER_ARGS.join(' ')
|
108
|
+
end
|
109
|
+
|
110
|
+
def banner_options
|
111
|
+
BANNER_OPTIONS.join(' ')
|
112
|
+
end
|
113
|
+
|
114
|
+
def banner
|
115
|
+
"\nUsage: \n\n#{$0} #{spec.name} MODEL_NAME"
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_options!(opt)
|
119
|
+
opt.separator ' '
|
120
|
+
opt.separator 'Scaffold + Model Options:'
|
121
|
+
|
122
|
+
opt.on('--skip-tests', "Test: Skip generation of tests.") do |v|
|
123
|
+
options[:skip_tests] = v
|
124
|
+
end
|
125
|
+
|
126
|
+
opt.on("--tunit", "Test: Generate \"test_unit\" tests. Note: Rails default.") do |v|
|
127
|
+
options[:test_unit] = v
|
128
|
+
options[:test_framework] = :test_unit
|
129
|
+
end
|
130
|
+
|
131
|
+
opt.on("--shoulda", "Test: Generate \"shoulda\" tests.") do |v|
|
132
|
+
options[:shoulda] = v
|
133
|
+
options[:test_framework] = :shoulda
|
134
|
+
end
|
135
|
+
|
136
|
+
opt.on("--rspec", "Test: Generate \"rspec\" tests.") do |v|
|
137
|
+
options[:rspec] = v
|
138
|
+
options[:test_framework] = :rspec
|
139
|
+
end
|
140
|
+
|
141
|
+
opt.on("--fixtures", "Test: Generate fixtures. Note: Rails default.") do |v|
|
142
|
+
options[:fixtures] = v
|
143
|
+
options[:factory_framework] = :fixtures
|
144
|
+
end
|
145
|
+
|
146
|
+
opt.on("--fgirl", "Test: Generate \"factory_girl\" factories.") do |v|
|
147
|
+
options[:factory_girl] = v
|
148
|
+
options[:factory_framework] = :factory_girl
|
149
|
+
end
|
150
|
+
|
151
|
+
opt.on("--machinist", "Test: Generate \"machinist\" blueprints (factories).") do |v|
|
152
|
+
options[:machinist] = v
|
153
|
+
options[:factory_framework] = :machinist
|
154
|
+
end
|
155
|
+
|
156
|
+
opt.on("--odaddy", "Test: Generate \"object_daddy\" generator/factory methods.") do |v|
|
157
|
+
options[:object_daddy] = v
|
158
|
+
options[:factory_framework] = :object_daddy
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
module Rails
|
165
|
+
module Generator
|
166
|
+
class GeneratedAttribute
|
167
|
+
def default_for_fixture
|
168
|
+
@default ||= case type
|
169
|
+
when :integer then 1
|
170
|
+
when :float then 1.5
|
171
|
+
when :decimal then '9.99'
|
172
|
+
when :datetime, :timestamp, :time then Time.now.to_s(:db)
|
173
|
+
when :date then Date.today.to_s(:db)
|
174
|
+
when :string then 'Hello'
|
175
|
+
when :text then 'Lorem ipsum dolor sit amet...'
|
176
|
+
when :boolean then false
|
177
|
+
else
|
178
|
+
''
|
179
|
+
end
|
180
|
+
end
|
181
|
+
def default_for_factory
|
182
|
+
@default ||= case type
|
183
|
+
when :integer then 1
|
184
|
+
when :float then 1.5
|
185
|
+
when :decimal then '9.99'
|
186
|
+
when :datetime, :timestamp, :time then 'Time.now'
|
187
|
+
when :date then 'Date.today'
|
188
|
+
when :string then '"Hello"'
|
189
|
+
when :text then '"Lorem ipsum dolor sit amet..."'
|
190
|
+
when :boolean then false
|
191
|
+
else
|
192
|
+
''
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|