rails3-generators 0.6.0 → 0.7.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/README.rdoc +2 -2
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/generators/haml/scaffold/templates/_form.haml.erb +1 -2
- data/lib/generators/shoulda/controller/controller_generator.rb +16 -0
- data/lib/generators/shoulda/controller/templates/controller.rb +84 -0
- data/lib/generators/shoulda/model/model_generator.rb +16 -0
- data/lib/generators/shoulda/model/templates/model.rb +7 -0
- data/lib/generators/shoulda.rb +11 -0
- data/rails3-generators.gemspec +9 -7
- metadata +10 -8
- data/lib/generators/mongoid/model/model_generator.rb +0 -21
- data/lib/generators/mongoid/model/templates/model.rb +0 -14
- data/lib/generators/mongoid.rb +0 -61
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= rails3-generators
|
2
2
|
|
3
|
-
Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and
|
3
|
+
Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and Shoulda
|
4
4
|
|
5
5
|
== Note on Patches/Pull Requests
|
6
6
|
|
@@ -20,4 +20,4 @@ MongoMapper: Jai-Gouk Kim
|
|
20
20
|
|
21
21
|
Machinist: Darcy Laycock
|
22
22
|
|
23
|
-
|
23
|
+
Shoulda: Peter Haza
|
data/Rakefile
CHANGED
@@ -6,10 +6,10 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "rails3-generators"
|
8
8
|
gem.summary = %Q{Rails 3 compatible generators}
|
9
|
-
gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and
|
9
|
+
gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and Shoulda}
|
10
10
|
gem.email = "andre@arko.net"
|
11
11
|
gem.homepage = "http://github.com/indirect/rails3-generators"
|
12
|
-
gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "
|
12
|
+
gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
14
|
end
|
15
15
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'generators/shoulda'
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Base
|
6
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
7
|
+
class_option :dir, :type => :string, :default => "test/functional", :desc => "The directory where the controller tests should go"
|
8
|
+
|
9
|
+
check_class_collision :suffix => 'ControllerTest'
|
10
|
+
|
11
|
+
def create_controller_file
|
12
|
+
template 'controller.rb', File.join(options[:dir], "#{file_name}_controller_test.rb")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= plural_name %>ControllerTest < ActionController::TestCase
|
4
|
+
<% if actions.include?('index') %>
|
5
|
+
|
6
|
+
context "index action" do
|
7
|
+
should "render index template" do
|
8
|
+
get :index
|
9
|
+
assert_template 'index'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
<% end %>
|
13
|
+
<% if actions.include?('show') %>
|
14
|
+
|
15
|
+
context "show action" do
|
16
|
+
should "render show template" do
|
17
|
+
get :show, :id => <%= class_name %>.first
|
18
|
+
assert_template 'show'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
<% end %>
|
22
|
+
<% if actions.include?('new') %>
|
23
|
+
|
24
|
+
context "new action" do
|
25
|
+
should "render new template" do
|
26
|
+
get :new
|
27
|
+
assert_template 'new'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
<% end %>
|
31
|
+
<% if actions.include?('create') %>
|
32
|
+
|
33
|
+
context "create action" do
|
34
|
+
should "render new template when model is invalid" do
|
35
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
36
|
+
post :create
|
37
|
+
assert_template 'new'
|
38
|
+
end
|
39
|
+
|
40
|
+
should "redirect when model is valid" do
|
41
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
42
|
+
post :create
|
43
|
+
assert_redirected_to
|
44
|
+
end
|
45
|
+
end
|
46
|
+
<% end %>
|
47
|
+
<% if actions.include?('edit') %>
|
48
|
+
|
49
|
+
context "edit action" do
|
50
|
+
should "render edit template" do
|
51
|
+
get :edit, :id => <%= class_name %>.first
|
52
|
+
assert_template 'edit'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
<% end %>
|
56
|
+
<% if actions.include?('update') %>
|
57
|
+
|
58
|
+
context "update action" do
|
59
|
+
should "render edit template when model is invalid" do
|
60
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(false)
|
61
|
+
put :update, :id => <%= class_name %>.first
|
62
|
+
assert_template 'edit'
|
63
|
+
end
|
64
|
+
|
65
|
+
should "redirect when model is valid" do
|
66
|
+
<%= class_name %>.any_instance.stubs(:valid?).returns(true)
|
67
|
+
put :update, :id => <%= class_name %>.first
|
68
|
+
assert_redirected_to
|
69
|
+
end
|
70
|
+
end
|
71
|
+
<% end %>
|
72
|
+
<% if actions.include?('destroy') %>
|
73
|
+
|
74
|
+
context "destroy action" do
|
75
|
+
should "destroy model and redirect to index action" do
|
76
|
+
<%= singular_name %> = <%= class_name %>.first
|
77
|
+
delete :destroy, :id => <%= singular_name %>
|
78
|
+
assert_redirected_to
|
79
|
+
assert !<%= class_name %>.exists?(<%= singular_name %>.id)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
<% end %>
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'generators/shoulda'
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :dir, :type => :string, :default => "test/unit", :desc => "The directory where the model tests should go"
|
8
|
+
|
9
|
+
def create_model_test_file
|
10
|
+
template 'model.rb', File.join(options[:dir], "#{singular_name}_test.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :fixture_replacement
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
6
|
+
def self.source_root
|
7
|
+
@_shoulda_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'shoulda', generator_name, 'templates'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/rails3-generators.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails3-generators}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "
|
12
|
-
s.date = %q{2010-
|
13
|
-
s.description = %q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and
|
11
|
+
s.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza"]
|
12
|
+
s.date = %q{2010-05-01}
|
13
|
+
s.description = %q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and Shoulda}
|
14
14
|
s.email = %q{andre@arko.net}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.rdoc"
|
@@ -70,13 +70,15 @@ Gem::Specification.new do |s|
|
|
70
70
|
"lib/generators/machinist/model/model_generator.rb",
|
71
71
|
"lib/generators/machinist/model/templates/blueprint.rb",
|
72
72
|
"lib/generators/machinist/model/templates/machinist_initializer.rb",
|
73
|
-
"lib/generators/mongoid.rb",
|
74
|
-
"lib/generators/mongoid/model/model_generator.rb",
|
75
|
-
"lib/generators/mongoid/model/templates/model.rb",
|
76
73
|
"lib/generators/mongomapper.rb",
|
77
74
|
"lib/generators/mongomapper/model/model_generator.rb",
|
78
75
|
"lib/generators/mongomapper/model/templates/model.rb",
|
79
76
|
"lib/generators/mongomapper/observer/observer_generator.rb",
|
77
|
+
"lib/generators/shoulda.rb",
|
78
|
+
"lib/generators/shoulda/controller/controller_generator.rb",
|
79
|
+
"lib/generators/shoulda/controller/templates/controller.rb",
|
80
|
+
"lib/generators/shoulda/model/model_generator.rb",
|
81
|
+
"lib/generators/shoulda/model/templates/model.rb",
|
80
82
|
"lib/rails3-generators.rb",
|
81
83
|
"rails3-generators.gemspec"
|
82
84
|
]
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 7
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Valim
|
@@ -16,12 +16,12 @@ authors:
|
|
16
16
|
- Louis T.
|
17
17
|
- Jai-Gouk Kim
|
18
18
|
- Darcy Laycock
|
19
|
-
-
|
19
|
+
- Peter Haza
|
20
20
|
autorequire:
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
23
|
|
24
|
-
date: 2010-
|
24
|
+
date: 2010-05-01 00:00:00 -04:00
|
25
25
|
default_executable:
|
26
26
|
dependencies:
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
version: 1.2.9
|
39
39
|
type: :development
|
40
40
|
version_requirements: *id001
|
41
|
-
description: Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and
|
41
|
+
description: Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, and Shoulda
|
42
42
|
email: andre@arko.net
|
43
43
|
executables: []
|
44
44
|
|
@@ -101,13 +101,15 @@ files:
|
|
101
101
|
- lib/generators/machinist/model/model_generator.rb
|
102
102
|
- lib/generators/machinist/model/templates/blueprint.rb
|
103
103
|
- lib/generators/machinist/model/templates/machinist_initializer.rb
|
104
|
-
- lib/generators/mongoid.rb
|
105
|
-
- lib/generators/mongoid/model/model_generator.rb
|
106
|
-
- lib/generators/mongoid/model/templates/model.rb
|
107
104
|
- lib/generators/mongomapper.rb
|
108
105
|
- lib/generators/mongomapper/model/model_generator.rb
|
109
106
|
- lib/generators/mongomapper/model/templates/model.rb
|
110
107
|
- lib/generators/mongomapper/observer/observer_generator.rb
|
108
|
+
- lib/generators/shoulda.rb
|
109
|
+
- lib/generators/shoulda/controller/controller_generator.rb
|
110
|
+
- lib/generators/shoulda/controller/templates/controller.rb
|
111
|
+
- lib/generators/shoulda/model/model_generator.rb
|
112
|
+
- lib/generators/shoulda/model/templates/model.rb
|
111
113
|
- lib/rails3-generators.rb
|
112
114
|
- rails3-generators.gemspec
|
113
115
|
has_rdoc: true
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'generators/mongoid'
|
2
|
-
|
3
|
-
module Mongoid
|
4
|
-
module Generators
|
5
|
-
class ModelGenerator < Base
|
6
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
-
|
8
|
-
check_class_collision
|
9
|
-
|
10
|
-
class_option :timestamps, :type => :boolean, :default => true
|
11
|
-
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
12
|
-
class_option :versioning, :type => :boolean, :default => false, :desc => "Enable mongoid versioning"
|
13
|
-
|
14
|
-
def create_model_file
|
15
|
-
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
16
|
-
end
|
17
|
-
|
18
|
-
hook_for :test_framework
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class <%= class_name %><%= "< #{options[:parent].classify}" if options[:parent] %>
|
2
|
-
<% unless options[:parent] -%>
|
3
|
-
include Mongoid::Document
|
4
|
-
<% if options[:timestamps] %>
|
5
|
-
include Mongoid::Timestamps
|
6
|
-
<% end %>
|
7
|
-
<% if options[:versioning] %>
|
8
|
-
include Mongoid::Versioning
|
9
|
-
<% end %>
|
10
|
-
<% end -%>
|
11
|
-
<% attributes.each do |attribute| -%>
|
12
|
-
field :<%= attribute.name %>, :type => <%= attribute.type_class %>
|
13
|
-
<% end -%>
|
14
|
-
end
|
data/lib/generators/mongoid.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'rails/generators/named_base'
|
2
|
-
# require 'rails/generators/migration'
|
3
|
-
require 'rails/generators/active_model'
|
4
|
-
|
5
|
-
module Mongoid
|
6
|
-
module Generators
|
7
|
-
class Base < Rails::Generators::NamedBase #:nodoc:
|
8
|
-
|
9
|
-
def self.source_root
|
10
|
-
@_mongoid_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
11
|
-
'mongoid', generator_name, 'templates'))
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
17
|
-
def self.all(klass)
|
18
|
-
"#{klass}.all"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.find(klass, params=nil)
|
22
|
-
"#{klass}.first(#{params})"
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.build(klass, params=nil)
|
26
|
-
if params
|
27
|
-
"#{klass}.new(#{params})"
|
28
|
-
else
|
29
|
-
"#{klass}.new"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def save
|
34
|
-
"#{name}.save"
|
35
|
-
end
|
36
|
-
|
37
|
-
def update_attributes(params=nil)
|
38
|
-
"#{name}.update(#{params})"
|
39
|
-
end
|
40
|
-
|
41
|
-
def errors
|
42
|
-
"#{name}.errors"
|
43
|
-
end
|
44
|
-
|
45
|
-
def destroy
|
46
|
-
"#{name}.destroy"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module Rails
|
53
|
-
module Generators
|
54
|
-
class GeneratedAttribute #:nodoc:
|
55
|
-
def type_class
|
56
|
-
return 'DateTime' if type.to_s == 'datetime'
|
57
|
-
return type.to_s.camelcase
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|