rubigen 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +0 -5
- data/README.txt +1 -1
- data/bin/install_rubigen_scripts +1 -1
- data/bin/ruby_app +1 -1
- data/config/hoe.rb +3 -3
- data/lib/rubigen/lookup.rb +3 -1
- data/lib/rubigen.rb +4 -0
- data/rubygems_generators/application_generator/templates/bin +1 -1
- data/rubygems_generators/component_generator/templates/generator.rb +4 -2
- data/rubygems_generators/component_generator/templates/test.rb +2 -1
- data/script/txt2html +2 -2
- data/tasks/website.rake +0 -2
- data/website/index.html +125 -231
- data/website/index.txt +6 -15
- data/website/stylesheets/screen.css +23 -6
- data/website/template.rhtml +24 -4
- metadata +14 -10
- data/lib/rubigen/version.rb +0 -9
- data/script/txt2js +0 -59
- data/test/examples_from_rails/generator_test_helper.rb +0 -195
- data/test/examples_from_rails/test_rails_resource_generator.rb +0 -106
- data/test/examples_from_rails/test_rails_scaffold_generator.rb +0 -185
@@ -1,185 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
# Optionally load RubyGems.
|
4
|
-
begin
|
5
|
-
require 'rubygems'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
|
9
|
-
# Mock out what we need from AR::Base.
|
10
|
-
module ActiveRecord
|
11
|
-
class Base
|
12
|
-
class << self
|
13
|
-
attr_accessor :pluralize_table_names
|
14
|
-
end
|
15
|
-
self.pluralize_table_names = true
|
16
|
-
end
|
17
|
-
|
18
|
-
module ConnectionAdapters
|
19
|
-
class Column
|
20
|
-
attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale
|
21
|
-
|
22
|
-
def initialize(name, default, sql_type = nil)
|
23
|
-
@name=name
|
24
|
-
@default=default
|
25
|
-
@type=@sql_type=sql_type
|
26
|
-
end
|
27
|
-
|
28
|
-
def human_name
|
29
|
-
@name.humanize
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# And what we need from ActionView
|
36
|
-
module ActionView
|
37
|
-
module Helpers
|
38
|
-
module ActiveRecordHelper; end
|
39
|
-
class InstanceTag; end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
# Must set before requiring generator libs.
|
45
|
-
tmp_dir="#{File.dirname(__FILE__)}/../fixtures/tmp"
|
46
|
-
if defined?(RAILS_ROOT)
|
47
|
-
RAILS_ROOT.replace(tmp_dir)
|
48
|
-
else
|
49
|
-
RAILS_ROOT=tmp_dir
|
50
|
-
end
|
51
|
-
Dir.mkdir(RAILS_ROOT) unless File.exists?(RAILS_ROOT)
|
52
|
-
|
53
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
|
54
|
-
require 'rails_generator'
|
55
|
-
require "#{File.dirname(__FILE__)}/generator_test_helper"
|
56
|
-
|
57
|
-
class RailsScaffoldGeneratorTest < Test::Unit::TestCase
|
58
|
-
|
59
|
-
include GeneratorTestHelper
|
60
|
-
|
61
|
-
def setup
|
62
|
-
ActiveRecord::Base.pluralize_table_names = true
|
63
|
-
Dir.mkdir("#{RAILS_ROOT}/app") unless File.exists?("#{RAILS_ROOT}/app")
|
64
|
-
Dir.mkdir("#{RAILS_ROOT}/app/views") unless File.exists?("#{RAILS_ROOT}/app/views")
|
65
|
-
Dir.mkdir("#{RAILS_ROOT}/app/views/layouts") unless File.exists?("#{RAILS_ROOT}/app/views/layouts")
|
66
|
-
Dir.mkdir("#{RAILS_ROOT}/config") unless File.exists?("#{RAILS_ROOT}/config")
|
67
|
-
Dir.mkdir("#{RAILS_ROOT}/db") unless File.exists?("#{RAILS_ROOT}/db")
|
68
|
-
Dir.mkdir("#{RAILS_ROOT}/test") unless File.exists?("#{RAILS_ROOT}/test")
|
69
|
-
Dir.mkdir("#{RAILS_ROOT}/test/fixtures") unless File.exists?("#{RAILS_ROOT}/test/fixtures")
|
70
|
-
Dir.mkdir("#{RAILS_ROOT}/public") unless File.exists?("#{RAILS_ROOT}/public")
|
71
|
-
Dir.mkdir("#{RAILS_ROOT}/public/stylesheets") unless File.exists?("#{RAILS_ROOT}/public/stylesheets")
|
72
|
-
File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
|
73
|
-
f<<"ActionController::Routing::Routes.draw do |map|\n\nend\n"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def teardown
|
78
|
-
FileUtils.rm_rf "#{RAILS_ROOT}/app"
|
79
|
-
FileUtils.rm_rf "#{RAILS_ROOT}/test"
|
80
|
-
FileUtils.rm_rf "#{RAILS_ROOT}/config"
|
81
|
-
FileUtils.rm_rf "#{RAILS_ROOT}/db"
|
82
|
-
FileUtils.rm_rf "#{RAILS_ROOT}/public"
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_scaffolded_names
|
86
|
-
g = RubiGen::Base.instance('scaffold', %w(ProductLine))
|
87
|
-
assert_equal "ProductLines", g.controller_name
|
88
|
-
assert_equal "ProductLines", g.controller_class_name
|
89
|
-
assert_equal "ProductLine", g.controller_singular_name
|
90
|
-
assert_equal "product_lines", g.controller_plural_name
|
91
|
-
assert_equal "product_lines", g.controller_file_name
|
92
|
-
assert_equal "product_lines", g.controller_table_name
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_scaffold_generates_resources
|
96
|
-
|
97
|
-
run_generator('scaffold', %w(Product))
|
98
|
-
|
99
|
-
assert_generated_controller_for :products do |f|
|
100
|
-
|
101
|
-
assert_has_method f, :index do |name, m|
|
102
|
-
assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
|
103
|
-
end
|
104
|
-
|
105
|
-
assert_has_method f, :show, :edit, :update, :destroy do |name, m|
|
106
|
-
assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table"
|
107
|
-
end
|
108
|
-
|
109
|
-
assert_has_method f, :new do |name, m|
|
110
|
-
assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product"
|
111
|
-
end
|
112
|
-
|
113
|
-
assert_has_method f, :create do |name, m|
|
114
|
-
assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product"
|
115
|
-
assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
assert_generated_model_for :product
|
121
|
-
assert_generated_functional_test_for :products
|
122
|
-
assert_generated_unit_test_for :product
|
123
|
-
assert_generated_fixtures_for :products
|
124
|
-
assert_generated_helper_for :products
|
125
|
-
assert_generated_stylesheet :scaffold
|
126
|
-
assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb"
|
127
|
-
assert_generated_migration :create_products
|
128
|
-
assert_added_route_for :products
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_scaffold_skip_migration_skips_migration
|
132
|
-
run_generator('scaffold', %w(Product --skip-migration))
|
133
|
-
|
134
|
-
assert_generated_model_for :product
|
135
|
-
assert_generated_functional_test_for :products
|
136
|
-
assert_generated_unit_test_for :product
|
137
|
-
assert_generated_fixtures_for :products
|
138
|
-
assert_generated_helper_for :products
|
139
|
-
assert_generated_stylesheet :scaffold
|
140
|
-
assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb"
|
141
|
-
assert_skipped_migration :create_products
|
142
|
-
assert_added_route_for :products
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_scaffold_generates_resources_with_attributes
|
146
|
-
run_generator('scaffold', %w(Product name:string supplier_id:integer created_at:timestamp))
|
147
|
-
|
148
|
-
assert_generated_controller_for :products do |f|
|
149
|
-
|
150
|
-
assert_has_method f, :index do |name, m|
|
151
|
-
assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table"
|
152
|
-
end
|
153
|
-
|
154
|
-
assert_has_method f, :show, :edit, :update, :destroy do |name, m|
|
155
|
-
assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table"
|
156
|
-
end
|
157
|
-
|
158
|
-
assert_has_method f, :new do |name, m|
|
159
|
-
assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product"
|
160
|
-
end
|
161
|
-
|
162
|
-
assert_has_method f, :create do |name, m|
|
163
|
-
assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product"
|
164
|
-
assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml"
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
assert_generated_model_for :product
|
170
|
-
assert_generated_functional_test_for :products
|
171
|
-
assert_generated_unit_test_for :product
|
172
|
-
assert_generated_fixtures_for :products
|
173
|
-
assert_generated_helper_for :products
|
174
|
-
assert_generated_stylesheet :scaffold
|
175
|
-
assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb"
|
176
|
-
assert_generated_migration :create_products do |t|
|
177
|
-
assert_generated_column t, :name, :string
|
178
|
-
assert_generated_column t, :supplier_id, :integer
|
179
|
-
assert_generated_column t, :created_at, :timestamp
|
180
|
-
end
|
181
|
-
|
182
|
-
assert_added_route_for :products
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|