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.
- data/CHANGELOG.textile +6 -0
- data/README.textile +26 -17
- data/TODO.textile +43 -6
- data/config/scaffold.yml +14 -6
- data/generators/dry_model/USAGE +2 -5
- data/generators/dry_model/dry_model_generator.rb +68 -145
- data/generators/dry_model/prototypes/active_record_migration.rb +1 -1
- data/generators/dry_model/prototypes/active_record_model.rb +2 -2
- 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/shoulda/unit_test.rb +20 -0
- data/generators/dry_model/prototypes/tests/test_unit/unit_test.rb +8 -2
- data/generators/dry_model/templates/models/active_record_migration.rb +2 -2
- data/generators/dry_model/templates/models/{test_data → fixture_data}/active_record_fixtures.yml +1 -1
- 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/shoulda/unit_test.rb +23 -0
- data/generators/dry_model/templates/models/tests/test_unit/unit_test.rb +10 -2
- data/generators/dry_scaffold/USAGE +4 -5
- data/generators/dry_scaffold/dry_scaffold_generator.rb +145 -151
- data/generators/dry_scaffold/prototypes/controllers/action_controller.rb +53 -52
- data/generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb +5 -4
- data/generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb +107 -0
- data/generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb +76 -0
- data/generators/dry_scaffold/prototypes/helpers/helper.rb +1 -1
- 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 +6 -2
- data/generators/dry_scaffold/prototypes/views/builder/index.atom.builder +9 -9
- data/generators/dry_scaffold/prototypes/views/builder/index.rss.builder +7 -7
- data/generators/dry_scaffold/prototypes/views/haml/_item.html.haml +6 -6
- data/generators/dry_scaffold/prototypes/views/haml/edit.html.haml +3 -3
- data/generators/dry_scaffold/prototypes/views/haml/index.html.haml +5 -5
- data/generators/dry_scaffold/prototypes/views/haml/layout.html.haml +1 -2
- data/generators/dry_scaffold/prototypes/views/haml/new.html.haml +3 -3
- data/generators/dry_scaffold/prototypes/views/haml/show.html.haml +6 -6
- data/generators/dry_scaffold/templates/controllers/action_controller.rb +7 -6
- data/generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb +2 -2
- 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 +46 -37
- 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 +4 -0
- data/generators/dry_scaffold/templates/views/haml/_item.html.haml +3 -3
- data/generators/dry_scaffold/templates/views/haml/edit.html.haml +1 -1
- data/generators/dry_scaffold/templates/views/haml/index.html.haml +1 -1
- data/generators/dry_scaffold/templates/views/haml/new.html.haml +1 -1
- data/generators/dry_scaffold/templates/views/haml/show.html.haml +2 -2
- data/lib/dry_generator.rb +176 -0
- data/tasks/dry_scaffold.rake +5 -1
- metadata +16 -9
- data/generators/dry_model/prototypes/test_data/active_record_fixtures.yml +0 -3
- data/generators/dry_model/prototypes/test_data/factory_girl_factories.rb +0 -4
- data/generators/dry_model/prototypes/test_data/machinist_factories.rb +0 -8
- data/generators/dry_model/templates/models/test_data/factory_girl_factories.rb +0 -5
- data/generators/dry_model/templates/models/test_data/machinist_factories.rb +0 -9
- data/generators/dry_scaffold/prototypes/controllers/tests/unit_test/functional_test.rb +0 -64
@@ -1,110 +1,110 @@
|
|
1
|
-
class
|
1
|
+
class DucksController < ApplicationController
|
2
2
|
|
3
3
|
before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
|
4
|
-
before_filter :
|
4
|
+
before_filter :load_and_paginate_resource, :only => [:index]
|
5
5
|
|
6
|
-
# GET /
|
7
|
-
# GET /
|
8
|
-
# GET /
|
6
|
+
# GET /ducks
|
7
|
+
# GET /ducks.xml
|
8
|
+
# GET /ducks.json
|
9
9
|
def index
|
10
10
|
respond_to do |format|
|
11
11
|
format.html # index.html.haml
|
12
12
|
#format.js # index.js.rjs
|
13
|
-
format.xml { render :xml => @
|
14
|
-
format.json { render :json => @
|
13
|
+
format.xml { render :xml => @ducks }
|
14
|
+
format.json { render :json => @ducks }
|
15
15
|
format.atom # index.atom.builder
|
16
16
|
format.rss # index.rss.builder
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
# GET /
|
21
|
-
# GET /
|
22
|
-
# GET /
|
20
|
+
# GET /ducks/:id
|
21
|
+
# GET /ducks/:id.xml
|
22
|
+
# GET /ducks/:id.json
|
23
23
|
def show
|
24
24
|
respond_to do |format|
|
25
25
|
format.html # show.html.haml
|
26
26
|
#format.js # show.js.rjs
|
27
|
-
format.xml { render :xml => @
|
28
|
-
format.json { render :json => @
|
27
|
+
format.xml { render :xml => @duck }
|
28
|
+
format.json { render :json => @duck }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# GET /
|
33
|
-
# GET /
|
34
|
-
# GET /
|
32
|
+
# GET /ducks/new
|
33
|
+
# GET /ducks/new.xml
|
34
|
+
# GET /ducks/new.json
|
35
35
|
def new
|
36
|
-
@
|
36
|
+
@duck = Duck.new
|
37
37
|
|
38
38
|
respond_to do |format|
|
39
39
|
format.html # new.html.haml
|
40
40
|
#format.js # new.js.rjs
|
41
|
-
format.xml { render :xml => @
|
42
|
-
format.json { render :json => @
|
41
|
+
format.xml { render :xml => @duck }
|
42
|
+
format.json { render :json => @duck }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
# GET /
|
46
|
+
# GET /ducks/:id/edit
|
47
47
|
def edit
|
48
48
|
end
|
49
49
|
|
50
|
-
# POST /
|
51
|
-
# POST /
|
52
|
-
# POST /
|
50
|
+
# POST /ducks
|
51
|
+
# POST /ducks.xml
|
52
|
+
# POST /ducks.json
|
53
53
|
def create
|
54
|
-
@
|
54
|
+
@duck = Duck.new(params[:duck])
|
55
55
|
|
56
56
|
respond_to do |format|
|
57
|
-
if @
|
58
|
-
flash[:notice] =
|
59
|
-
format.html { redirect_to(@
|
57
|
+
if @duck.save
|
58
|
+
flash[:notice] = "Duck was successfully created."
|
59
|
+
format.html { redirect_to(@duck) }
|
60
60
|
#format.js # create.js.rjs
|
61
|
-
format.xml { render :xml => @
|
62
|
-
format.json { render :json => @
|
61
|
+
format.xml { render :xml => @duck, :status => :created, :location => @duck }
|
62
|
+
format.json { render :json => @duck, :status => :created, :location => @duck }
|
63
63
|
else
|
64
|
-
|
64
|
+
flash[:error] = "Duck could not be created."
|
65
65
|
format.html { render 'new' }
|
66
66
|
#format.js # create.js.rjs
|
67
|
-
format.xml { render :xml => @
|
68
|
-
format.json { render :json => @
|
67
|
+
format.xml { render :xml => @duck.errors, :status => :unprocessable_entity }
|
68
|
+
format.json { render :json => @duck.errors, :status => :unprocessable_entity }
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
# PUT /
|
74
|
-
# PUT /
|
75
|
-
# PUT /
|
73
|
+
# PUT /ducks/:id
|
74
|
+
# PUT /ducks/:id.xml
|
75
|
+
# PUT /ducks/:id.json
|
76
76
|
def update
|
77
77
|
respond_to do |format|
|
78
|
-
if @
|
79
|
-
flash[:notice] =
|
80
|
-
format.html { redirect_to(@
|
78
|
+
if @duck.update_attributes(params[:duck])
|
79
|
+
flash[:notice] = "Duck was successfully updated."
|
80
|
+
format.html { redirect_to(@duck) }
|
81
81
|
#format.js # update.js.rjs
|
82
82
|
format.xml { head :ok }
|
83
83
|
format.json { head :ok }
|
84
84
|
else
|
85
|
-
|
85
|
+
flash[:error] = "Duck could not be updated."
|
86
86
|
format.html { render 'edit' }
|
87
87
|
#format.js # update.js.rjs
|
88
|
-
format.xml { render :xml => @
|
89
|
-
format.json { render :json => @
|
88
|
+
format.xml { render :xml => @duck.errors, :status => :unprocessable_entity }
|
89
|
+
format.json { render :json => @duck.errors, :status => :unprocessable_entity }
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
# DELETE /
|
95
|
-
# DELETE /
|
96
|
-
# DELETE /
|
94
|
+
# DELETE /ducks/:id
|
95
|
+
# DELETE /ducks/:id.xml
|
96
|
+
# DELETE /ducks/:id.json
|
97
97
|
def destroy
|
98
98
|
respond_to do |format|
|
99
|
-
if @
|
100
|
-
flash[:notice] =
|
101
|
-
format.html { redirect_to(
|
99
|
+
if @duck.destroy
|
100
|
+
flash[:notice] = "Duck was successfully destroyed."
|
101
|
+
format.html { redirect_to(ducks_url) }
|
102
102
|
#format.js # destroy.js.rjs
|
103
103
|
format.xml { head :ok }
|
104
104
|
format.json { head :ok }
|
105
105
|
else
|
106
|
-
flash[:error] =
|
107
|
-
format.html { redirect_to(
|
106
|
+
flash[:error] = "Duck could not be destroyed."
|
107
|
+
format.html { redirect_to(duck_url(@duck)) }
|
108
108
|
#format.js # destroy.js.rjs
|
109
109
|
format.xml { head :unprocessable_entity }
|
110
110
|
format.json { head :unprocessable_entity }
|
@@ -112,8 +112,9 @@ class ResourcesController < ApplicationController
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
# GET /
|
115
|
+
# GET /ducks/custom_action
|
116
116
|
def custom_action
|
117
|
+
|
117
118
|
end
|
118
119
|
|
119
120
|
protected
|
@@ -122,12 +123,12 @@ class ResourcesController < ApplicationController
|
|
122
123
|
paginate_options ||= {}
|
123
124
|
paginate_options[:page] ||= (params[:page] || 1)
|
124
125
|
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
125
|
-
@collection = @
|
126
|
+
@collection = @ducks ||= Duck.paginate(paginate_options)
|
126
127
|
end
|
127
|
-
alias :
|
128
|
+
alias :load_and_paginate_ducks :collection
|
128
129
|
|
129
130
|
def resource
|
130
|
-
@resource = @
|
131
|
+
@resource = @duck = ||= Duck.find(params[:id])
|
131
132
|
end
|
132
133
|
alias :load_resource :resource
|
133
134
|
|
@@ -1,11 +1,12 @@
|
|
1
|
-
class
|
1
|
+
class DucksController < InheritedResources::Base
|
2
2
|
|
3
3
|
actions :index, :show, :new, :create, :edit, :update, :destroy
|
4
4
|
respond_to :html, :xml, :json
|
5
5
|
respond_to :atom, :rss, :only => [:index]
|
6
6
|
|
7
|
-
# GET /
|
7
|
+
# GET /ducks/custom_action
|
8
8
|
def custom_action
|
9
|
+
|
9
10
|
end
|
10
11
|
|
11
12
|
protected
|
@@ -14,11 +15,11 @@ class ResourcesController < InheritedResources::Base
|
|
14
15
|
paginate_options ||= {}
|
15
16
|
paginate_options[:page] ||= (params[:page] || 1)
|
16
17
|
paginate_options[:per_page] ||= (params[:per_page] || 20)
|
17
|
-
@collection = @
|
18
|
+
@collection = @ducks ||= end_of_association_chain.paginate(paginate_options)
|
18
19
|
end
|
19
20
|
|
20
21
|
def resource
|
21
|
-
@resource = @
|
22
|
+
@resource = @duck ||= end_of_association_chain.find(params[:id])
|
22
23
|
end
|
23
24
|
|
24
25
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DucksControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
context 'create' do
|
6
|
+
context 'with success' do
|
7
|
+
setup do
|
8
|
+
Duck.any_instance.expects(:save).returns(true)
|
9
|
+
@duck = Factory(:duck)
|
10
|
+
post :create, :duck => @duck.attributes
|
11
|
+
@duck = Resource.find(:all).last
|
12
|
+
end
|
13
|
+
should_assign_to flash[:notice]
|
14
|
+
should_redirect_to 'duck_path(@duck)'
|
15
|
+
end
|
16
|
+
context 'with failure' do
|
17
|
+
setup do
|
18
|
+
Duck.any_instance.expects(:save).returns(false)
|
19
|
+
@duck = Factory(:duck)
|
20
|
+
post :create, :duck => @duck.attributes
|
21
|
+
@duck = Resource.find(:all).last
|
22
|
+
end
|
23
|
+
should_assign_to flash[:error]
|
24
|
+
should_render_template :new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'update' do
|
29
|
+
context 'with success' do
|
30
|
+
setup do
|
31
|
+
Duck.any_instance.expects(:save).returns(true)
|
32
|
+
@duck = Factory(:duck)
|
33
|
+
put :update, :id => @duck.to_param, :duck => @duck.attributes
|
34
|
+
end
|
35
|
+
should_assign_to flash[:notice]
|
36
|
+
should_redirect_to 'duck_path(@duck)'
|
37
|
+
end
|
38
|
+
context 'with failure' do
|
39
|
+
setup do
|
40
|
+
Duck.any_instance.expects(:save).returns(false)
|
41
|
+
@duck = Factory(:duck)
|
42
|
+
put :update, :id => @duck.to_param, :duck => @duck.attributes
|
43
|
+
end
|
44
|
+
should_assign_to flash[:error]
|
45
|
+
should_render_template :edit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'destroy' do
|
50
|
+
context 'with success' do
|
51
|
+
setup do
|
52
|
+
Duck.any_instance.expects(:destroy).returns(true)
|
53
|
+
@duck = Factory(:duck)
|
54
|
+
delete :destroy, :id => @duck.to_param
|
55
|
+
end
|
56
|
+
should_assign_to flash[:notice]
|
57
|
+
should_redirect_to 'ducks_path'
|
58
|
+
end
|
59
|
+
context 'with failure' do
|
60
|
+
setup do
|
61
|
+
Duck.any_instance.expects(:destroy).returns(false)
|
62
|
+
@duck = Factory(:duck)
|
63
|
+
delete :destroy, :id => @duck.to_param
|
64
|
+
end
|
65
|
+
should_assign_to flash[:error]
|
66
|
+
should_redirect_to 'ducks_path'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'new' do
|
71
|
+
setup do
|
72
|
+
get :new
|
73
|
+
end
|
74
|
+
should_respond_with :success
|
75
|
+
should_render_template :new
|
76
|
+
should_assign_to :duck
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'edit' do
|
80
|
+
setup do
|
81
|
+
@duck = Factory(:duck)
|
82
|
+
get :edit, :id => @duck.to_param
|
83
|
+
end
|
84
|
+
should_respond_with :success
|
85
|
+
should_render_template :edit
|
86
|
+
should_assign_to :duck
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'show' do
|
90
|
+
setup do
|
91
|
+
@duck = Factory(:duck)
|
92
|
+
get :show, :id => @duck.to_param
|
93
|
+
end
|
94
|
+
should_respond_with :success
|
95
|
+
should_render_template :show
|
96
|
+
should_assign_to :duck
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'index' do
|
100
|
+
setup do
|
101
|
+
get :index
|
102
|
+
end
|
103
|
+
should_respond_with :success
|
104
|
+
should_assign_to :ducks
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DucksControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test 'create' do
|
6
|
+
Duck.any_instance.expects(:save).returns(true)
|
7
|
+
@duck = ducks(:basic)
|
8
|
+
post :create, :duck => @duck.attributes
|
9
|
+
assert_not_nil flash[:notice]
|
10
|
+
assert_response :redirect
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'create with failure' do
|
14
|
+
Duck.any_instance.expects(:save).returns(false)
|
15
|
+
@duck = ducks(:basic)
|
16
|
+
post :create, :duck => @duck.attributes
|
17
|
+
assert_not_nil flash[:error]
|
18
|
+
assert_template 'new'
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'update' do
|
22
|
+
Duck.any_instance.expects(:save).returns(true)
|
23
|
+
@duck = ducks(:basic)
|
24
|
+
put :update, :id => @duck.to_param, :duck => @duck.attributes
|
25
|
+
assert_not_nil flash[:notice]
|
26
|
+
assert_response :redirect
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'update with failure' do
|
30
|
+
Duck.any_instance.expects(:save).returns(false)
|
31
|
+
@duck = ducks(:basic)
|
32
|
+
put :update, :id => @duck.to_param, :duck => @duck.attributes
|
33
|
+
assert_not_nil flash[:error]
|
34
|
+
assert_template 'edit'
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'destroy' do
|
38
|
+
Duck.any_instance.expects(:destroy).returns(true)
|
39
|
+
@duck = ducks(:basic)
|
40
|
+
delete :destroy, :id => @duck.to_param
|
41
|
+
assert_not_nil flash[:notice]
|
42
|
+
assert_response :redirect
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'destroy with failure' do
|
46
|
+
Duck.any_instance.expects(:destroy).returns(false)
|
47
|
+
@duck = ducks(:basic)
|
48
|
+
delete :destroy, :id => @duck.to_param
|
49
|
+
assert_not_nil flash[:error]
|
50
|
+
assert_response :redirect
|
51
|
+
end
|
52
|
+
|
53
|
+
test 'new' do
|
54
|
+
get :new
|
55
|
+
assert_response :success
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'edit' do
|
59
|
+
@duck = ducks(:basic)
|
60
|
+
get :edit, :id => @duck.to_param
|
61
|
+
assert_response :success
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'show' do
|
65
|
+
@duck = ducks(:basic)
|
66
|
+
get :show, :id => @duck.to_param
|
67
|
+
assert_response :success
|
68
|
+
end
|
69
|
+
|
70
|
+
test 'index' do
|
71
|
+
get :index
|
72
|
+
assert_response :success
|
73
|
+
assert_not_nil assigns(:ducks)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
|
2
2
|
|
3
|
-
class
|
3
|
+
class DucksHelperTest < ActionView::TestCase
|
4
|
+
|
5
|
+
test 'something' do
|
6
|
+
assert true
|
7
|
+
end
|
4
8
|
|
5
9
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
atom_feed(:language => I18n.locale) do |feed|
|
2
|
-
feed.title '
|
3
|
-
feed.subtitle 'Index of all
|
4
|
-
# Optional: feed.link :href =>
|
5
|
-
feed.updated (@
|
2
|
+
feed.title 'Ducks'
|
3
|
+
feed.subtitle 'Index of all ducks.'
|
4
|
+
# Optional: feed.link :href => ducks_url(:atom), :rel => 'self'
|
5
|
+
feed.updated (@ducks.first.created_at rescue Time.now.utc).strftime('%Y-%m-%dT%H:%M:%SZ'))
|
6
6
|
|
7
|
-
@
|
8
|
-
feed.entry(
|
7
|
+
@ducks.each do |duck|
|
8
|
+
feed.entry(duck) do |entry|
|
9
9
|
entry.title 'title'
|
10
10
|
entry.summary 'summary'
|
11
11
|
# Optional: entry.content 'content', :type => 'html'
|
12
|
-
# Optional: entry.updated
|
13
|
-
# Optional: entry.link :href =>
|
12
|
+
# Optional: entry.updated duck.try(:updated_at).strftime('%Y-%m-%dT%H:%M:%SZ')
|
13
|
+
# Optional: entry.link :href => duck_url(duck, :atom)
|
14
14
|
|
15
|
-
|
15
|
+
duck.author do |author|
|
16
16
|
author.name 'author_name'
|
17
17
|
end
|
18
18
|
end
|