Skip to content
Browse files

updated demo example with Rails 3.0.0.beta4 and oracle_enhanced 1.3.0

  • Loading branch information...
1 parent 1a706a8 commit d0c6ea946de4b6189e1ca9d6068d4bac1bfdd286 @rsim committed Jun 21, 2010
Showing with 4 additions and 69 deletions.
  1. +4 −5 Gemfile
  2. +0 −1 app/views/layouts/employees.html.erb
  3. +0 −3 config/initializers/oracle.rb
  4. +0 −60 lib/rails3_oracle_patches.rb
View
9 Gemfile
@@ -1,15 +1,14 @@
source 'http://rubygems.org'
-gem "rails", "3.0.0.beta2"
+gem "rails", "3.0.0.beta4"
gem "ruby-oci8", ">=2.0.4"
-gem "activerecord-oracle_enhanced-adapter", ">=1.3.0.beta2", :git => 'git://github.com/rsim/oracle-enhanced.git', :branch => 'rails3',
- :require => 'active_record/connection_adapters/oracle_enhanced_adapter'
+gem "activerecord-oracle_enhanced-adapter", ">=1.3.0", :require => 'active_record/connection_adapters/oracle_enhanced_adapter'
# optionally also use ruby-plsql
gem "ruby-plsql", ">=0.4.3"
# group :test do
-# gem "rspec", ">= 2.0.0.beta.2"
-# gem "rspec-rails", ">= 2.0.0.beta.2"
+# gem "rspec", ">= 2.0.0.beta.12"
+# gem "rspec-rails", ">= 2.0.0.beta.12"
# end
View
1 app/views/layouts/employees.html.erb
@@ -3,7 +3,6 @@
<head>
<title>Employees: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
- <%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
View
3 config/initializers/oracle.rb
@@ -1,6 +1,3 @@
-# monkey patches for Rails 3 beta that are needed for oracle_enhanced adapter
-require 'rails3_oracle_patches'
-
# it's recommended to set time zone to ensure that Oracle session time zone
# will be the same as Ruby Time.local time zone
ENV['TZ'] = 'Europe/Riga'
View
60 lib/rails3_oracle_patches.rb
@@ -1,60 +0,0 @@
-# patches for Rails 3.0 beta1 that are required by oracle_enhanced adapter
-
-# PATCH: downcase table names in aliased_table_name_for and references_eager_loaded_tables? methods
-# (as Oracle quoted table names are in uppercase)
-ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.class_eval do
- protected
-
- def aliased_table_name_for(name, suffix = nil)
- # always downcase quoted table name as Oracle quoted table names are in uppercase
- if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{active_record.connection.quote_table_name(name).downcase}\son}
- @join_dependency.table_aliases[name] += 1
- end
-
- unless @join_dependency.table_aliases[name].zero?
- # if the table name has been used, then use an alias
- name = active_record.connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}#{suffix}"
- table_index = @join_dependency.table_aliases[name]
- @join_dependency.table_aliases[name] += 1
- name = name[0..active_record.connection.table_alias_length-3] + "_#{table_index+1}" if table_index > 0
- else
- @join_dependency.table_aliases[name] += 1
- end
-
- name
- end
-end
-
-
-
-# PATCH: fix conditions when DateTime#to_date and DateTime#xmlschema methods are defined
-ActiveRecord::Relation.class_eval do
- private
-
- def references_eager_loaded_tables?
- # always convert table names to downcase as in Oracle quoted table names are in uppercase
- joined_tables = (tables_in_string(arel.joins(arel)) + [table.name, table.table_alias]).compact.map(&:downcase).uniq
- (tables_in_string(to_sql) - joined_tables).any?
- end
-
- def tables_in_string(string)
- return [] if string.blank?
- # always convert table names to downcase as in Oracle quoted table names are in uppercase
- string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq
- end
-end
-
-
-
-# PATCH: fix conditions when DateTime#to_date and DateTime#xmlschema methods are defined
-class DateTime
- # Converts self to a Ruby Date object; time portion is discarded
- def to_date
- ::Date.new(year, month, day)
- end unless instance_methods(false).include?(:to_date)
-
- # Converts datetime to an appropriate format for use in XML
- def xmlschema
- strftime("%Y-%m-%dT%H:%M:%S%Z")
- end unless instance_methods(false).include?(:xmlschema)
-end

0 comments on commit d0c6ea9

Please sign in to comment.
Something went wrong with that request. Please try again.