Created
March 9, 2012 11:46
-
-
Save iain/2006213 to your computer and use it in GitHub Desktop.
Monkey Patch of Today
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
if defined?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) | |
ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = true | |
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'ntext' | |
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar' | |
end | |
version = ActiveRecord::ConnectionAdapters::Sqlserver::Version::VERSION | |
preferred_version = '3.2.1' | |
if version == preferred_version | |
module ActiveRecord | |
module ConnectionAdapters | |
module Sqlserver | |
module Quoting | |
def quoted_date(value) | |
if value.acts_like?(:time) && value.respond_to?(:usec) | |
"#{super}.#{sprintf("%03d",value.usec/1000)}" | |
elsif value.is_a?(Date) | |
quoted_datetime(value.to_time_in_current_zone) | |
elsif value.acts_like?(:date) | |
value.to_s(:_sqlserver_dateformat) | |
else | |
super | |
end | |
end | |
end | |
end | |
end | |
end | |
else | |
warning = %q{ | |
_____ _____ _ _____ | |
/ ___| _ | | / ___| | |
\ `--.| | | | | \ `--. ___ _ ____ _____ _ __ | |
`--. \ | | | | `--. \/ _ \ '__\ \ / / _ \ '__| | |
/\__/ | \/' / |____ /\__/ / __/ | \ V / __/ | | |
\____/ \_/\_\_____/ \____/ \___|_| \_/ \___|_| | |
_ _ ___________ _____ _____ _____ _ _ ___ ________ ________ ___ ___ _____ _____ _ _ | |
| | | | ___| ___ | ___|_ _| _ | \ | | | \/ |_ _/ ___| \/ |/ _ \_ _/ __ \ | | | | |
| | | | |__ | |_/ | `--. | | | | | | \| | | . . | | | \ `--.| . . / /_\ \| | | / \/ |_| | | |
| | | | __|| / `--. \ | | | | | | . ` | | |\/| | | | `--. \ |\/| | _ || | | | | _ | | |
\ \_/ / |___| |\ \/\__/ /_| |_\ \_/ / |\ | | | | |_| |_/\__/ / | | | | | || | | \__/\ | | | | |
\___/\____/\_| \_\____/ \___/ \___/\_| \_/ \_| |_/\___/\____/\_| |_|_| |_/\_/ \____|_| |_/ | |
} | |
warn warning | |
warn <<-MORE | |
We have made a monkey patch for activerecord-sqlserver-adapter, version #{preferred_version}. | |
You've updated the version to #{version}. Please verify that this is still working. | |
To test it, run the tests against MSSQL. You should get failures where certain | |
job offerings are not visible when they should be, when their dates are today. | |
The monkey patch is not loaded now. Please edit | |
#{__FILE__} | |
to change the preferred_version and run the tests again. | |
MORE | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment