Created
September 27, 2010 16:38
-
-
Save xaviershay/599327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Need a method that works regardless of whether active_support/core_ext is loaded or not | |
| def today | |
| (Time.respond_to?(:zone) && Time.zone) ? | |
| Time.zone.today : | |
| Date.today | |
| end | |
| describe 'timezone support' do | |
| before :all do | |
| Time.extend(MethodVisibility) | |
| end | |
| it 'should fallback to standard ruby date if Time.zone is not available' do | |
| Time.hide_class_method(:zone) do | |
| today.should == date(:today) | |
| end | |
| end | |
| end | |
| module MethodVisibility | |
| def hide_class_method(method) | |
| metaclass = (class << self; self; end) | |
| metaclass.send :alias_method, :old_method, method | |
| metaclass.send :remove_method, method | |
| begin | |
| yield | |
| ensure | |
| metaclass.send :alias_method, method, :old_method | |
| metaclass.send :remove_method, :old_method | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment