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,110 +1,110 @@
1
- class ResourcesController < ApplicationController
1
+ class DucksController < ApplicationController
2
2
 
3
3
  before_filter :load_resource, :only => [:show, :edit, :update, :destroy]
4
- before_filter :load_and_paginate_resources, :only => [:index]
4
+ before_filter :load_and_paginate_resource, :only => [:index]
5
5
 
6
- # GET /resources
7
- # GET /resources.xml
8
- # GET /resources.json
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 => @resources }
14
- format.json { render :json => @resources }
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 /resources/:id
21
- # GET /resources/:id.xml
22
- # GET /resources/:id.json
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 => @resource }
28
- format.json { render :json => @resource }
27
+ format.xml { render :xml => @duck }
28
+ format.json { render :json => @duck }
29
29
  end
30
30
  end
31
31
 
32
- # GET /resources/new
33
- # GET /resources/new.xml
34
- # GET /resources/new.json
32
+ # GET /ducks/new
33
+ # GET /ducks/new.xml
34
+ # GET /ducks/new.json
35
35
  def new
36
- @resource = Resource.new
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 => @resource }
42
- format.json { render :json => @resource }
41
+ format.xml { render :xml => @duck }
42
+ format.json { render :json => @duck }
43
43
  end
44
44
  end
45
45
 
46
- # GET /resources/:id/edit
46
+ # GET /ducks/:id/edit
47
47
  def edit
48
48
  end
49
49
 
50
- # POST /resources
51
- # POST /resources.xml
52
- # POST /resources.json
50
+ # POST /ducks
51
+ # POST /ducks.xml
52
+ # POST /ducks.json
53
53
  def create
54
- @resource = Resource.new(params[:resource])
54
+ @duck = Duck.new(params[:duck])
55
55
 
56
56
  respond_to do |format|
57
- if @resource.save
58
- flash[:notice] = 'Resource was successfully created.'
59
- format.html { redirect_to(@resource) }
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 => @resource, :status => :created, :location => @resource }
62
- format.json { render :json => @resource, :status => :created, :location => @resource }
61
+ format.xml { render :xml => @duck, :status => :created, :location => @duck }
62
+ format.json { render :json => @duck, :status => :created, :location => @duck }
63
63
  else
64
- #flash[:error] = 'Resource could not be created.'
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 => @resource.errors, :status => :unprocessable_entity }
68
- format.json { render :json => @resource.errors, :status => :unprocessable_entity }
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 /resources/:id
74
- # PUT /resources/:id.xml
75
- # PUT /resources/:id.json
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 @resource.update_attributes(params[:resource])
79
- flash[:notice] = 'Resource was successfully updated.'
80
- format.html { redirect_to(@resource) }
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
- #flash[:error] = 'Resource could not be updated.'
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 => @resource.errors, :status => :unprocessable_entity }
89
- format.json { render :json => @resource.errors, :status => :unprocessable_entity }
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 /resources/:id
95
- # DELETE /resources/:id.xml
96
- # DELETE /resources/:id.json
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 @resource.destroy
100
- flash[:notice] = 'Resource was successfully destroyed.'
101
- format.html { redirect_to(resources_url) }
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] = 'Resource could not be destroyed.'
107
- format.html { redirect_to(resource_url(@resource)) }
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 /resources/custom_action
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 = @resources ||= Resource.paginate(paginate_options)
126
+ @collection = @ducks ||= Duck.paginate(paginate_options)
126
127
  end
127
- alias :load_and_paginate_resources :collection
128
+ alias :load_and_paginate_ducks :collection
128
129
 
129
130
  def resource
130
- @resource = @resource = ||= Resource.find(params[:id])
131
+ @resource = @duck = ||= Duck.find(params[:id])
131
132
  end
132
133
  alias :load_resource :resource
133
134
 
@@ -1,11 +1,12 @@
1
- class ResourcesController < InheritedResources::Base
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 /resources/custom_action
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 = @resources ||= end_of_association_chain.paginate(paginate_options)
18
+ @collection = @ducks ||= end_of_association_chain.paginate(paginate_options)
18
19
  end
19
20
 
20
21
  def resource
21
- @resource = @resource ||= end_of_association_chain.find(params[:id])
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,3 +1,3 @@
1
- module ResourcesHelper
1
+ module DucksHelper
2
2
 
3
3
  end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
2
+
3
+ class DucksHelperTest < ActionView::TestCase
4
+
5
+ should 'test something' do
6
+ assert true
7
+ end
8
+
9
+ 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 ResourcesHelperTest < ActionView::TestCase
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 'Resources'
3
- feed.subtitle 'Index of all resources.'
4
- # Optional: feed.link :href => resources_url(:atom), :rel => 'self'
5
- feed.updated (@resources.first.created_at rescue Time.now.utc).strftime('%Y-%m-%dT%H:%M:%SZ'))
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
- @resources.each do |resource|
8
- feed.entry(resource) do |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 resource.try(:updated_at).strftime('%Y-%m-%dT%H:%M:%SZ')
13
- # Optional: entry.link :href => resource_url(resource, :atom)
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
- resource.author do |author|
15
+ duck.author do |author|
16
16
  author.name 'author_name'
17
17
  end
18
18
  end