sob-shoulda_generator 0.2.1
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/LICENSE +20 -0
- data/Manifest +32 -0
- data/README.markdown +81 -0
- data/Rakefile +26 -0
- data/TODO +8 -0
- data/VERSION.yml +4 -0
- data/rails_generators/shoulda_model/USAGE +27 -0
- data/rails_generators/shoulda_model/shoulda_model_generator.rb +49 -0
- data/rails_generators/shoulda_model/templates/factory.rb +5 -0
- data/rails_generators/shoulda_model/templates/fixtures.yml +19 -0
- data/rails_generators/shoulda_model/templates/migration.rb +16 -0
- data/rails_generators/shoulda_model/templates/model.rb +2 -0
- data/rails_generators/shoulda_model/templates/unit_test.rb +7 -0
- data/rails_generators/shoulda_scaffold/USAGE +34 -0
- data/rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb +163 -0
- data/rails_generators/shoulda_scaffold/templates/controller.rb +90 -0
- data/rails_generators/shoulda_scaffold/templates/erb/_form.html.erb +8 -0
- data/rails_generators/shoulda_scaffold/templates/erb/edit.html.erb +12 -0
- data/rails_generators/shoulda_scaffold/templates/erb/index.html.erb +22 -0
- data/rails_generators/shoulda_scaffold/templates/erb/layout.html.erb +22 -0
- data/rails_generators/shoulda_scaffold/templates/erb/new.html.erb +8 -0
- data/rails_generators/shoulda_scaffold/templates/erb/show.html.erb +12 -0
- data/rails_generators/shoulda_scaffold/templates/functional_test/basic.rb +292 -0
- data/rails_generators/shoulda_scaffold/templates/haml/_form.html.haml +11 -0
- data/rails_generators/shoulda_scaffold/templates/haml/edit.html.haml +2 -0
- data/rails_generators/shoulda_scaffold/templates/haml/index.html.haml +20 -0
- data/rails_generators/shoulda_scaffold/templates/haml/layout.html.haml +26 -0
- data/rails_generators/shoulda_scaffold/templates/haml/new.html.haml +2 -0
- data/rails_generators/shoulda_scaffold/templates/haml/show.html.haml +10 -0
- data/rails_generators/shoulda_scaffold/templates/helper.rb +2 -0
- data/rails_generators/shoulda_scaffold/templates/performance_test/browser_test.rb +32 -0
- data/rails_generators/shoulda_scaffold/templates/stylesheets/basic.css +4 -0
- data/rails_generators/shoulda_scaffold/templates/yui/reset-fonts-grids.css +9 -0
- data/test/fixtures/about_yml_plugins/bad_about_yml/about.yml +1 -0
- data/test/fixtures/about_yml_plugins/bad_about_yml/init.rb +1 -0
- data/test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb +1 -0
- data/test/fixtures/eager/zoo.rb +3 -0
- data/test/fixtures/eager/zoo/reptile_house.rb +2 -0
- data/test/fixtures/environment_with_constant.rb +1 -0
- data/test/fixtures/lib/generators/missing_class/missing_class_generator.rb +0 -0
- data/test/fixtures/lib/generators/working/working_generator.rb +2 -0
- data/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb +4 -0
- data/test/fixtures/plugins/default/gemlike/init.rb +1 -0
- data/test/fixtures/plugins/default/gemlike/lib/gemlike.rb +2 -0
- data/test/fixtures/plugins/default/gemlike/rails/init.rb +7 -0
- data/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb +0 -0
- data/test/fixtures/plugins/default/stubby/about.yml +2 -0
- data/test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb +4 -0
- data/test/fixtures/plugins/default/stubby/init.rb +7 -0
- data/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb +2 -0
- data/test/rails_generators/shoulda_model_generator_test.rb +39 -0
- data/test/shoulda_macros/generator_macros.rb +36 -0
- data/test/stolen_from_railties.rb +288 -0
- data/test/test_helper.rb +41 -0
- metadata +152 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
|
2
|
+
def index
|
|
3
|
+
@<%= controller_plural_name %> = <%= class_name %>.paginate(:all, :page => params[:page], :per_page => params[:per_page])
|
|
4
|
+
@page_title = "Listing <%= class_name.pluralize.titleize %>"
|
|
5
|
+
|
|
6
|
+
respond_to do |format|
|
|
7
|
+
format.html # index.html.<%= templating %>
|
|
8
|
+
format.xml { render :xml => @<%= controller_plural_name %> }
|
|
9
|
+
format.json { render :json => @<%= controller_plural_name %> }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def show
|
|
14
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(params[:id])
|
|
15
|
+
@page_title = "Displaying <%= class_name.titleize %> #{@<%= controller_singular_name %>.to_param}"
|
|
16
|
+
|
|
17
|
+
respond_to do |format|
|
|
18
|
+
format.html # show.html.<%= templating %>
|
|
19
|
+
format.xml { render :xml => @<%= controller_singular_name %> }
|
|
20
|
+
format.json { render :json => @<%= controller_singular_name %> }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def new
|
|
25
|
+
@<%= controller_singular_name %> = <%= class_name %>.new(params[:<%= controller_singular_name %>])
|
|
26
|
+
@page_title = "Add a new <%= class_name.titleize %>"
|
|
27
|
+
|
|
28
|
+
respond_to do |format|
|
|
29
|
+
format.html # new.html.<%= templating %>
|
|
30
|
+
format.xml { render :xml => @<%= controller_singular_name %> }
|
|
31
|
+
format.json { render :json => @<%= controller_singular_name %> }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def edit
|
|
36
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(params[:id])
|
|
37
|
+
@page_title = "Editing <%= class_name.titleize %> #{@<%= controller_singular_name %>.to_param}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create
|
|
41
|
+
@<%= controller_singular_name %> = <%= class_name %>.new(params[:<%= controller_singular_name %>])
|
|
42
|
+
@page_title = "Adding a new <%= class_name.titleize %>"
|
|
43
|
+
|
|
44
|
+
respond_to do |format|
|
|
45
|
+
if @<%= controller_singular_name %>.save
|
|
46
|
+
flash[:notice] = '<%= controller_singular_name.humanize %> was successfully created.'
|
|
47
|
+
format.html { redirect_to(<%= controller_member_path %>_path(@<%= controller_singular_name %>)) }
|
|
48
|
+
format.xml { render :xml => @<%= controller_singular_name %>, :status => :created, :location => @<%= controller_singular_name %> }
|
|
49
|
+
format.json { render :json => @<%= controller_singular_name %>, :status => :created, :location => @<%= controller_singular_name %> }
|
|
50
|
+
else
|
|
51
|
+
flash[:error] = '<%= controller_singular_name.humanize %> could not be created.'
|
|
52
|
+
format.html { render :action => "new" }
|
|
53
|
+
format.xml { render :xml => @<%= controller_singular_name %>.errors, :status => :unprocessable_entity }
|
|
54
|
+
format.json { render :json => @<%= controller_singular_name %>.errors, :status => :unprocessable_entity }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def update
|
|
60
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(params[:id])
|
|
61
|
+
@page_title = "Updating <%= class_name.titleize %> #{@<%= controller_singular_name %>.to_param}"
|
|
62
|
+
|
|
63
|
+
respond_to do |format|
|
|
64
|
+
if @<%= controller_singular_name %>.update_attributes(params[:<%= controller_singular_name %>])
|
|
65
|
+
flash[:notice] = '<%= controller_singular_name.humanize %> was successfully updated.'
|
|
66
|
+
format.html { redirect_to(<%= controller_member_path %>_path(@<%= controller_singular_name %>)) }
|
|
67
|
+
format.xml { head :ok }
|
|
68
|
+
format.json { head :ok }
|
|
69
|
+
else
|
|
70
|
+
flash[:error] = '<%= controller_singular_name.humanize %> could not be updated.'
|
|
71
|
+
format.html { render :action => "edit" }
|
|
72
|
+
format.xml { render :xml => @<%= controller_singular_name %>.errors, :status => :unprocessable_entity }
|
|
73
|
+
format.json { render :json => @<%= controller_singular_name %>.errors, :status => :unprocessable_entity }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def destroy
|
|
79
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(params[:id])
|
|
80
|
+
@page_title = 'Removing <%= class_name.titleize %> #{@<%= controller_singular_name %>.to_param}'
|
|
81
|
+
@<%= controller_singular_name %>.destroy
|
|
82
|
+
|
|
83
|
+
respond_to do |format|
|
|
84
|
+
flash[:notice] = '<%= controller_singular_name.humanize %> was successfully removed.'
|
|
85
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
|
86
|
+
format.xml { head :ok }
|
|
87
|
+
format.json { head :ok }
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<h1>Editing <%= singular_name.humanize %></h1>
|
|
2
|
+
|
|
3
|
+
<%% form_for(@<%= singular_name %>) do |form| %>
|
|
4
|
+
<%%= render :partial => 'form', :locals => {:form => form} %>
|
|
5
|
+
<p><%%= form.submit 'Update' %></p>
|
|
6
|
+
<%% end %>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<%%= link_to 'Show', @<%= singular_name %> %>
|
|
10
|
+
|
|
|
11
|
+
<%%= link_to 'Back', <%= plural_name %>_path %>
|
|
12
|
+
</p>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h1> Listing <%= plural_name.humanize %></h1>
|
|
2
|
+
|
|
3
|
+
<table>
|
|
4
|
+
<tr>
|
|
5
|
+
<% for attribute in attributes -%>
|
|
6
|
+
<th><%= attribute.column.human_name %></th>
|
|
7
|
+
<% end -%>
|
|
8
|
+
</tr>
|
|
9
|
+
|
|
10
|
+
<%% for <%= singular_name %> in @<%= plural_name %> %>
|
|
11
|
+
<tr>
|
|
12
|
+
<% for attribute in attributes -%>
|
|
13
|
+
<td><%%= h <%= singular_name %>.<%= attribute.name %> %></td>
|
|
14
|
+
<% end -%>
|
|
15
|
+
<td><%%= link_to 'Show', <%= singular_name %> %></td>
|
|
16
|
+
<td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
|
|
17
|
+
<td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
|
|
18
|
+
</tr>
|
|
19
|
+
<%% end %>
|
|
20
|
+
</table>
|
|
21
|
+
|
|
22
|
+
<p><%%= link_to 'New <%= singular_name.humanize %>', new_<%= singular_name %>_path %></p>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title><%%= "#{controller.controller_name}: #{controller.action_name}" %></title>
|
|
5
|
+
<%%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
|
|
6
|
+
<%%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
|
|
7
|
+
<%%= "<!--[if IE]>#{stylesheet_link_tag 'blueprint/ie', :media => 'screen'}<![endif]-->" %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container">
|
|
11
|
+
<div id="content" class="column span-24">
|
|
12
|
+
<%% flash.each do |key, value| -%>
|
|
13
|
+
<div class="<%%= key %>">
|
|
14
|
+
<%%= h(value) %>
|
|
15
|
+
</div>
|
|
16
|
+
<%% end %>
|
|
17
|
+
|
|
18
|
+
<%%= yield %>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<h1>New <%= singular_name.humanize %></h1>
|
|
2
|
+
|
|
3
|
+
<%% form_for(@<%= singular_name %>) do |form| %>
|
|
4
|
+
<%%= render :partial => 'form', :locals => {:form => form} %>
|
|
5
|
+
<p><%%= form.submit 'Create' %></p>
|
|
6
|
+
<%% end %>
|
|
7
|
+
|
|
8
|
+
<p><%%= link_to 'Back', <%= plural_name %>_path %></p>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<dl>
|
|
2
|
+
<% for attribute in attributes -%>
|
|
3
|
+
<dt><%= attribute.column.human_name %></dt>
|
|
4
|
+
<dd><%%= h @<%= singular_name %>.<%= attribute.name %> %></dd>
|
|
5
|
+
<% end -%>
|
|
6
|
+
</dl>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)%>
|
|
10
|
+
|
|
|
11
|
+
<%%= link_to 'Back', <%= plural_name %>_path %>
|
|
12
|
+
</p>
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + "<%= '/..' * controller_class_nesting_depth + '/../test_helper' %>"
|
|
2
|
+
|
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
|
4
|
+
context "on GET to <%= controller_class_name %>#index" do
|
|
5
|
+
setup do
|
|
6
|
+
get :index
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
should_assign_to :page_title, :<%= controller_plural_name %>
|
|
10
|
+
should_render_template :index
|
|
11
|
+
should_respond_with :success
|
|
12
|
+
should_not_set_the_flash
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "on GET to <%= controller_class_name %>#index as xml" do
|
|
16
|
+
setup do
|
|
17
|
+
get :index, :format => 'xml'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
should_assign_to :<%= controller_plural_name %>
|
|
21
|
+
should_respond_with :success
|
|
22
|
+
should_respond_with_content_type :xml
|
|
23
|
+
should_not_set_the_flash
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "on GET to <%= controller_class_name %>#index as json" do
|
|
27
|
+
setup do
|
|
28
|
+
get :index, :format => 'json'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
should_assign_to :<%= controller_plural_name %>
|
|
32
|
+
should_respond_with :success
|
|
33
|
+
should_respond_with_content_type :json
|
|
34
|
+
should_not_set_the_flash
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "on GET to <%= controller_class_name %>#new" do
|
|
38
|
+
setup do
|
|
39
|
+
get :new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should_assign_to :page_title, :<%= controller_singular_name %>
|
|
43
|
+
should_respond_with :success
|
|
44
|
+
should_render_template :new
|
|
45
|
+
should_not_set_the_flash
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "on GET to <%= controller_class_name %>#new as xml" do
|
|
49
|
+
setup do
|
|
50
|
+
get :new, :format => 'xml'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should_assign_to :<%= controller_singular_name %>
|
|
54
|
+
should_respond_with :success
|
|
55
|
+
should_respond_with_content_type :xml
|
|
56
|
+
should_not_set_the_flash
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "on GET to <%= controller_class_name %>#new as json" do
|
|
60
|
+
setup do
|
|
61
|
+
get :new, :format => 'json'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
should_assign_to :<%= controller_singular_name %>
|
|
65
|
+
should_respond_with :success
|
|
66
|
+
should_respond_with_content_type :json
|
|
67
|
+
should_not_set_the_flash
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "on POST to <%= controller_class_name %>#create" do
|
|
71
|
+
setup do
|
|
72
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>)
|
|
73
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(:all).last
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
77
|
+
should_redirect_to '<%= controller_member_path %>_path(@<%= controller_singular_name %>)'
|
|
78
|
+
should_set_the_flash_to /created/i
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "on POST to <%= controller_class_name %>#create (unsuccessful)" do
|
|
82
|
+
setup do
|
|
83
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, :class => <%= class_name %>, :errors => '', :id => '1')
|
|
84
|
+
@<%= controller_singular_name %>.stubs(:save).returns(false)
|
|
85
|
+
<%= class_name %>.expects(:new).returns(@<%= controller_singular_name %>)
|
|
86
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
90
|
+
should_render_template :new
|
|
91
|
+
should_set_the_flash_to /could not/i
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "on POST to <%= controller_class_name %>#create as xml" do
|
|
95
|
+
setup do
|
|
96
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'xml'
|
|
97
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(:all).last
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
should_assign_to :<%= controller_singular_name %>
|
|
101
|
+
should_respond_with :created
|
|
102
|
+
should_respond_with_content_type :xml
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context "on POST to <%= controller_class_name %>#create as xml (unsuccessful)" do
|
|
106
|
+
setup do
|
|
107
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, :class => <%= class_name %>, :errors => '', :id => '1')
|
|
108
|
+
@<%= controller_singular_name %>.stubs(:save).returns(false)
|
|
109
|
+
<%= class_name %>.expects(:new).returns(@<%= controller_singular_name %>)
|
|
110
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'xml'
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
should_assign_to :<%= controller_singular_name %>
|
|
114
|
+
should_respond_with :unprocessable_entity
|
|
115
|
+
should_respond_with_content_type :xml
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context "on POST to <%= controller_class_name %>#create as json" do
|
|
119
|
+
setup do
|
|
120
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'json'
|
|
121
|
+
@<%= controller_singular_name %> = <%= class_name %>.find(:all).last
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
should_assign_to :<%= controller_singular_name %>
|
|
125
|
+
should_respond_with :created
|
|
126
|
+
should_respond_with_content_type :json
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
context "on POST to <%= controller_class_name %>#create as json (unsuccessful)" do
|
|
130
|
+
setup do
|
|
131
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, :class => <%= class_name %>, :errors => '', :id => '1')
|
|
132
|
+
@<%= controller_singular_name %>.stubs(:save).returns(false)
|
|
133
|
+
<%= class_name %>.expects(:new).returns(@<%= controller_singular_name %>)
|
|
134
|
+
post :create, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'json'
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
should_assign_to :<%= controller_singular_name %>
|
|
138
|
+
should_respond_with :unprocessable_entity
|
|
139
|
+
should_respond_with_content_type :json
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
context "on GET to <%= controller_class_name %>#show" do
|
|
143
|
+
setup do
|
|
144
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
145
|
+
get :show, :id => @<%= controller_singular_name %>.to_param
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
149
|
+
should_respond_with :success
|
|
150
|
+
should_render_template :show
|
|
151
|
+
should_not_set_the_flash
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context "on GET to <%= controller_class_name %>#show as xml" do
|
|
155
|
+
setup do
|
|
156
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
157
|
+
get :show, :id => @<%= controller_singular_name %>.to_param, :format => 'xml'
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
should_assign_to :<%= controller_singular_name %>
|
|
161
|
+
should_respond_with :success
|
|
162
|
+
should_respond_with_content_type :xml
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context "on GET to <%= controller_class_name %>#show as json" do
|
|
166
|
+
setup do
|
|
167
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
168
|
+
get :show, :id => @<%= controller_singular_name %>.to_param, :format => 'json'
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
should_assign_to :<%= controller_singular_name %>
|
|
172
|
+
should_respond_with :success
|
|
173
|
+
should_respond_with_content_type :json
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context "on GET to <%= controller_class_name %>#edit" do
|
|
177
|
+
setup do
|
|
178
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
179
|
+
get :edit, :id => @<%= controller_singular_name %>.to_param
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
should_assign_to :<%= controller_singular_name %>
|
|
183
|
+
should_respond_with :success
|
|
184
|
+
should_render_template :edit
|
|
185
|
+
should_not_set_the_flash
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
context "on PUT to <%= controller_class_name %>#update" do
|
|
189
|
+
setup do
|
|
190
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
191
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
195
|
+
should_redirect_to '<%= controller_member_path %>_path(@<%= controller_singular_name %>)'
|
|
196
|
+
should_set_the_flash_to /updated/i
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
context "on PUT to <%= controller_class_name %>#update (unsuccessful)" do
|
|
200
|
+
setup do
|
|
201
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, {:class => <%= class_name %>, :errors => '', :id => '1'}.merge(Factory.attributes_for(:<%= controller_singular_name %>)))
|
|
202
|
+
@<%= controller_singular_name %>.stubs(:update_attributes).returns(false)
|
|
203
|
+
<%= class_name %>.expects(:find).returns(@<%= controller_singular_name %>)
|
|
204
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
208
|
+
should_render_template :edit
|
|
209
|
+
should_set_the_flash_to /could not/i
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
context "on PUT to <%= controller_class_name %>#update with xml" do
|
|
213
|
+
setup do
|
|
214
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
215
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'xml'
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
should_assign_to :<%= controller_singular_name %>
|
|
219
|
+
should_respond_with :ok
|
|
220
|
+
should_respond_with_content_type :xml
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context "on PUT to <%= controller_class_name %>#update with xml (unsuccessful)" do
|
|
224
|
+
setup do
|
|
225
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, {:class => <%= class_name %>, :errors => '', :id => '1'}.merge(Factory.attributes_for(:<%= controller_singular_name %>)))
|
|
226
|
+
@<%= controller_singular_name %>.stubs(:update_attributes).returns(false)
|
|
227
|
+
<%= class_name %>.expects(:find).returns(@<%= controller_singular_name %>)
|
|
228
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'xml'
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
should_assign_to :<%= controller_singular_name %>
|
|
232
|
+
should_respond_with :unprocessable_entity
|
|
233
|
+
should_respond_with_content_type :xml
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
context "on PUT to <%= controller_class_name %>#update with json" do
|
|
237
|
+
setup do
|
|
238
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
239
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'json'
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
should_assign_to :<%= controller_singular_name %>
|
|
243
|
+
should_respond_with :ok
|
|
244
|
+
should_respond_with_content_type :json
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
context "on PUT to <%= controller_class_name %>#update with json (unsuccessful)" do
|
|
248
|
+
setup do
|
|
249
|
+
@<%= controller_singular_name %> = Factory.stub(:<%= controller_singular_name %>, {:class => <%= class_name %>, :errors => '', :id => '1'}.merge(Factory.attributes_for(:<%= controller_singular_name %>)))
|
|
250
|
+
@<%= controller_singular_name %>.stubs(:update_attributes).returns(false)
|
|
251
|
+
<%= class_name %>.expects(:find).returns(@<%= controller_singular_name %>)
|
|
252
|
+
put :update, :id => @<%= controller_singular_name %>.to_param, :<%= controller_singular_name %> => Factory.attributes_for(:<%= controller_singular_name %>), :format => 'json'
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
should_assign_to :<%= controller_singular_name %>
|
|
256
|
+
should_respond_with :unprocessable_entity
|
|
257
|
+
should_respond_with_content_type :json
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context "on DELETE to <%= controller_class_name %>#destroy" do
|
|
261
|
+
setup do
|
|
262
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
263
|
+
delete :destroy, :id => @<%= controller_singular_name %>.to_param
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
should_assign_to :<%= controller_singular_name %>, :page_title
|
|
267
|
+
should_set_the_flash_to /removed/i
|
|
268
|
+
should_redirect_to '<%= controller_collection_path %>_path()'
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
context "on DELETE to <%= controller_class_name %>#destroy with xml" do
|
|
272
|
+
setup do
|
|
273
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
274
|
+
delete :destroy, :id => @<%= controller_singular_name %>.to_param, :format => 'xml'
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
should_assign_to :<%= controller_singular_name %>
|
|
278
|
+
should_respond_with :ok
|
|
279
|
+
should_respond_with_content_type :xml
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
context "on DELETE to <%= controller_class_name %>#destroy with json" do
|
|
283
|
+
setup do
|
|
284
|
+
@<%= controller_singular_name %> = Factory(:<%= controller_singular_name %>)
|
|
285
|
+
delete :destroy, :id => @<%= controller_singular_name %>.to_param, :format => 'json'
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
should_assign_to :<%= controller_singular_name %>
|
|
289
|
+
should_respond_with :ok
|
|
290
|
+
should_respond_with_content_type :json
|
|
291
|
+
end
|
|
292
|
+
end
|