Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Rails.initialized? can be called at any time without raising an exception [Closes #2507] #2528

Merged
merged 1 commit into from

3 participants

Franck Verrot José Valim Carlos Antonio da Silva
Franck Verrot

Rails.initialized? can be called at any time without raising an exception [Closes #2507]

José Valim
Owner

This looks good. Maybe, instead of adding a new test file, let's add simply a test case to railties/test/application/initializion_test that asserts that initialized? starts with false and ends up with true?

Franck Verrot

After digging a bit more I did some cleanup too. I say this in the commit message:

Rails.initialized? can be called at any time without raising an exception [Closes #2507]

Changes:

  • Rails.initialized= has been removed
  • Rails.initialized? and Rails.application.initialized? are now
  • delegating to MyApp::Application.initialized?

Is it what you had in mind?

Carlos Antonio da Silva

@cesario hey, I guess it's better to check for assert !... and assert ... for instance, instead of using assert_equal in this case, perhaps you could change that :)

@josevalim I think this still apply, right? initialized= seems to not be used anywhere.

Franck Verrot

@carlosantoniodasilva thanks for taking a look at this PR, if it's stlill relevant I'll push my changes ASAP.

José Valim
Owner

@cesario please push your new changes, this is relevant. :)

Sorry for not replying back 8 months ago. It seems I missed it somehow.

Franck Verrot

No problem, I'll send a PR in a couple of hours.

railties/lib/rails/application.rb
@@ -134,6 +134,10 @@ def initialize!(group=:default) #:nodoc:
self
end
+ def initialized?
+ @initialized ||= false
+ end

Ahm, I wonder if we need the ||= false clause here. The variable is initialized to false and changed later to true on initialize!, so it should never be nil. And if it's false, ||= doesn't make sense. Wdyt?

||= ensured calling Rais.initialized? wouldn't throw an exception because the class variable @@initialized was uninitialized. Now that I refactored and use an instance variable the problem goes away. So I'm pushing a new commit now. Thanks!

Ah yeah, it was using a class variable before.. great, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Franck Verrot franckverrot Rails.initialized? can be called at any time without raising an excep…
…tion [Closes #2507]

Changes:

* `Rails.initialized=` has been removed
* `Rails.initialized?` and `Rails.application.initialized?` are now
* delegating to `MyApp::Application.initialized?`
4882271
José Valim josevalim merged commit 0560ce0 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. Franck Verrot

    Rails.initialized? can be called at any time without raising an excep…

    franckverrot authored
    …tion [Closes #2507]
    
    Changes:
    
    * `Rails.initialized=` has been removed
    * `Rails.initialized?` and `Rails.application.initialized?` are now
    * delegating to `MyApp::Application.initialized?`
This page is out of date. Refresh to see the latest.
6 railties/lib/rails.rb
View
@@ -42,11 +42,7 @@ def initialize!
end
def initialized?
- @@initialized || false
- end
-
- def initialized=(initialized)
- @@initialized ||= initialized
+ application.initialized?
end
def logger
4 railties/lib/rails/application.rb
View
@@ -134,6 +134,10 @@ def initialize!(group=:default) #:nodoc:
self
end
+ def initialized?
+ @initialized
+ end
+
# Load the application and its railties tasks and invoke the registered hooks.
# Check <tt>Rails::Railtie.rake_tasks</tt> for more info.
def load_tasks(app=self)
10 railties/test/application/loading_test.rb
View
@@ -285,6 +285,16 @@ def show
assert_equal 'OK', last_response.body
end
+ def test_initialize_can_be_called_at_any_time
+ require "#{app_path}/config/application"
+
+ assert !Rails.initialized?
+ assert !AppTemplate::Application.initialized?
+ Rails.initialize!
+ assert Rails.initialized?
+ assert AppTemplate::Application.initialized?
+ end
+
protected
def setup_ar!
Something went wrong with that request. Please try again.