activerecord-mysql2legacydb-adapter 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +11 -0
- data/.gitignore +45 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/lib/active_record/connection_adapters/mysql2legacydb_adapter.rb +61 -0
- data/lib/activerecord-mysql2legacydb-adapter.rb +6 -0
- data/lib/mysql2legacydb/default_translator.rb +12 -0
- data/nbproject/project.properties +7 -0
- data/nbproject/project.xml +15 -0
- data/spec/.rspec +1 -0
- data/spec/activerecord-mysql2legacydb-adapter_spec.rb +73 -0
- data/spec/mysql2legacydb/default_translator_spec.rb +43 -0
- data/spec/spec_helper.rb +20 -0
- metadata +250 -0
    
        data/.document
    ADDED
    
    | @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            # .document is used by rdoc and yard to know how to generate documentation 
         | 
| 2 | 
            +
            # for example, it can be used to control how rdoc gets built when you do `gem install foo`
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            README.rdoc
         | 
| 5 | 
            +
            lib/**/*.rb
         | 
| 6 | 
            +
            bin/*
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # Files below this - are treated as 'extra files', and aren't parsed for ruby code
         | 
| 9 | 
            +
            - 
         | 
| 10 | 
            +
            features/**/*.feature
         | 
| 11 | 
            +
            LICENSE
         | 
    
        data/.gitignore
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            # rcov generated
         | 
| 2 | 
            +
            coverage
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # rdoc generated
         | 
| 5 | 
            +
            rdoc
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # yard generated
         | 
| 8 | 
            +
            doc
         | 
| 9 | 
            +
            .yardoc
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            # bundler
         | 
| 12 | 
            +
            .bundle
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # jeweler generated
         | 
| 15 | 
            +
            pkg
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            # netbeans non-shared
         | 
| 18 | 
            +
            nbproject/private
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: 
         | 
| 21 | 
            +
            #
         | 
| 22 | 
            +
            # * Create a file at ~/.gitignore
         | 
| 23 | 
            +
            # * Include files you want ignored
         | 
| 24 | 
            +
            # * Run: git config --global core.excludesfile ~/.gitignore
         | 
| 25 | 
            +
            #
         | 
| 26 | 
            +
            # After doing this, these files will be ignored in all your git projects,
         | 
| 27 | 
            +
            # saving you from having to 'pollute' every project you touch with them
         | 
| 28 | 
            +
            #
         | 
| 29 | 
            +
            # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
         | 
| 30 | 
            +
            #
         | 
| 31 | 
            +
            # For MacOS:
         | 
| 32 | 
            +
            #
         | 
| 33 | 
            +
            #.DS_Store
         | 
| 34 | 
            +
            #
         | 
| 35 | 
            +
            # For TextMate
         | 
| 36 | 
            +
            #*.tmproj
         | 
| 37 | 
            +
            #tmtags
         | 
| 38 | 
            +
            #
         | 
| 39 | 
            +
            # For emacs:
         | 
| 40 | 
            +
            #*~
         | 
| 41 | 
            +
            #\#*
         | 
| 42 | 
            +
            #.\#*
         | 
| 43 | 
            +
            #
         | 
| 44 | 
            +
            # For vim:
         | 
| 45 | 
            +
            #*.swp
         | 
    
        data/Gemfile
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            source "http://rubygems.org"
         | 
| 2 | 
            +
            # Add dependencies required to use your gem here.
         | 
| 3 | 
            +
            # Example:
         | 
| 4 | 
            +
            #   gem "activesupport", ">= 2.3.5"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            gem "mysql2", "~> 0.2.4"
         | 
| 7 | 
            +
            gem "activerecord", "~> 3.0.0"
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # Add dependencies to develop your gem here.
         | 
| 10 | 
            +
            # Include everything needed to run rake, tests, features, etc.
         | 
| 11 | 
            +
            group :development do
         | 
| 12 | 
            +
              gem "rspec", ">= 2.0.0.beta.19"
         | 
| 13 | 
            +
              gem "bundler", "~> 1.0.0"
         | 
| 14 | 
            +
              gem "jeweler", "~> 1.5.0.pre3"
         | 
| 15 | 
            +
              gem "rcov", ">= 0"
         | 
| 16 | 
            +
            end
         | 
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            GEM
         | 
| 2 | 
            +
              remote: http://rubygems.org/
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                activemodel (3.0.0)
         | 
| 5 | 
            +
                  activesupport (= 3.0.0)
         | 
| 6 | 
            +
                  builder (~> 2.1.2)
         | 
| 7 | 
            +
                  i18n (~> 0.4.1)
         | 
| 8 | 
            +
                activerecord (3.0.0)
         | 
| 9 | 
            +
                  activemodel (= 3.0.0)
         | 
| 10 | 
            +
                  activesupport (= 3.0.0)
         | 
| 11 | 
            +
                  arel (~> 1.0.0)
         | 
| 12 | 
            +
                  tzinfo (~> 0.3.23)
         | 
| 13 | 
            +
                activesupport (3.0.0)
         | 
| 14 | 
            +
                arel (1.0.1)
         | 
| 15 | 
            +
                  activesupport (~> 3.0.0)
         | 
| 16 | 
            +
                builder (2.1.2)
         | 
| 17 | 
            +
                diff-lcs (1.1.2)
         | 
| 18 | 
            +
                git (1.2.5)
         | 
| 19 | 
            +
                i18n (0.4.1)
         | 
| 20 | 
            +
                jeweler (1.5.0.pre3)
         | 
| 21 | 
            +
                  bundler (~> 1.0.0)
         | 
| 22 | 
            +
                  git (>= 1.2.5)
         | 
| 23 | 
            +
                  rake
         | 
| 24 | 
            +
                mysql2 (0.2.4)
         | 
| 25 | 
            +
                rake (0.8.7)
         | 
| 26 | 
            +
                rcov (0.9.9)
         | 
| 27 | 
            +
                rspec (2.0.0.beta.22)
         | 
| 28 | 
            +
                  rspec-core (= 2.0.0.beta.22)
         | 
| 29 | 
            +
                  rspec-expectations (= 2.0.0.beta.22)
         | 
| 30 | 
            +
                  rspec-mocks (= 2.0.0.beta.22)
         | 
| 31 | 
            +
                rspec-core (2.0.0.beta.22)
         | 
| 32 | 
            +
                rspec-expectations (2.0.0.beta.22)
         | 
| 33 | 
            +
                  diff-lcs (>= 1.1.2)
         | 
| 34 | 
            +
                rspec-mocks (2.0.0.beta.22)
         | 
| 35 | 
            +
                  rspec-core (= 2.0.0.beta.22)
         | 
| 36 | 
            +
                  rspec-expectations (= 2.0.0.beta.22)
         | 
| 37 | 
            +
                tzinfo (0.3.23)
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            PLATFORMS
         | 
| 40 | 
            +
              ruby
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            DEPENDENCIES
         | 
| 43 | 
            +
              activerecord (~> 3.0.0)
         | 
| 44 | 
            +
              bundler (~> 1.0.0)
         | 
| 45 | 
            +
              jeweler (~> 1.5.0.pre3)
         | 
| 46 | 
            +
              mysql2 (~> 0.2.4)
         | 
| 47 | 
            +
              rcov
         | 
| 48 | 
            +
              rspec (>= 2.0.0.beta.19)
         | 
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            Copyright (c) 2010 Anders Johannsen
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 4 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 5 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 6 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 7 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 8 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 9 | 
            +
            the following conditions:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 12 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 15 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 16 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 17 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 18 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 19 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 20 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.rdoc
    ADDED
    
    | @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            = activerecord-mysql2legacydb-adapter
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Description goes here.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            == Note on Patches/Pull Requests
         | 
| 6 | 
            +
             
         | 
| 7 | 
            +
            * Fork the project.
         | 
| 8 | 
            +
            * Make your feature addition or bug fix.
         | 
| 9 | 
            +
            * Add tests for it. This is important so I don't break it in a
         | 
| 10 | 
            +
              future version unintentionally.
         | 
| 11 | 
            +
            * Commit, do not mess with rakefile, version, or history.
         | 
| 12 | 
            +
              (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
         | 
| 13 | 
            +
            * Send me a pull request. Bonus points for topic branches.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            == Copyright
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Copyright (c) 2010 Anders Johannsen. See LICENSE for details.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
            require 'bundler'
         | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              Bundler.setup(:default, :development)
         | 
| 5 | 
            +
            rescue Bundler::BundlerError => e
         | 
| 6 | 
            +
              $stderr.puts e.message
         | 
| 7 | 
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         | 
| 8 | 
            +
              exit e.status_code
         | 
| 9 | 
            +
            end
         | 
| 10 | 
            +
            require 'rake'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            require 'jeweler'
         | 
| 13 | 
            +
            Jeweler::Tasks.new do |gem|
         | 
| 14 | 
            +
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         | 
| 15 | 
            +
              gem.name = "activerecord-mysql2legacydb-adapter"
         | 
| 16 | 
            +
              gem.name = "activerecord-mysql2legacydb-adapter"
         | 
| 17 | 
            +
              gem.summary = %Q{Translates table and field names of legacy databases}
         | 
| 18 | 
            +
              gem.description = %Q{If you are stuck with a MySQL database where the naming is, well, unrailslike,
         | 
| 19 | 
            +
                activerecord-mysql2-legacy-db-adapter offers a way to do the translation. It works at the driver level and doesn't
         | 
| 20 | 
            +
                require you ro change the structure of the database. Also there are no database views which should be kept up to date
         | 
| 21 | 
            +
                as you add or remove fields.
         | 
| 22 | 
            +
              }
         | 
| 23 | 
            +
              gem.email = "anders@johannsen.com"
         | 
| 24 | 
            +
              gem.homepage = "http://github.com/andersjo/activerecord-mysql2legacydb-adapter"
         | 
| 25 | 
            +
              gem.authors = ["Anders Johannsen"]
         | 
| 26 | 
            +
              # Include your dependencies below. Runtime dependencies are required when using your gem,
         | 
| 27 | 
            +
              # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
         | 
| 28 | 
            +
              #  spec.add_runtime_dependency 'jabber4r', '> 0.1'
         | 
| 29 | 
            +
              #  spec.add_development_dependency 'rspec', '> 1.2.3'
         | 
| 30 | 
            +
              gem.add_runtime_dependency "mysql2", ">= 0.2.4"
         | 
| 31 | 
            +
              gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
         | 
| 32 | 
            +
              gem.add_development_dependency "bundler", "~> 1.0.0"
         | 
| 33 | 
            +
              gem.add_development_dependency "jeweler", "~> 1.5.0.pre3"
         | 
| 34 | 
            +
              gem.add_development_dependency "rcov", ">= 0"
         | 
| 35 | 
            +
            end
         | 
| 36 | 
            +
            Jeweler::RubygemsDotOrgTasks.new
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            require 'rspec/core'
         | 
| 39 | 
            +
            require 'rspec/core/rake_task'
         | 
| 40 | 
            +
            RSpec::Core::RakeTask.new(:spec) do |spec|
         | 
| 41 | 
            +
              spec.pattern = FileList['spec/**/*_spec.rb']
         | 
| 42 | 
            +
            end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            RSpec::Core::RakeTask.new(:rcov) do |spec|
         | 
| 45 | 
            +
              spec.pattern = 'spec/**/*_spec.rb'
         | 
| 46 | 
            +
              spec.rcov = true
         | 
| 47 | 
            +
            end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            task :default => :spec
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            require 'rake/rdoctask'
         | 
| 52 | 
            +
            Rake::RDocTask.new do |rdoc|
         | 
| 53 | 
            +
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              rdoc.rdoc_dir = 'rdoc'
         | 
| 56 | 
            +
              rdoc.title = "activerecord-mysql2legacydb-adapter #{version}"
         | 
| 57 | 
            +
              rdoc.rdoc_files.include('README*')
         | 
| 58 | 
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         | 
| 59 | 
            +
            end
         | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.2.0
         | 
| @@ -0,0 +1,61 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            module ActiveRecord
         | 
| 3 | 
            +
              class Base
         | 
| 4 | 
            +
                # same as "def.self.mysql2_connection(config)" in mysql2 gem
         | 
| 5 | 
            +
                # except that the ConnectionAdapter returned is a Mysql2LegacyAdapter
         | 
| 6 | 
            +
                # instead of a regular Mysql2Adapter
         | 
| 7 | 
            +
                def self.mysql2legacydb_connection(config)
         | 
| 8 | 
            +
                  config[:username] = 'root' if config[:username].nil?
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  if Mysql2::Client.const_defined? :FOUND_ROWS
         | 
| 11 | 
            +
                    config[:flags] = Mysql2::Client::FOUND_ROWS
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  client = Mysql2::Client.new(config.symbolize_keys)
         | 
| 15 | 
            +
                  options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
         | 
| 16 | 
            +
                  ConnectionAdapters::Mysql2LegacyDBAdapter.new(client, logger, options, config)
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              module ConnectionAdapters
         | 
| 21 | 
            +
                class Mysql2LegacyDBAdapter < Mysql2Adapter
         | 
| 22 | 
            +
                  delegate :legacy_to_new, :new_to_legacy, :to => :"Mysql2legacydb::DefaultTranslator.new"
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def columns(table_name, name = nil)
         | 
| 25 | 
            +
                    sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}"
         | 
| 26 | 
            +
                    columns = []
         | 
| 27 | 
            +
                    result = execute(sql, :skip_logging)
         | 
| 28 | 
            +
                    result.each(:symbolize_keys => true, :as => :hash) { |field|
         | 
| 29 | 
            +
                      columns << Mysql2Column.new(legacy_to_new(field[:Field]), field[:Default], field[:Type], field[:Null] == "YES")
         | 
| 30 | 
            +
                    }
         | 
| 31 | 
            +
                    columns
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def tables_with_translation
         | 
| 35 | 
            +
                    tables_without_translation.map {|table| legacy_to_new(table) }
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
                  alias_method_chain :tables, :translation
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  def quote_column_name_with_translation(name)
         | 
| 40 | 
            +
                    quote_column_name_without_translation(new_to_legacy(name))
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                  alias_method_chain :quote_column_name, :translation
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def quote_table_name_with_translation(name)
         | 
| 45 | 
            +
                    quote_table_name_without_translation(new_to_legacy(name))
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                  alias_method_chain :quote_table_name, :translation
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  def select_with_translation(sql, name = nil)
         | 
| 50 | 
            +
                    select_without_translation(sql, name).collect { |row|
         | 
| 51 | 
            +
                      translated = {}
         | 
| 52 | 
            +
                      row.each { |key,val|
         | 
| 53 | 
            +
                        translated[legacy_to_new(key)] = val
         | 
| 54 | 
            +
                      }
         | 
| 55 | 
            +
                      translated
         | 
| 56 | 
            +
                    }
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                  alias_method_chain :select, :translation
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
| @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            file.reference.activerecord-mysql2legacydb-adapter-lib=lib
         | 
| 2 | 
            +
            file.reference.activerecord-mysql2legacydb-adapter-spec=spec
         | 
| 3 | 
            +
            main.file=
         | 
| 4 | 
            +
            platform.active=Ruby_0
         | 
| 5 | 
            +
            source.encoding=UTF-8
         | 
| 6 | 
            +
            src.dir=${file.reference.activerecord-mysql2legacydb-adapter-lib}
         | 
| 7 | 
            +
            test.src.dir=${file.reference.activerecord-mysql2legacydb-adapter-spec}
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            <?xml version="1.0" encoding="UTF-8"?>
         | 
| 2 | 
            +
            <project xmlns="http://www.netbeans.org/ns/project/1">
         | 
| 3 | 
            +
                <type>org.netbeans.modules.ruby.rubyproject</type>
         | 
| 4 | 
            +
                <configuration>
         | 
| 5 | 
            +
                    <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
         | 
| 6 | 
            +
                        <name>activerecord-mysql2legacydb-adapter</name>
         | 
| 7 | 
            +
                        <source-roots>
         | 
| 8 | 
            +
                            <root id="src.dir"/>
         | 
| 9 | 
            +
                        </source-roots>
         | 
| 10 | 
            +
                        <test-roots>
         | 
| 11 | 
            +
                            <root id="test.src.dir"/>
         | 
| 12 | 
            +
                        </test-roots>
         | 
| 13 | 
            +
                    </data>
         | 
| 14 | 
            +
                </configuration>
         | 
| 15 | 
            +
            </project>
         | 
    
        data/spec/.rspec
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            --color
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe ActiveRecord::Base do
         | 
| 6 | 
            +
              context "'mysql2' adapter" do
         | 
| 7 | 
            +
                before do
         | 
| 8 | 
            +
                  ActiveRecord::Base.establish_connection(TEST_CONFIG.merge({:adapter => 'mysql2'}))
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "should return a normal db connection" do
         | 
| 12 | 
            +
                  ActiveRecord::Base.connection.should be_an_instance_of(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              context "'mysql2legacydb' adapter" do
         | 
| 17 | 
            +
                before do
         | 
| 18 | 
            +
                  ActiveRecord::Base.establish_connection(TEST_CONFIG.merge({:adapter => 'mysql2legacydb'}))
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                it "should return a legacy db connection" do
         | 
| 22 | 
            +
                  ActiveRecord::Base.connection.should be_an_instance_of(ActiveRecord::ConnectionAdapters::Mysql2LegacyDBAdapter)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            describe "ActiveRecord::ConnectionAdapters::Mysql2LegacyDBAdapter" do
         | 
| 29 | 
            +
              context "using connection" do
         | 
| 30 | 
            +
                it "returns altered table names" do
         | 
| 31 | 
            +
                  conn = River.connection
         | 
| 32 | 
            +
                  conn.stub!(:execute).and_return [["WildRivers"]]
         | 
| 33 | 
            +
                  conn.tables.first.should == "wild_rivers"
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              context "in ActiveRecord class" do
         | 
| 38 | 
            +
                before do
         | 
| 39 | 
            +
                  VeryLongRiver.establish_connection(TEST_CONFIG.merge({:adapter => 'mysql2legacydb'}))
         | 
| 40 | 
            +
                  River.establish_connection(TEST_CONFIG.merge({:adapter => 'mysql2legacydb'}))
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                it "should have altered column names" do
         | 
| 44 | 
            +
                  River.column_names.should == ["name", "total_length_in_km", "total_length_in_miles"]
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                it "should have altered table names" do
         | 
| 48 | 
            +
                  River.table_name.should == "rivers"
         | 
| 49 | 
            +
                  VeryLongRiver.table_name.should == "very_long_rivers"
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              context "in ActiveRecord instance" do
         | 
| 55 | 
            +
                before do
         | 
| 56 | 
            +
                  @nile = River.where(:name => "Nile").first
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                it "should map altered column names" do
         | 
| 60 | 
            +
                  @nile.total_length_in_miles.should == 4132
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
            end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            TEST_CONFIG = {
         | 
| 67 | 
            +
              :host     => "localhost",
         | 
| 68 | 
            +
              :username => "root",
         | 
| 69 | 
            +
              :password => "",
         | 
| 70 | 
            +
              :database => "test"
         | 
| 71 | 
            +
            }
         | 
| 72 | 
            +
            class River < ActiveRecord::Base; end
         | 
| 73 | 
            +
            class VeryLongRiver < ActiveRecord::Base; end
         | 
| @@ -0,0 +1,43 @@ | |
| 1 | 
            +
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Mysql2legacydb::DefaultTranslator do
         | 
| 4 | 
            +
                EXAMPLE_MAPPINGS = {
         | 
| 5 | 
            +
                  'veryLongRivers' => 'very_long_rivers',
         | 
| 6 | 
            +
                  'rivers' => 'rivers'
         | 
| 7 | 
            +
                }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              before {
         | 
| 10 | 
            +
                @translator = Mysql2legacydb::DefaultTranslator.new
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              describe "legacy_to_new" do
         | 
| 14 | 
            +
                it "should underscore input" do
         | 
| 15 | 
            +
                  EXAMPLE_MAPPINGS.each do |legacy,new|
         | 
| 16 | 
            +
                    @translator.legacy_to_new(legacy).should == new
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                it "should be reversible" do
         | 
| 21 | 
            +
                  EXAMPLE_MAPPINGS.each do |legacy,new|
         | 
| 22 | 
            +
                    translated_new = @translator.legacy_to_new(legacy)
         | 
| 23 | 
            +
                    @translator.new_to_legacy(translated_new).should == legacy
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              describe "new_to_legacy" do
         | 
| 29 | 
            +
                it "should camelcase underscores" do
         | 
| 30 | 
            +
                  EXAMPLE_MAPPINGS.each do |legacy,new|
         | 
| 31 | 
            +
                    @translator.new_to_legacy(new).should == legacy
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "should be reversible" do
         | 
| 36 | 
            +
                  EXAMPLE_MAPPINGS.each do |legacy,new|
         | 
| 37 | 
            +
                    translated_legacy = @translator.new_to_legacy(new)
         | 
| 38 | 
            +
                    @translator.legacy_to_new(translated_legacy).should == new
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'bundler'
         | 
| 2 | 
            +
            begin
         | 
| 3 | 
            +
              Bundler.setup(:default, :development)
         | 
| 4 | 
            +
            rescue Bundler::BundlerError => e
         | 
| 5 | 
            +
              $stderr.puts e.message
         | 
| 6 | 
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         | 
| 7 | 
            +
              exit e.status_code
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         | 
| 10 | 
            +
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         | 
| 11 | 
            +
            require 'activerecord-mysql2legacydb-adapter'
         | 
| 12 | 
            +
            require 'rspec'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            # Requires supporting files with custom matchers and macros, etc,
         | 
| 15 | 
            +
            # in ./support/ and its subdirectories.
         | 
| 16 | 
            +
            Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            RSpec.configure do |config|
         | 
| 19 | 
            +
              
         | 
| 20 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,250 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: activerecord-mysql2legacydb-adapter
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: false
         | 
| 5 | 
            +
              segments: 
         | 
| 6 | 
            +
              - 0
         | 
| 7 | 
            +
              - 2
         | 
| 8 | 
            +
              - 0
         | 
| 9 | 
            +
              version: 0.2.0
         | 
| 10 | 
            +
            platform: ruby
         | 
| 11 | 
            +
            authors: 
         | 
| 12 | 
            +
            - Anders Johannsen
         | 
| 13 | 
            +
            autorequire: 
         | 
| 14 | 
            +
            bindir: bin
         | 
| 15 | 
            +
            cert_chain: []
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            date: 2010-09-21 00:00:00 +02:00
         | 
| 18 | 
            +
            default_executable: 
         | 
| 19 | 
            +
            dependencies: 
         | 
| 20 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 21 | 
            +
              name: mysql2
         | 
| 22 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 23 | 
            +
                none: false
         | 
| 24 | 
            +
                requirements: 
         | 
| 25 | 
            +
                - - ~>
         | 
| 26 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 27 | 
            +
                    segments: 
         | 
| 28 | 
            +
                    - 0
         | 
| 29 | 
            +
                    - 2
         | 
| 30 | 
            +
                    - 4
         | 
| 31 | 
            +
                    version: 0.2.4
         | 
| 32 | 
            +
              type: :runtime
         | 
| 33 | 
            +
              prerelease: false
         | 
| 34 | 
            +
              version_requirements: *id001
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              name: activerecord
         | 
| 37 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 38 | 
            +
                none: false
         | 
| 39 | 
            +
                requirements: 
         | 
| 40 | 
            +
                - - ~>
         | 
| 41 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 42 | 
            +
                    segments: 
         | 
| 43 | 
            +
                    - 3
         | 
| 44 | 
            +
                    - 0
         | 
| 45 | 
            +
                    - 0
         | 
| 46 | 
            +
                    version: 3.0.0
         | 
| 47 | 
            +
              type: :runtime
         | 
| 48 | 
            +
              prerelease: false
         | 
| 49 | 
            +
              version_requirements: *id002
         | 
| 50 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 51 | 
            +
              name: rspec
         | 
| 52 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 53 | 
            +
                none: false
         | 
| 54 | 
            +
                requirements: 
         | 
| 55 | 
            +
                - - ">="
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 57 | 
            +
                    segments: 
         | 
| 58 | 
            +
                    - 2
         | 
| 59 | 
            +
                    - 0
         | 
| 60 | 
            +
                    - 0
         | 
| 61 | 
            +
                    - beta
         | 
| 62 | 
            +
                    - 19
         | 
| 63 | 
            +
                    version: 2.0.0.beta.19
         | 
| 64 | 
            +
              type: :development
         | 
| 65 | 
            +
              prerelease: false
         | 
| 66 | 
            +
              version_requirements: *id003
         | 
| 67 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 68 | 
            +
              name: bundler
         | 
| 69 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 70 | 
            +
                none: false
         | 
| 71 | 
            +
                requirements: 
         | 
| 72 | 
            +
                - - ~>
         | 
| 73 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 74 | 
            +
                    segments: 
         | 
| 75 | 
            +
                    - 1
         | 
| 76 | 
            +
                    - 0
         | 
| 77 | 
            +
                    - 0
         | 
| 78 | 
            +
                    version: 1.0.0
         | 
| 79 | 
            +
              type: :development
         | 
| 80 | 
            +
              prerelease: false
         | 
| 81 | 
            +
              version_requirements: *id004
         | 
| 82 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 83 | 
            +
              name: jeweler
         | 
| 84 | 
            +
              requirement: &id005 !ruby/object:Gem::Requirement 
         | 
| 85 | 
            +
                none: false
         | 
| 86 | 
            +
                requirements: 
         | 
| 87 | 
            +
                - - ~>
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 89 | 
            +
                    segments: 
         | 
| 90 | 
            +
                    - 1
         | 
| 91 | 
            +
                    - 5
         | 
| 92 | 
            +
                    - 0
         | 
| 93 | 
            +
                    - pre3
         | 
| 94 | 
            +
                    version: 1.5.0.pre3
         | 
| 95 | 
            +
              type: :development
         | 
| 96 | 
            +
              prerelease: false
         | 
| 97 | 
            +
              version_requirements: *id005
         | 
| 98 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 99 | 
            +
              name: rcov
         | 
| 100 | 
            +
              requirement: &id006 !ruby/object:Gem::Requirement 
         | 
| 101 | 
            +
                none: false
         | 
| 102 | 
            +
                requirements: 
         | 
| 103 | 
            +
                - - ">="
         | 
| 104 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 105 | 
            +
                    segments: 
         | 
| 106 | 
            +
                    - 0
         | 
| 107 | 
            +
                    version: "0"
         | 
| 108 | 
            +
              type: :development
         | 
| 109 | 
            +
              prerelease: false
         | 
| 110 | 
            +
              version_requirements: *id006
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 112 | 
            +
              name: mysql2
         | 
| 113 | 
            +
              requirement: &id007 !ruby/object:Gem::Requirement 
         | 
| 114 | 
            +
                none: false
         | 
| 115 | 
            +
                requirements: 
         | 
| 116 | 
            +
                - - ">="
         | 
| 117 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 118 | 
            +
                    segments: 
         | 
| 119 | 
            +
                    - 0
         | 
| 120 | 
            +
                    - 2
         | 
| 121 | 
            +
                    - 4
         | 
| 122 | 
            +
                    version: 0.2.4
         | 
| 123 | 
            +
              type: :runtime
         | 
| 124 | 
            +
              prerelease: false
         | 
| 125 | 
            +
              version_requirements: *id007
         | 
| 126 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 127 | 
            +
              name: rspec
         | 
| 128 | 
            +
              requirement: &id008 !ruby/object:Gem::Requirement 
         | 
| 129 | 
            +
                none: false
         | 
| 130 | 
            +
                requirements: 
         | 
| 131 | 
            +
                - - ">="
         | 
| 132 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 133 | 
            +
                    segments: 
         | 
| 134 | 
            +
                    - 2
         | 
| 135 | 
            +
                    - 0
         | 
| 136 | 
            +
                    - 0
         | 
| 137 | 
            +
                    - beta
         | 
| 138 | 
            +
                    - 19
         | 
| 139 | 
            +
                    version: 2.0.0.beta.19
         | 
| 140 | 
            +
              type: :development
         | 
| 141 | 
            +
              prerelease: false
         | 
| 142 | 
            +
              version_requirements: *id008
         | 
| 143 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 144 | 
            +
              name: bundler
         | 
| 145 | 
            +
              requirement: &id009 !ruby/object:Gem::Requirement 
         | 
| 146 | 
            +
                none: false
         | 
| 147 | 
            +
                requirements: 
         | 
| 148 | 
            +
                - - ~>
         | 
| 149 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 150 | 
            +
                    segments: 
         | 
| 151 | 
            +
                    - 1
         | 
| 152 | 
            +
                    - 0
         | 
| 153 | 
            +
                    - 0
         | 
| 154 | 
            +
                    version: 1.0.0
         | 
| 155 | 
            +
              type: :development
         | 
| 156 | 
            +
              prerelease: false
         | 
| 157 | 
            +
              version_requirements: *id009
         | 
| 158 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 159 | 
            +
              name: jeweler
         | 
| 160 | 
            +
              requirement: &id010 !ruby/object:Gem::Requirement 
         | 
| 161 | 
            +
                none: false
         | 
| 162 | 
            +
                requirements: 
         | 
| 163 | 
            +
                - - ~>
         | 
| 164 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 165 | 
            +
                    segments: 
         | 
| 166 | 
            +
                    - 1
         | 
| 167 | 
            +
                    - 5
         | 
| 168 | 
            +
                    - 0
         | 
| 169 | 
            +
                    - pre3
         | 
| 170 | 
            +
                    version: 1.5.0.pre3
         | 
| 171 | 
            +
              type: :development
         | 
| 172 | 
            +
              prerelease: false
         | 
| 173 | 
            +
              version_requirements: *id010
         | 
| 174 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 175 | 
            +
              name: rcov
         | 
| 176 | 
            +
              requirement: &id011 !ruby/object:Gem::Requirement 
         | 
| 177 | 
            +
                none: false
         | 
| 178 | 
            +
                requirements: 
         | 
| 179 | 
            +
                - - ">="
         | 
| 180 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 181 | 
            +
                    segments: 
         | 
| 182 | 
            +
                    - 0
         | 
| 183 | 
            +
                    version: "0"
         | 
| 184 | 
            +
              type: :development
         | 
| 185 | 
            +
              prerelease: false
         | 
| 186 | 
            +
              version_requirements: *id011
         | 
| 187 | 
            +
            description: "If you are stuck with a MySQL database where the naming is, well, unrailslike,\n    activerecord-mysql2-legacy-db-adapter offers a way to do the translation. It works at the driver level and doesn't\n    require you ro change the structure of the database. Also there are no database views which should be kept up to date\n    as you add or remove fields.\n  "
         | 
| 188 | 
            +
            email: anders@johannsen.com
         | 
| 189 | 
            +
            executables: []
         | 
| 190 | 
            +
             | 
| 191 | 
            +
            extensions: []
         | 
| 192 | 
            +
             | 
| 193 | 
            +
            extra_rdoc_files: 
         | 
| 194 | 
            +
            - LICENSE
         | 
| 195 | 
            +
            - README.rdoc
         | 
| 196 | 
            +
            files: 
         | 
| 197 | 
            +
            - .document
         | 
| 198 | 
            +
            - .gitignore
         | 
| 199 | 
            +
            - Gemfile
         | 
| 200 | 
            +
            - Gemfile.lock
         | 
| 201 | 
            +
            - LICENSE
         | 
| 202 | 
            +
            - README.rdoc
         | 
| 203 | 
            +
            - Rakefile
         | 
| 204 | 
            +
            - VERSION
         | 
| 205 | 
            +
            - lib/active_record/connection_adapters/mysql2legacydb_adapter.rb
         | 
| 206 | 
            +
            - lib/activerecord-mysql2legacydb-adapter.rb
         | 
| 207 | 
            +
            - lib/mysql2legacydb/default_translator.rb
         | 
| 208 | 
            +
            - nbproject/project.properties
         | 
| 209 | 
            +
            - nbproject/project.xml
         | 
| 210 | 
            +
            - spec/.rspec
         | 
| 211 | 
            +
            - spec/activerecord-mysql2legacydb-adapter_spec.rb
         | 
| 212 | 
            +
            - spec/mysql2legacydb/default_translator_spec.rb
         | 
| 213 | 
            +
            - spec/spec_helper.rb
         | 
| 214 | 
            +
            has_rdoc: true
         | 
| 215 | 
            +
            homepage: http://github.com/andersjo/activerecord-mysql2legacydb-adapter
         | 
| 216 | 
            +
            licenses: []
         | 
| 217 | 
            +
             | 
| 218 | 
            +
            post_install_message: 
         | 
| 219 | 
            +
            rdoc_options: []
         | 
| 220 | 
            +
             | 
| 221 | 
            +
            require_paths: 
         | 
| 222 | 
            +
            - lib
         | 
| 223 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 224 | 
            +
              none: false
         | 
| 225 | 
            +
              requirements: 
         | 
| 226 | 
            +
              - - ">="
         | 
| 227 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 228 | 
            +
                  hash: -1619170428146622390
         | 
| 229 | 
            +
                  segments: 
         | 
| 230 | 
            +
                  - 0
         | 
| 231 | 
            +
                  version: "0"
         | 
| 232 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 233 | 
            +
              none: false
         | 
| 234 | 
            +
              requirements: 
         | 
| 235 | 
            +
              - - ">="
         | 
| 236 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 237 | 
            +
                  segments: 
         | 
| 238 | 
            +
                  - 0
         | 
| 239 | 
            +
                  version: "0"
         | 
| 240 | 
            +
            requirements: []
         | 
| 241 | 
            +
             | 
| 242 | 
            +
            rubyforge_project: 
         | 
| 243 | 
            +
            rubygems_version: 1.3.7
         | 
| 244 | 
            +
            signing_key: 
         | 
| 245 | 
            +
            specification_version: 3
         | 
| 246 | 
            +
            summary: Translates table and field names of legacy databases
         | 
| 247 | 
            +
            test_files: 
         | 
| 248 | 
            +
            - spec/activerecord-mysql2legacydb-adapter_spec.rb
         | 
| 249 | 
            +
            - spec/mysql2legacydb/default_translator_spec.rb
         | 
| 250 | 
            +
            - spec/spec_helper.rb
         |