rails3-generators 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/CHANGELOG.rdoc +18 -2
- data/README.rdoc +5 -1
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/lib/generators/{datamapper.rb → data_mapper.rb} +6 -3
- data/lib/generators/{datamapper → data_mapper}/migration/migration_generator.rb +2 -2
- data/lib/generators/{datamapper → data_mapper}/migration/templates/migration.rb +0 -0
- data/lib/generators/{datamapper → data_mapper}/model/model_generator.rb +27 -3
- data/lib/generators/{datamapper → data_mapper}/model/templates/migration.rb +0 -0
- data/lib/generators/{datamapper → data_mapper}/model/templates/model.rb +4 -2
- data/lib/generators/{datamapper → data_mapper}/observer/observer_generator.rb +2 -2
- data/lib/generators/{datamapper → data_mapper}/observer/templates/observer.rb +1 -1
- data/lib/generators/helpers/migration_helper.rb +53 -0
- data/lib/generators/helpers/model_helper.rb +75 -0
- data/lib/generators/jquery/install/install_generator.rb +6 -6
- data/lib/generators/jquery/install/templates/README +10 -0
- data/lib/generators/{mongomapper.rb → mongo_mapper.rb} +3 -24
- data/lib/generators/mongo_mapper/install/install_generator.rb +30 -0
- data/lib/generators/mongo_mapper/install/templates/database.mongo.yml +25 -0
- data/lib/generators/mongo_mapper/install/templates/mongo_mapper.rb +9 -0
- data/lib/generators/mongo_mapper/model/model_generator.rb +84 -0
- data/lib/generators/mongo_mapper/model/templates/model.rb +36 -0
- data/lib/generators/{mongomapper → mongo_mapper}/observer/observer_generator.rb +2 -2
- data/lib/generators/mongo_mapper/observer/templates/observer.rb +3 -0
- data/lib/generators/mongoid.rb +24 -0
- data/lib/generators/mongoid/install/install_generator.rb +35 -0
- data/lib/generators/mongoid/install/templates/database.mongo.yml +25 -0
- data/lib/generators/mongoid/install/templates/mongoid.rb +12 -0
- data/lib/generators/mongoid/model/model_generator.rb +111 -0
- data/lib/generators/{mongomapper → mongoid}/model/templates/model.rb +11 -9
- data/lib/generators/mustache/install/templates/lib/mustache_rails.rb +1 -3
- data/lib/rails3-generators.rb +1 -1
- data/rails3-generators.gemspec +60 -29
- data/test/lib/generators/data_mapper/migration_generator_test.rb +40 -0
- data/test/lib/generators/data_mapper/model_generator_test.rb +53 -0
- data/test/lib/generators/data_mapper/observer_generator_test.rb +22 -0
- data/test/lib/generators/haml/controller_generator_test.rb +1 -0
- data/test/lib/generators/haml/install_generator_test.rb +1 -0
- data/test/lib/generators/haml/scaffold_generator_test.rb +1 -0
- data/test/lib/generators/haml/testing_helper.rb +1 -0
- data/test/lib/generators/jquery/install_generator_test.rb +0 -1
- data/test/lib/generators/mongo_mapper/install_generator_test.rb +17 -0
- data/test/lib/generators/mongo_mapper/model_generator_test.rb +73 -0
- data/test/lib/generators/mongo_mapper/observer_generator_test.rb +20 -0
- data/test/lib/generators/mongo_mapper/testing_helper.rb +1 -0
- data/test/lib/generators/mongoid/install_generator_test.rb +18 -0
- data/test/lib/generators/mongoid/model_generator_test.rb +72 -0
- data/test/lib/generators/mongoid/testing_helper.rb +1 -0
- data/test/lib/generators/mustache/controller_generator_test.rb +1 -0
- data/test/lib/generators/mustache/scaffold_generator_test.rb +1 -0
- data/test/lib/generators/mustache/testing_helper.rb +1 -0
- data/test/test_helper.rb +31 -28
- metadata +61 -30
- data/lib/generators/jquery/install/templates/config/initializers/jquery.rb.tt +0 -9
- data/lib/generators/mongomapper/model/model_generator.rb +0 -29
- data/test/lib/generators/datamapper/migration_generator_test.rb +0 -13
- data/test/lib/generators/datamapper/model_generator_test.rb +0 -13
- data/test/lib/generators/datamapper/observer_generator_test.rb +0 -13
- data/test/lib/generators/mongomapper/model_generator_test.rb +0 -13
- data/test/lib/generators/mongomapper/observer_generator_test.rb +0 -13
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_generator :data_mapper => ['migration']
|
3
|
+
|
4
|
+
class DataMapper::Generators::MigrationGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests DataMapper::Generators::MigrationGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with name of migration" do
|
12
|
+
name = 'account'
|
13
|
+
run_generator %w{Account}
|
14
|
+
migration_name = Dir[File.join(Rails.root, "db/migrate/*_#{name}.rb")].first
|
15
|
+
if migration_name
|
16
|
+
assert_file migration_name do |migration|
|
17
|
+
assert_match /up do/, migration
|
18
|
+
assert_match /down do/, migration
|
19
|
+
end
|
20
|
+
else
|
21
|
+
fail "No migration generated for #{name}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test "invoke with name and attributes" do
|
26
|
+
name = 'account'
|
27
|
+
run_generator %w{Account name:string}
|
28
|
+
migration_name = Dir[File.join(Rails.root, "db/migrate/*_#{name}.rb")].first
|
29
|
+
if migration_name
|
30
|
+
assert_file migration_name do |migration|
|
31
|
+
assert_match /up do/, migration
|
32
|
+
assert_match /down do/, migration
|
33
|
+
assert_match /modify_table :#{name.tableize}/, migration
|
34
|
+
end
|
35
|
+
else
|
36
|
+
fail "No migration generated for #{name}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_generator :data_mapper => ['model']
|
3
|
+
|
4
|
+
class DataMapper::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests DataMapper::Generators::ModelGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with model name" do
|
12
|
+
content = run_generator %w(Account)
|
13
|
+
|
14
|
+
assert_file "app/models/account.rb" do |account|
|
15
|
+
assert_class "Account", account do |klass|
|
16
|
+
assert_match /include DataMapper::Resource/, klass
|
17
|
+
assert_match /property :id, Serial/, klass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test "invoke with model name and attributes" do
|
23
|
+
content = run_generator %w(Account name:string age:integer)
|
24
|
+
|
25
|
+
assert_file "app/models/account.rb" do |account|
|
26
|
+
assert_class "Account", account do |klass|
|
27
|
+
assert_match /property :name, String/, klass
|
28
|
+
assert_match /property :age, Integer/, klass
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "invoke with model name and --timestamps option" do
|
34
|
+
content = run_generator %w(Account --timestamps)
|
35
|
+
|
36
|
+
assert_file "app/models/account.rb" do |account|
|
37
|
+
assert_class "Account", account do |klass|
|
38
|
+
assert_match /property :created_at, DateTime/, klass
|
39
|
+
assert_match /property :updated_at, DateTime/, klass
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test "invoke with model name and --parent option" do
|
45
|
+
content = run_generator %w(Admin --parent User)
|
46
|
+
assert_file "app/models/admin.rb" do |account|
|
47
|
+
assert_class "Admin", account do |klass|
|
48
|
+
assert_no_match /property :id, Serial/, klass
|
49
|
+
assert_match /<\s+User/, klass
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require_generator :data_mapper => ['observer']
|
3
|
+
|
4
|
+
class DataMapper::Generators::ObserverGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests DataMapper::Generators::ObserverGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with model name" do
|
12
|
+
name = 'account'
|
13
|
+
content = run_generator %w(Account)
|
14
|
+
|
15
|
+
assert_file "app/models/#{name}_observer.rb" do |account|
|
16
|
+
assert_class "Account", account do |klass|
|
17
|
+
assert_match /include DataMapper::Observer/, klass
|
18
|
+
assert_match /observe\s+#{name.camelize}/, klass
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_generators :haml => ['scaffold', 'controller', 'install']
|
@@ -10,7 +10,6 @@ class Jquery::Generators::InstallGeneratorTest < Rails::Generators::TestCase
|
|
10
10
|
test 'jquery is installed' do
|
11
11
|
run_generator
|
12
12
|
|
13
|
-
assert_file "config/initializers/jquery.rb"
|
14
13
|
%w(jquery.js rails.js).each { |js| assert_file "public/javascripts/#{js}" }
|
15
14
|
%w(controls.js dragdrop.js effects.js prototype.js).each { |js| assert_no_file "public/javascripts/#{js}" }
|
16
15
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/mongo_mapper/testing_helper'
|
3
|
+
|
4
|
+
class MongoMapper::Generators::InstallGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests MongoMapper::Generators::InstallGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke" do
|
12
|
+
run_generator ['test-db']
|
13
|
+
assert_file "config/initializers/mongo_mapper.rb" do |initializer|
|
14
|
+
assert_match /MongoMapper.connection = Mongo::Connection.new(\S+)/, initializer
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/mongo_mapper/testing_helper'
|
3
|
+
|
4
|
+
class MongoMapper::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests MongoMapper::Generators::ModelGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with model name" do
|
12
|
+
content = run_generator %w(Account)
|
13
|
+
|
14
|
+
assert_file "app/models/account.rb" do |account|
|
15
|
+
assert_class "Account", account do |klass|
|
16
|
+
assert_match /include MongoMapper::Document/, klass
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test "invoke with model name and attributes" do
|
22
|
+
content = run_generator %w(Account name:string age:integer)
|
23
|
+
|
24
|
+
assert_file "app/models/account.rb" do |account|
|
25
|
+
assert_class "Account", account do |klass|
|
26
|
+
assert_match /key :name, String/, klass
|
27
|
+
assert_match /key :age, Integer/, klass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "invoke with model name and --embedded option" do
|
33
|
+
content = run_generator %w(Account --embedded)
|
34
|
+
|
35
|
+
assert_file "app/models/account.rb" do |account|
|
36
|
+
assert_class "Account", account do |klass|
|
37
|
+
assert_match /include MongoMapper::EmbeddedDocument/, klass
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test "invoke with model name and --timestamps option" do
|
43
|
+
content = run_generator %w(Account --timestamps)
|
44
|
+
|
45
|
+
assert_file "app/models/account.rb" do |account|
|
46
|
+
assert_class "Account", account do |klass|
|
47
|
+
assert_match /timestamps!/, klass
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
test "invoke with model name and --version option" do
|
53
|
+
content = run_generator %w(Account --version)
|
54
|
+
|
55
|
+
assert_file "app/models/account.rb" do |account|
|
56
|
+
assert_class "Account", account do |klass|
|
57
|
+
assert_match /include Versioned/, klass
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
test "invoke with model name and --parent option" do
|
64
|
+
content = run_generator %w(Admin --parent User)
|
65
|
+
|
66
|
+
assert_file "app/models/admin.rb" do |account|
|
67
|
+
assert_class "Admin", account do |klass|
|
68
|
+
assert_no_match /include MongoMapper::Document/, klass
|
69
|
+
assert_match /<\s+User/, klass
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/mongo_mapper/testing_helper'
|
3
|
+
|
4
|
+
class MongoMapper::Generators::ObserverGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests MongoMapper::Generators::ObserverGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with name Account" do
|
12
|
+
name = 'account'
|
13
|
+
run_generator [name]
|
14
|
+
assert_file "app/models/#{name}_observer.rb" do |file_content|
|
15
|
+
assert_class "Account", file_content do |klass|
|
16
|
+
assert_match /< MongoMapper::Observer/, klass
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_generators :mongo_mapper => ['model', 'observer', 'install']
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/mongoid/testing_helper'
|
3
|
+
|
4
|
+
class Mongoid::Generators::InstallGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Mongoid::Generators::InstallGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke" do
|
12
|
+
run_generator ['test-db']
|
13
|
+
|
14
|
+
assert_file "config/initializers/mongoid.rb" do |initializer|
|
15
|
+
assert_match /Mongo::Connection.new(\S+)/, initializer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'lib/generators/mongoid/testing_helper'
|
3
|
+
|
4
|
+
class Mongoid::Generators::ModelGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Mongoid::Generators::ModelGenerator
|
7
|
+
|
8
|
+
setup :prepare_destination
|
9
|
+
setup :copy_routes
|
10
|
+
|
11
|
+
test "invoke with model name" do
|
12
|
+
content = run_generator %w(Account)
|
13
|
+
|
14
|
+
assert_file "app/models/account.rb" do |account|
|
15
|
+
assert_class "Account", account do |klass|
|
16
|
+
assert_match /Mongoid::Document/, klass
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
test "invoke with model name and attributes" do
|
22
|
+
content = run_generator %w(Account name:string age:integer)
|
23
|
+
|
24
|
+
assert_file "app/models/account.rb" do |account|
|
25
|
+
assert_class "Account", account do |klass|
|
26
|
+
assert_match /field :name, :type => String/, klass
|
27
|
+
assert_match /field :age, :type => Integer/, klass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "invoke with model name and --embedded_in option" do
|
33
|
+
content = run_generator %w(Room --embedded-in House)
|
34
|
+
|
35
|
+
assert_file "app/models/room.rb" do |account|
|
36
|
+
assert_class "Room", account do |klass|
|
37
|
+
assert_match /embedded_in :house, :inverse_of => :rooms/, klass
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test "invoke with model name and --timestamps option" do
|
43
|
+
content = run_generator %w(Account --timestamps)
|
44
|
+
|
45
|
+
assert_file "app/models/account.rb" do |account|
|
46
|
+
assert_class "Account", account do |klass|
|
47
|
+
assert_match /include Mongoid::Timestamps/, klass
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
test "invoke with model name and --version option" do
|
53
|
+
content = run_generator %w(Account --version)
|
54
|
+
|
55
|
+
assert_file "app/models/account.rb" do |account|
|
56
|
+
assert_class "Account", account do |klass|
|
57
|
+
assert_match /include Mongoid::Versioning/, klass
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test "invoke with model name and --parent option" do
|
63
|
+
content = run_generator %w(Admin --parent User)
|
64
|
+
|
65
|
+
assert_file "app/models/admin.rb" do |account|
|
66
|
+
assert_class "Admin", account do |klass|
|
67
|
+
assert_no_match /Mongoid::Document/, klass
|
68
|
+
assert_match /<\s+User/, klass
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_generators :mongoid => ['model', 'install']
|
@@ -0,0 +1 @@
|
|
1
|
+
require_generators :mustache => ['scaffold', 'controller', 'install']
|
data/test/test_helper.rb
CHANGED
@@ -43,34 +43,37 @@ def assert_class(klass, content)
|
|
43
43
|
yield $2.strip if block_given?
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
require 'generators/datamapper/migration/migration_generator'
|
62
|
-
require 'generators/datamapper/model/model_generator'
|
63
|
-
require 'generators/datamapper/observer/observer_generator'
|
64
|
-
require 'generators/mongomapper/model/model_generator'
|
65
|
-
require 'generators/mongomapper/observer/observer_generator'
|
66
|
-
|
67
|
-
require 'generators/factory_girl/model/model_generator'
|
68
|
-
require 'generators/machinist/model/model_generator'
|
69
|
-
|
70
|
-
require 'generators/authlogic/session/session_generator'
|
46
|
+
def generator_list
|
47
|
+
{
|
48
|
+
:rails => ['scaffold', 'controller'],
|
49
|
+
:erubis => ['scaffold'],
|
50
|
+
:simple_form => ['scaffold'],
|
51
|
+
:formtastic => ['scaffold'],
|
52
|
+
:factory_girl => ['model'],
|
53
|
+
:machinist => ['model'],
|
54
|
+
:authlogic => ['session'],
|
55
|
+
:jquery => ['install'],
|
56
|
+
:koala => ['install'],
|
57
|
+
:shoulda => ['controller']
|
58
|
+
}
|
59
|
+
end
|
71
60
|
|
72
|
-
|
61
|
+
def path_prefix(name)
|
62
|
+
case name
|
63
|
+
when :rails
|
64
|
+
'rails/generators'
|
65
|
+
else
|
66
|
+
'generators'
|
67
|
+
end
|
68
|
+
end
|
73
69
|
|
74
|
-
|
70
|
+
def require_generators(generator_list)
|
71
|
+
generator_list.each do |name, generators|
|
72
|
+
generators.each do |generator_name|
|
73
|
+
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
alias :require_generator :require_generators
|
75
78
|
|
76
|
-
|
79
|
+
require_generators generator_list
|