authorized_rails_scaffolds 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -4
- data/lib/authorized_rails_scaffolds/version.rb +1 -1
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/_form.html.erb +14 -5
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/controller.rb +21 -16
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/edit.html.erb +6 -1
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/index.html.erb +23 -14
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/new.html.erb +6 -1
- data/lib/generators/authorized_rails_scaffolds/install_scaffold/templates/show.html.erb +37 -12
- data/lib/generators/authorized_rails_scaffolds/install_spec/install_spec_generator.rb +28 -7
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/controller_spec.rb +71 -65
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/devise_can_can/USAGE +7 -0
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/devise_can_can/controller_macros.rb +25 -0
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/edit_spec.rb +57 -43
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/index_spec.rb +81 -59
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/model_spec.rb +28 -0
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/new_spec.rb +53 -39
- data/lib/generators/authorized_rails_scaffolds/install_spec/templates/show_spec.rb +85 -37
- metadata +11 -8
data/README.md
CHANGED
@@ -55,11 +55,9 @@ For example:
|
|
55
55
|
rails g model FooBar name:string age:integer date_of_birth:date lunch_time:time programmer:boolean joined_at:datetime
|
56
56
|
rails g scaffold_controller Awesome/FooBar name:string age:integer date_of_birth:date lunch_time:time programmer:boolean joined_at:datetime
|
57
57
|
|
58
|
-
### Install Spec
|
58
|
+
### Install Spec Templates
|
59
59
|
|
60
|
-
`authorized_rails_scaffolds` provides a series of rspec generators that replace the default controller and view spec templates generated by RSpec.
|
61
|
-
|
62
|
-
The generated specs assume you are have a FactoryGirl factory called `user`.
|
60
|
+
`authorized_rails_scaffolds` provides a series of rspec generators that replace the default controller and view spec templates generated by RSpec.
|
63
61
|
|
64
62
|
You can install the generators by running:
|
65
63
|
|
@@ -1,7 +1,14 @@
|
|
1
|
-
<%-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<%-
|
2
|
+
|
3
|
+
local_class_name = file_name.classify # Non-Namespaced class name
|
4
|
+
var_name = file_name # Non-namespaced variable name
|
5
|
+
plural_var_name = var_name.pluralize # Pluralized non-namespaced variable name
|
6
|
+
|
7
|
+
form_objects = singular_table_name.split(file_name, -1)[0..-2].join(file_name)
|
8
|
+
form_object_array = form_objects.blank? ? "@#{var_name}" : "[:#{form_objects.split('_').join(', :')}, @#{var_name}]"
|
9
|
+
|
10
|
+
-%>
|
11
|
+
<%%= simple_form_for(<%= form_object_array %>, :html => { class: 'form-horizontal' }) do |f| %>
|
5
12
|
<%%= f.error_notification %>
|
6
13
|
|
7
14
|
<div class="form-inputs">
|
@@ -13,6 +20,8 @@
|
|
13
20
|
<div class="form-actions">
|
14
21
|
<%%= f.button :submit, :class => 'btn-primary' %>
|
15
22
|
<%%= link_to t('.cancel', :default => t("helpers.links.cancel")),
|
16
|
-
<%= index_helper %>_path,
|
23
|
+
<%= index_helper %>_path,
|
24
|
+
:class => 'btn'
|
25
|
+
%>
|
17
26
|
</div>
|
18
27
|
<%% end %>
|
@@ -2,10 +2,15 @@
|
|
2
2
|
require_dependency "<%= namespaced_file_path %>/application_controller"
|
3
3
|
|
4
4
|
<% end -%>
|
5
|
-
<%-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
<%-
|
6
|
+
|
7
|
+
local_class_name = local_class_name = class_name.split("::")[-1] # Non-Namespaced class name
|
8
|
+
var_name = file_name # Non-namespaced variable name
|
9
|
+
plural_var_name = var_name.pluralize # Pluralized non-namespaced variable name
|
10
|
+
|
11
|
+
orm_instance = Rails::Generators::ActiveModel.new var_name
|
12
|
+
|
13
|
+
-%>
|
9
14
|
<% module_namespacing do -%>
|
10
15
|
class <%= controller_class_name %>Controller < ApplicationController
|
11
16
|
load_and_authorize_resource
|
@@ -24,39 +29,39 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
24
29
|
# GET <%= route_url %>/1
|
25
30
|
# GET <%= route_url %>/1.json
|
26
31
|
def show
|
27
|
-
# @<%=
|
32
|
+
# @<%= var_name %> = <%= orm_class.find(local_class_name, "params[:id]") %>
|
28
33
|
|
29
34
|
respond_to do |format|
|
30
35
|
format.html # show.html.erb
|
31
|
-
format.json { render <%= key_value :json, "@#{
|
36
|
+
format.json { render <%= key_value :json, "@#{var_name}" %> }
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
40
|
# GET <%= route_url %>/new
|
36
41
|
# GET <%= route_url %>/new.json
|
37
42
|
def new
|
38
|
-
# @<%=
|
43
|
+
# @<%= var_name %> = <%= orm_class.build(local_class_name) %>
|
39
44
|
|
40
45
|
respond_to do |format|
|
41
46
|
format.html # new.html.erb
|
42
|
-
format.json { render <%= key_value :json, "@#{
|
47
|
+
format.json { render <%= key_value :json, "@#{var_name}" %> }
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
51
|
# GET <%= route_url %>/1/edit
|
47
52
|
def edit
|
48
|
-
# @<%=
|
53
|
+
# @<%= var_name %> = <%= orm_class.find(local_class_name, "params[:id]") %>
|
49
54
|
end
|
50
55
|
|
51
56
|
# POST <%= route_url %>
|
52
57
|
# POST <%= route_url %>.json
|
53
58
|
def create
|
54
|
-
# @<%=
|
59
|
+
# @<%= var_name %> = <%= orm_class.build(local_class_name, "params[:#{var_name}]") %>
|
55
60
|
|
56
61
|
respond_to do |format|
|
57
62
|
if @<%= orm_instance.save %>
|
58
|
-
format.html { redirect_to <%= singular_table_name %>_path(@<%=
|
59
|
-
format.json { render <%= key_value :json, "@#{
|
63
|
+
format.html { redirect_to <%= singular_table_name %>_path(@<%= var_name %>), <%= key_value :notice, "'#{human_name} was successfully created.'" %> }
|
64
|
+
format.json { render <%= key_value :json, "@#{var_name}" %>, <%= key_value :status, ':created' %>, <%= key_value :location, "#{singular_table_name}_path(@#{var_name})" %> }
|
60
65
|
else
|
61
66
|
format.html { render <%= key_value :action, '"new"' %> }
|
62
67
|
format.json { render <%= key_value :json, "@#{orm_instance.errors}" %>, <%= key_value :status, ':unprocessable_entity' %> }
|
@@ -67,11 +72,11 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
67
72
|
# PUT <%= route_url %>/1
|
68
73
|
# PUT <%= route_url %>/1.json
|
69
74
|
def update
|
70
|
-
# @<%=
|
75
|
+
# @<%= var_name %> = <%= orm_class.find(local_class_name, "params[:id]") %>
|
71
76
|
|
72
77
|
respond_to do |format|
|
73
|
-
if @<%= orm_instance.update_attributes("params[:#{
|
74
|
-
format.html { redirect_to <%= singular_table_name %>_path(@<%=
|
78
|
+
if @<%= orm_instance.update_attributes("params[:#{var_name}]") %>
|
79
|
+
format.html { redirect_to <%= singular_table_name %>_path(@<%= var_name %>), <%= key_value :notice, "'#{human_name} was successfully updated.'" %> }
|
75
80
|
format.json { head :no_content }
|
76
81
|
else
|
77
82
|
format.html { render <%= key_value :action, '"edit"' %> }
|
@@ -83,7 +88,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
83
88
|
# DELETE <%= route_url %>/1
|
84
89
|
# DELETE <%= route_url %>/1.json
|
85
90
|
def destroy
|
86
|
-
# @<%=
|
91
|
+
# @<%= var_name %> = <%= orm_class.find(local_class_name, "params[:id]") %>
|
87
92
|
@<%= orm_instance.destroy %>
|
88
93
|
|
89
94
|
respond_to do |format|
|
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
<%-
|
2
|
+
|
3
|
+
local_class_name = file_name.classify # Non-Namespaced class name
|
4
|
+
|
5
|
+
-%>
|
6
|
+
<%%- model_class = <%= local_class_name %> -%>
|
2
7
|
<div class="page-header">
|
3
8
|
<h1><%%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human %></h1>
|
4
9
|
</div>
|
@@ -1,6 +1,11 @@
|
|
1
|
-
<%-
|
2
|
-
|
3
|
-
|
1
|
+
<%-
|
2
|
+
|
3
|
+
local_class_name = file_name.classify # Non-Namespaced class name
|
4
|
+
var_name = file_name # Non-namespaced variable name
|
5
|
+
plural_var_name = var_name.pluralize # Pluralized non-namespaced variable name
|
6
|
+
|
7
|
+
-%>
|
8
|
+
<%%- model_class = <%= local_class_name %> -%>
|
4
9
|
<div class="page-header">
|
5
10
|
<h1><%%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
|
6
11
|
</div>
|
@@ -16,36 +21,40 @@
|
|
16
21
|
</tr>
|
17
22
|
</thead>
|
18
23
|
<tbody>
|
19
|
-
<%% @<%= plural_var_name %>.each do |<%=
|
20
|
-
<tr class="<%=
|
21
|
-
<td class="id-column"><%%= <%=
|
24
|
+
<%% @<%= plural_var_name %>.each do |<%= var_name %>| %>
|
25
|
+
<tr class="<%= var_name %>_<%%= <%= var_name %>.id %>">
|
26
|
+
<td class="id-column"><%%= <%= var_name %>.id %></td>
|
22
27
|
<%- if attributes.any? -%>
|
23
|
-
<td class="title-column"><%%= link_to <%=
|
28
|
+
<td class="title-column"><%%= link_to <%= var_name %>.<%= attributes[0].name %>, <%= singular_table_name %>_path(<%= var_name %>) %></td>
|
24
29
|
<%- attributes[1..-1].each do |attribute| -%>
|
25
30
|
<%- if [:datetime, :timestamp, :time, :date].include? attribute.type -%>
|
26
|
-
<td
|
31
|
+
<td><%% unless <%= var_name %>.<%= attribute.name %>.nil? %><%%=l <%= var_name %>.<%= attribute.name %><% if attribute.type == :datetime %>, :format => :long<% end %><% if attribute.type == :time %>, :format => :short<% end %> %><%% end %></td>
|
27
32
|
<%- else -%>
|
28
|
-
<td><%%= <%=
|
33
|
+
<td><%%= <%= var_name %>.<%= attribute.name %> %></td>
|
29
34
|
<%- end -%>
|
30
35
|
<%- end -%>
|
31
36
|
<%- end -%>
|
32
|
-
<td><%%=l <%=
|
37
|
+
<td><%%=l <%= var_name %>.created_at, :format => :long %></td>
|
33
38
|
<td class="table-actions">
|
34
39
|
<%%= link_to t('.edit', :default => t("helpers.links.edit")),
|
35
|
-
edit_<%= singular_table_name %>_path(<%=
|
40
|
+
edit_<%= singular_table_name %>_path(<%= var_name %>),
|
41
|
+
:class => 'btn btn-mini',
|
42
|
+
:disabled => !can?(:update, <%= var_name %>)
|
43
|
+
%>
|
36
44
|
<%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
|
37
|
-
<%= singular_table_name %>_path(<%=
|
45
|
+
<%= singular_table_name %>_path(<%= var_name %>),
|
38
46
|
:method => :delete,
|
39
47
|
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
|
40
48
|
:class => 'btn btn-mini btn-danger',
|
41
|
-
:disabled => !can?(:destroy, <%=
|
49
|
+
:disabled => !can?(:destroy, <%= var_name %>)
|
50
|
+
%>
|
42
51
|
</td>
|
43
52
|
</tr>
|
44
53
|
<%% end %>
|
45
54
|
</tbody>
|
46
55
|
</table>
|
47
56
|
|
48
|
-
<%% if can?(:create, <%=
|
57
|
+
<%% if can?(:create, <%= local_class_name %>) %>
|
49
58
|
<%%= link_to t('.new', :default => t("helpers.links.new")),
|
50
59
|
new_<%= singular_table_name %>_path,
|
51
60
|
:class => 'btn btn-primary' %>
|
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
<%-
|
2
|
+
|
3
|
+
local_class_name = file_name.classify # Non-Namespaced class name
|
4
|
+
|
5
|
+
-%>
|
6
|
+
<%%- model_class = <%= local_class_name %> -%>
|
2
7
|
<div class="page-header">
|
3
8
|
<h1><%%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human %></h1>
|
4
9
|
</div>
|
@@ -1,18 +1,40 @@
|
|
1
|
-
<%-
|
2
|
-
|
1
|
+
<%-
|
2
|
+
|
3
|
+
local_class_name = file_name.classify # Non-Namespaced class name
|
4
|
+
var_name = file_name # Non-namespaced variable name
|
5
|
+
plural_var_name = var_name.pluralize # Pluralized non-namespaced variable name
|
6
|
+
|
7
|
+
path_prefix = singular_table_name[0..-(file_name.length+1)]
|
8
|
+
|
9
|
+
-%>
|
10
|
+
<%%- model_class = <%= local_class_name %> -%>
|
3
11
|
<div class="page-header">
|
4
12
|
<h1><%%=t '.title', :default => model_class.model_name.human %></h1>
|
5
13
|
</div>
|
6
14
|
|
7
15
|
<dl class="dl-horizontal item-summary">
|
8
16
|
<%- attributes.each do |attribute| -%>
|
9
|
-
|
10
|
-
<%- if
|
11
|
-
<%%
|
12
|
-
<
|
17
|
+
<%- attribute_label = "model_class.human_attribute_name(:#{attribute.name})" -%>
|
18
|
+
<%- if attribute.type == :references -%>
|
19
|
+
<%% if @<%= var_name %>.<%= attribute.name %>.present? && can?(:read, @<%= var_name %>.<%= attribute.name %>) %>
|
20
|
+
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
21
|
+
<dd><%%= link_to @<%= var_name %>.<%= attribute.name %>, <%= path_prefix %><%= attribute.name %>_path(@<%= var_name %>.<%= attribute.name %>) %></dd>
|
22
|
+
<%% end %>
|
23
|
+
<%- elsif [:datetime, :timestamp, :time, :date].include? attribute.type -%>
|
24
|
+
<%% unless @<%= var_name %>.<%= attribute.name %>.nil? %>
|
25
|
+
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
26
|
+
<dd><%%=l @<%= var_name %>.<%= attribute.name %><% if attribute.type == :datetime %>, :format => :long<% end %><% if attribute.type == :time %>, :format => :short<% end %> %></dd>
|
27
|
+
<%% end %>
|
28
|
+
<%- elsif attribute.type == :string -%>
|
29
|
+
<%% unless @<%= var_name %>.<%= attribute.name %>.blank? %>
|
30
|
+
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
31
|
+
<dd><%%= @<%= var_name %>.<%= attribute.name %> %></dd>
|
13
32
|
<%% end %>
|
14
33
|
<%- else -%>
|
15
|
-
|
34
|
+
<%% unless @<%= var_name %>.<%= attribute.name %>.nil? %>
|
35
|
+
<dt><strong><%%= <%= attribute_label %> %>:</strong></dt>
|
36
|
+
<dd><%%= @<%= var_name %>.<%= attribute.name %> %></dd>
|
37
|
+
<%% end %>
|
16
38
|
<%- end -%>
|
17
39
|
<%- end -%>
|
18
40
|
</dl>
|
@@ -20,15 +42,18 @@
|
|
20
42
|
<div class="form-actions">
|
21
43
|
<%%= link_to t('.back', :default => t("helpers.links.back")),
|
22
44
|
<%= index_helper %>_path, :class => 'btn' %>
|
23
|
-
<%% if can? :update, @<%=
|
45
|
+
<%% if can? :update, @<%= var_name %> %>
|
24
46
|
<%%= link_to t('.edit', :default => t("helpers.links.edit")),
|
25
|
-
edit_<%= singular_table_name %>_path(@<%=
|
47
|
+
edit_<%= singular_table_name %>_path(@<%= var_name %>),
|
48
|
+
:class => 'btn'
|
49
|
+
%>
|
26
50
|
<%% end %>
|
27
|
-
<%% if can? :destroy, @<%=
|
51
|
+
<%% if can? :destroy, @<%= var_name %> %>
|
28
52
|
<%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
|
29
|
-
<%= singular_table_name %>_path(@<%=
|
53
|
+
<%= singular_table_name %>_path(@<%= var_name %>),
|
30
54
|
:method => 'delete',
|
31
55
|
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
|
32
|
-
:class => 'act act-danger pull-right'
|
56
|
+
:class => 'act act-danger pull-right'
|
57
|
+
%>
|
33
58
|
<%% end %>
|
34
59
|
</div>
|
@@ -1,17 +1,38 @@
|
|
1
1
|
class AuthorizedRailsScaffolds::InstallSpecGenerator < Rails::Generators::Base
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
class_option :authentication, :type => 'string', :default => 'devise', :desc => "Authentication Provider (Devise)"
|
5
|
+
class_option :authorization, :type => 'string', :default => 'can_can', :desc => "Authorization Provider (CanCan)"
|
6
|
+
|
7
|
+
def create_model_templates
|
8
|
+
copy_model_template 'model_spec.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_scaffold_templates
|
12
|
+
copy_scaffold_template 'controller_spec.rb'
|
13
|
+
copy_scaffold_template 'edit_spec.rb'
|
14
|
+
copy_scaffold_template 'index_spec.rb'
|
15
|
+
copy_scaffold_template 'new_spec.rb'
|
16
|
+
copy_scaffold_template 'show_spec.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_controller_macros
|
20
|
+
parts = []
|
21
|
+
parts << options[:authentication].underscore unless options[:authentication].nil?
|
22
|
+
parts << options[:authorization].underscore unless options[:authorization].nil?
|
23
|
+
template_file = parts.any? ? parts.join('_') : nil
|
24
|
+
|
25
|
+
copy_file [template_file, 'controller_macros.rb'].join('/'), "spec/support/#{template_file}_controller_macros.rb"
|
26
|
+
readme [template_file, 'USAGE'].join('/')
|
10
27
|
end
|
11
28
|
|
12
29
|
protected
|
13
30
|
|
14
|
-
def
|
31
|
+
def copy_model_template(template_name)
|
32
|
+
copy_file template_name, "lib/templates/rspec/model/#{template_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_scaffold_template(template_name)
|
15
36
|
copy_file template_name, "lib/templates/rspec/scaffold/#{template_name}"
|
16
37
|
end
|
17
38
|
|
@@ -19,19 +19,25 @@ require 'spec_helper'
|
|
19
19
|
# that an instance is receiving a specific message.
|
20
20
|
|
21
21
|
<% module_namespacing do -%>
|
22
|
-
<%-
|
22
|
+
<%-
|
23
|
+
|
24
|
+
local_class_name = class_name.split('::')[-1] # Non-Namespaced class name
|
25
|
+
var_name = file_name # Non-namespaced variable name
|
26
|
+
plural_var_name = var_name.pluralize # Pluralized non-namespaced variable name
|
27
|
+
|
28
|
+
-%>
|
23
29
|
describe <%= controller_class_name %>Controller do
|
24
30
|
|
25
31
|
# This should return the minimal set of attributes required to create a valid
|
26
32
|
# <%= local_class_name %>.
|
27
33
|
def valid_create_attributes
|
28
|
-
FactoryGirl.attributes_for(:<%=
|
34
|
+
FactoryGirl.attributes_for(:<%= var_name %>)
|
29
35
|
end
|
30
36
|
|
31
37
|
# This should return the minimal set of attributes required to update a valid
|
32
38
|
# <%= local_class_name %>.
|
33
39
|
def valid_update_attributes
|
34
|
-
FactoryGirl.attributes_for(:<%=
|
40
|
+
FactoryGirl.attributes_for(:<%= var_name %>)
|
35
41
|
end
|
36
42
|
|
37
43
|
<% unless options[:singleton] -%>
|
@@ -39,7 +45,7 @@ describe <%= controller_class_name %>Controller do
|
|
39
45
|
context 'without a user' do
|
40
46
|
describe 'with valid request' do
|
41
47
|
before(:each) do
|
42
|
-
@<%=
|
48
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
43
49
|
get :index, {}
|
44
50
|
end
|
45
51
|
it { should redirect_to(new_user_session_path) }
|
@@ -50,7 +56,7 @@ describe <%= controller_class_name %>Controller do
|
|
50
56
|
login_unauthorized_user
|
51
57
|
describe 'with valid request' do
|
52
58
|
before(:each) do
|
53
|
-
@<%=
|
59
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
54
60
|
get :index, {}
|
55
61
|
end
|
56
62
|
it { should redirect_to(root_url) }
|
@@ -61,14 +67,14 @@ describe <%= controller_class_name %>Controller do
|
|
61
67
|
login_user_with_ability :read, <%= local_class_name %>
|
62
68
|
describe 'with valid request' do
|
63
69
|
before(:each) do
|
64
|
-
@<%=
|
70
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
65
71
|
get :index, {}
|
66
72
|
end
|
67
73
|
it { should respond_with(:success) }
|
68
74
|
it { should render_template(:index) }
|
69
75
|
it { should render_with_layout(:application) }
|
70
|
-
it "assigns all <%=
|
71
|
-
assigns(:<%=
|
76
|
+
it "assigns all <%= plural_var_name %> as @<%= plural_var_name %>" do
|
77
|
+
assigns(:<%= plural_var_name %>).should eq([@<%= var_name %>])
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
@@ -79,8 +85,8 @@ describe <%= controller_class_name %>Controller do
|
|
79
85
|
context 'without a user' do
|
80
86
|
describe 'with valid request' do
|
81
87
|
before(:each) do
|
82
|
-
@<%=
|
83
|
-
get :show, {:id => @<%=
|
88
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
89
|
+
get :show, {:id => @<%= var_name %>.to_param}
|
84
90
|
end
|
85
91
|
it { should redirect_to(new_user_session_path) }
|
86
92
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -90,8 +96,8 @@ describe <%= controller_class_name %>Controller do
|
|
90
96
|
login_unauthorized_user
|
91
97
|
describe 'with valid request' do
|
92
98
|
before(:each) do
|
93
|
-
@<%=
|
94
|
-
get :show, {:id => @<%=
|
99
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
100
|
+
get :show, {:id => @<%= var_name %>.to_param}
|
95
101
|
end
|
96
102
|
it { should redirect_to(<%= index_helper %>_path) }
|
97
103
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
@@ -101,14 +107,14 @@ describe <%= controller_class_name %>Controller do
|
|
101
107
|
login_user_with_ability :read, <%= local_class_name %>
|
102
108
|
describe 'with valid request' do
|
103
109
|
before(:each) do
|
104
|
-
@<%=
|
105
|
-
get :show, {:id => @<%=
|
110
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
111
|
+
get :show, {:id => @<%= var_name %>.to_param}
|
106
112
|
end
|
107
113
|
it { should respond_with(:success) }
|
108
114
|
it { should render_template(:show) }
|
109
115
|
it { should render_with_layout(:application) }
|
110
|
-
it "assigns the requested <%=
|
111
|
-
assigns(:<%=
|
116
|
+
it "assigns the requested <%= var_name %> as @<%= var_name %>" do
|
117
|
+
assigns(:<%= var_name %>).should eq(@<%= var_name %>)
|
112
118
|
end
|
113
119
|
end
|
114
120
|
end
|
@@ -143,8 +149,8 @@ describe <%= controller_class_name %>Controller do
|
|
143
149
|
it { should respond_with(:success) }
|
144
150
|
it { should render_template(:new) }
|
145
151
|
it { should render_with_layout(:application) }
|
146
|
-
it "assigns a new <%=
|
147
|
-
assigns(:<%=
|
152
|
+
it "assigns a new <%= var_name %> as @<%= var_name %>" do
|
153
|
+
assigns(:<%= var_name %>).should be_a_new(<%= local_class_name %>)
|
148
154
|
end
|
149
155
|
end
|
150
156
|
end
|
@@ -154,8 +160,8 @@ describe <%= controller_class_name %>Controller do
|
|
154
160
|
context 'without a user' do
|
155
161
|
describe 'with valid request' do
|
156
162
|
before(:each) do
|
157
|
-
@<%=
|
158
|
-
get :edit, {:id => @<%=
|
163
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
164
|
+
get :edit, {:id => @<%= var_name %>.to_param}
|
159
165
|
end
|
160
166
|
it { should redirect_to(new_user_session_path) }
|
161
167
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -165,8 +171,8 @@ describe <%= controller_class_name %>Controller do
|
|
165
171
|
login_unauthorized_user
|
166
172
|
describe 'with valid request' do
|
167
173
|
before(:each) do
|
168
|
-
@<%=
|
169
|
-
get :edit, {:id => @<%=
|
174
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
175
|
+
get :edit, {:id => @<%= var_name %>.to_param}
|
170
176
|
end
|
171
177
|
it { should redirect_to(<%= index_helper %>_url) }
|
172
178
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
@@ -176,14 +182,14 @@ describe <%= controller_class_name %>Controller do
|
|
176
182
|
login_user_with_ability :update, <%= local_class_name %>
|
177
183
|
describe 'with valid request' do
|
178
184
|
before(:each) do
|
179
|
-
@<%=
|
180
|
-
get :edit, {:id => @<%=
|
185
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
186
|
+
get :edit, {:id => @<%= var_name %>.to_param}
|
181
187
|
end
|
182
188
|
it { should respond_with(:success) }
|
183
189
|
it { should render_template(:edit) }
|
184
190
|
it { should render_with_layout(:application) }
|
185
|
-
it "assigns the requested <%=
|
186
|
-
assigns(:<%=
|
191
|
+
it "assigns the requested <%= var_name %> as @<%= var_name %>" do
|
192
|
+
assigns(:<%= var_name %>).should eq(@<%= var_name %>)
|
187
193
|
end
|
188
194
|
end
|
189
195
|
end
|
@@ -193,7 +199,7 @@ describe <%= controller_class_name %>Controller do
|
|
193
199
|
context 'without a user' do
|
194
200
|
describe 'with valid params' do
|
195
201
|
before(:each) do
|
196
|
-
post :create, {:<%=
|
202
|
+
post :create, {:<%= var_name %> => valid_create_attributes}
|
197
203
|
end
|
198
204
|
it { should redirect_to(new_user_session_path) }
|
199
205
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -203,7 +209,7 @@ describe <%= controller_class_name %>Controller do
|
|
203
209
|
login_unauthorized_user
|
204
210
|
describe "with valid params" do
|
205
211
|
before(:each) do
|
206
|
-
post :create, {:<%=
|
212
|
+
post :create, {:<%= var_name %> => valid_create_attributes}
|
207
213
|
end
|
208
214
|
it { should redirect_to(<%= index_helper %>_url) }
|
209
215
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
@@ -214,19 +220,19 @@ describe <%= controller_class_name %>Controller do
|
|
214
220
|
describe "with valid params" do
|
215
221
|
it "creates a new <%= local_class_name %>" do
|
216
222
|
expect {
|
217
|
-
post :create, {:<%=
|
223
|
+
post :create, {:<%= var_name %> => valid_create_attributes}
|
218
224
|
}.to change(<%= local_class_name %>, :count).by(1)
|
219
225
|
end
|
220
226
|
end
|
221
227
|
describe 'with valid params' do
|
222
228
|
before(:each) do
|
223
|
-
post :create, {:<%=
|
229
|
+
post :create, {:<%= var_name %> => valid_create_attributes}
|
224
230
|
end
|
225
|
-
it "assigns a newly created <%=
|
226
|
-
assigns(:<%=
|
227
|
-
assigns(:<%=
|
231
|
+
it "assigns a newly created <%= var_name %> as @<%= var_name %>" do
|
232
|
+
assigns(:<%= var_name %>).should be_a(<%= local_class_name %>)
|
233
|
+
assigns(:<%= var_name %>).should be_persisted
|
228
234
|
end
|
229
|
-
it "redirects to the created <%=
|
235
|
+
it "redirects to the created <%= var_name %>" do
|
230
236
|
response.should redirect_to(<%= ns_file_name %>_path(<%= local_class_name %>.last))
|
231
237
|
end
|
232
238
|
end
|
@@ -234,12 +240,12 @@ describe <%= controller_class_name %>Controller do
|
|
234
240
|
before(:each) do
|
235
241
|
# Trigger the behavior that occurs when invalid params are submitted
|
236
242
|
<%= local_class_name %>.any_instance.stub(:save).and_return(false)
|
237
|
-
post :create, {:<%=
|
243
|
+
post :create, {:<%= var_name %> => <%= formatted_hash(example_invalid_attributes) %>}
|
238
244
|
end
|
239
245
|
it { should render_template(:new) }
|
240
246
|
it { should render_with_layout(:application) }
|
241
|
-
it "assigns a newly created but unsaved <%=
|
242
|
-
assigns(:<%=
|
247
|
+
it "assigns a newly created but unsaved <%= var_name %> as @<%= var_name %>" do
|
248
|
+
assigns(:<%= var_name %>).should be_a_new(<%= local_class_name %>)
|
243
249
|
end
|
244
250
|
end
|
245
251
|
end
|
@@ -249,8 +255,8 @@ describe <%= controller_class_name %>Controller do
|
|
249
255
|
context 'without a user' do
|
250
256
|
describe 'with valid params' do
|
251
257
|
before(:each) do
|
252
|
-
@<%=
|
253
|
-
put :update, {:id => @<%=
|
258
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
259
|
+
put :update, {:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
|
254
260
|
end
|
255
261
|
it { should redirect_to(new_user_session_path) }
|
256
262
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -260,8 +266,8 @@ describe <%= controller_class_name %>Controller do
|
|
260
266
|
login_unauthorized_user
|
261
267
|
describe "with valid params" do
|
262
268
|
before(:each) do
|
263
|
-
@<%=
|
264
|
-
put :update, {:id => @<%=
|
269
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
270
|
+
put :update, {:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
|
265
271
|
end
|
266
272
|
it { should redirect_to(<%= index_helper %>_url) }
|
267
273
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
@@ -270,9 +276,9 @@ describe <%= controller_class_name %>Controller do
|
|
270
276
|
context 'as user with update ability' do
|
271
277
|
login_user_with_ability :update, <%= local_class_name %>
|
272
278
|
describe "with valid params" do
|
273
|
-
it "updates the requested <%=
|
274
|
-
@<%=
|
275
|
-
# Assuming there are no other <%=
|
279
|
+
it "updates the requested <%= var_name %>" do
|
280
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
281
|
+
# Assuming there are no other <%= var_name %> in the database, this
|
276
282
|
# specifies that the <%= local_class_name %> created on the previous line
|
277
283
|
# receives the :update_attributes message with whatever params are
|
278
284
|
# submitted in the request.
|
@@ -281,32 +287,32 @@ describe <%= controller_class_name %>Controller do
|
|
281
287
|
<%- else -%>
|
282
288
|
<%= local_class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
|
283
289
|
<%- end -%>
|
284
|
-
put :update, {:id => @<%=
|
290
|
+
put :update, {:id => @<%= var_name %>.to_param, :<%= var_name %> => <%= formatted_hash(example_params_for_update) %>}
|
285
291
|
end
|
286
292
|
end
|
287
293
|
describe "with valid params" do
|
288
294
|
before(:each) do
|
289
|
-
@<%=
|
290
|
-
put :update, {:id => @<%=
|
295
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
296
|
+
put :update, {:id => @<%= var_name %>.to_param, :<%= var_name %> => valid_update_attributes}
|
291
297
|
end
|
292
|
-
it "assigns the requested <%=
|
293
|
-
assigns(:<%=
|
298
|
+
it "assigns the requested <%= var_name %> as @<%= var_name %>" do
|
299
|
+
assigns(:<%= var_name %>).should eq(@<%= var_name %>)
|
294
300
|
end
|
295
|
-
it "redirects to the <%=
|
296
|
-
response.should redirect_to(<%= ns_file_name %>_path(@<%=
|
301
|
+
it "redirects to the <%= var_name %>" do
|
302
|
+
response.should redirect_to(<%= ns_file_name %>_path(@<%= var_name %>))
|
297
303
|
end
|
298
304
|
end
|
299
305
|
describe "with invalid params" do
|
300
306
|
before(:each) do
|
301
|
-
@<%=
|
307
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
302
308
|
# Trigger the behavior that occurs when invalid params are submitted
|
303
309
|
<%= local_class_name %>.any_instance.stub(:save).and_return(false)
|
304
|
-
put :update, {:id => @<%=
|
310
|
+
put :update, {:id => @<%= var_name %>.to_param, :<%= var_name %> => <%= formatted_hash(example_invalid_attributes) %>}
|
305
311
|
end
|
306
312
|
it { should render_template(:edit) }
|
307
313
|
it { should render_with_layout(:application) }
|
308
|
-
it "assigns the <%=
|
309
|
-
assigns(:<%=
|
314
|
+
it "assigns the <%= var_name %> as @<%= var_name %>" do
|
315
|
+
assigns(:<%= var_name %>).should eq(@<%= var_name %>)
|
310
316
|
end
|
311
317
|
end
|
312
318
|
end
|
@@ -316,8 +322,8 @@ describe <%= controller_class_name %>Controller do
|
|
316
322
|
context 'without a user' do
|
317
323
|
describe 'with valid request' do
|
318
324
|
before(:each) do
|
319
|
-
@<%=
|
320
|
-
delete :destroy, {:id => @<%=
|
325
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
326
|
+
delete :destroy, {:id => @<%= var_name %>.to_param}
|
321
327
|
end
|
322
328
|
it { should redirect_to(new_user_session_path) }
|
323
329
|
it { should set_the_flash[:alert].to("You need to sign in or sign up before continuing.") }
|
@@ -327,8 +333,8 @@ describe <%= controller_class_name %>Controller do
|
|
327
333
|
login_unauthorized_user
|
328
334
|
describe "with valid request" do
|
329
335
|
before(:each) do
|
330
|
-
@<%=
|
331
|
-
delete :destroy, {:id => @<%=
|
336
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
337
|
+
delete :destroy, {:id => @<%= var_name %>.to_param}
|
332
338
|
end
|
333
339
|
it { should redirect_to(<%= index_helper %>_url) }
|
334
340
|
it { should set_the_flash[:alert].to("You are not authorized to access this page.") }
|
@@ -336,18 +342,18 @@ describe <%= controller_class_name %>Controller do
|
|
336
342
|
end
|
337
343
|
context 'as user with destroy ability' do
|
338
344
|
login_user_with_ability :destroy, <%= local_class_name %>
|
339
|
-
it "destroys the requested <%=
|
340
|
-
@<%=
|
345
|
+
it "destroys the requested <%= var_name %>" do
|
346
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
341
347
|
expect {
|
342
|
-
delete :destroy, {:id => @<%=
|
348
|
+
delete :destroy, {:id => @<%= var_name %>.to_param}
|
343
349
|
}.to change(<%= local_class_name %>, :count).by(-1)
|
344
350
|
end
|
345
351
|
describe 'with valid request' do
|
346
352
|
before(:each) do
|
347
|
-
@<%=
|
348
|
-
delete :destroy, {:id => @<%=
|
353
|
+
@<%= var_name %> = FactoryGirl.create(:<%= var_name %>)
|
354
|
+
delete :destroy, {:id => @<%= var_name %>.to_param}
|
349
355
|
end
|
350
|
-
it "redirects to the <%=
|
356
|
+
it "redirects to the <%= var_name %> list" do
|
351
357
|
response.should redirect_to(<%= index_helper %>_url)
|
352
358
|
end
|
353
359
|
end
|