rails3-generators 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +11 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/features/support/env.rb +4 -0
- data/lib/generators/authlogic.rb +11 -0
- data/lib/generators/authlogic/session/session_generator.rb +18 -0
- data/lib/generators/authlogic/session/templates/session.rb +2 -0
- data/lib/generators/datamapper.rb +80 -0
- data/lib/generators/datamapper/migration/migration_generator.rb +26 -0
- data/lib/generators/datamapper/migration/templates/migration.rb +21 -0
- data/lib/generators/datamapper/model/model_generator.rb +29 -0
- data/lib/generators/datamapper/model/templates/migration.rb +17 -0
- data/lib/generators/datamapper/model/templates/model.rb +10 -0
- data/lib/generators/datamapper/observer/observer_generator.rb +15 -0
- data/lib/generators/datamapper/observer/templates/observer.rb +5 -0
- data/lib/generators/factory_girl.rb +11 -0
- data/lib/generators/factory_girl/model/model_generator.rb +14 -0
- data/lib/generators/factory_girl/model/templates/fixtures.rb +7 -0
- data/lib/generators/haml.rb +9 -0
- data/lib/generators/haml/controller/controller_generator.rb +24 -0
- data/lib/generators/haml/controller/templates/view.html.haml +0 -0
- data/lib/generators/haml/scaffold/scaffold_generator.rb +23 -0
- data/lib/generators/haml/scaffold/templates/_form.haml.erb +10 -0
- data/lib/generators/haml/scaffold/templates/edit.haml.erb +7 -0
- data/lib/generators/haml/scaffold/templates/index.haml.erb +23 -0
- data/lib/generators/haml/scaffold/templates/layout.haml.erb +8 -0
- data/lib/generators/haml/scaffold/templates/new.haml.erb +5 -0
- data/lib/generators/haml/scaffold/templates/show.haml.erb +9 -0
- data/lib/generators/rspec.rb +25 -0
- data/lib/generators/rspec/controller/controller_generator.rb +26 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +23 -0
- data/lib/generators/rspec/controller/templates/view_spec.rb +12 -0
- data/lib/generators/rspec/helper/helper_generator.rb +11 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +11 -0
- data/lib/generators/rspec/install/install_generator.rb +28 -0
- data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +182 -0
- data/lib/generators/rspec/install/templates/script/autospec.tt +6 -0
- data/lib/generators/rspec/install/templates/script/spec.tt +10 -0
- data/lib/generators/rspec/install/templates/script/spec_server.tt +9 -0
- data/lib/generators/rspec/install/templates/spec/rcov.opts +2 -0
- data/lib/generators/rspec/install/templates/spec/spec.opts +4 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb +51 -0
- data/lib/generators/rspec/integration/integration_generator.rb +12 -0
- data/lib/generators/rspec/integration/templates/integration_spec.rb +4 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +21 -0
- data/lib/generators/rspec/mailer/templates/fixture +3 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +14 -0
- data/lib/generators/rspec/model/model_generator.rb +22 -0
- data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
- data/lib/generators/rspec/model/templates/model_spec.rb +13 -0
- data/lib/generators/rspec/observer/observer_generator.rb +12 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +5 -0
- data/lib/generators/rspec/plugin/plugin_generator.rb +11 -0
- data/lib/generators/rspec/plugin/templates/%file_name%_spec.rb.tt +5 -0
- data/lib/generators/rspec/plugin/templates/test_helper.rb +5 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +112 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +127 -0
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +25 -0
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +27 -0
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +25 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +67 -0
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +22 -0
- data/lib/rails3-generators.rb +2 -0
- data/rails3-generators.gemspec +116 -0
- data/spec/rails3-generators_spec.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +8 -0
- metadata +144 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class IntegrationGenerator < Base
|
6
|
+
def create_integration_file
|
7
|
+
template 'integration_spec.rb',
|
8
|
+
File.join('spec/integration', class_path, "#{table_name}_spec.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class MailerGenerator < Base
|
6
|
+
argument :actions, :type => :array, :default => [], :banner => "method method"
|
7
|
+
|
8
|
+
def create_mailer_files
|
9
|
+
template "mailer_spec.rb",
|
10
|
+
File.join('spec', 'models', class_path, "#{file_name}_spec.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_fixtures_files
|
14
|
+
actions.each do |action|
|
15
|
+
@action, @path = action, File.join(file_path, action)
|
16
|
+
template "fixture", File.join("spec/fixtures", @path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %> do
|
4
|
+
<% for action in actions -%>
|
5
|
+
it "should deliver <%= action.gsub("_", " ") %> message" do
|
6
|
+
@expected.subject = '<%= class_name %>#<%= action %>'
|
7
|
+
@expected.body = read_fixture('<%= action %>')
|
8
|
+
@expected.date = Time.now
|
9
|
+
|
10
|
+
@expected.encoded.should == <%= class_name %>.create_<%= action %>(@expected.date).encoded
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :fixture, :type => :boolean
|
8
|
+
|
9
|
+
def create_test_file
|
10
|
+
template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :fixture_replacement
|
14
|
+
|
15
|
+
def create_fixture_file
|
16
|
+
if options[:fixture] && options[:fixture_replacement].nil?
|
17
|
+
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
|
3
|
+
<% unless attributes.empty? -%>
|
4
|
+
one:
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<%= attribute.name %>: <%= attribute.default %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
two:
|
10
|
+
<% for attribute in attributes -%>
|
11
|
+
<%= attribute.name %>: <%= attribute.default %>
|
12
|
+
<% end -%>
|
13
|
+
<% else -%>
|
14
|
+
# one:
|
15
|
+
# column: value
|
16
|
+
#
|
17
|
+
# two:
|
18
|
+
# column: value
|
19
|
+
<% end -%>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %> do
|
4
|
+
before(:each) do
|
5
|
+
@valid_attributes = {
|
6
|
+
<%= attributes.map{ |a| ":#{a.name} => #{a.default.inspect}" }.join(",\n ") %>
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create a new instance given valid attributes" do
|
11
|
+
<%= class_name %>.create!(@valid_attributes)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
class ObserverGenerator < Base
|
6
|
+
def create_observer_files
|
7
|
+
template 'observer_spec.rb',
|
8
|
+
File.join('spec', 'models', class_path, "#{file_name}_observer_spec.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
require 'rails/generators/resource_helpers'
|
3
|
+
|
4
|
+
module Rspec
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Base
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
|
+
|
10
|
+
class_option :orm, :desc => "ORM used to generate the controller"
|
11
|
+
class_option :template_engine, :desc => "Template engine to generate view files"
|
12
|
+
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
|
13
|
+
|
14
|
+
class_option :views, :type => :boolean, :default => true
|
15
|
+
class_option :routes, :type => :boolean, :default => true
|
16
|
+
|
17
|
+
def copy_controller_files
|
18
|
+
template 'controller_spec.rb',
|
19
|
+
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_view_files
|
23
|
+
return unless options[:views]
|
24
|
+
|
25
|
+
copy_view :edit
|
26
|
+
copy_view :index unless options[:singleton]
|
27
|
+
copy_view :new
|
28
|
+
copy_view :show
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_routing_files
|
32
|
+
return unless options[:routes]
|
33
|
+
|
34
|
+
template 'routing_spec.rb',
|
35
|
+
File.join('spec/routing', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
36
|
+
end
|
37
|
+
|
38
|
+
hook_for :integration_tool, :as => :integration
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def copy_view(view)
|
43
|
+
template "#{view}_spec.rb",
|
44
|
+
File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
45
|
+
end
|
46
|
+
|
47
|
+
def params
|
48
|
+
"{'these' => 'params'}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the name of the mock. For example, if the file name is user,
|
52
|
+
# it returns mock_user.
|
53
|
+
#
|
54
|
+
# If a hash is given, it uses the hash key as the ORM method and the
|
55
|
+
# value as response. So, for ActiveRecord and file name "User":
|
56
|
+
#
|
57
|
+
# mock_file_name(:save => true)
|
58
|
+
# #=> mock_user(:save => true)
|
59
|
+
#
|
60
|
+
# If another ORM is being used and another method instead of save is
|
61
|
+
# called, it will be the one used.
|
62
|
+
#
|
63
|
+
def mock_file_name(hash=nil)
|
64
|
+
if hash
|
65
|
+
method, and_return = hash.to_a.first
|
66
|
+
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
67
|
+
"mock_#{file_name}(:#{method} => #{and_return})"
|
68
|
+
else
|
69
|
+
"mock_#{file_name}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Receives the ORM chain and convert to expects. For ActiveRecord:
|
74
|
+
#
|
75
|
+
# should! orm_class.find(User, "37")
|
76
|
+
# #=> User.should_receive(:find).with(37)
|
77
|
+
#
|
78
|
+
# For Datamapper:
|
79
|
+
#
|
80
|
+
# should! orm_class.find(User, "37")
|
81
|
+
# #=> User.should_receive(:get).with(37)
|
82
|
+
#
|
83
|
+
def should!(chain)
|
84
|
+
stub_or_should_chain(:should_receive, chain)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Receives the ORM chain and convert to stub. For ActiveRecord:
|
88
|
+
#
|
89
|
+
# stub! orm_class.find(User, "37")
|
90
|
+
# #=> User.stub!(:find).with(37)
|
91
|
+
#
|
92
|
+
# For Datamapper:
|
93
|
+
#
|
94
|
+
# stub! orm_class.find(User, "37")
|
95
|
+
# #=> User.stub!(:get).with(37)
|
96
|
+
#
|
97
|
+
def stub!(chain)
|
98
|
+
stub_or_should_chain(:stub!, chain)
|
99
|
+
end
|
100
|
+
|
101
|
+
def stub_or_should_chain(mode, chain)
|
102
|
+
receiver, method = chain.split(".")
|
103
|
+
method.gsub!(/\((.*?)\)/, '')
|
104
|
+
|
105
|
+
response = "#{receiver}.#{mode}(:#{method})"
|
106
|
+
response << ".with(#{$1})" unless $1.blank?
|
107
|
+
response
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= controller_class_name %>Controller do
|
4
|
+
|
5
|
+
def <%= mock_file_name %>(stubs={})
|
6
|
+
@<%= mock_file_name %> ||= mock_model(<%= class_name %>, stubs)
|
7
|
+
end
|
8
|
+
|
9
|
+
<% unless options[:singleton] -%>
|
10
|
+
describe "GET index" do
|
11
|
+
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
|
12
|
+
<%= stub! orm_class.all(class_name) %>.and_return([<%= mock_file_name %>])
|
13
|
+
get :index
|
14
|
+
assigns[:<%= table_name %>].should == [<%= mock_file_name %>]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
<% end -%>
|
18
|
+
|
19
|
+
describe "GET show" do
|
20
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
21
|
+
<%= stub! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
22
|
+
get :show, :id => "37"
|
23
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "GET new" do
|
28
|
+
it "assigns a new <%= file_name %> as @<%= file_name %>" do
|
29
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name %>)
|
30
|
+
get :new
|
31
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "GET edit" do
|
36
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
37
|
+
<%= stub! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
38
|
+
get :edit, :id => "37"
|
39
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "POST create" do
|
44
|
+
|
45
|
+
describe "with valid params" do
|
46
|
+
it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
|
47
|
+
<%= stub! orm_class.build(class_name, params) %>.and_return(<%= mock_file_name(:save => true) %>)
|
48
|
+
post :create, :<%= file_name %> => <%= params %>
|
49
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "redirects to the created <%= file_name %>" do
|
53
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name(:save => true) %>)
|
54
|
+
post :create, :<%= file_name %> => {}
|
55
|
+
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "with invalid params" do
|
60
|
+
it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
|
61
|
+
<%= stub! orm_class.build(class_name, params) %>.and_return(<%= mock_file_name(:save => false) %>)
|
62
|
+
post :create, :<%= file_name %> => <%= params %>
|
63
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "re-renders the 'new' template" do
|
67
|
+
<%= stub! orm_class.build(class_name) %>.and_return(<%= mock_file_name(:save => false) %>)
|
68
|
+
post :create, :<%= file_name %> => {}
|
69
|
+
response.should render_template('new')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "PUT update" do
|
76
|
+
|
77
|
+
describe "with valid params" do
|
78
|
+
it "updates the requested <%= file_name %>" do
|
79
|
+
<%= should! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
80
|
+
mock_<%= should! orm_instance.update_attributes(params) %>
|
81
|
+
put :update, :id => "37", :<%= file_name %> => <%= params %>
|
82
|
+
end
|
83
|
+
|
84
|
+
it "assigns the requested <%= file_name %> as @<%= file_name %>" do
|
85
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => true) %>)
|
86
|
+
put :update, :id => "1"
|
87
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "redirects to the <%= file_name %>" do
|
91
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => true) %>)
|
92
|
+
put :update, :id => "1"
|
93
|
+
response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "with invalid params" do
|
98
|
+
it "assigns the <%= file_name %> as @<%= file_name %>" do
|
99
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => false) %>)
|
100
|
+
put :update, :id => "1"
|
101
|
+
assigns[:<%= file_name %>].should equal(<%= mock_file_name %>)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "re-renders the 'edit' template" do
|
105
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:update_attributes => false) %>)
|
106
|
+
put :update, :id => "1"
|
107
|
+
response.should render_template('edit')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "DELETE destroy" do
|
114
|
+
it "destroys the requested <%= file_name %>" do
|
115
|
+
<%= should! orm_class.find(class_name, "37".inspect) %>.and_return(<%= mock_file_name %>)
|
116
|
+
mock_<%= should! orm_instance.destroy %>
|
117
|
+
delete :destroy, :id => "37"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "redirects to the <%= table_name %> list" do
|
121
|
+
<%= stub! orm_class.find(class_name) %>.and_return(<%= mock_file_name(:destroy => true) %>)
|
122
|
+
delete :destroy, :id => "1"
|
123
|
+
response.should redirect_to(<%= table_name %>_url)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
2
|
+
|
3
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
+
describe "/<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
|
5
|
+
include <%= controller_class_name %>Helper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
|
9
|
+
:new_record? => false<%= output_attributes.empty? ? '' : ',' %>
|
10
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
11
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
12
|
+
<% end -%>
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "renders the edit <%= file_name %> form" do
|
17
|
+
render
|
18
|
+
|
19
|
+
response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
|
20
|
+
<% for attribute in output_attributes -%>
|
21
|
+
with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
|
22
|
+
<% end -%>
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
2
|
+
|
3
|
+
<% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
|
4
|
+
describe "/<%= table_name %>/index.html.<%= options[:template_engine] %>" do
|
5
|
+
include <%= controller_class_name %>Helper
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
assigns[:<%= table_name %>] = [
|
9
|
+
<% [1,2].each_with_index do |id, model_index| -%>
|
10
|
+
stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
|
11
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
12
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
13
|
+
<% end -%>
|
14
|
+
<% if !output_attributes.empty? -%>
|
15
|
+
<%= model_index == 1 ? ')' : '),' %>
|
16
|
+
<% end -%>
|
17
|
+
<% end -%>
|
18
|
+
]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "renders a list of <%= table_name %>" do
|
22
|
+
render
|
23
|
+
<% for attribute in output_attributes -%>
|
24
|
+
response.should have_tag("tr>td", <%= attribute.default.inspect %>.to_s, 2)
|
25
|
+
<% end -%>
|
26
|
+
end
|
27
|
+
end
|