iain-pizza-generators 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/Manifest +113 -0
  2. data/README.rdoc +34 -12
  3. data/Rakefile +2 -2
  4. data/pizza-generators.gemspec +16 -13
  5. data/rails_generators/pizza_authentication/pizza_authentication_generator.rb +32 -24
  6. data/rails_generators/pizza_authentication/templates/authentication.rb +35 -9
  7. data/rails_generators/pizza_authentication/templates/factories.rb +24 -0
  8. data/rails_generators/pizza_authentication/templates/initializer.rb +5 -0
  9. data/rails_generators/pizza_authentication/templates/migration.rb +14 -4
  10. data/rails_generators/pizza_authentication/templates/session.rb +1 -0
  11. data/rails_generators/pizza_authentication/templates/sessions_controller.rb +17 -15
  12. data/rails_generators/pizza_authentication/templates/tests/rspec/sessions_controller.rb +104 -21
  13. data/rails_generators/pizza_authentication/templates/tests/rspec/user.rb +81 -29
  14. data/rails_generators/pizza_authentication/templates/tests/rspec/users_controller.rb +1 -1
  15. data/rails_generators/pizza_authentication/templates/tests/testunit/sessions_controller.rb +8 -4
  16. data/rails_generators/pizza_authentication/templates/tests/testunit/users_controller.rb +2 -2
  17. data/rails_generators/pizza_authentication/templates/user.rb +16 -1
  18. data/rails_generators/pizza_authentication/templates/users_controller.rb +32 -7
  19. data/rails_generators/pizza_authentication/templates/views/haml/edit.html.haml +21 -0
  20. data/rails_generators/pizza_authentication/templates/views/haml/login.html.haml +2 -2
  21. data/rails_generators/pizza_authentication/templates/views/haml/new.html.haml +19 -0
  22. data/rails_generators/pizza_authentication/templates/views/haml/show.html.haml +15 -0
  23. data/rails_generators/pizza_authentication/templates/views/haml/signup.html.haml +3 -2
  24. data/rails_generators/pizza_scaffold/pizza_scaffold_generator.rb +4 -5
  25. data/rails_generators/pizza_scaffold/templates/actions/create.rb +15 -3
  26. data/rails_generators/pizza_scaffold/templates/actions/destroy.rb +10 -3
  27. data/rails_generators/pizza_scaffold/templates/actions/edit.rb +4 -0
  28. data/rails_generators/pizza_scaffold/templates/actions/index.rb +9 -2
  29. data/rails_generators/pizza_scaffold/templates/actions/new.rb +10 -0
  30. data/rails_generators/pizza_scaffold/templates/actions/show.rb +10 -0
  31. data/rails_generators/pizza_scaffold/templates/actions/update.rb +15 -3
  32. data/rails_generators/pizza_scaffold/templates/controller.rb +1 -7
  33. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/create.rb +78 -10
  34. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/destroy.rb +28 -6
  35. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/edit.rb +12 -4
  36. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/index.rb +29 -4
  37. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/new.rb +29 -4
  38. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/show.rb +26 -4
  39. data/rails_generators/pizza_scaffold/templates/tests/rspec/actions/update.rb +72 -10
  40. data/rails_generators/pizza_scaffold/templates/tests/rspec/controller.rb +3 -3
  41. data/rails_generators/pizza_scaffold/templates/views/haml/_form.html.haml +4 -5
  42. data/rails_generators/pizza_scaffold/templates/views/haml/edit.html.haml +3 -5
  43. data/rails_generators/pizza_scaffold/templates/views/haml/index.html.haml +7 -6
  44. data/rails_generators/pizza_scaffold/templates/views/haml/new.html.haml +2 -4
  45. data/rails_generators/pizza_scaffold/templates/views/haml/show.html.haml +3 -5
  46. metadata +127 -104
@@ -1,10 +1,4 @@
1
- class <%= plural_class_name %>Controller < ResourceController::Base
2
-
3
- <%- if controller_actions.size < 3 -%>
4
- actions <%= controller_actions.map(&:to_sym).map(&:inspect).join(', ') %>
5
- <%- elsif controller_actions.size < 7 -%>
6
- actions :all, :except => [ <%= not_used_actions.map(&:to_sym).map(&:inspect).join(', ') %> ]
7
- <%- end -%>
1
+ class <%= plural_class_name %>Controller < ApplicationController
8
2
 
9
3
  <%= controller_methods :actions %>
10
4
 
@@ -1,15 +1,83 @@
1
- describe "create action" do
1
+ describe "the create action" do
2
2
 
3
- it "should render new template when model is invalid" do
4
- <%= class_name %>.any_instance.stubs(:valid?).returns(false)
5
- post :create
6
- response.should render_template(:new)
3
+ before :each do
4
+ @<%= singular_name %> = <%= class_name %>.new
5
+ mock(<%= class_name %>).new("these" => "params") { @<%= singular_name %> }
7
6
  end
8
-
9
- it "should redirect when model is valid" do
10
- <%= class_name %>.any_instance.stubs(:valid?).returns(true)
11
- post :create
12
- response.should redirect_to(<%= item_path_for_spec('url') %>)
7
+
8
+ context "with valid data" do
9
+
10
+ before :each do
11
+ mock(@<%= singular_name %>).save { true }
12
+ stub(@<%= singular_name %>).id { 1337 }
13
+ stub(@<%= singular_name %>).new_record? { false }
14
+ end
15
+
16
+ context "in html format" do
17
+
18
+ before :each do
19
+ post :create, :<%= singular_name %> => { "these" => "params" }
20
+ end
21
+
22
+ it { should route(:post, <%= plural_name %>_path).to(:action => :create) }
23
+ it { should set_the_flash.to("<%= class_name.titleize %> was successfully created.") }
24
+ it { should respond_with(:redirect) }
25
+ it { should redirect_to(<%= item_path('url') %>) }
26
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
27
+
28
+ end
29
+
30
+ context "in xml format" do
31
+
32
+ before :each do
33
+ mock(@<%= singular_name %>).to_xml { "Generated XML" }
34
+ post :create, :<%= singular_name %> => { "these" => "params" }, :format => "xml"
35
+ end
36
+
37
+ it { should route(:post, <%= plural_name %>_path(:format => :xml)).to(:action => :create, :format => :xml) }
38
+ it { should respond_with_content_type(:xml) }
39
+ it { should respond_with(:created) }
40
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
41
+ specify { response.location.should == <%= singular_name %>_url(@<%= singular_name %>) }
42
+ specify { response.should have_text("Generated XML") }
43
+
44
+ end
45
+
46
+ end
47
+
48
+ context "with invalid data" do
49
+
50
+ before :each do
51
+ mock(@<%= singular_name %>).save { false }
52
+ end
53
+
54
+ context "in html format" do
55
+
56
+ before :each do
57
+ post :create, :<%= singular_name %> => { "these" => "params" }
58
+ end
59
+
60
+ it { should respond_with(:success) }
61
+ it { should render_template(:new) }
62
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
63
+ it { should_not set_the_flash }
64
+
65
+ end
66
+
67
+ context "in xml format" do
68
+
69
+ before :each do
70
+ mock(@<%= singular_name %>.errors).to_xml { "XML errors" }
71
+ post :create, :<%= singular_name %> => { "these" => "params" }, :format => "xml"
72
+ end
73
+
74
+ it { should respond_with_content_type(:xml) }
75
+ it { should respond_with(:unprocessable_entity) }
76
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
77
+ specify { response.should have_text("XML errors") }
78
+
79
+ end
80
+
13
81
  end
14
82
 
15
83
  end
@@ -1,10 +1,32 @@
1
- describe "destroy action" do
1
+ describe "the destroy action" do
2
+
3
+ before :each do
4
+ @<%= singular_name %> = mock_record <%= class_name %>, :destroy => true
5
+ end
6
+
7
+ context "in html format" do
8
+
9
+ before :each do
10
+ delete :destroy, :id => @<%= singular_name %>.to_param
11
+ end
12
+
13
+ it { should respond_with(:redirect) }
14
+ it { should redirect_to(<%= plural_name %>_url) }
15
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
16
+ it { should_not set_the_flash }
17
+
18
+ end
19
+
20
+ context "in xml format" do
21
+
22
+ before :each do
23
+ delete :destroy, :id => @<%= singular_name %>.to_param, :format => "xml"
24
+ end
25
+
26
+ it { should respond_with_content_type(:xml) }
27
+ it { should respond_with(:ok) }
28
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
2
29
 
3
- it "should destroy model and redirect to index action" do
4
- <%= singular_name %> = <%= class_name %>.first
5
- delete :destroy, :id => <%= singular_name %>
6
- response.should redirect_to(<%= plural_name %>_url)
7
- <%= class_name %>.exists?(<%= singular_name %>.id).should be_false
8
30
  end
9
31
 
10
32
  end
@@ -1,8 +1,16 @@
1
- describe "edit action" do
1
+ describe "the edit page" do
2
2
 
3
- it "should render edit template" do
4
- get :edit, :id => <%= class_name %>.first
5
- response.should render_template(:edit)
3
+ before :each do
4
+ @<%= singular_name %> = mock_record <%= class_name %>
5
+ get :edit, :id => @<%= singular_name %>.to_param
6
6
  end
7
7
 
8
+ it { should route(:get, edit_<%= singular_name %>_path(@<%= singular_name %>)).to(:action => :edit, :id => @<%= singular_name %>.to_param) }
9
+ it { should respond_with(:success) }
10
+ it { should render_template(:edit) }
11
+ it { should_not set_the_flash }
12
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
13
+ it { should have_form_to(<%= singular_name %>_path(@<%= singular_name %>)) }
14
+ it { should have_link_to(<%= plural_name %>_path) }
15
+
8
16
  end
@@ -1,8 +1,33 @@
1
- describe "index action" do
1
+ describe "the index page" do
2
2
 
3
- it "should render index template" do
4
- get :index
5
- response.should render_template(:index)
3
+ before :each do
4
+ @<%= singular_name %> = mock_record <%= class_name %>
5
+ @<%= plural_name %> = [@<%= singular_name %>].paginate
6
+ mock(<%= class_name %>).paginate(:page => "100") { @<%= plural_name %> }
7
+ end
8
+
9
+ context "in html format" do
10
+ before(:each) { get :index, :page => "100" }
11
+ it { should route(:get, <%= plural_name %>_path).to(:action => :index) }
12
+ it { should respond_with(:success) }
13
+ it { should render_template(:index) }
14
+ it { should_not set_the_flash }
15
+ it { should assign_to(:<%= plural_name %>).with(@<%= plural_name %>) }
16
+ it { should have_link_to(new_<%= singular_name %>_path) }
17
+ it { should have_link_to(edit_<%= singular_name %>_path(@<%= singular_name %>)) }
18
+ it { should have_link_to(<%= singular_name %>_path(@<%= singular_name %>)) }
19
+ end
20
+
21
+ context "in xml format" do
22
+ before(:each) do
23
+ mock(@<%= plural_name %>).to_xml { "Generated XML" }
24
+ get :index, :page => "100", :format => "xml"
25
+ end
26
+ it { should route(:get, <%= plural_name %>_path(:format => :xml)).to(:action => :index, :format => :xml) }
27
+ it { should respond_with(:success) }
28
+ it { should respond_with_content_type(:xml) }
29
+ it { should assign_to(:<%= plural_name %>).with(@<%= plural_name %>) }
30
+ specify { response.should have_text("Generated XML") }
6
31
  end
7
32
 
8
33
  end
@@ -1,8 +1,33 @@
1
- describe "new action" do
1
+ describe "the new page" do
2
+
3
+ before :each do
4
+ @<%= singular_name %> = <%= class_name %>.new
5
+ mock(<%= class_name %>).new { @<%= singular_name %> }
6
+ end
7
+
8
+ context "in html format" do
9
+ before(:each) { get :new }
10
+ it { should route(:get, new_<%= singular_name %>_path).to(:action => :new) }
11
+ it { should respond_with(:success) }
12
+ it { should render_template(:new) }
13
+ it { should_not set_the_flash }
14
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
15
+ it { should have_form_to(<%= plural_name %>_path) }
16
+ end
17
+
18
+ context "in xml format" do
19
+
20
+ before :each do
21
+ mock(@<%= singular_name %>).to_xml { "Generated XML" }
22
+ get :new, :format => "xml"
23
+ end
24
+
25
+ it { should route(:get, new_<%= singular_name %>_path(:format => :xml)).to(:action => :new, :format => :xml) }
26
+ it { should respond_with(:success) }
27
+ it { should respond_with_content_type(:xml) }
28
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
29
+ specify { response.should have_text("Generated XML") }
2
30
 
3
- it "should render new template" do
4
- get :new
5
- response.should render_template(:new)
6
31
  end
7
32
 
8
33
  end
@@ -1,8 +1,30 @@
1
- describe "show action" do
1
+ describe "the show page" do
2
2
 
3
- it "should render show template" do
4
- get :show, :id => <%= class_name %>.first
5
- response.should render_template(:show)
3
+ before :each do
4
+ @<%= singular_name %> = mock_record <%= class_name %>
5
+ end
6
+
7
+ context "in html format" do
8
+ before(:each) { get :show, :id => @<%= singular_name %>.to_param }
9
+ it { should route(:get, <%= singular_name %>_path(@<%= singular_name %>)).to(:action => :show, :id => @<%= singular_name %>.to_param) }
10
+ it { should respond_with(:success) }
11
+ it { should render_template(:show) }
12
+ it { should_not set_the_flash }
13
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
14
+ it { should have_link_to(edit_<%= singular_name %>_path(@<%= singular_name %>)) }
15
+ it { should have_link_to(<%= plural_name %>_path) }
16
+ end
17
+
18
+ context "in xml format" do
19
+ before(:each) do
20
+ mock(@<%= singular_name %>).to_xml { "Generated XML" }
21
+ get :show, :id => @<%= singular_name %>.to_param, :format => "xml"
22
+ end
23
+ it { should route(:get, <%= singular_name %>_path(@<%= singular_name %>, :format => :xml)).to(:action => :show, :id => @<%= singular_name %>.to_param, :format => :xml) }
24
+ it { should respond_with(:success) }
25
+ it { should respond_with_content_type(:xml) }
26
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
27
+ specify { response.should have_text("Generated XML") }
6
28
  end
7
29
 
8
30
  end
@@ -1,15 +1,77 @@
1
- describe "update action" do
1
+ describe "the update action" do
2
2
 
3
- it "should render edit template when model is invalid" do
4
- <%= class_name %>.any_instance.stubs(:valid?).returns(false)
5
- put :update, :id => <%= class_name %>.first
6
- response.should render_template(:edit)
3
+ before :each do
4
+ @<%= singular_name %> = mock_record <%= class_name %>
7
5
  end
8
-
9
- it "should redirect when model is valid" do
10
- <%= class_name %>.any_instance.stubs(:valid?).returns(true)
11
- put :update, :id => <%= class_name %>.first
12
- response.should redirect_to(<%= item_path_for_spec('url') %>)
6
+
7
+ context "with valid data" do
8
+
9
+ before :each do
10
+ mock(@<%= singular_name %>).update_attributes("these" => "params") { true }
11
+ end
12
+
13
+ context "in html format" do
14
+
15
+ before :each do
16
+ put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }
17
+ end
18
+
19
+ it { should route(:put, <%= singular_name %>_path(@<%= singular_name %>)).to(:action => :update, :id => @<%= singular_name %>.to_param) }
20
+ it { should respond_with(:redirect) }
21
+ it { should redirect_to(<%= singular_name %>_url(@<%= singular_name %>)) }
22
+ it { should set_the_flash.to("<%= class_name.titleize %> was successfully updated.") }
23
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
24
+
25
+ end
26
+
27
+ context "in xml format" do
28
+
29
+ before :each do
30
+ put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }, :format => "xml"
31
+ end
32
+
33
+ it { should route(:put, <%= singular_name %>_path(@<%= singular_name %>, :format => :xml)).to(:action => :update, :id => @<%= singular_name %>.to_param, :format => :xml) }
34
+ it { should respond_with_content_type(:xml) }
35
+ it { should respond_with(:ok) }
36
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
37
+ end
38
+
39
+ end
40
+
41
+ context "with invalid data" do
42
+
43
+ before :each do
44
+ mock(@<%= singular_name %>).update_attributes("these" => "params") { false }
45
+ end
46
+
47
+ context "in html format" do
48
+
49
+ before :each do
50
+ put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }
51
+ end
52
+
53
+ it { should respond_with(:success) }
54
+ it { should render_template(:edit) }
55
+ it { should_not set_the_flash }
56
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
57
+ it { should have_form_to(<%= singular_name %>_path(@<%= singular_name %>)) }
58
+
59
+ end
60
+
61
+ context "in xml format" do
62
+
63
+ before :each do
64
+ mock(@<%= singular_name %>.errors).to_xml { "XML errors" }
65
+ put :update, :id => @<%= singular_name %>.to_param, :<%= singular_name %> => { "these" => "params" }, :format => "xml"
66
+ end
67
+
68
+ it { should respond_with_content_type(:xml) }
69
+ it { should respond_with(:unprocessable_entity) }
70
+ it { should assign_to(:<%= singular_name %>).with(@<%= singular_name %>) }
71
+ specify { response.should have_text("XML errors") }
72
+
73
+ end
74
+
13
75
  end
14
76
 
15
77
  end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= plural_class_name %>Controller do
4
- fixtures :all
4
+
5
5
  integrate_views
6
-
6
+
7
7
  <%= controller_methods 'tests/rspec/actions' %>
8
8
  end
@@ -1,10 +1,9 @@
1
- - form_for @<%= singular_name %>, :url => form_url do |f|
2
- = f.error_messages
3
- - f.fieldset do
1
+ - form_for @<%= singular_name %> do |f|
2
+
3
+ = f.fieldset do
4
+
4
5
  <%- for attribute in attributes -%>
5
6
  - f.field :<%= attribute.name %>
6
7
  <%- end -%>
7
8
  - f.field do
8
- %label &nbsp;
9
9
  = f.submit t(:submit)
10
- = cancel_link
@@ -1,13 +1,11 @@
1
- - title t(:title, :model => <%= class_name %>.human_name)
2
-
3
- <%= render_form :object_path %>
1
+ <%= render_form %>
4
2
 
5
3
  <%- if actions? :show, :index -%>
6
4
  %ol.actions
7
5
  <%- if action? :show -%>
8
- %li.show= link_to t(:show), object_path
6
+ %li.show= link_to t(:show), <%= item_path %>
9
7
  <%- end -%>
10
8
  <%- if action? :index -%>
11
- %li.index= link_to t(:index), collection_path
9
+ %li.index= link_to t(:index), <%= plural_name %>_path
12
10
  <%- end -%>
13
11
  <%- end -%>
@@ -1,31 +1,32 @@
1
- - title t(:title, :model => <%= class_name %>.human_name)
2
-
3
1
  - table_for @<%= plural_name %> do |t|
2
+
4
3
  - t.head do
5
4
  <%- for attribute in attributes -%>
6
5
  - t.th :<%= attribute.name %>
7
6
  <%- end -%>
8
7
  - t.th t("actions"), :colspan => <%= table_link_count %>
8
+
9
9
  - unless will_paginate(@<%= plural_name %>).blank?
10
10
  - t.foot do
11
11
  - t.tr do
12
12
  - t.td will_paginate(@<%= plural_name %>), :colspan => t.width
13
+
13
14
  - t.body do |<%= singular_name %>|
14
15
  - t.tr do
15
16
  <%- for attribute in attributes -%>
16
17
  - t.td_h :<%= attribute.name %>
17
18
  <%- end -%>
18
19
  <%- if action? :show -%>
19
- - t.td link_to(t(:show), object_path(<%= singular_name %>))
20
+ - t.td link_to(t(:show), <%= item_path %>)
20
21
  <%- end -%>
21
22
  <%- if action? :edit -%>
22
- - t.td link_to(t(:edit), edit_object_path(<%= singular_name %>))
23
+ - t.td link_to(t(:edit), edit_<%= singular_name %>_path(<%= singular_name %>))
23
24
  <%- end -%>
24
25
  <%- if action? :destroy -%>
25
- - t.td link_to(t(:destroy), object_path(<%= singular_name %>), :confirm => h(t(:confirm)), :method => :delete)
26
+ - t.td link_to(t(:destroy), <%= singular_name %>, :confirm => h(t(:confirm)), :method => :delete)
26
27
  <%- end -%>
27
28
 
28
29
  <%- if actions? :new -%>
29
30
  %ol.actions
30
- %li.new= link_to t(:new), new_object_path
31
+ %li.new= link_to t(:new), new_<%= singular_name %>_path
31
32
  <%- end -%>
@@ -1,8 +1,6 @@
1
- - title t(:title, :model => <%= class_name %>.human_name)
2
-
3
- <%= render_form :collection_url %>
1
+ <%= render_form %>
4
2
 
5
3
  <%- if action? :index -%>
6
4
  %ol.actions
7
- %li.index= link_to t(:index), collection_path
5
+ %li.index= link_to t(:index), <%= plural_name %>_path
8
6
  <%- end -%>
@@ -1,5 +1,3 @@
1
- - title t(:title, :model => <%= class_name %>.human_name)
2
-
3
1
  - definition_list_for @<%= singular_name %> do |dl|
4
2
  <%- for attribute in attributes -%>
5
3
  - dl.show_h :<%= attribute.name %>
@@ -7,11 +5,11 @@
7
5
 
8
6
  %ol.actions
9
7
  <%- if action? :edit -%>
10
- %li.edit= link_to t(:edit), edit_object_path
8
+ %li.edit= link_to t(:edit), edit_<%= singular_name %>_path(@<%= singular_name %>)
11
9
  <%- end -%>
12
10
  <%- if action? :destroy -%>
13
- %li.destroy= link_to t(:destroy), object_path, :confirm => h(t(:confirm)), :method => :delete
11
+ %li.destroy= link_to t(:destroy), @<%= singular_name %>, :confirm => h(t(:confirm)), :method => :delete
14
12
  <%- end -%>
15
13
  <%- if action? :index -%>
16
- %li.index= link_to t(:index), collection_path
14
+ %li.index= link_to t(:index), <%= plural_name %>_path
17
15
  <%- end -%>