objective_spec 0.2.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 +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +59 -0
- data/TODO +6 -0
- data/VERSION +1 -0
- data/generators/objective_controller/USAGE +33 -0
- data/generators/objective_controller/objective_controller_generator.rb +45 -0
- data/generators/objective_controller/templates/controller_spec.rb +25 -0
- data/generators/objective_controller/templates/helper_spec.rb +11 -0
- data/generators/objective_controller/templates/view.html.haml +3 -0
- data/generators/objective_controller/templates/view_spec.rb +10 -0
- data/generators/objective_model/objective_model_generator.rb +40 -0
- data/generators/objective_model/templates/model_spec.rb +13 -0
- data/generators/objective_observer/objective_observer_generator.rb +16 -0
- data/generators/objective_observer/templates/observer.rb +2 -0
- data/generators/objective_observer/templates/observer_spec.rb +11 -0
- data/generators/objective_resource/.DS_Store +0 -0
- data/generators/objective_resource/objective_resource_generator.rb +172 -0
- data/generators/objective_resource/templates/.DS_Store +0 -0
- data/generators/objective_resource/templates/controller.rb +2 -0
- data/generators/objective_resource/templates/helper.rb +2 -0
- data/generators/objective_resource/templates/migration.rb +15 -0
- data/generators/objective_resource/templates/model.rb +2 -0
- data/generators/objective_resource/templates/rspec/functional_spec.rb +247 -0
- data/generators/objective_resource/templates/rspec/helper_spec.rb +11 -0
- data/generators/objective_resource/templates/rspec/routing_spec.rb +61 -0
- data/generators/objective_resource/templates/rspec/unit_spec.rb +10 -0
- data/generators/objective_resource/templates/rspec/views/edit_spec.rb +23 -0
- data/generators/objective_resource/templates/rspec/views/index_spec.rb +21 -0
- data/generators/objective_resource/templates/rspec/views/new_spec.rb +23 -0
- data/generators/objective_resource/templates/rspec/views/show_spec.rb +19 -0
- data/generators/objective_resource/templates/view__form.haml +5 -0
- data/generators/objective_resource/templates/view_edit.haml +11 -0
- data/generators/objective_resource/templates/view_index.haml +19 -0
- data/generators/objective_resource/templates/view_new.haml +9 -0
- data/generators/objective_resource/templates/view_show.haml +9 -0
- data/generators/objective_service/objective_service_generator.rb +22 -0
- data/generators/objective_service/templates/controller.rb +2 -0
- data/generators/objective_service/templates/controller_spec.rb +175 -0
- data/generators/objective_spec/objective_spec_generator.rb +33 -0
- data/generators/objective_spec/templates/support/common.rb +3 -0
- data/generators/objective_spec/templates/support/controller_spec_helper.rb +3 -0
- data/generators/objective_spec/templates/support/model_spec_helper.rb +3 -0
- data/generators/objective_spec/templates/support/shared_examples.rb +1 -0
- data/generators/objective_spec/templates/support/view_spec_helper.rb +3 -0
- data/generators/rspec_default_values.rb +28 -0
- data/init.rb +2 -0
- data/lib/objective_spec/assets.rb +2 -0
- data/lib/objective_spec/mailer_example_group.rb +14 -0
- data/lib/objective_spec/matchers/use_layout_matcher.rb +25 -0
- data/lib/objective_spec/matchers.rb +26 -0
- data/lib/objective_spec.rb +2 -0
- data/objective_spec.gemspec +95 -0
- data/spec/objective_spec_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +112 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Blake Watters
|
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,13 @@
|
|
1
|
+
= Objective Spec
|
2
|
+
Author: Blake Watters <blake@objective3.com>
|
3
|
+
|
4
|
+
Additional RSpec testing goodness for Rails from Objective 3.
|
5
|
+
|
6
|
+
Includes:
|
7
|
+
* An example group for testing Mailers
|
8
|
+
* Infrastructure for matchers and spec_helpers
|
9
|
+
* Disable asset timestamping during spec runs
|
10
|
+
|
11
|
+
== Copyright
|
12
|
+
|
13
|
+
Copyright (c) 2009 Objective 3. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "objective_spec"
|
8
|
+
gem.summary = "A set of extensions to RSpec for building Rails applications against Objective Spec"
|
9
|
+
gem.email = "blake@objective3.com"
|
10
|
+
gem.homepage = "http://github.com/Objective3/objective_spec"
|
11
|
+
gem.authors = ["Blake Watters"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "objective_spec #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
task :rebuild do
|
51
|
+
if File.exist?('VERSION')
|
52
|
+
version = File.read('VERSION').chomp
|
53
|
+
else
|
54
|
+
puts "Unable to rebuild -- no VERSION.yml found"
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
command = "sudo gem uninstall objective_spec; rake gemspec; rm objective_spec-#{version}.gem objective_spec.gemspec ; rake gemspec; gem build objective_spec.gemspec && sudo gem install objective_spec-#{version}.gem"
|
58
|
+
puts(`#{command}`)
|
59
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Description:
|
2
|
+
The objective_controller generator creates stub specs and files for a new
|
3
|
+
controller and its views.
|
4
|
+
|
5
|
+
The generator takes a controller name and a list of views as arguments.
|
6
|
+
The controller name may be given in CamelCase or under_score and should
|
7
|
+
not be suffixed with 'Controller'. To create a controller within a
|
8
|
+
module, specify the controller name as 'module/controller'.
|
9
|
+
|
10
|
+
The generator creates stubs for a controller (and spec), a view (and spec)
|
11
|
+
for each view in the argument list, plus a helper.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
./script/generate objective_controller dog bark fetch
|
15
|
+
...
|
16
|
+
create spec/controllers/dog_controller_spec.rb
|
17
|
+
create app/controllers/dog_controller.rb
|
18
|
+
create app/helpers/dog_helper.rb
|
19
|
+
create spec/views/dog/bark_view_spec.rb
|
20
|
+
create app/views/dog/bark.html.haml
|
21
|
+
create spec/views/dog/fetch_view_spec.rb
|
22
|
+
create app/views/dog/fetch.html.haml
|
23
|
+
|
24
|
+
Modules Example:
|
25
|
+
./script/generate objective_controller 'pets/dog' bark fetch
|
26
|
+
...
|
27
|
+
create spec/controllers/pets/dog_controller_spec.rb
|
28
|
+
create app/controllers/pets/dog_controller.rb
|
29
|
+
create app/helpers/pets/dog_helper.rb
|
30
|
+
create spec/views/pets/dog/bark_view_spec.rb
|
31
|
+
create app/views/pets/dog/bark.html.haml
|
32
|
+
create spec/views/pets/dog/fetch_view_spec.rb
|
33
|
+
create app/views/pets/dog/fetch.html.haml
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails_generator/generators/components/controller/controller_generator'
|
2
|
+
|
3
|
+
class ObjectiveControllerGenerator < ControllerGenerator
|
4
|
+
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
# Check for class naming collisions.
|
8
|
+
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
|
9
|
+
|
10
|
+
# Controller, helper, views, and spec directories.
|
11
|
+
m.directory File.join('app/controllers', class_path)
|
12
|
+
m.directory File.join('app/helpers', class_path)
|
13
|
+
m.directory File.join('app/views', class_path, file_name)
|
14
|
+
m.directory File.join('spec/controllers', class_path)
|
15
|
+
m.directory File.join('spec/helpers', class_path)
|
16
|
+
m.directory File.join('spec/views', class_path, file_name)
|
17
|
+
|
18
|
+
@default_file_extension = "html.haml"
|
19
|
+
|
20
|
+
# Controller spec, class, and helper.
|
21
|
+
m.template 'controller_spec.rb',
|
22
|
+
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
23
|
+
|
24
|
+
m.template 'helper_spec.rb',
|
25
|
+
File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
26
|
+
|
27
|
+
m.template 'controller:controller.rb',
|
28
|
+
File.join('app/controllers', class_path, "#{file_name}_controller.rb")
|
29
|
+
|
30
|
+
m.template 'controller:helper.rb',
|
31
|
+
File.join('app/helpers', class_path, "#{file_name}_helper.rb")
|
32
|
+
|
33
|
+
# Spec and view template for each action.
|
34
|
+
actions.each do |action|
|
35
|
+
m.template 'view_spec.rb',
|
36
|
+
File.join('spec/views', class_path, file_name, "#{action}.#{@default_file_extension}_spec.rb"),
|
37
|
+
:assigns => { :action => action, :model => file_name }
|
38
|
+
path = File.join('app/views', class_path, file_name, "#{action}.#{@default_file_extension}")
|
39
|
+
m.template "view.html.haml",
|
40
|
+
path,
|
41
|
+
:assigns => { :action => action, :path => path }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %>Controller do
|
4
|
+
|
5
|
+
<% if actions.empty? -%>
|
6
|
+
# Delete this example and add some real ones
|
7
|
+
<% else -%>
|
8
|
+
# Delete these examples and add some real ones
|
9
|
+
<% end -%>
|
10
|
+
it "should use <%= class_name %>Controller" do
|
11
|
+
controller.should be_an_instance_of(<%= class_name %>Controller)
|
12
|
+
end
|
13
|
+
|
14
|
+
<% unless actions.empty? -%>
|
15
|
+
<% for action in actions -%>
|
16
|
+
|
17
|
+
describe "GET '<%= action %>'" do
|
18
|
+
it "should be successful" do
|
19
|
+
get '<%= action %>'
|
20
|
+
response.should be_success
|
21
|
+
end
|
22
|
+
end
|
23
|
+
<% end -%>
|
24
|
+
<% end -%>
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../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
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
2
|
+
|
3
|
+
describe "/<%= class_name.underscore %>/<%= action %>" do
|
4
|
+
|
5
|
+
# Delete this example and add some real ones or delete this file
|
6
|
+
it "should tell you where to find the file" do
|
7
|
+
render '<%= class_name.underscore %>/<%= action %>'
|
8
|
+
response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails_generator/generators/components/model/model_generator'
|
2
|
+
require File.dirname(__FILE__) + '/../rspec_default_values'
|
3
|
+
|
4
|
+
class ObjectiveModelGenerator < ModelGenerator
|
5
|
+
|
6
|
+
def manifest
|
7
|
+
|
8
|
+
record do |m|
|
9
|
+
# Check for class naming collisions.
|
10
|
+
m.class_collisions class_path, class_name
|
11
|
+
|
12
|
+
# Model, spec, and fixture directories.
|
13
|
+
m.directory File.join('app/models', class_path)
|
14
|
+
m.directory File.join('spec/models', class_path)
|
15
|
+
|
16
|
+
# Model class, spec and fixtures.
|
17
|
+
m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
18
|
+
m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
19
|
+
|
20
|
+
unless options[:skip_migration]
|
21
|
+
m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
|
22
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
23
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
24
|
+
end
|
25
|
+
|
26
|
+
model_factory = "\n\nFactory.define(:#{file_name}) do |f|\n"
|
27
|
+
for attribute in attributes
|
28
|
+
model_factory << "\tf.#{attribute.name} #{attribute.default_value}\n"
|
29
|
+
end
|
30
|
+
model_factory << "end\n"
|
31
|
+
append_file("spec/factories.rb", model_factory)
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def append_file(path, data)
|
37
|
+
File.open(path, 'ab') { |file| file.write(data) }
|
38
|
+
end
|
39
|
+
|
40
|
+
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_or_reference} => #{a.default_value}" }.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,16 @@
|
|
1
|
+
class ObjectiveObserverGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
# Check for class naming collisions.
|
5
|
+
m.class_collisions "#{class_name}Observer"
|
6
|
+
|
7
|
+
# Observer, and test directories.
|
8
|
+
m.directory File.join('app/models', class_path)
|
9
|
+
m.directory File.join('spec/observers', class_path)
|
10
|
+
|
11
|
+
# Observer class and unit test fixtures.
|
12
|
+
m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
|
13
|
+
m.template 'observer_spec.rb', File.join('spec/observers', class_path, "#{file_name}_observer_spec.rb")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
2
|
+
|
3
|
+
describe <%= class_name %>Observer do
|
4
|
+
|
5
|
+
it "should observe <%= class_name %>" do
|
6
|
+
<%= file_name %> = Factory(:<%= file_name %>)
|
7
|
+
observer = <%= class_name %>Observer.instance
|
8
|
+
observer.after_create(<%= file_name %>)
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
Binary file
|
@@ -0,0 +1,172 @@
|
|
1
|
+
class ObjectiveResourceGenerator < Rails::Generator::NamedBase
|
2
|
+
attr_reader :controller_name,
|
3
|
+
:controller_class_path,
|
4
|
+
:controller_file_path,
|
5
|
+
:controller_class_nesting,
|
6
|
+
:controller_class_nesting_depth,
|
7
|
+
:controller_class_name,
|
8
|
+
:controller_singular_name,
|
9
|
+
:controller_plural_name,
|
10
|
+
:resource_edit_path,
|
11
|
+
:default_file_extension,
|
12
|
+
:generator_default_file_extension
|
13
|
+
alias_method :controller_file_name, :controller_singular_name
|
14
|
+
alias_method :controller_table_name, :controller_plural_name
|
15
|
+
|
16
|
+
def initialize(runtime_args, runtime_options = {})
|
17
|
+
super
|
18
|
+
|
19
|
+
if has_rspec?
|
20
|
+
if ActionController::Base.respond_to?(:resource_action_separator)
|
21
|
+
@resource_edit_path = "/edit"
|
22
|
+
else
|
23
|
+
@resource_edit_path = ";edit"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
raise "You do not have rspec installed. WTF are you doing?"
|
27
|
+
end
|
28
|
+
|
29
|
+
raise "You don't have haml installed, WTF are you, a joker?" unless defined?(Haml)
|
30
|
+
@generator_default_file_extension = "haml"
|
31
|
+
@default_file_extension = "html.#{@generator_default_file_extension}"
|
32
|
+
|
33
|
+
@controller_name = @name.pluralize
|
34
|
+
|
35
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
36
|
+
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
|
37
|
+
|
38
|
+
if @controller_class_nesting.empty?
|
39
|
+
@controller_class_name = @controller_class_name_without_nesting
|
40
|
+
else
|
41
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def manifest
|
46
|
+
record do |m|
|
47
|
+
# Check for class naming collisions.
|
48
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
49
|
+
m.class_collisions(class_path, "#{class_name}")
|
50
|
+
|
51
|
+
# Controller, helper, views, and test directories.
|
52
|
+
m.directory(File.join('app/models', class_path))
|
53
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
54
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
55
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
56
|
+
|
57
|
+
m.directory(File.join('spec/controllers', controller_class_path))
|
58
|
+
m.directory(File.join('spec/helpers', class_path))
|
59
|
+
m.directory(File.join('spec/models', class_path))
|
60
|
+
m.directory File.join('spec/views', controller_class_path, controller_file_name)
|
61
|
+
|
62
|
+
scaffold_views.each do |action|
|
63
|
+
m.template(
|
64
|
+
"view_#{action}.#{generator_default_file_extension}",
|
65
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
|
70
|
+
m.template('controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
|
71
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
72
|
+
|
73
|
+
m.template('rspec/functional_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb"))
|
74
|
+
m.template('rspec/routing_spec.rb', File.join('spec/controllers', controller_class_path, "#{controller_file_name}_routing_spec.rb"))
|
75
|
+
m.template('rspec/helper_spec.rb', File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb"))
|
76
|
+
m.template('rspec/unit_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb"))
|
77
|
+
|
78
|
+
#Use Factories instead of fixtures
|
79
|
+
model_factory = "\n\nFactory.define(:#{file_name}) do |f|\n"
|
80
|
+
for attribute in attributes
|
81
|
+
model_factory << "\tf.#{attribute.name} #{attribute.default_value}\n"
|
82
|
+
end
|
83
|
+
model_factory << "end\n"
|
84
|
+
append_file("spec/factories.rb", model_factory)
|
85
|
+
|
86
|
+
rspec_views.each do |action|
|
87
|
+
m.template(
|
88
|
+
"rspec/views/#{action}_spec.rb",
|
89
|
+
File.join('spec/views', controller_class_path, controller_file_name, "#{action}_spec.rb")
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
unless options[:skip_migration]
|
95
|
+
migration_template = 'migration.rb'
|
96
|
+
|
97
|
+
m.migration_template(
|
98
|
+
migration_template, 'db/migrate',
|
99
|
+
:assigns => {
|
100
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
|
101
|
+
:attributes => attributes
|
102
|
+
},
|
103
|
+
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
m.route_resources controller_file_name
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Lifted from Rick Olson's restful_authentication
|
112
|
+
def has_rspec?
|
113
|
+
options[:rspec] || (File.exist?('spec') && File.directory?('spec'))
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
# Override with your own usage banner.
|
118
|
+
def banner
|
119
|
+
"Usage: #{$0} scaffold_resource ModelName [field:type, field:type]"
|
120
|
+
end
|
121
|
+
|
122
|
+
def rspec_views
|
123
|
+
%w[ index show new edit ]
|
124
|
+
end
|
125
|
+
|
126
|
+
def scaffold_views
|
127
|
+
rspec_views + %w[ _form ]
|
128
|
+
end
|
129
|
+
|
130
|
+
def model_name
|
131
|
+
class_name.demodulize
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_options!(opt)
|
135
|
+
opt.separator ''
|
136
|
+
opt.separator 'Options:'
|
137
|
+
opt.on("--rspec", "Force rspec mode (checks for RAILS_ROOT/spec by default)") { |v| options[:rspec] = true }
|
138
|
+
end
|
139
|
+
|
140
|
+
def append_file(path, data)
|
141
|
+
File.open(path, 'ab') { |file| file.write(data) }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
module Rails
|
146
|
+
module Generator
|
147
|
+
class GeneratedAttribute
|
148
|
+
def default_value
|
149
|
+
@default_value ||= case type
|
150
|
+
when :int, :integer then "\"1\""
|
151
|
+
when :float then "\"1.5\""
|
152
|
+
when :decimal then "\"9.99\""
|
153
|
+
when :datetime, :timestamp, :time then "Time.now"
|
154
|
+
when :date then "Date.today"
|
155
|
+
when :string then "\"MyString\""
|
156
|
+
when :text then "\"MyText\""
|
157
|
+
when :boolean then "false"
|
158
|
+
else
|
159
|
+
""
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def input_type
|
164
|
+
@input_type ||= case type
|
165
|
+
when :text then "textarea"
|
166
|
+
else
|
167
|
+
"input"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %>, :force => true do |t|
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= table_name %>
|
14
|
+
end
|
15
|
+
end
|