gisikw-restful_controller_generator 0.1.4
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/.autotest +23 -0
- data/History.txt +6 -0
- data/Manifest.txt +14 -0
- data/README.rdoc +40 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/bin/restful_controller +3 -0
- data/example/foos_controller.rb +41 -0
- data/example/foos_controller_spec.rb +96 -0
- data/example/foos_controller_test.rb +57 -0
- data/lib/restful_controller.rb +3 -0
- data/restful_controller_generator.gemspec +60 -0
- data/restful_controller_generator.rb +38 -0
- data/templates/controller.rb +41 -0
- data/templates/controller_spec.rb +94 -0
- data/templates/controller_test.rb +57 -0
- data/templates/helper.rb +2 -0
- data/templates/helper_spec.rb +11 -0
- data/templates/helper_test.rb +4 -0
- data/test/test_restful_controller.rb +8 -0
- metadata +73 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
bin/restful_controller
|
6
|
+
lib/restful_controller.rb
|
7
|
+
test/test_restful_controller.rb
|
8
|
+
restful_controller_generator.rb
|
9
|
+
templates/controller.rb
|
10
|
+
templates/controller_spec.rb
|
11
|
+
templates/controller_test.rb
|
12
|
+
templates/helper.rb
|
13
|
+
templates/helper_spec.rb
|
14
|
+
templates/helper_test.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= RESTful Controller Generator
|
2
|
+
|
3
|
+
Views change, models change, but RESTful controllers could stand some foundational code.
|
4
|
+
This generator will create
|
5
|
+
* A RESTful controller
|
6
|
+
* A Test::Unit or Rspec test to cover each action
|
7
|
+
|
8
|
+
== REQUIREMENTS:
|
9
|
+
|
10
|
+
To ensure that all actions are fully covered, both Test::Unit and Rspec require the Mocha stubbing framework (or go in and write your own tests for the create and update actions).
|
11
|
+
|
12
|
+
== INSTALL:
|
13
|
+
|
14
|
+
# Install the gem:
|
15
|
+
sudo gem install restful_controller_generator
|
16
|
+
|
17
|
+
== LICENSE:
|
18
|
+
|
19
|
+
(The MIT License)
|
20
|
+
|
21
|
+
Copyright (c) 2009 FIX
|
22
|
+
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
24
|
+
a copy of this software and associated documentation files (the
|
25
|
+
'Software'), to deal in the Software without restriction, including
|
26
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
27
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
28
|
+
permit persons to whom the Software is furnished to do so, subject to
|
29
|
+
the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be
|
32
|
+
included in all copies or substantial portions of the Software.
|
33
|
+
|
34
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
35
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
36
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
37
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
38
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
39
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
40
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "restful_controller_generator"
|
8
|
+
gem.summary = %Q{Generator for a RESTful controller}
|
9
|
+
gem.description = %Q{Generator for a RESTful controller}
|
10
|
+
gem.email = "kevin.gisi@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/gisikw/restful_controller_generator"
|
12
|
+
gem.authors = ["Kevin W. Gisi"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION')
|
46
|
+
version = File.read('VERSION')
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "restful_controller_generator #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class FoosController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :new_foo, :only => [:new,:create]
|
4
|
+
before_filter :find_foo, :only => [:show,:edit,:update,:destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@foos = Foo.all
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
if @foo.save
|
12
|
+
redirect_to foos_url
|
13
|
+
else
|
14
|
+
render :action => 'new'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
if @foo.update_attributes(params[:foo])
|
20
|
+
redirect_to foos_url
|
21
|
+
else
|
22
|
+
render :action => 'edit'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
@foo.destroy
|
28
|
+
redirect_to foos_url
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def new_foo
|
34
|
+
@foo = Foo.new(params[:foo])
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_foo
|
38
|
+
@foo = Foo.find(params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe FooController do
|
4
|
+
|
5
|
+
before
|
6
|
+
@foo = Foo.new.save(false)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'index action' do
|
10
|
+
before do
|
11
|
+
get :index
|
12
|
+
end
|
13
|
+
it 'should render index template' do
|
14
|
+
response.should render_template('index')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'new action' do
|
19
|
+
before do
|
20
|
+
get :new
|
21
|
+
end
|
22
|
+
it 'should render new template' do
|
23
|
+
response.should render_template('new')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'edit action' do
|
28
|
+
before do
|
29
|
+
get :edit, :id => @foo.id
|
30
|
+
end
|
31
|
+
it 'should render edit template' do
|
32
|
+
response.should render_template('edit')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'show action' do
|
37
|
+
before do
|
38
|
+
get :show, :id => @foo.id
|
39
|
+
end
|
40
|
+
it 'should render show template' do
|
41
|
+
response.should render_template('show')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'create action' do
|
46
|
+
describe 'on save' do
|
47
|
+
before do
|
48
|
+
Foo.any_instance.stubs(:save).returns(true)
|
49
|
+
post :create
|
50
|
+
end
|
51
|
+
it 'should redirect to index' do
|
52
|
+
response.should redirect_to(foos_url)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
describe 'on failed save' do
|
56
|
+
before do
|
57
|
+
Foo.any_instance.stubs(:save).returns(true)
|
58
|
+
post :create
|
59
|
+
end
|
60
|
+
it 'should render new action' do
|
61
|
+
response.should render_remplate('new')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'update action' do
|
67
|
+
describe 'on update' do
|
68
|
+
before do
|
69
|
+
Foo.any_instance.stubs(:update_attributes).returns(true)
|
70
|
+
put :update, :id => @foo.id
|
71
|
+
end
|
72
|
+
it 'should redirect to index' do
|
73
|
+
response.should redirect_to(foos_url)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
describe 'on failed update' do
|
77
|
+
before do
|
78
|
+
Foo.any_instance.stubs(:update_attributes).returns(false)
|
79
|
+
put :update, :id => @foo.id
|
80
|
+
end
|
81
|
+
it 'should render edit template' do
|
82
|
+
response.should render_template('edit')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'destroy action' do
|
88
|
+
before do
|
89
|
+
delete :destroy, @foo.id
|
90
|
+
end
|
91
|
+
it 'should redirect to index action' do
|
92
|
+
response.should redirect_to(foos_url)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FoosControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@foo = Foo.new.save(false)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "index action should render index template" do
|
10
|
+
get :index
|
11
|
+
assert_template :index
|
12
|
+
end
|
13
|
+
|
14
|
+
test "new action should render new template" do
|
15
|
+
get :new
|
16
|
+
assert_template :new
|
17
|
+
end
|
18
|
+
|
19
|
+
test "edit action should render edit template" do
|
20
|
+
get :edit, :id => @foo.id
|
21
|
+
assert_template :edit
|
22
|
+
end
|
23
|
+
|
24
|
+
test "show action should render show template" do
|
25
|
+
get :show, :id => @foo.id
|
26
|
+
end
|
27
|
+
|
28
|
+
test "create action on save should redirect to index" do
|
29
|
+
Foo.any_instance.stubs(:save).returns(true)
|
30
|
+
post :create
|
31
|
+
assert_redirected_to :action => 'index'
|
32
|
+
end
|
33
|
+
|
34
|
+
test "create action on failed save should render new action" do
|
35
|
+
Foo.any_instance.stubs(:save).returns(false)
|
36
|
+
post :create
|
37
|
+
assert_template :new
|
38
|
+
end
|
39
|
+
|
40
|
+
test "update action on update should redirect to index" do
|
41
|
+
Foo.any_instance.stubs(:update_attributes).returns(true)
|
42
|
+
put :update, :id => @foo.id
|
43
|
+
assert_redirected_to :action => 'index'
|
44
|
+
end
|
45
|
+
|
46
|
+
test "update action on failed update should render edit template" do
|
47
|
+
Foo.any_instance.stubs(:update_attributes).returns(false)
|
48
|
+
put :update, :id => @foo.id
|
49
|
+
assert_template :edit
|
50
|
+
end
|
51
|
+
|
52
|
+
test "destroy action should redirect to index action" do
|
53
|
+
delete :destroy, :id => @foo.id
|
54
|
+
assert_redirected_to :action => 'index'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{restful_controller_generator}
|
8
|
+
s.version = "0.1.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kevin W. Gisi"]
|
12
|
+
s.date = %q{2009-08-12}
|
13
|
+
s.default_executable = %q{restful_controller}
|
14
|
+
s.description = %q{Generator for a RESTful controller}
|
15
|
+
s.email = %q{kevin.gisi@gmail.com}
|
16
|
+
s.executables = ["restful_controller"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".autotest",
|
22
|
+
"History.txt",
|
23
|
+
"Manifest.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bin/restful_controller",
|
28
|
+
"example/foos_controller.rb",
|
29
|
+
"example/foos_controller_spec.rb",
|
30
|
+
"example/foos_controller_test.rb",
|
31
|
+
"lib/restful_controller.rb",
|
32
|
+
"restful_controller_generator.gemspec",
|
33
|
+
"restful_controller_generator.rb",
|
34
|
+
"templates/controller.rb",
|
35
|
+
"templates/controller_spec.rb",
|
36
|
+
"templates/controller_test.rb",
|
37
|
+
"templates/helper.rb",
|
38
|
+
"templates/helper_spec.rb",
|
39
|
+
"templates/helper_test.rb",
|
40
|
+
"test/test_restful_controller.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/gisikw/restful_controller_generator}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.3}
|
46
|
+
s.summary = %q{Generator for a RESTful controller}
|
47
|
+
s.test_files = [
|
48
|
+
"test/test_restful_controller.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
else
|
57
|
+
end
|
58
|
+
else
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class RestfulControllerGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
attr_accessor :models_name, :model_name, :controller_name
|
4
|
+
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
@controller_name = "#{@class_name}Controller"
|
8
|
+
@models_name = @class_name.downcase
|
9
|
+
@model_name = @models_name.singularize
|
10
|
+
m.directory('app/controllers')
|
11
|
+
m.directory('app/helpers')
|
12
|
+
m.directory(File.join('app/views',@models_name))
|
13
|
+
m.template('controller.rb',"app/controllers/#{@models_name}_controller.rb")
|
14
|
+
m.template('helper.rb',"app/helpers/#{models_name}_helper.rb")
|
15
|
+
m.route_resources @models_name
|
16
|
+
if options[:spec]
|
17
|
+
m.directory('spec/controllers')
|
18
|
+
m.directory('spec/helpers')
|
19
|
+
m.directory(File.join('spec/views',@model_names))
|
20
|
+
m.template spec/controllers/foos_controller_spec.rb
|
21
|
+
m.template('helper_spec.rb',"spec/helpers/#{models_name}_helper_spec.rb")
|
22
|
+
else
|
23
|
+
m.directory('test/function')
|
24
|
+
m.directory('test/unit/helpers')
|
25
|
+
m.template('controller_test.rb',"test/functional/#{models_name}_controller_test.rb")
|
26
|
+
m.template('helper_test.rb',"test/unit/helpers/#{models_name}_helper_test.rb")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def add_options!(opt)
|
34
|
+
opt.separator ''
|
35
|
+
opt.separator 'Options:'
|
36
|
+
opt.on("--spec","Create a spec file rather than a test::unit file"){|v| options[:spec] = v}
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class <%= controller_name %> < ApplicationController
|
2
|
+
|
3
|
+
before_filter :new_<%= model_name %>, :only => [:new,:create]
|
4
|
+
before_filter :find_<%= model_name %>, :only => [:show,:edit,:update.:destroy]
|
5
|
+
|
6
|
+
def index
|
7
|
+
@<%= models_name %> = <%= model_name.capitalize %>.all
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
if @<%= model_name %>.save
|
12
|
+
redirect_to <%= models_name %>_url
|
13
|
+
else
|
14
|
+
render :action => 'new'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
if @<%= model_name %>.update_attributes(params[:<%= model_name %>])
|
20
|
+
redirect_to <%= models_name %>_url
|
21
|
+
else
|
22
|
+
render :action => 'edit'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
@<%= model_name %>.destroy
|
28
|
+
redirect_to <%= models_name %>_url
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def new_<%= model_name %>
|
34
|
+
@<%= model_name %> = <%= model_name.capitalize %>.new(params[:<%= model_name %>])
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_<%= model_name %>
|
38
|
+
@<%= model_name %> = <%= model_name.capitalize %>.find(params[:id])
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= controller_name %> do
|
4
|
+
|
5
|
+
before
|
6
|
+
@<%= model_name %> = <%= model_name.capitalize %>.new.save(false)
|
7
|
+
|
8
|
+
describe 'index action' do
|
9
|
+
before do
|
10
|
+
get :index
|
11
|
+
end
|
12
|
+
it 'should render index template' do
|
13
|
+
response.should render_template('index')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'new action' do
|
18
|
+
before do
|
19
|
+
get :new
|
20
|
+
end
|
21
|
+
it 'should render new template' do
|
22
|
+
response.should render_template('new')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'edit action' do
|
27
|
+
before do
|
28
|
+
get :edit, :id => @<%= model_name %>.id
|
29
|
+
end
|
30
|
+
it 'should render edit template' do
|
31
|
+
response.should render_template('edit')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'show action' do
|
36
|
+
before do
|
37
|
+
get :show, :id => @<%= model_name %>.id
|
38
|
+
end
|
39
|
+
it 'should render show template' do
|
40
|
+
response.should render_template('show')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'create action' do
|
45
|
+
describe 'on save' do
|
46
|
+
before do
|
47
|
+
<%= model_name.capitalize %>.any_instance.stubs(:save).returns(true)
|
48
|
+
post :create
|
49
|
+
end
|
50
|
+
it 'should redirect to index' do
|
51
|
+
response.should redirect_to(<%= models_name %>_url)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
describe 'on failed save' do
|
55
|
+
before do
|
56
|
+
<%= model_name.capitalize %>.any_instance.stubs(:save).returns(true)
|
57
|
+
post :create
|
58
|
+
end
|
59
|
+
it 'should render new action' do
|
60
|
+
response.should render_remplate('new')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'update action' do
|
66
|
+
describe 'on update' do
|
67
|
+
before do
|
68
|
+
<%= model_name.capitalize %>.any_instance.stubs(:update_attributes).returns(true)
|
69
|
+
put :update, :id => @<%= model_name %>.id
|
70
|
+
end
|
71
|
+
it 'should redirect to index' do
|
72
|
+
response.should redirect_to(<%= models_name %>_url)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
describe 'on failed update' do
|
76
|
+
before do
|
77
|
+
<%= model_name.capitalize %>.any_instance.stubs(:update_attributes).returns(false)
|
78
|
+
put :update, :id => @<%= model_name %>.id
|
79
|
+
end
|
80
|
+
it 'should render edit template' do
|
81
|
+
response.should render_template('edit')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'destroy action' do
|
87
|
+
before do
|
88
|
+
delete :destroy, :id => @<%= model_name %>.id
|
89
|
+
end
|
90
|
+
it 'should redirect to index action' do
|
91
|
+
response.should redirect_to(<%= models_name %>_url)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_name %>Test < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
<%= model_name %> = <%= model_name.capitalize %>.new.save(false)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "index action should render index template" do
|
10
|
+
get :index
|
11
|
+
assert_template :index
|
12
|
+
end
|
13
|
+
|
14
|
+
test "new action should render new template" do
|
15
|
+
get :new
|
16
|
+
assert_template :new
|
17
|
+
end
|
18
|
+
|
19
|
+
test "edit action should render edit template" do
|
20
|
+
get :edit, :id => @<%= model_name %>.id
|
21
|
+
assert_template :edit
|
22
|
+
end
|
23
|
+
|
24
|
+
test "show action should render show template" do
|
25
|
+
get :show, :id => @<%= model_name %>.id
|
26
|
+
end
|
27
|
+
|
28
|
+
test "create action on save should redirect to index" do
|
29
|
+
<%= model_name.capitalize %>.any_instance.stubs(:save).returns(true)
|
30
|
+
post :create
|
31
|
+
assert_redirected_to :action => 'index'
|
32
|
+
end
|
33
|
+
|
34
|
+
test "create action on failed save should render new action" do
|
35
|
+
<%= model_name.capitalize %>.any_instance.stubs(:save).returns(false)
|
36
|
+
post :create
|
37
|
+
assert_template :new
|
38
|
+
end
|
39
|
+
|
40
|
+
test "update action on update should redirect to index" do
|
41
|
+
<%= model_name.capitalize %>.any_instance.stubs(:update_attributes).returns(true)
|
42
|
+
put :update, :id => @<%= model_name %>.id
|
43
|
+
assert_redirected_to :action => 'index'
|
44
|
+
end
|
45
|
+
|
46
|
+
test "update action on failed update should render edit template" do
|
47
|
+
<%= model_name.capitalize %>.any_instance.stubs(:update_attributes).returns(false)
|
48
|
+
put :update, :id => @<%= model_name %>.id
|
49
|
+
assert_template :edit
|
50
|
+
end
|
51
|
+
|
52
|
+
test "destroy action should redirect to index action" do
|
53
|
+
delete :destroy, :id => @<%= model_name %>.id
|
54
|
+
assert_redirected_to :action => 'index'
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/templates/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %>Helper do
|
4
|
+
|
5
|
+
#Delete this example and add some real ones or delete this file
|
6
|
+
it "should be included in the object returned by #helper" do
|
7
|
+
included_modules = (class << helper; self; end).send :included_modules
|
8
|
+
included_modules.should include(<%= class_name %>Helper)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gisikw-restful_controller_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin W. Gisi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-12 00:00:00 -07:00
|
13
|
+
default_executable: restful_controller
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generator for a RESTful controller
|
17
|
+
email: kevin.gisi@gmail.com
|
18
|
+
executables:
|
19
|
+
- restful_controller
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- .autotest
|
26
|
+
- History.txt
|
27
|
+
- Manifest.txt
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- bin/restful_controller
|
32
|
+
- example/foos_controller.rb
|
33
|
+
- example/foos_controller_spec.rb
|
34
|
+
- example/foos_controller_test.rb
|
35
|
+
- lib/restful_controller.rb
|
36
|
+
- restful_controller_generator.gemspec
|
37
|
+
- restful_controller_generator.rb
|
38
|
+
- templates/controller.rb
|
39
|
+
- templates/controller_spec.rb
|
40
|
+
- templates/controller_test.rb
|
41
|
+
- templates/helper.rb
|
42
|
+
- templates/helper_spec.rb
|
43
|
+
- templates/helper_test.rb
|
44
|
+
- test/test_restful_controller.rb
|
45
|
+
has_rdoc: false
|
46
|
+
homepage: http://github.com/gisikw/restful_controller_generator
|
47
|
+
licenses:
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --charset=UTF-8
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Generator for a RESTful controller
|
72
|
+
test_files:
|
73
|
+
- test/test_restful_controller.rb
|