railties 3.0.0.beta2 → 3.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -2
- data/guides/{images → assets/images}/belongs_to.png +0 -0
- data/guides/{images → assets/images}/book_icon.gif +0 -0
- data/guides/{images → assets/images}/bullet.gif +0 -0
- data/guides/{images → assets/images}/challenge.png +0 -0
- data/guides/{images → assets/images}/chapters_icon.gif +0 -0
- data/guides/{images → assets/images}/check_bullet.gif +0 -0
- data/guides/{images → assets/images}/credits_pic_blank.gif +0 -0
- data/guides/{images → assets/images}/csrf.png +0 -0
- data/guides/{images → assets/images}/customized_error_messages.png +0 -0
- data/guides/{images → assets/images}/edge_badge.png +0 -0
- data/guides/{images → assets/images}/error_messages.png +0 -0
- data/guides/{images → assets/images}/feature_tile.gif +0 -0
- data/guides/{images → assets/images}/footer_tile.gif +0 -0
- data/guides/{images → assets/images}/fxn.png +0 -0
- data/guides/{images → assets/images}/grey_bullet.gif +0 -0
- data/guides/{images → assets/images}/habtm.png +0 -0
- data/guides/{images → assets/images}/has_many.png +0 -0
- data/guides/{images → assets/images}/has_many_through.png +0 -0
- data/guides/{images → assets/images}/has_one.png +0 -0
- data/guides/{images → assets/images}/has_one_through.png +0 -0
- data/guides/{images → assets/images}/header_backdrop.png +0 -0
- data/guides/{images → assets/images}/header_tile.gif +0 -0
- data/guides/{images → assets/images}/i18n/demo_localized_pirate.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translated_en.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translated_pirate.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_translation_missing.png +0 -0
- data/guides/{images → assets/images}/i18n/demo_untranslated.png +0 -0
- data/guides/{images → assets/images}/icons/README +0 -0
- data/guides/{images → assets/images}/icons/callouts/1.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/10.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/11.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/12.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/13.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/14.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/15.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/2.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/3.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/4.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/5.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/6.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/7.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/8.png +0 -0
- data/guides/{images → assets/images}/icons/callouts/9.png +0 -0
- data/guides/{images → assets/images}/icons/caution.png +0 -0
- data/guides/{images → assets/images}/icons/example.png +0 -0
- data/guides/{images → assets/images}/icons/home.png +0 -0
- data/guides/{images → assets/images}/icons/important.png +0 -0
- data/guides/{images → assets/images}/icons/next.png +0 -0
- data/guides/{images → assets/images}/icons/note.png +0 -0
- data/guides/{images → assets/images}/icons/prev.png +0 -0
- data/guides/{images → assets/images}/icons/tip.png +0 -0
- data/guides/{images → assets/images}/icons/up.png +0 -0
- data/guides/{images → assets/images}/icons/warning.png +0 -0
- data/guides/assets/images/jaimeiniesta.jpg +0 -0
- data/guides/{images → assets/images}/nav_arrow.gif +0 -0
- data/guides/{images → assets/images}/polymorphic.png +0 -0
- data/guides/{images → assets/images}/posts_index.png +0 -0
- data/guides/{images → assets/images}/rails_guides_logo.gif +0 -0
- data/guides/{images → assets/images}/rails_logo_remix.gif +0 -0
- data/guides/{images → assets/images}/rails_welcome.png +0 -0
- data/guides/{images → assets/images}/session_fixation.png +0 -0
- data/guides/{images → assets/images}/tab_grey.gif +0 -0
- data/guides/{images → assets/images}/tab_info.gif +0 -0
- data/guides/{images → assets/images}/tab_note.gif +0 -0
- data/guides/{images → assets/images}/tab_red.gif +0 -0
- data/guides/{images → assets/images}/tab_yellow.gif +0 -0
- data/guides/{images → assets/images}/tab_yellow.png +0 -0
- data/guides/{images → assets/images}/validation_error_messages.png +0 -0
- data/guides/{files → assets}/javascripts/code_highlighter.js +0 -0
- data/guides/{files → assets}/javascripts/guides.js +0 -0
- data/guides/{files → assets}/javascripts/highlighters.js +0 -0
- data/guides/{files → assets}/stylesheets/main.css +26 -15
- data/guides/{files → assets}/stylesheets/print.css +0 -0
- data/guides/{files → assets}/stylesheets/reset.css +0 -0
- data/guides/{files → assets}/stylesheets/style.css +0 -0
- data/guides/{files → assets}/stylesheets/syntax.css +0 -0
- data/guides/rails_guides/generator.rb +79 -29
- data/guides/rails_guides/helpers.rb +2 -2
- data/guides/rails_guides/indexer.rb +24 -11
- data/guides/source/2_2_release_notes.textile +1 -1
- data/guides/source/3_0_release_notes.textile +27 -1
- data/guides/source/action_controller_overview.textile +7 -7
- data/guides/source/action_view_overview.textile +15 -15
- data/guides/source/active_record_querying.textile +4 -3
- data/guides/source/active_support_core_extensions.textile +6 -6
- data/guides/source/activerecord_validations_callbacks.textile +1 -1
- data/guides/source/association_basics.textile +83 -82
- data/guides/source/command_line.textile +16 -12
- data/guides/source/configuring.textile +1 -1
- data/guides/source/contribute.textile +1 -1
- data/guides/source/contributing_to_rails.textile +3 -4
- data/guides/source/credits.html.erb +64 -0
- data/guides/source/debugging_rails_applications.textile +2 -1
- data/guides/source/form_helpers.textile +15 -13
- data/guides/source/getting_started.textile +9 -8
- data/guides/source/index.html.erb +154 -0
- data/guides/source/initialization.textile +4138 -0
- data/guides/source/layout.html.erb +15 -7
- data/guides/source/layouts_and_rendering.textile +6 -5
- data/guides/source/nested_model_forms.textile +3 -3
- data/guides/source/performance_testing.textile +4 -4
- data/guides/source/plugins.textile +15 -14
- data/guides/source/rails_on_rack.textile +1 -1
- data/guides/source/routing.textile +379 -490
- data/guides/source/security.textile +5 -5
- data/guides/source/testing.textile +3 -2
- data/lib/rails.rb +7 -2
- data/lib/rails/application.rb +9 -2
- data/lib/rails/application/configuration.rb +19 -10
- data/lib/rails/application/finisher.rb +4 -0
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/{bin/rails → lib/rails/cli.rb} +0 -0
- data/lib/rails/commands/runner.rb +1 -1
- data/lib/rails/configuration.rb +12 -0
- data/lib/rails/engine.rb +6 -10
- data/lib/rails/engine/configuration.rb +2 -3
- data/lib/rails/generators.rb +1 -6
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -7
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +10 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb +2 -0
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/rails/app/app_generator.rb +1 -1
- data/lib/rails/generators/rails/app/templates/Gemfile +2 -0
- data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +1 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +14 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb +4 -1
- data/lib/rails/generators/rails/app/templates/config/boot.rb +5 -13
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/{cookie_verification_secret.rb.tt → secret_token.rb.tt} +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -3
- data/lib/rails/generators/rails/app/templates/public/index.html +2 -1
- data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +41 -32
- data/lib/rails/generators/rails/app/templates/test/{test_helper.rb → test_helper.rb.tt} +2 -0
- data/lib/rails/generators/rails/model/USAGE +15 -0
- data/lib/rails/generators/rails/stylesheets/templates/scaffold.css +3 -8
- data/lib/rails/paths.rb +17 -5
- data/lib/rails/plugin.rb +1 -1
- data/lib/rails/railtie.rb +3 -25
- data/lib/rails/test_unit/testing.rake +11 -7
- data/lib/rails/version.rb +1 -1
- data/lib/rails/webrick_server.rb +2 -2
- metadata +93 -92
- data/guides/source/credits.textile.erb +0 -60
- data/guides/source/index.textile.erb +0 -139
- data/lib/rails/generators/erb/scaffold/templates/layout.html.erb +0 -17
- data/lib/rails/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
@@ -1,14 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# Otherwise, use RubyGems.
|
7
|
-
require 'rubygems'
|
8
|
-
|
9
|
-
# And set up the gems listed in the Gemfile.
|
10
|
-
if File.exist?(File.expand_path('../../Gemfile', __FILE__))
|
11
|
-
require 'bundler'
|
12
|
-
Bundler.setup
|
13
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
# Set up gems listed in the Gemfile.
|
3
|
+
if File.exist?(File.expand_path('../../Gemfile', __FILE__))
|
4
|
+
require 'bundler'
|
5
|
+
Bundler.setup
|
14
6
|
end
|
@@ -14,6 +14,9 @@
|
|
14
14
|
config.consider_all_requests_local = true
|
15
15
|
config.action_controller.perform_caching = false
|
16
16
|
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
17
20
|
# Disable request forgery protection in test environment
|
18
21
|
config.action_controller.allow_forgery_protection = false
|
19
22
|
|
@@ -4,4 +4,4 @@
|
|
4
4
|
# If you change this key, all old signed cookies will become invalid!
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
Rails.application.config.
|
7
|
+
Rails.application.config.secret_token = '<%= app_secret %>'
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
Rails.application.config.session_store :cookie_store,
|
4
|
-
:key => '_<%= app_name %>_session',
|
5
|
-
}
|
3
|
+
Rails.application.config.session_store :cookie_store, :key => '_<%= app_name %>_session'
|
6
4
|
|
7
5
|
# Use the database for sessions instead of the cookie-based default,
|
8
6
|
# which shouldn't be used to store highly confidential information
|
@@ -1,15 +1,8 @@
|
|
1
1
|
document.observe("dom:loaded", function() {
|
2
|
-
var authToken = $$('meta[name=csrf-token]').first().readAttribute('content'),
|
3
|
-
authParam = $$('meta[name=csrf-param]').first().readAttribute('content'),
|
4
|
-
formTemplate = '<form method="#{method}" action="#{action}">\
|
5
|
-
#{realmethod}<input name="#{param}" value="#{token}" type="hidden">\
|
6
|
-
</form>',
|
7
|
-
realmethodTemplate = '<input name="_method" value="#{method}" type="hidden">';
|
8
|
-
|
9
2
|
function handleRemote(element) {
|
10
3
|
var method, url, params;
|
11
4
|
|
12
|
-
if (element.tagName.toLowerCase()
|
5
|
+
if (element.tagName.toLowerCase() === 'form') {
|
13
6
|
method = element.readAttribute('method') || 'post';
|
14
7
|
url = element.readAttribute('action');
|
15
8
|
params = element.serialize(true);
|
@@ -39,65 +32,81 @@ document.observe("dom:loaded", function() {
|
|
39
32
|
element.fire("ajax:after");
|
40
33
|
}
|
41
34
|
|
35
|
+
function handleMethod(element) {
|
36
|
+
var method, url, token_name, token;
|
37
|
+
|
38
|
+
method = element.readAttribute('data-method');
|
39
|
+
url = element.readAttribute('href');
|
40
|
+
csrf_param = $$('meta[name=csrf-param]').first();
|
41
|
+
csrf_token = $$('meta[name=csrf-token]').first();
|
42
|
+
|
43
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
44
|
+
element.parentNode.appendChild(form);
|
45
|
+
|
46
|
+
if (method != 'post') {
|
47
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
48
|
+
form.appendChild(field);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (csrf_param) {
|
52
|
+
var param = csrf_param.readAttribute('content');
|
53
|
+
var token = csrf_token.readAttribute('content');
|
54
|
+
var field = new Element('input', { type: 'hidden', name: param, value: token });
|
55
|
+
form.appendChild(field);
|
56
|
+
}
|
57
|
+
|
58
|
+
form.submit();
|
59
|
+
}
|
60
|
+
|
42
61
|
$(document.body).observe("click", function(event) {
|
43
|
-
var message = event.
|
62
|
+
var message = event.findElement().readAttribute('data-confirm');
|
44
63
|
if (message && !confirm(message)) {
|
45
64
|
event.stop();
|
46
65
|
return false;
|
47
66
|
}
|
48
67
|
|
49
|
-
var element = event.findElement("a[data-remote
|
68
|
+
var element = event.findElement("a[data-remote]");
|
50
69
|
if (element) {
|
51
70
|
handleRemote(element);
|
52
71
|
event.stop();
|
72
|
+
return true;
|
53
73
|
}
|
54
74
|
|
55
75
|
var element = event.findElement("a[data-method]");
|
56
|
-
if (element
|
57
|
-
|
58
|
-
piggyback = method.toLowerCase() != 'post',
|
59
|
-
formHTML = formTemplate.interpolate({
|
60
|
-
method: 'POST',
|
61
|
-
realmethod: piggyback ? realmethodTemplate.interpolate({ method: method }) : '',
|
62
|
-
action: element.readAttribute('href'),
|
63
|
-
token: authToken,
|
64
|
-
param: authParam
|
65
|
-
});
|
66
|
-
|
67
|
-
var form = new Element('div').update(formHTML).down().hide();
|
68
|
-
this.insert({ bottom: form });
|
69
|
-
|
70
|
-
form.submit();
|
76
|
+
if (element) {
|
77
|
+
handleMethod(element);
|
71
78
|
event.stop();
|
79
|
+
return true;
|
72
80
|
}
|
73
81
|
});
|
74
82
|
|
75
83
|
// TODO: I don't think submit bubbles in IE
|
76
84
|
$(document.body).observe("submit", function(event) {
|
77
|
-
var
|
85
|
+
var element = event.findElement(),
|
86
|
+
message = element.readAttribute('data-confirm');
|
78
87
|
if (message && !confirm(message)) {
|
79
88
|
event.stop();
|
80
89
|
return false;
|
81
90
|
}
|
82
91
|
|
83
|
-
var inputs =
|
92
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
84
93
|
inputs.each(function(input) {
|
85
94
|
input.disabled = true;
|
86
95
|
input.writeAttribute('data-original-value', input.value);
|
87
96
|
input.value = input.readAttribute('data-disable-with');
|
88
97
|
});
|
89
98
|
|
90
|
-
var element = event.findElement("form[data-remote
|
99
|
+
var element = event.findElement("form[data-remote]");
|
91
100
|
if (element) {
|
92
101
|
handleRemote(element);
|
93
102
|
event.stop();
|
94
103
|
}
|
95
104
|
});
|
96
105
|
|
97
|
-
$(document.body).observe("ajax:
|
98
|
-
var element = event.
|
106
|
+
$(document.body).observe("ajax:after", function(event) {
|
107
|
+
var element = event.findElement();
|
99
108
|
|
100
|
-
if (element.tagName.toLowerCase()
|
109
|
+
if (element.tagName.toLowerCase() === 'form') {
|
101
110
|
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
102
111
|
inputs.each(function(input) {
|
103
112
|
input.value = input.readAttribute('data-original-value');
|
@@ -106,4 +115,4 @@ document.observe("dom:loaded", function() {
|
|
106
115
|
});
|
107
116
|
}
|
108
117
|
});
|
109
|
-
});
|
118
|
+
});
|
@@ -3,11 +3,13 @@ require File.expand_path('../../config/environment', __FILE__)
|
|
3
3
|
require 'rails/test_help'
|
4
4
|
|
5
5
|
class ActiveSupport::TestCase
|
6
|
+
<% unless options[:skip_activerecord] -%>
|
6
7
|
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
8
|
#
|
8
9
|
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
10
|
# -- they do not yet inherit this setting
|
10
11
|
fixtures :all
|
11
12
|
|
13
|
+
<% end -%>
|
12
14
|
# Add more helper methods to be used by all tests here...
|
13
15
|
end
|
@@ -15,6 +15,10 @@ Description:
|
|
15
15
|
Finally, if --parent option is given, it's used as superclass of the
|
16
16
|
created model. This allows you create Single Table Inheritance models.
|
17
17
|
|
18
|
+
If you pass a namespaced model name (e.g. admin/account or Admin::Account)
|
19
|
+
then the generator will create a module with a table_name_prefix method
|
20
|
+
to prefix the model's table name with the module name (e.g. admin_account)
|
21
|
+
|
18
22
|
Examples:
|
19
23
|
`rails generate model account`
|
20
24
|
|
@@ -28,3 +32,14 @@ Examples:
|
|
28
32
|
`rails generate model post title:string body:text published:boolean`
|
29
33
|
|
30
34
|
Creates a Post model with a string title, text body, and published flag.
|
35
|
+
|
36
|
+
`rails generate model admin/account`
|
37
|
+
|
38
|
+
For ActiveRecord and TestUnit it creates:
|
39
|
+
|
40
|
+
Module: app/models/admin.rb
|
41
|
+
Model: app/models/admin/account.rb
|
42
|
+
Test: test/unit/admin/account_test.rb
|
43
|
+
Fixtures: test/fixtures/admin_accounts.yml
|
44
|
+
Migration: db/migrate/XXX_add_admin_accounts.rb
|
45
|
+
|
@@ -35,10 +35,10 @@ div.field, div.actions {
|
|
35
35
|
}
|
36
36
|
|
37
37
|
#errorExplanation {
|
38
|
-
width:
|
38
|
+
width: 450px;
|
39
39
|
border: 2px solid red;
|
40
40
|
padding: 7px;
|
41
|
-
padding-bottom:
|
41
|
+
padding-bottom: 0;
|
42
42
|
margin-bottom: 20px;
|
43
43
|
background-color: #f0f0f0;
|
44
44
|
}
|
@@ -49,16 +49,11 @@ div.field, div.actions {
|
|
49
49
|
padding: 5px 5px 5px 15px;
|
50
50
|
font-size: 12px;
|
51
51
|
margin: -7px;
|
52
|
+
margin-bottom: 0px;
|
52
53
|
background-color: #c00;
|
53
54
|
color: #fff;
|
54
55
|
}
|
55
56
|
|
56
|
-
#errorExplanation p {
|
57
|
-
color: #333;
|
58
|
-
margin-bottom: 0;
|
59
|
-
padding: 5px;
|
60
|
-
}
|
61
|
-
|
62
57
|
#errorExplanation ul li {
|
63
58
|
font-size: 12px;
|
64
59
|
list-style: square;
|
data/lib/rails/paths.rb
CHANGED
@@ -3,6 +3,8 @@ require 'set'
|
|
3
3
|
module Rails
|
4
4
|
module Paths
|
5
5
|
module PathParent
|
6
|
+
attr_reader :children
|
7
|
+
|
6
8
|
def method_missing(id, *args)
|
7
9
|
name = id.to_s
|
8
10
|
|
@@ -37,15 +39,15 @@ module Rails
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def load_once
|
40
|
-
|
42
|
+
filter_by(:load_once?)
|
41
43
|
end
|
42
44
|
|
43
45
|
def eager_load
|
44
|
-
|
46
|
+
filter_by(:eager_load?)
|
45
47
|
end
|
46
48
|
|
47
49
|
def load_paths
|
48
|
-
|
50
|
+
filter_by(:load_path?)
|
49
51
|
end
|
50
52
|
|
51
53
|
def push(*)
|
@@ -58,8 +60,16 @@ module Rails
|
|
58
60
|
|
59
61
|
protected
|
60
62
|
|
61
|
-
def
|
62
|
-
all_paths.map
|
63
|
+
def filter_by(constraint)
|
64
|
+
all_paths.map do |path|
|
65
|
+
if path.send(constraint)
|
66
|
+
paths = path.paths
|
67
|
+
paths -= path.children.values.map { |p| p.send(constraint) ? [] : p.paths }.flatten
|
68
|
+
paths
|
69
|
+
else
|
70
|
+
[]
|
71
|
+
end
|
72
|
+
end.flatten.uniq.select { |p| File.exists?(p) }
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
@@ -129,10 +139,12 @@ module Rails
|
|
129
139
|
|
130
140
|
def paths
|
131
141
|
raise "You need to set a path root" unless @root.path
|
142
|
+
|
132
143
|
result = @paths.map do |p|
|
133
144
|
path = File.expand_path(p, @root.path)
|
134
145
|
@glob ? Dir[File.join(path, @glob)] : path
|
135
146
|
end
|
147
|
+
|
136
148
|
result.flatten!
|
137
149
|
result.uniq!
|
138
150
|
result
|
data/lib/rails/plugin.rb
CHANGED
@@ -61,7 +61,7 @@ module Rails
|
|
61
61
|
@config ||= Engine::Configuration.new
|
62
62
|
end
|
63
63
|
|
64
|
-
initializer :load_init_rb, :before => :
|
64
|
+
initializer :load_init_rb, :before => :load_config_initializers do |app|
|
65
65
|
files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root }
|
66
66
|
if initrb = files.find { |path| File.file? path }
|
67
67
|
if initrb == files.first
|
data/lib/rails/railtie.rb
CHANGED
@@ -39,7 +39,6 @@ module Rails
|
|
39
39
|
# # lib/my_gem/railtie.rb
|
40
40
|
# module MyGem
|
41
41
|
# class Railtie < Rails::Railtie
|
42
|
-
# railtie_name :mygem
|
43
42
|
# end
|
44
43
|
# end
|
45
44
|
#
|
@@ -51,24 +50,8 @@ module Rails
|
|
51
50
|
#
|
52
51
|
# module MyGem
|
53
52
|
# class Railtie < Rails::Railtie
|
54
|
-
# railtie_name :mygem
|
55
53
|
# end
|
56
54
|
# end
|
57
|
-
#
|
58
|
-
# * Make sure your Gem loads the railtie.rb file if Rails is loaded first, an easy
|
59
|
-
# way to check is by checking for the Rails constant which will exist if Rails
|
60
|
-
# has started:
|
61
|
-
#
|
62
|
-
# # lib/my_gem.rb
|
63
|
-
# module MyGem
|
64
|
-
# require 'lib/my_gem/railtie' if defined?(Rails)
|
65
|
-
# end
|
66
|
-
#
|
67
|
-
# * Or instead of doing the require automatically, you can ask your users to require
|
68
|
-
# it for you in their Gemfile:
|
69
|
-
#
|
70
|
-
# # #{USER_RAILS_ROOT}/Gemfile
|
71
|
-
# gem "my_gem", :require_as => ["my_gem", "my_gem/railtie"]
|
72
55
|
#
|
73
56
|
# == Initializers
|
74
57
|
#
|
@@ -82,13 +65,11 @@ module Rails
|
|
82
65
|
# end
|
83
66
|
#
|
84
67
|
# If specified, the block can also receive the application object, in case you
|
85
|
-
# need to access some application specific configuration:
|
68
|
+
# need to access some application specific configuration, like middleware:
|
86
69
|
#
|
87
70
|
# class MyRailtie < Rails::Railtie
|
88
71
|
# initializer "my_railtie.configure_rails_initialization" do |app|
|
89
|
-
#
|
90
|
-
# # some initialization behavior
|
91
|
-
# end
|
72
|
+
# app.middlewares.use MyRailtie::Middleware
|
92
73
|
# end
|
93
74
|
# end
|
94
75
|
#
|
@@ -104,9 +85,6 @@ module Rails
|
|
104
85
|
# # Customize the ORM
|
105
86
|
# config.generators.orm :my_railtie_orm
|
106
87
|
#
|
107
|
-
# # Add a middleware
|
108
|
-
# config.middlewares.use MyRailtie::Middleware
|
109
|
-
#
|
110
88
|
# # Add a to_prepare block which is executed once in production
|
111
89
|
# # and before which request in development
|
112
90
|
# config.to_prepare do
|
@@ -160,7 +138,7 @@ module Rails
|
|
160
138
|
# By registering it:
|
161
139
|
#
|
162
140
|
# class MyRailtie < Railtie
|
163
|
-
# subscriber MyRailtie::Subscriber.new
|
141
|
+
# subscriber :my_gem, MyRailtie::Subscriber.new
|
164
142
|
# end
|
165
143
|
#
|
166
144
|
# Take a look in Rails::Subscriber docs for more information.
|
@@ -52,7 +52,11 @@ task :test do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
namespace :test do
|
55
|
-
|
55
|
+
task :prepare do
|
56
|
+
# Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
|
57
|
+
end
|
58
|
+
|
59
|
+
Rake::TestTask.new(:recent => "test:prepare") do |t|
|
56
60
|
since = TEST_CHANGES_SINCE
|
57
61
|
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
|
58
62
|
recent_tests('app/models/**/*.rb', 'test/unit', since) +
|
@@ -63,7 +67,7 @@ namespace :test do
|
|
63
67
|
end
|
64
68
|
Rake::Task['test:recent'].comment = "Test recent changes"
|
65
69
|
|
66
|
-
Rake::TestTask.new(:uncommitted => "
|
70
|
+
Rake::TestTask.new(:uncommitted => "test:prepare") do |t|
|
67
71
|
def t.file_list
|
68
72
|
if File.directory?(".svn")
|
69
73
|
changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }
|
@@ -86,32 +90,32 @@ namespace :test do
|
|
86
90
|
end
|
87
91
|
Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"
|
88
92
|
|
89
|
-
Rake::TestTask.new(:units => "
|
93
|
+
Rake::TestTask.new(:units => "test:prepare") do |t|
|
90
94
|
t.libs << "test"
|
91
95
|
t.pattern = 'test/unit/**/*_test.rb'
|
92
96
|
end
|
93
97
|
Rake::Task['test:units'].comment = "Run the unit tests in test/unit"
|
94
98
|
|
95
|
-
Rake::TestTask.new(:functionals => "
|
99
|
+
Rake::TestTask.new(:functionals => "test:prepare") do |t|
|
96
100
|
t.libs << "test"
|
97
101
|
t.pattern = 'test/functional/**/*_test.rb'
|
98
102
|
end
|
99
103
|
Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional"
|
100
104
|
|
101
|
-
Rake::TestTask.new(:integration => "
|
105
|
+
Rake::TestTask.new(:integration => "test:prepare") do |t|
|
102
106
|
t.libs << "test"
|
103
107
|
t.pattern = 'test/integration/**/*_test.rb'
|
104
108
|
end
|
105
109
|
Rake::Task['test:integration'].comment = "Run the integration tests in test/integration"
|
106
110
|
|
107
|
-
Rake::TestTask.new(:benchmark => '
|
111
|
+
Rake::TestTask.new(:benchmark => 'test:prepare') do |t|
|
108
112
|
t.libs << 'test'
|
109
113
|
t.pattern = 'test/performance/**/*_test.rb'
|
110
114
|
t.options = '-- --benchmark'
|
111
115
|
end
|
112
116
|
Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests'
|
113
117
|
|
114
|
-
Rake::TestTask.new(:profile => '
|
118
|
+
Rake::TestTask.new(:profile => 'test:prepare') do |t|
|
115
119
|
t.libs << 'test'
|
116
120
|
t.pattern = 'test/performance/**/*_test.rb'
|
117
121
|
end
|