thorero-gen 0.9.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/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +65 -0
- data/TODO +13 -0
- data/bin/merb-gen +10 -0
- data/lib/merb-gen.rb +37 -0
- data/lib/merb-gen/controller.rb +69 -0
- data/lib/merb-gen/freezer.rb +19 -0
- data/lib/merb-gen/generator.rb +55 -0
- data/lib/merb-gen/helper.rb +53 -0
- data/lib/merb-gen/merb.rb +27 -0
- data/lib/merb-gen/merb/merb_flat.rb +31 -0
- data/lib/merb-gen/merb/merb_full.rb +35 -0
- data/lib/merb-gen/merb/merb_very_flat.rb +33 -0
- data/lib/merb-gen/merb_plugin.rb +33 -0
- data/lib/merb-gen/migration.rb +69 -0
- data/lib/merb-gen/model.rb +67 -0
- data/lib/merb-gen/part_controller.rb +55 -0
- data/lib/merb-gen/resource.rb +32 -0
- data/lib/merb-gen/resource_controller.rb +91 -0
- data/lib/merb-gen/session_migration.rb +44 -0
- data/lib/merb-gen/slice.rb +25 -0
- data/lib/merb-gen/slice/full.rb +31 -0
- data/lib/merb-gen/slice/thin.rb +31 -0
- data/lib/merb-gen/slice/very_thin.rb +31 -0
- data/spec/controller_spec.rb +94 -0
- data/spec/merb_spec.rb +28 -0
- data/spec/migration_spec.rb +47 -0
- data/spec/model_spec.rb +95 -0
- data/spec/resource_controller_spec.rb +98 -0
- data/spec/spec_helper.rb +7 -0
- data/templates/application/merb/Rakefile +76 -0
- data/templates/application/merb/app/controllers/application.rb +2 -0
- data/templates/application/merb/app/controllers/exceptions.rb +13 -0
- data/templates/application/merb/app/helpers/global_helpers.rb +5 -0
- data/templates/application/merb/app/views/exceptions/internal_server_error.html.erb +216 -0
- data/templates/application/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/templates/application/merb/app/views/exceptions/not_found.html.erb +47 -0
- data/templates/application/merb/app/views/layout/application.html.erb +11 -0
- data/templates/application/merb/autotest/discover.rb +1 -0
- data/templates/application/merb/autotest/merb.rb +149 -0
- data/templates/application/merb/autotest/merb_rspec.rb +166 -0
- data/templates/application/merb/config/environments/development.rb +7 -0
- data/templates/application/merb/config/environments/production.rb +7 -0
- data/templates/application/merb/config/environments/rake.rb +7 -0
- data/templates/application/merb/config/environments/test.rb +6 -0
- data/templates/application/merb/config/init.rb +164 -0
- data/templates/application/merb/config/rack.rb +12 -0
- data/templates/application/merb/config/router.rb +35 -0
- data/templates/application/merb/public/images/merb.jpg +0 -0
- data/templates/application/merb/public/merb.fcgi +22 -0
- data/templates/application/merb/public/stylesheets/master.css +119 -0
- data/templates/application/merb/spec/spec.opts +0 -0
- data/templates/application/merb/spec/spec_helper.rb +13 -0
- data/templates/application/merb/test/test_helper.rb +14 -0
- data/templates/application/merb_flat/README.txt +10 -0
- data/templates/application/merb_flat/application.rb +15 -0
- data/templates/application/merb_flat/config/framework.rb +7 -0
- data/templates/application/merb_flat/config/init.rb +18 -0
- data/templates/application/merb_flat/views/foo.html.erb +3 -0
- data/templates/application/merb_plugin/LICENSE +20 -0
- data/templates/application/merb_plugin/README +4 -0
- data/templates/application/merb_plugin/Rakefile +59 -0
- data/templates/application/merb_plugin/TODO +5 -0
- data/templates/application/merb_plugin/lib/%base_name%.rb +18 -0
- data/templates/application/merb_plugin/lib/%base_name%/merbtasks.rb +6 -0
- data/templates/application/merb_plugin/spec/%base_name%_spec.rb +7 -0
- data/templates/application/merb_plugin/spec/spec_helper.rb +2 -0
- data/templates/application/merb_plugin/test/%base_name%_test.rb +0 -0
- data/templates/application/merb_plugin/test/test_helper.rb +2 -0
- data/templates/application/merb_very_flat/application.rbt +17 -0
- data/templates/application/slice/full/LICENSE +20 -0
- data/templates/application/slice/full/README +170 -0
- data/templates/application/slice/full/Rakefile +48 -0
- data/templates/application/slice/full/TODO +15 -0
- data/templates/application/slice/full/app/controllers/application.rb +5 -0
- data/templates/application/slice/full/app/controllers/main.rb +7 -0
- data/templates/application/slice/full/app/helpers/application_helper.rb +64 -0
- data/templates/application/slice/full/app/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/full/app/views/main/index.html.erb +1 -0
- data/templates/application/slice/full/lib/%base_name%.rb +78 -0
- data/templates/application/slice/full/lib/%base_name%/merbtasks.rb +166 -0
- data/templates/application/slice/full/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/full/public/javascripts/master.js +0 -0
- data/templates/application/slice/full/public/stylesheets/master.css +2 -0
- data/templates/application/slice/full/spec/%base_name%_spec.rb +130 -0
- data/templates/application/slice/full/spec/controllers/main_spec.rb +61 -0
- data/templates/application/slice/full/spec/spec_helper.rb +44 -0
- data/templates/application/slice/full/stubs/app/controllers/application.rb +2 -0
- data/templates/application/slice/full/stubs/app/controllers/main.rb +2 -0
- data/templates/application/slice/thin/LICENSE +20 -0
- data/templates/application/slice/thin/README +130 -0
- data/templates/application/slice/thin/Rakefile +46 -0
- data/templates/application/slice/thin/TODO +7 -0
- data/templates/application/slice/thin/application.rb +36 -0
- data/templates/application/slice/thin/lib/%base_name%.rb +93 -0
- data/templates/application/slice/thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/thin/public/javascripts/master.js +0 -0
- data/templates/application/slice/thin/public/stylesheets/master.css +2 -0
- data/templates/application/slice/thin/stubs/application.rb +9 -0
- data/templates/application/slice/thin/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/thin/views/main/index.html.erb +1 -0
- data/templates/application/slice/very_thin/LICENSE +20 -0
- data/templates/application/slice/very_thin/README +110 -0
- data/templates/application/slice/very_thin/Rakefile +46 -0
- data/templates/application/slice/very_thin/TODO +7 -0
- data/templates/application/slice/very_thin/application.rb +36 -0
- data/templates/application/slice/very_thin/lib/%base_name%.rb +89 -0
- data/templates/application/slice/very_thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/very_thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/component/controller/app/controllers/%file_name%.rb +11 -0
- data/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
- data/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
- data/templates/component/freezer/script/frozen_merb +43 -0
- data/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
- data/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
- data/templates/component/migration/activerecord/schema/migrations/%file_name%.rb +19 -0
- data/templates/component/migration/datamapper/schema/migrations/%file_name%.rb +7 -0
- data/templates/component/migration/sequel/schema/migrations/%file_name%.rb +24 -0
- data/templates/component/model/activerecord/app/models/%file_name%.rb +2 -0
- data/templates/component/model/datamapper/app/models/%file_name%.rb +6 -0
- data/templates/component/model/none/app/models/%file_name%.rb +5 -0
- data/templates/component/model/rspec/spec/models/%file_name%_spec.rb +7 -0
- data/templates/component/model/sequel/app/models/%file_name%.rb +2 -0
- data/templates/component/model/test_unit/test/models/%file_name%_test.rb +9 -0
- data/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
- data/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/controllers/%file_name%.rb +57 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/datamapper/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/edit.html.erb +21 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/index.html.erb +24 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/new.html.erb +20 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/show.html.erb +14 -0
- data/templates/component/resource_controller/none/app/controllers/%file_name%.rb +36 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/session_migration/activerecord/schema/migrations/%version%_sessions.rb +12 -0
- data/templates/component/session_migration/sequel/schema/migrations/%version%_sessions.rb +16 -0
- metadata +362 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class FullSliceGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'slice', 'full')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
glob!
|
|
10
|
+
|
|
11
|
+
first_argument :name, :required => true
|
|
12
|
+
|
|
13
|
+
def module_name
|
|
14
|
+
self.name.camel_case
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def base_name
|
|
18
|
+
self.name.snake_case
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias_method :underscored_name, :base_name
|
|
22
|
+
|
|
23
|
+
def destination_root
|
|
24
|
+
File.join(@destination_root, base_name)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
add_private :full_slice, FullSliceGenerator
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class ThinSliceGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'slice', 'thin')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
glob!
|
|
10
|
+
|
|
11
|
+
first_argument :name, :required => true
|
|
12
|
+
|
|
13
|
+
def module_name
|
|
14
|
+
self.name.camel_case
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def base_name
|
|
18
|
+
self.name.snake_case
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias_method :underscored_name, :base_name
|
|
22
|
+
|
|
23
|
+
def destination_root
|
|
24
|
+
File.join(@destination_root, base_name)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
add_private :thin_slice, ThinSliceGenerator
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Merb::Generators
|
|
2
|
+
|
|
3
|
+
class VeryThinSliceGenerator < ApplicationGenerator
|
|
4
|
+
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.join(super, 'slice', 'very_thin')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
glob!
|
|
10
|
+
|
|
11
|
+
first_argument :name, :required => true
|
|
12
|
+
|
|
13
|
+
def module_name
|
|
14
|
+
self.name.camel_case
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def base_name
|
|
18
|
+
self.name.snake_case
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
alias_method :underscored_name, :base_name
|
|
22
|
+
|
|
23
|
+
def destination_root
|
|
24
|
+
File.join(@destination_root, base_name)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
add_private :very_thin_slice, VeryThinSliceGenerator
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Merb::Generators::ControllerGenerator do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@generator = Merb::Generators::ControllerGenerator.new('/tmp', {}, 'Stuff')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "#controller_class_name" do
|
|
10
|
+
it "should camelize the name" do
|
|
11
|
+
@generator.name = "project_pictures"
|
|
12
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should split off the last double colon separated chunk" do
|
|
16
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
17
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should split off the last slash separated chunk" do
|
|
21
|
+
@generator.name = "test/monkey/project_pictures"
|
|
22
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#controller_modules" do
|
|
27
|
+
it "should be empty if no modules are passed to the name" do
|
|
28
|
+
@generator.name = "project_pictures"
|
|
29
|
+
@generator.controller_modules.should == []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should split off all but the last double colon separated chunks" do
|
|
33
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
34
|
+
@generator.controller_modules.should == ["Test", "Monkey"]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should split off all but the last slash separated chunk" do
|
|
38
|
+
@generator.name = "test/monkey/project_pictures"
|
|
39
|
+
@generator.controller_modules.should == ["Test", "Monkey"]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#file_name" do
|
|
44
|
+
it "should snakify the name" do
|
|
45
|
+
@generator.name = "ProjectPictures"
|
|
46
|
+
@generator.file_name.should == "project_pictures"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should split off the last double colon separated chunk and snakify it" do
|
|
50
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
51
|
+
@generator.file_name.should == "project_pictures"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should split off the last slash separated chunk and snakify it" do
|
|
55
|
+
@generator.name = "test/monkey/project_pictures"
|
|
56
|
+
@generator.file_name.should == "project_pictures"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#test_class_name" do
|
|
61
|
+
it "should camelize the name and append 'Test'" do
|
|
62
|
+
@generator.name = "project_pictures"
|
|
63
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should split off the last double colon separated chunk" do
|
|
67
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
68
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should split off the last slash separated chunk" do
|
|
72
|
+
@generator.name = "test/monkey/project_pictures"
|
|
73
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#full_class_name" do
|
|
78
|
+
it "should camelize the name" do
|
|
79
|
+
@generator.name = "project_pictures"
|
|
80
|
+
@generator.full_class_name.should == "ProjectPictures"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should leave double colon separated chunks" do
|
|
84
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
85
|
+
@generator.full_class_name.should == "Test::Monkey::ProjectPictures"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should convert slashes to double colons and camel case" do
|
|
89
|
+
@generator.name = "test/monkey/project_pictures"
|
|
90
|
+
@generator.full_class_name.should == "Test::Monkey::ProjectPictures"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
data/spec/merb_spec.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Merb::Generators::MerbGenerator do
|
|
4
|
+
|
|
5
|
+
describe "templates" do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@generator = Merb::Generators::MerbGenerator.new('/tmp', {}, 'testing')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should have an init.rb" do
|
|
12
|
+
template = @generator.template(:config_init_rb)
|
|
13
|
+
template.destination.should == '/tmp/testing/config/init.rb'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should have an application controller" do
|
|
17
|
+
template = @generator.template(:app_controllers_application_rb)
|
|
18
|
+
template.destination.should == '/tmp/testing/app/controllers/application.rb'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should have an exceptions controller" do
|
|
22
|
+
template = @generator.template(:app_controllers_exceptions_rb)
|
|
23
|
+
template.destination.should == '/tmp/testing/app/controllers/exceptions.rb'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Merb::Generators::MigrationGenerator do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@generator = Merb::Generators::MigrationGenerator.new('/tmp', {}, 'SomeMoreStuff')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe '#file_name' do
|
|
10
|
+
|
|
11
|
+
it "should convert the name to snake case and prepend the version number" do
|
|
12
|
+
@generator.name = 'SomeMoreStuff'
|
|
13
|
+
@generator.file_name.should == '001_some_more_stuff'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#class_name' do
|
|
19
|
+
|
|
20
|
+
it "should convert the name to camel case" do
|
|
21
|
+
@generator.name = 'some_more_stuff'
|
|
22
|
+
@generator.class_name.should == 'SomeMoreStuff'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#version' do
|
|
28
|
+
it "should find the current migration version and increase it by one" do
|
|
29
|
+
@previous_migration_files = [
|
|
30
|
+
"/tmp/schema/migrations/001_monkey.rb",
|
|
31
|
+
"/tmp/schema/migrations/002_blah.rb",
|
|
32
|
+
"/tmp/schema/migrations/005_gurr_blah.rb",
|
|
33
|
+
"/tmp/schema/migrations/006_garr.rb"
|
|
34
|
+
]
|
|
35
|
+
Dir.should_receive(:[]).with('/tmp/schema/migrations/*').and_return(@previous_migration_files)
|
|
36
|
+
|
|
37
|
+
@generator.version.should == "007"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should be 1 if there are no previous migrations" do
|
|
41
|
+
Dir.should_receive(:[]).with('/tmp/schema/migrations/*').and_return([])
|
|
42
|
+
|
|
43
|
+
@generator.version.should == "001"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
data/spec/model_spec.rb
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Merb::Generators::ModelGenerator do
|
|
4
|
+
|
|
5
|
+
it "should complain if no name is specified" do
|
|
6
|
+
lambda {
|
|
7
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', {})
|
|
8
|
+
}.should raise_error(::Templater::TooFewArgumentsError)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should default to the rspec testing framework" do
|
|
12
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', {}, 'User')
|
|
13
|
+
@generator.testing_framework.should == :rspec
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should have the model and spec actions by default" do
|
|
17
|
+
pending "this doesn't really work with fs generators"
|
|
18
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', {}, 'User')
|
|
19
|
+
@generator.templates.map{|t| t.name}.should == [:model, :spec]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should have the model and test_unit templates if test_unit is specified as testing framework" do
|
|
23
|
+
pending "this doesn't really work with fs generators"
|
|
24
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', { :testing_framework => :test_unit }, 'User')
|
|
25
|
+
@generator.templates.map{|t| t.name}.should == [:model, :test_unit]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should have the model and spec templates if spec is specified as testing framework" do
|
|
29
|
+
pending "this doesn't really work with fs generators"
|
|
30
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', { :testing_framework => :rspec }, 'User')
|
|
31
|
+
@generator.templates.map{|t| t.name}.should == [:model, :spec]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe Merb::Generators::ModelGenerator do
|
|
37
|
+
|
|
38
|
+
before do
|
|
39
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', {}, 'SomeMoreStuff')
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe '#file_name' do
|
|
43
|
+
|
|
44
|
+
it "should convert the name to snake case" do
|
|
45
|
+
@generator.name = 'SomeMoreStuff'
|
|
46
|
+
@generator.file_name.should == 'some_more_stuff'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe '#class_name' do
|
|
52
|
+
|
|
53
|
+
it "should convert the name to camel case" do
|
|
54
|
+
@generator.name = 'some_more_stuff'
|
|
55
|
+
@generator.class_name.should == 'SomeMoreStuff'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe '#attributes_for_accessor' do
|
|
61
|
+
|
|
62
|
+
it "should convert the name to camel case" do
|
|
63
|
+
@generator = Merb::Generators::ModelGenerator.new('/tmp', {}, 'SomeMoreStuff', 'test:object', 'arg:object', 'blah:object')
|
|
64
|
+
@generator.attributes_for_accessor.should == ':arg, :blah, :test'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe '#invocations' do
|
|
70
|
+
|
|
71
|
+
before(:each) do
|
|
72
|
+
@generator.attributes = { 'test' => 'string', 'blah' => 'integer' }
|
|
73
|
+
@invocation = @generator.invocations.first
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should invoke a migration" do
|
|
77
|
+
@invocation.should be_kind_of(Merb::Generators::MigrationGenerator)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should have the same name as the model" do
|
|
81
|
+
@invocation.name.should == "SomeMoreStuff"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should have the same attributes" do
|
|
85
|
+
@invocation.attributes['test'].should == 'string'
|
|
86
|
+
@invocation.attributes['blah'].should == 'integer'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "should set the options 'model' to true" do
|
|
90
|
+
@invocation.options[:model].should be_true
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Merb::Generators::ResourceControllerGenerator do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@generator = Merb::Generators::ResourceControllerGenerator.new('/tmp', {}, 'Stuff')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "#controller_class_name" do
|
|
10
|
+
it "should camelize the name" do
|
|
11
|
+
@generator.name = "project_pictures"
|
|
12
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should split off the last double colon separated chunk" do
|
|
16
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
17
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should split off the last slash separated chunk" do
|
|
21
|
+
@generator.name = "test/monkey/project_pictures"
|
|
22
|
+
@generator.controller_class_name.should == "ProjectPictures"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#controller_modules" do
|
|
27
|
+
it "should be empty if no modules are passed to the name" do
|
|
28
|
+
@generator.name = "project_pictures"
|
|
29
|
+
@generator.controller_modules.should == []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should split off all but the last double colon separated chunks" do
|
|
33
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
34
|
+
@generator.controller_modules.should == ["Test", "Monkey"]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should split off all but the last slash separated chunk" do
|
|
38
|
+
@generator.name = "test/monkey/project_pictures"
|
|
39
|
+
@generator.controller_modules.should == ["Test", "Monkey"]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe "#file_name" do
|
|
44
|
+
it "should snakify the name" do
|
|
45
|
+
@generator.name = "ProjectPictures"
|
|
46
|
+
@generator.file_name.should == "project_pictures"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should split off the last double colon separated chunk and snakify it" do
|
|
50
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
51
|
+
@generator.file_name.should == "project_pictures"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should split off the last slash separated chunk and snakify it" do
|
|
55
|
+
@generator.name = "test/monkey/project_pictures"
|
|
56
|
+
@generator.file_name.should == "project_pictures"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "#test_class_name" do
|
|
61
|
+
it "should camelize the name and append 'Test'" do
|
|
62
|
+
@generator.name = "project_pictures"
|
|
63
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should split off the last double colon separated chunk" do
|
|
67
|
+
@generator.name = "Test::Monkey::ProjectPictures"
|
|
68
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should split off the last slash separated chunk" do
|
|
72
|
+
@generator.name = "test/monkey/project_pictures"
|
|
73
|
+
@generator.test_class_name.should == "ProjectPicturesTest"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#model_class_name" do
|
|
78
|
+
it "should camel case and singularize the controller name" do
|
|
79
|
+
@generator.name = "project_pictures"
|
|
80
|
+
@generator.model_class_name == "ProjectPicture"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "#plural_model" do
|
|
85
|
+
it "should snake case the controller name" do
|
|
86
|
+
@generator.name = "ProjectPictures"
|
|
87
|
+
@generator.plural_model == "project_pictures"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "#singular_model" do
|
|
92
|
+
it "should snake case and singularize the controller name" do
|
|
93
|
+
@generator.name = "ProjectPictures"
|
|
94
|
+
@generator.singular_model == "project_picture"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|