my_generators 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/generators/my_generators/controller/controller_generator.rb +18 -0
- data/lib/generators/my_generators/controller/templates/view.html.haml +2 -0
- data/lib/generators/my_generators/model/model_generator.rb +28 -0
- data/lib/generators/my_generators/model/templates/model.rb +26 -0
- data/lib/generators/my_generators/scaffold/scaffold_generator.rb +49 -0
- data/lib/generators/my_generators/scaffold/templates/_form.html.haml +15 -0
- data/lib/generators/my_generators/scaffold/templates/edit.html.haml +7 -0
- data/lib/generators/my_generators/scaffold/templates/index.html.haml +23 -0
- data/lib/generators/my_generators/scaffold/templates/new.html.haml +5 -0
- data/lib/generators/my_generators/scaffold/templates/show.html.haml +11 -0
- data/lib/generators/my_scaffold_generator.rb +161 -0
- data/lib/generators/my_spec/controller/controller_generator.rb +33 -0
- data/lib/generators/my_spec/controller/templates/controller_spec.rb +14 -0
- data/lib/generators/my_spec/controller/templates/view_spec.rb +5 -0
- data/lib/generators/my_spec/helper/helper_generator.rb +20 -0
- data/lib/generators/my_spec/helper/templates/helper_spec.rb +15 -0
- data/lib/generators/my_spec/integration/integration_generator.rb +20 -0
- data/lib/generators/my_spec/integration/templates/request_spec.rb +14 -0
- data/lib/generators/my_spec/model/model_generator.rb +33 -0
- data/lib/generators/my_spec/model/templates/fixtures.yml +19 -0
- data/lib/generators/my_spec/model/templates/model_spec.rb +20 -0
- data/lib/generators/my_spec/model/templates/mongoid.rb +4 -0
- data/lib/generators/my_spec/observer/observer_generator.rb +16 -0
- data/lib/generators/my_spec/observer/templates/observer_spec.rb +5 -0
- data/lib/generators/my_spec/scaffold/scaffold_generator.rb +93 -0
- data/lib/generators/my_spec/scaffold/templates/controller_spec.rb +140 -0
- data/lib/generators/my_spec/scaffold/templates/edit_spec.rb +38 -0
- data/lib/generators/my_spec/scaffold/templates/index_spec.rb +37 -0
- data/lib/generators/my_spec/scaffold/templates/inherited_resources_stubs.rb +28 -0
- data/lib/generators/my_spec/scaffold/templates/new_spec.rb +37 -0
- data/lib/generators/my_spec/scaffold/templates/routing_spec.rb +37 -0
- data/lib/generators/my_spec/scaffold/templates/show_spec.rb +33 -0
- data/lib/generators/my_spec/view/templates/view_spec.rb +5 -0
- data/lib/generators/my_spec/view/view_generator.rb +24 -0
- data/lib/generators/rails/USAGE +10 -0
- data/lib/generators/rails/my_controller_generator.rb +33 -0
- data/lib/generators/rails/templates/controller.rb +13 -0
- data/lib/my_generators.rb +16 -0
- data/my_generators.gemspec +88 -0
- data/test/helper.rb +10 -0
- data/test/test_my_generators.rb +7 -0
- metadata +112 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tyler Gannon
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= my_generators
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Tyler Gannon. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "my_generators"
|
8
|
+
gem.summary = %Q{Generators that I use for rails apps}
|
9
|
+
gem.description = %Q{Just a replacement for default rails generators, specifig to my configuration of mongoid, inherited_resources, etc.}
|
10
|
+
gem.email = "tgannon@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/tylergannon/my_generators"
|
12
|
+
gem.authors = ["Tyler Gannon"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "my_generators #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/erb/controller/controller_generator'
|
2
|
+
require 'generators/my_scaffold_generator'
|
3
|
+
|
4
|
+
module MyGenerators
|
5
|
+
module Generators
|
6
|
+
class ControllerGenerator < Erb::Generators::ControllerGenerator
|
7
|
+
include MyGenerators::Generators::MyScaffoldGenerator
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def handler
|
13
|
+
:haml
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "rails/generators/mongoid_generator"
|
3
|
+
require 'generators/my_scaffold_generator'
|
4
|
+
|
5
|
+
module MyGenerators #:nodoc:
|
6
|
+
module Generators #:nodoc:
|
7
|
+
class ModelGenerator < Mongoid::Generators::Base #:nodoc:
|
8
|
+
include MyGenerators::Generators::MyScaffoldGenerator
|
9
|
+
desc "Creates a Mongoid model"
|
10
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
11
|
+
|
12
|
+
class_option :timestamps, :type => :boolean
|
13
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
14
|
+
class_option :versioning, :type => :boolean, :default => false, :desc => "Enable mongoid versioning"
|
15
|
+
|
16
|
+
def create_model_file
|
17
|
+
template "model.rb", File.join("app/models", class_path, "#{file_name}.rb")
|
18
|
+
end
|
19
|
+
|
20
|
+
hook_for :test_framework
|
21
|
+
|
22
|
+
def self.source_root
|
23
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= class_name %><%= " < #{options[:parent].classify}" if options[:parent] %>
|
2
|
+
<% unless options[:parent] -%>
|
3
|
+
include Mongoid::Document
|
4
|
+
<% end -%>
|
5
|
+
<% if options[:timestamps] -%>
|
6
|
+
include Mongoid::Timestamps
|
7
|
+
<% end -%>
|
8
|
+
<%= 'include Mongoid::Versioning' if options[:versioning] -%>
|
9
|
+
<% if options[:embedded_in] %>
|
10
|
+
embedded_in :<%= options[:embedded_in] %>, :inverse_of => :<%= options[:singleton] ? class_name.underscore : class_name.tableize %>
|
11
|
+
<% end %>
|
12
|
+
<% if options[:referenced_in] %>
|
13
|
+
referenced_in :<%= options[:referenced_in] %>, :inverse_of => :<%= options[:singleton] ? class_name.underscore : class_name.tableize %>
|
14
|
+
<% end %>
|
15
|
+
<% attributes.reject{|attr| attr.reference?}.each do |attribute| -%>
|
16
|
+
field :<%= attribute.name %>, :type => <%= attribute.type_class %>
|
17
|
+
<% end -%>
|
18
|
+
<% attributes.select{|attr| attr.reference? }.each do |attribute| -%>
|
19
|
+
embedded_in :<%= attribute.name%>, :inverse_of => :<%= class_name.tableize %>
|
20
|
+
<% end -%>
|
21
|
+
<% if references_one -%> references_one :<%=references_one%> <% end %>
|
22
|
+
<% if references_many -%> references_many :<%=references_many%> <% end %>
|
23
|
+
<% if embeds_one -%> embeds_one :<%=embeds_one%> <% end %>
|
24
|
+
<% if embeds_many -%> embeds_many :<%=embeds_many%> <% end %>
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'generators/my_scaffold_generator'
|
3
|
+
|
4
|
+
module MyGenerators::Generators
|
5
|
+
class ScaffoldGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
include MyScaffoldGenerator
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
|
+
|
10
|
+
def create_root_folder
|
11
|
+
empty_directory File.join("app/views", controller_file_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
source_root File.expand_path("../templates", __FILE__)
|
15
|
+
|
16
|
+
def copy_view_files
|
17
|
+
available_views.each do |view|
|
18
|
+
filename = filename_with_extensions(view)
|
19
|
+
template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
hook_for :form_builder, :as => :scaffold
|
24
|
+
|
25
|
+
def copy_form_file
|
26
|
+
if options[:form_builder].nil?
|
27
|
+
filename = filename_with_extensions("_form")
|
28
|
+
template "_form.html.haml", File.join("app/views", controller_file_path, filename)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def available_views
|
35
|
+
%w(index edit show new)
|
36
|
+
end
|
37
|
+
|
38
|
+
def handler
|
39
|
+
:haml
|
40
|
+
end
|
41
|
+
def format
|
42
|
+
:html
|
43
|
+
end
|
44
|
+
|
45
|
+
def filename_with_extensions(name)
|
46
|
+
[name, format, handler].compact.join(".")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
= form_for <%= belongs_to ? "[@#{parent_name}, @#{model_name}]" : "@#{model_name}" %> do |f|
|
2
|
+
-if @<%= singular_table_name %>.errors.any?
|
3
|
+
#error_explanation
|
4
|
+
%h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
|
5
|
+
%ul
|
6
|
+
- @<%= singular_table_name %>.errors.full_messages.each do |msg|
|
7
|
+
%li= msg
|
8
|
+
|
9
|
+
<% for attribute in attributes -%>
|
10
|
+
.field
|
11
|
+
= f.label :<%= attribute.name %>
|
12
|
+
= f.<%= attribute.field_type %> :<%= attribute.name %>
|
13
|
+
<% end -%>
|
14
|
+
.actions
|
15
|
+
= f.submit 'Save'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
%h1 Listing <%= plural_table_name %>
|
2
|
+
|
3
|
+
%table
|
4
|
+
%tr
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
%th <%= attribute.human_name %>
|
7
|
+
<% end -%>
|
8
|
+
%th
|
9
|
+
%th
|
10
|
+
%th
|
11
|
+
|
12
|
+
- @<%= plural_table_name %>.each do |<%= singular_table_name %>|
|
13
|
+
%tr
|
14
|
+
<% for attribute in attributes -%>
|
15
|
+
%td= <%= singular_table_name %>.<%= attribute.name %>
|
16
|
+
<% end -%>
|
17
|
+
%td= link_to 'Show', <%= resource_url_helper(model_name) %>
|
18
|
+
%td= link_to 'Edit', edit_<%= resource_url_helper(model_name) %>
|
19
|
+
%td= link_to 'Destroy', <%= resource_url_helper(model_name) %>, :confirm => 'Are you sure?', :method => :delete
|
20
|
+
|
21
|
+
%br
|
22
|
+
|
23
|
+
= link_to 'New <%= human_name %>', new_<%= resource_url_helper() %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%p#notice= notice
|
2
|
+
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
%p
|
5
|
+
%b <%= attribute.human_name %>:
|
6
|
+
= @<%= singular_table_name %>.<%= attribute.name %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
= link_to 'Edit', edit_<%= resource_url_helper %>
|
10
|
+
\|
|
11
|
+
= link_to 'Back', <%= index_url_helper %>
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module MyGenerators
|
2
|
+
module Generators
|
3
|
+
module MyScaffoldGenerator
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
class_option :embedded_in, :type => :string, :default=>nil
|
8
|
+
class_option :referenced_in, :type => :string, :default=>nil
|
9
|
+
class_option :belongs_to, :type => :boolean, :default=>false
|
10
|
+
|
11
|
+
class_option :embeds_one, :type => :string, :default=>nil
|
12
|
+
class_option :embeds_many, :type => :string, :default=>nil
|
13
|
+
class_option :references_one, :type => :string, :default=>nil
|
14
|
+
class_option :references_many, :type => :string, :default=>nil
|
15
|
+
|
16
|
+
class_option :orm, :desc => "ORM used to generate the controller"
|
17
|
+
class_option :template_engine, :default=>'haml', :desc => "Template engine to generate view files"
|
18
|
+
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
|
19
|
+
class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
|
20
|
+
class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
|
21
|
+
class_option :webrat_matchers, :type => :boolean, :default => true, :desc => "Use webrat matchers in view specs"
|
22
|
+
class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
|
23
|
+
class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_missing(method, *args)
|
27
|
+
options[method.to_sym]
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
def resource_url_helper(resource=nil)
|
32
|
+
belongs_to ?
|
33
|
+
"#{parent_name}_#{model_name}_path(@#{parent_name}, #{resource||'@'+model_name})" :
|
34
|
+
"#{resource||'@'+model_name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def new_resource_url_helper
|
38
|
+
belongs_to ? "new_#{parent_name}_#{model_name}_path(@#{parent_name})" :
|
39
|
+
"new_#{model_name}_path"
|
40
|
+
end
|
41
|
+
|
42
|
+
def index_url_helper
|
43
|
+
belongs_to ? "#{parent_name}_#{table_name}_path(@#{parent_name})" : "#{table_name}_path"
|
44
|
+
end
|
45
|
+
|
46
|
+
def webrat?
|
47
|
+
options[:webrat_matchers] || @webrat_matchers_requested
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_view(view)
|
51
|
+
template "#{view}_spec.rb",
|
52
|
+
File.join("spec/views", controller_file_path, "#{view}.html.haml_spec.rb")
|
53
|
+
end
|
54
|
+
|
55
|
+
def params
|
56
|
+
"{'these' => 'params'}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the name of the mock. For example, if the file name is user,
|
60
|
+
# it returns mock_user.
|
61
|
+
#
|
62
|
+
# If a hash is given, it uses the hash key as the ORM method and the
|
63
|
+
# value as response. So, for ActiveRecord and file name "User":
|
64
|
+
#
|
65
|
+
# mock_file_name(:save => true)
|
66
|
+
# #=> mock_user(:save => true)
|
67
|
+
#
|
68
|
+
# If another ORM is being used and another method instead of save is
|
69
|
+
# called, it will be the one used.
|
70
|
+
#
|
71
|
+
def mock_file_name(hash=nil)
|
72
|
+
if hash
|
73
|
+
method, and_return = hash.to_a.first
|
74
|
+
method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
|
75
|
+
"mock_#{file_name}(:#{method} => #{and_return})"
|
76
|
+
else
|
77
|
+
"mock_#{file_name}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Receives the ORM chain and convert to expects. For ActiveRecord:
|
82
|
+
#
|
83
|
+
# should! orm_class.find(User, "37")
|
84
|
+
# #=> User.should_receive(:find).with(37)
|
85
|
+
#
|
86
|
+
# For Datamapper:
|
87
|
+
#
|
88
|
+
# should! orm_class.find(User, "37")
|
89
|
+
# #=> User.should_receive(:get).with(37)
|
90
|
+
#
|
91
|
+
def should_receive!(chain)
|
92
|
+
stub_or_should_chain(:should_receive, chain)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Receives the ORM chain and convert to stub. For ActiveRecord:
|
96
|
+
#
|
97
|
+
# stub! orm_class.find(User, "37")
|
98
|
+
# #=> User.stub!(:find).with(37)
|
99
|
+
#
|
100
|
+
# For Datamapper:
|
101
|
+
#
|
102
|
+
# stub! orm_class.find(User, "37")
|
103
|
+
# #=> User.stub!(:get).with(37)
|
104
|
+
#
|
105
|
+
def stub!(chain)
|
106
|
+
stub_or_should_chain(:stub, chain)
|
107
|
+
end
|
108
|
+
|
109
|
+
def stub_or_should_chain(mode, chain)
|
110
|
+
receiver, method = chain.split(".")
|
111
|
+
method.gsub!(/\((.*?)\)/, '')
|
112
|
+
|
113
|
+
response = "#{receiver}.#{mode}(:#{method})"
|
114
|
+
response << ".with(#{$1})" unless $1.blank?
|
115
|
+
response
|
116
|
+
end
|
117
|
+
|
118
|
+
def value_for(attribute)
|
119
|
+
case attribute.type
|
120
|
+
when :string
|
121
|
+
"#{attribute.name.titleize}".inspect
|
122
|
+
else
|
123
|
+
attribute.default.inspect
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def parent_name
|
128
|
+
embedded_in || referenced_in
|
129
|
+
end
|
130
|
+
def parent_class
|
131
|
+
parent_name.camelize
|
132
|
+
end
|
133
|
+
def parents_name
|
134
|
+
parent_name.tableize
|
135
|
+
end
|
136
|
+
def parent_id
|
137
|
+
parent_name + "_id"
|
138
|
+
end
|
139
|
+
|
140
|
+
def association_matcher
|
141
|
+
embedded_in ? "be_embedded_in" : "be_referenced_in"
|
142
|
+
end
|
143
|
+
def parent_association
|
144
|
+
singleton ? class_name.underscore : class_name.tableize
|
145
|
+
end
|
146
|
+
def parent_association_matcher
|
147
|
+
singleton ? (embedded_in ? "embed_one" : "reference_one") :
|
148
|
+
(embedded_in ? "embed_many" : "reference_many")
|
149
|
+
|
150
|
+
end
|
151
|
+
def model_name
|
152
|
+
class_name.underscore
|
153
|
+
end
|
154
|
+
|
155
|
+
def child_model?
|
156
|
+
embedded_in || referenced_in
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'generators/my_scaffold_generator'
|
2
|
+
|
3
|
+
module MySpec
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < ::Rails::Generators::NamedBase
|
6
|
+
include MyScaffoldGenerator
|
7
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
8
|
+
|
9
|
+
def generate_controller_spec
|
10
|
+
return unless options[:controller_specs]
|
11
|
+
|
12
|
+
template 'controller_spec.rb',
|
13
|
+
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_view_specs
|
17
|
+
return if actions.empty?
|
18
|
+
return unless options[:view_specs]
|
19
|
+
|
20
|
+
empty_directory File.join("spec", "views", file_path)
|
21
|
+
|
22
|
+
actions.each do |action|
|
23
|
+
@action = action
|
24
|
+
template 'view_spec.rb',
|
25
|
+
File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def self.source_root
|
29
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe <%= class_name %>Controller do
|
4
|
+
|
5
|
+
<% for action in actions -%>
|
6
|
+
describe "GET '<%= action %>'" do
|
7
|
+
it "should be successful" do
|
8
|
+
get '<%= action %>'
|
9
|
+
response.should be_success
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'generators/my_scaffold_generator'
|
2
|
+
|
3
|
+
module MySpec
|
4
|
+
module Generators
|
5
|
+
class HelperGenerator < Rails::Generators::NamedBase
|
6
|
+
include MyGenerators::Generators::MyScaffoldGenerator
|
7
|
+
|
8
|
+
def generate_helper_spec
|
9
|
+
return unless options[:helper_specs]
|
10
|
+
|
11
|
+
template 'helper_spec.rb', File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.source_root
|
15
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the <%= class_name %>Helper. For example:
|
5
|
+
#
|
6
|
+
# describe <%= class_name %>Helper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# helper.concat_strings("this","that").should == "this that"
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
describe <%= class_name %>Helper do
|
14
|
+
pending "add some examples to (or delete) #{__FILE__}"
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'generators/my_scaffold_generator'
|
2
|
+
|
3
|
+
module MySpec
|
4
|
+
module Generators
|
5
|
+
class IntegrationGenerator < Rails::Generators::NamedBase
|
6
|
+
include MyGenerators::Generators::MyScaffoldGenerator
|
7
|
+
class_option :request_specs, :type => :boolean, :default => true, :desc => "Generate request specs"
|
8
|
+
|
9
|
+
def generate_request_spec
|
10
|
+
return unless options[:request_specs]
|
11
|
+
|
12
|
+
template 'request_spec.rb',
|
13
|
+
File.join('spec/requests', class_path, "#{table_name}_spec.rb")
|
14
|
+
end
|
15
|
+
def self.source_root
|
16
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "<%= class_name.pluralize %>" do
|
4
|
+
describe "GET /<%= table_name %>" do
|
5
|
+
before :each do
|
6
|
+
<% if child_model? %>
|
7
|
+
<%=parent_class%>.stub(:find).with(anything()) {john_q :<%=parent_name%>}
|
8
|
+
<% end %>
|
9
|
+
end
|
10
|
+
it "works! (now write some real specs)" do
|
11
|
+
get <%= table_name %>_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'generators/my_scaffold_generator'
|
2
|
+
|
3
|
+
module MySpec
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Rails::Generators::NamedBase
|
6
|
+
include MyGenerators::Generators::MyScaffoldGenerator
|
7
|
+
class_option :fixture, :type => :boolean
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
|
+
|
10
|
+
def copy_spec_support_files
|
11
|
+
empty_directory 'spec/support'
|
12
|
+
template 'mongoid.rb', 'spec/support/mongoid.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_model_spec
|
16
|
+
template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
hook_for :fixture_replacement
|
20
|
+
|
21
|
+
def create_fixture_file
|
22
|
+
if options[:fixture] && options[:fixture_replacement].nil?
|
23
|
+
template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.source_root
|
28
|
+
@source_root ||= File.expand_path("templates", File.dirname(__FILE__))
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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 -%>
|