hashrocket-hashrocket-terraformation 0.0.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/LICENSE +1 -0
- data/README.rdoc +14 -0
- data/Rakefile +30 -0
- data/bin/terrarails +94 -0
- data/rails_generators/terracontroller/USAGE +26 -0
- data/rails_generators/terracontroller/templates/controller_spec.rb.erb +20 -0
- data/rails_generators/terracontroller/templates/view.builder.erb +2 -0
- data/rails_generators/terracontroller/templates/view.erb +2 -0
- data/rails_generators/terracontroller/templates/view.haml.erb +2 -0
- data/rails_generators/terracontroller/templates/view.rjs.erb +1 -0
- data/rails_generators/terracontroller/templates/view.rss.builder.erb +18 -0
- data/rails_generators/terracontroller/templates/view_spec.rb.erb +15 -0
- data/rails_generators/terracontroller/terracontroller_generator.rb +44 -0
- data/rails_generators/terraformation/USAGE +2 -0
- data/rails_generators/terraformation/templates/application.html.haml.erb +25 -0
- data/rails_generators/terraformation/templates/blueprint/ie.css +22 -0
- data/rails_generators/terraformation/templates/blueprint/print.css +29 -0
- data/rails_generators/terraformation/templates/blueprint/screen.css +226 -0
- data/rails_generators/terraformation/templates/clear_test_default.rake +3 -0
- data/rails_generators/terraformation/templates/cucumber +8 -0
- data/rails_generators/terraformation/templates/cucumber.rake +15 -0
- data/rails_generators/terraformation/templates/gitignore +11 -0
- data/rails_generators/terraformation/templates/jquery.js +19 -0
- data/rails_generators/terraformation/templates/null_gitignore +2 -0
- data/rails_generators/terraformation/templates/paths.rb +23 -0
- data/rails_generators/terraformation/templates/rcov.opts +2 -0
- data/rails_generators/terraformation/templates/rspec.rake +149 -0
- data/rails_generators/terraformation/templates/spec.opts +2 -0
- data/rails_generators/terraformation/templates/spec_helper.rb +12 -0
- data/rails_generators/terraformation/terraformation_generator.rb +86 -0
- data/rails_generators/terraforming.rb +51 -0
- data/rails_generators/terrahelper/USAGE +9 -0
- data/rails_generators/terrahelper/templates/helper.rb.erb +10 -0
- data/rails_generators/terrahelper/templates/helper_spec.rb.erb +13 -0
- data/rails_generators/terrahelper/terrahelper_generator.rb +27 -0
- data/rails_generators/terramodel/USAGE +11 -0
- data/rails_generators/terramodel/templates/model_exemplar.rb.erb +5 -0
- data/rails_generators/terramodel/templates/model_factory.rb.erb +5 -0
- data/rails_generators/terramodel/templates/model_spec.rb.erb +17 -0
- data/rails_generators/terramodel/terramodel_generator.rb +54 -0
- data/rails_generators/terraresource/USAGE +20 -0
- data/rails_generators/terraresource/terraresource_generator.rb +93 -0
- data/rails_generators/terrascaffold/USAGE +2 -0
- data/rails_generators/terrascaffold/templates/controller.rb.erb +85 -0
- data/rails_generators/terrascaffold/templates/controller_spec.rb.erb +173 -0
- data/rails_generators/terrascaffold/templates/partial_form.html.haml.erb +7 -0
- data/rails_generators/terrascaffold/templates/view_edit.html.haml.erb +8 -0
- data/rails_generators/terrascaffold/templates/view_edit.html_spec.rb.erb +23 -0
- data/rails_generators/terrascaffold/templates/view_index.html.haml.erb +18 -0
- data/rails_generators/terrascaffold/templates/view_index.html_spec.rb.erb +25 -0
- data/rails_generators/terrascaffold/templates/view_new.html.haml.erb +7 -0
- data/rails_generators/terrascaffold/templates/view_new.html_spec.rb.erb +23 -0
- data/rails_generators/terrascaffold/templates/view_show.html.haml.erb +8 -0
- data/rails_generators/terrascaffold/templates/view_show.html_spec.rb.erb +21 -0
- data/rails_generators/terrascaffold/terrascaffold_generator.rb +97 -0
- metadata +121 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rails_generator/generators/components/model/model_generator'
|
2
|
+
require File.dirname(__FILE__) + '/../terraforming'
|
3
|
+
|
4
|
+
class TerramodelGenerator < ModelGenerator
|
5
|
+
include Terraforming
|
6
|
+
|
7
|
+
def manifest
|
8
|
+
|
9
|
+
record do |m|
|
10
|
+
m.class_collisions class_path, class_name
|
11
|
+
|
12
|
+
m.directory File.join('app/models', class_path)
|
13
|
+
m.directory File.join('spec/models', class_path)
|
14
|
+
if exemplar?
|
15
|
+
m.directory File.join('spec/exemplars', class_path)
|
16
|
+
end
|
17
|
+
if factory?
|
18
|
+
m.directory File.join('spec/factories')
|
19
|
+
end
|
20
|
+
|
21
|
+
m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
22
|
+
m.template 'model_spec.rb.erb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
23
|
+
if exemplar?
|
24
|
+
m.template 'model_exemplar.rb.erb', File.join('spec/exemplars', class_path, "#{file_name}_exemplar.rb")
|
25
|
+
end
|
26
|
+
if factory?
|
27
|
+
m.template 'model_factory.rb.erb', File.join('spec/factories', "#{full_name}_factory.rb")
|
28
|
+
end
|
29
|
+
if exist?('spec/fixtures')
|
30
|
+
m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
31
|
+
end
|
32
|
+
|
33
|
+
unless options[:skip_migration]
|
34
|
+
m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
|
35
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
36
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def banner
|
45
|
+
"Usage: #{$0} terramodel ModelName [field:type field:type]"
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opt)
|
49
|
+
super
|
50
|
+
opt.on("--[no-]exemplar", "Create Object Daddy Exemplar") { |v| options[:exemplar] = v }
|
51
|
+
opt.on("--[no-]factory", "Create Factory Girl Factory") { |v| options[:factory] = v }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
The terraresource generator creates a model, restful controller, and
|
3
|
+
optionally views.
|
4
|
+
|
5
|
+
This command accepts both field arguments (as with terramodel) and
|
6
|
+
template arguments (as with terracontroller).
|
7
|
+
|
8
|
+
Example:
|
9
|
+
./script/generate terraresource space_colony population:integer show
|
10
|
+
...
|
11
|
+
create spec/controllers/space_colonies_controller_spec.rb
|
12
|
+
create app/controllers/space_colonies_controller.rb
|
13
|
+
create spec/views/space_colonies/show.html_spec.rb
|
14
|
+
create app/views/space_colonies/show.html.haml
|
15
|
+
route map.resources :space_colonies
|
16
|
+
dependency terramodel
|
17
|
+
create app/models/space_colony.rb
|
18
|
+
create spec/models/space_colony_spec.rb
|
19
|
+
create spec/exemplars/space_colony_exemplar.rb
|
20
|
+
create db/migrate/20090121225002_create_space_colonies.rb
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../terraforming'
|
2
|
+
|
3
|
+
class TerraresourceGenerator < Rails::Generator::NamedBase
|
4
|
+
include Terraforming
|
5
|
+
|
6
|
+
default_options :skip_migration => false
|
7
|
+
|
8
|
+
attr_reader :controller_class_path,
|
9
|
+
:controller_class_name,
|
10
|
+
:controller_file_name
|
11
|
+
|
12
|
+
def initialize(runtime_args, runtime_options = {})
|
13
|
+
super
|
14
|
+
|
15
|
+
@controller_name = @name.pluralize
|
16
|
+
|
17
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
18
|
+
@controller_class_name_without_nesting, @controller_file_name = inflect_names(base_name)
|
19
|
+
|
20
|
+
if @controller_class_nesting.empty?
|
21
|
+
@controller_class_name = @controller_class_name_without_nesting
|
22
|
+
else
|
23
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def manifest
|
29
|
+
record do |m|
|
30
|
+
views
|
31
|
+
|
32
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller")
|
33
|
+
m.class_collisions(class_path, "#{class_name}")
|
34
|
+
|
35
|
+
m.directory(File.join('app/models', class_path))
|
36
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
37
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
38
|
+
m.directory(File.join('spec/controllers', controller_class_path))
|
39
|
+
m.directory(File.join('spec/models', class_path))
|
40
|
+
m.directory File.join('spec/views', controller_class_path, controller_file_name)
|
41
|
+
|
42
|
+
m.template 'terracontroller:controller_spec.rb.erb',
|
43
|
+
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb"),
|
44
|
+
:assigns => {:class_name => @controller_class_name}
|
45
|
+
|
46
|
+
m.template 'resource:controller.rb',
|
47
|
+
File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
48
|
+
|
49
|
+
views.each do |view|
|
50
|
+
name, format, engine = view.split('.')
|
51
|
+
m.template 'terracontroller:view_spec.rb.erb',
|
52
|
+
File.join('spec/views', controller_class_path, controller_file_name, "#{name}.#{format}_spec.rb"),
|
53
|
+
:assigns => { :name => name, :format => format, :engine => engine, :class_name => controller_class_name, :class_nesting_depth => @controller_class_nesting_depth }
|
54
|
+
path = File.join('app/views', controller_class_path, controller_file_name, view)
|
55
|
+
template = ["terracontroller:view.#{format}.#{engine}.erb", "terracontroller:view.#{engine}.erb", "terracontroller:view.erb"].detect {|f| File.exist?(source_path(f))}
|
56
|
+
m.template template,
|
57
|
+
path,
|
58
|
+
:assigns => { :class_name => @controller_class_name, :action => "#{name}.#{format}", :path => path }
|
59
|
+
end
|
60
|
+
m.route_resources controller_file_name
|
61
|
+
|
62
|
+
m.dependency 'terramodel', [name] + args, :collision => 'skip'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def banner
|
69
|
+
"Usage: #{$0} terraresource ModelName [field:type action.format.engine]"
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_options!(opt)
|
73
|
+
opt.separator ''
|
74
|
+
opt.separator 'Options:'
|
75
|
+
opt.on("--skip-timestamps",
|
76
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = true }
|
77
|
+
opt.on("--skip-migration",
|
78
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
79
|
+
opt.on("--skip-fixture",
|
80
|
+
"Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v }
|
81
|
+
opt.on("--[no-]exemplar", "Create Object Daddy Exemplar") { |v| options[:exemplar] = v }
|
82
|
+
opt.on("--[no-]factory", "Create Factory Girl Factory") { |v| options[:factory] = v }
|
83
|
+
end
|
84
|
+
|
85
|
+
def scaffold_views
|
86
|
+
%w[ index show new edit ]
|
87
|
+
end
|
88
|
+
|
89
|
+
def model_name
|
90
|
+
class_name.demodulize
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= plural_name %>
|
3
|
+
# GET /<%= plural_name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= plural_name %> = <%= class_name %>.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.xml { render :xml => @<%= plural_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= plural_name %>/1
|
14
|
+
# GET /<%= plural_name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.xml { render :xml => @<%= singular_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= plural_name %>/new
|
25
|
+
# GET /<%= plural_name %>/new.xml
|
26
|
+
def new
|
27
|
+
@<%= singular_name %> = <%= class_name %>.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.xml { render :xml => @<%= singular_name %> }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /<%= plural_name %>/1/edit
|
36
|
+
def edit
|
37
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /<%= plural_name %>
|
41
|
+
# POST /<%= plural_name %>.xml
|
42
|
+
def create
|
43
|
+
@<%= singular_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @<%= singular_name %>.save
|
47
|
+
flash[:notice] = '<%= singular_name.humanize %> was successfully created.'
|
48
|
+
format.html { redirect_to(@<%= file_name %>) }
|
49
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
50
|
+
else
|
51
|
+
format.html { render :action => "new" }
|
52
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PUT /<%= plural_name %>/1
|
58
|
+
# PUT /<%= plural_name %>/1.xml
|
59
|
+
def update
|
60
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= singular_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = '<%= singular_name.humanize %> was successfully updated.'
|
65
|
+
format.html { redirect_to(@<%= file_name %>) }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# DELETE /<%= plural_name %>/1
|
75
|
+
# DELETE /<%= plural_name %>/1.xml
|
76
|
+
def destroy
|
77
|
+
@<%= singular_name %> = <%= class_name %>.find(params[:id])
|
78
|
+
@<%= singular_name %>.destroy
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
format.html { redirect_to(<%= plural_name %>_path) }
|
82
|
+
format.xml { head :ok }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,173 @@
|
|
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
|
+
describe "responding to GET index" do
|
10
|
+
|
11
|
+
it "should expose all <%= plural_name %> as @<%= plural_name %>" do
|
12
|
+
<%= class_name %>.should_receive(:all).and_return([mock_<%= file_name %>])
|
13
|
+
get :index
|
14
|
+
assigns[:<%= plural_name %>].should == [mock_<%= file_name %>]
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "with mime type of xml" do
|
18
|
+
|
19
|
+
it "should render all <%= plural_name %> as xml" do
|
20
|
+
request.env["HTTP_ACCEPT"] = "application/xml"
|
21
|
+
<%= class_name %>.should_receive(:all).and_return(<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>"))
|
22
|
+
<%= file_name.pluralize %>.should_receive(:to_xml).and_return("generated XML")
|
23
|
+
get :index
|
24
|
+
response.body.should == "generated XML"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "responding to GET show" do
|
32
|
+
|
33
|
+
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
|
34
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
35
|
+
get :show, :id => "37"
|
36
|
+
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "with mime type of xml" do
|
40
|
+
|
41
|
+
it "should render the requested <%= file_name %> as xml" do
|
42
|
+
request.env["HTTP_ACCEPT"] = "application/xml"
|
43
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
44
|
+
mock_<%= file_name %>.should_receive(:to_xml).and_return("generated XML")
|
45
|
+
get :show, :id => "37"
|
46
|
+
response.body.should == "generated XML"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "responding to GET new" do
|
54
|
+
|
55
|
+
it "should expose a new <%= file_name %> as @<%= file_name %>" do
|
56
|
+
<%= class_name %>.should_receive(:new).and_return(mock_<%= file_name %>)
|
57
|
+
get :new
|
58
|
+
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "responding to GET edit" do
|
64
|
+
|
65
|
+
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
|
66
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
67
|
+
get :edit, :id => "37"
|
68
|
+
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "responding to POST create" do
|
74
|
+
|
75
|
+
describe "with valid params" do
|
76
|
+
|
77
|
+
it "should expose a newly created <%= file_name %> as @<%= file_name %>" do
|
78
|
+
<%= class_name %>.should_receive(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
|
79
|
+
post :create, :<%= file_name %> => {:these => 'params'}
|
80
|
+
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should redirect to the created <%= file_name %>" do
|
84
|
+
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => true))
|
85
|
+
post :create, :<%= file_name %> => {}
|
86
|
+
response.should redirect_to(<%= singular_name %>_url(mock_<%= file_name %>))
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "with invalid params" do
|
92
|
+
|
93
|
+
it "should expose a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
|
94
|
+
<%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
|
95
|
+
post :create, :<%= file_name %> => {:these => 'params'}
|
96
|
+
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should re-render the 'new' template" do
|
100
|
+
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => false))
|
101
|
+
post :create, :<%= file_name %> => {}
|
102
|
+
response.should render_template('new')
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "responding to PUT udpate" do
|
110
|
+
|
111
|
+
describe "with valid params" do
|
112
|
+
|
113
|
+
it "should update the requested <%= file_name %>" do
|
114
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
115
|
+
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
|
116
|
+
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
|
120
|
+
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
|
121
|
+
put :update, :id => "1"
|
122
|
+
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should redirect to the <%= file_name %>" do
|
126
|
+
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
|
127
|
+
put :update, :id => "1"
|
128
|
+
response.should redirect_to(<%= singular_name %>_url(mock_<%= file_name %>))
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "with invalid params" do
|
134
|
+
|
135
|
+
it "should update the requested <%= file_name %>" do
|
136
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
137
|
+
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
|
138
|
+
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should expose the <%= file_name %> as @<%= file_name %>" do
|
142
|
+
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
|
143
|
+
put :update, :id => "1"
|
144
|
+
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should re-render the 'edit' template" do
|
148
|
+
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
|
149
|
+
put :update, :id => "1"
|
150
|
+
response.should render_template('edit')
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "responding to DELETE destroy" do
|
158
|
+
|
159
|
+
it "should destroy the requested <%= file_name %>" do
|
160
|
+
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
|
161
|
+
mock_<%= file_name %>.should_receive(:destroy)
|
162
|
+
delete :destroy, :id => "37"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should redirect to the <%= plural_name %> list" do
|
166
|
+
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:destroy => true))
|
167
|
+
delete :destroy, :id => "1"
|
168
|
+
response.should redirect_to(<%= plural_name %>_path)
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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 "/<%= plural_name %>/edit.html" do
|
5
|
+
before do
|
6
|
+
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
|
7
|
+
:new_record? => false<%= output_attributes.empty? ? '' : ',' %>
|
8
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
9
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
10
|
+
<% end -%>
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should render edit form" do
|
15
|
+
render "<%= plural_name %>/edit.html"
|
16
|
+
|
17
|
+
response.should have_tag("form[action=?][method=post]", <%= file_name %>_path(@<%= file_name %>)) do
|
18
|
+
<% for attribute in output_attributes -%>
|
19
|
+
with_tag('#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
|
20
|
+
<% end -%>
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%h2 Listing <%= plural_name.humanize %>
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
%th <%= attribute.column.human_name %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
- for <%= singular_name %> in @<%= plural_name %>
|
10
|
+
%tr
|
11
|
+
<% for attribute in attributes -%>
|
12
|
+
%td= h <%= singular_name %>.<%= attribute.name %>
|
13
|
+
<% end %>
|
14
|
+
%td= link_to 'Show', <%= singular_name %>
|
15
|
+
%td= link_to 'Edit', [:edit, <%= singular_name %>]
|
16
|
+
%td= link_to 'Destroy', <%= singular_name %>, :method => :delete, :confirm => 'Are you sure?'
|
17
|
+
|
18
|
+
= link_to 'New <%= singular_name.humanize %>', new_<%= singular_name %>_path
|
@@ -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 "/<%= plural_name %>/index.html" do
|
5
|
+
before do
|
6
|
+
assigns[:<%= plural_name %>] = [
|
7
|
+
<% [1,2].each_with_index do |id, model_index| -%>
|
8
|
+
stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
|
9
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
10
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
11
|
+
<% end -%>
|
12
|
+
<% if !output_attributes.empty? -%>
|
13
|
+
<%= model_index == 1 ? ')' : '),' %>
|
14
|
+
<% end -%>
|
15
|
+
<% end -%>
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should render list of <%= plural_name %>" do
|
20
|
+
render "<%= plural_name %>/index.html"
|
21
|
+
<% for attribute in output_attributes -%>
|
22
|
+
response.should have_tag("tr>td", <%= attribute.default.inspect %>.to_s, 2)
|
23
|
+
<% end -%>
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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 "/<%= plural_name %>/new.html" do
|
5
|
+
before do
|
6
|
+
assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
|
7
|
+
:new_record? => true<%= output_attributes.empty? ? '' : ',' %>
|
8
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
9
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
10
|
+
<% end -%>
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should render new form" do
|
15
|
+
render "<%= plural_name %>/new.html"
|
16
|
+
|
17
|
+
response.should have_tag("form[action=?][method=post]", <%= plural_name %>_path) do
|
18
|
+
<% for attribute in output_attributes -%>
|
19
|
+
with_tag("#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
|
20
|
+
<% end -%>
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
%dl[@<%= singular_name %>]
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
%dt <%= attribute.column.human_name %>
|
4
|
+
%dd= h @<%= singular_name %>.<%= attribute.name %>
|
5
|
+
|
6
|
+
<% end -%>
|
7
|
+
%p= link_to 'Edit', [:edit, @<%= singular_name %>]
|
8
|
+
%p= link_to 'Back', <%= plural_name %>_path
|
@@ -0,0 +1,21 @@
|
|
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 "/<%= plural_name %>/show.html" do
|
5
|
+
before do
|
6
|
+
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
|
7
|
+
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
|
8
|
+
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
|
9
|
+
<% end -%>
|
10
|
+
<% if !output_attributes.empty? -%>
|
11
|
+
)
|
12
|
+
<% end -%>
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should render attributes in <p>" do
|
16
|
+
render "<%= plural_name %>/show.html"
|
17
|
+
<% for attribute in output_attributes -%>
|
18
|
+
response.should have_text(/<%= Regexp.escape(attribute.default.inspect).gsub(/^"|"$/, '')%>/)
|
19
|
+
<% end -%>
|
20
|
+
end
|
21
|
+
end
|