Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 676525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:56:16+00:00 2026-05-14T00:56:16+00:00

I wrote a little monkeypatch to the Rails MySQLAdapter and want to package it

  • 0

I wrote a little monkeypatch to the Rails MySQLAdapter and want to package it up to use it in my other projects. I am trying to write some tests for it but I am still new to testing and I am not sure how to test this. Can someone help get me started?

Here is the code I want to test:

unless RAILS_ENV == 'production'
      module ActiveRecord
        module ConnectionAdapters
          class MysqlAdapter < AbstractAdapter
            def select_with_explain(sql, name = nil)
              explanation = execute_with_disable_logging('EXPLAIN ' + sql)
              e = explanation.all_hashes.first
              exp = e.collect{|k,v| " | #{k}: #{v} "}.join
              log(exp, 'Explain')
              select_without_explain(sql, name)
            end

            def execute_with_disable_logging(sql, name = nil) #:nodoc:
              #Run a query without logging
              @connection.query(sql)
            rescue ActiveRecord::StatementInvalid => exception
              if exception.message.split(":").first =~ /Packets out of order/
                raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information.  If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
              else
                raise
              end
            end
            alias_method_chain :select, :explain
          end
        end
      end
    end

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:56:16+00:00Added an answer on May 14, 2026 at 12:56 am

    General testing

    You could start reading about testing.

    After you are understanding the basics of testing, you should think what you have changed. Then make some tests which test for

    • the original situation, resulting in errors since you updated it. So reverse the test after it indeed is working for the original situation.
    • the new situation to see whether you have implemented your idea correctly

    The hardest part is to be sure that you covered all situations. Finally, if both parts pass then you could say that your code it working as expected.

    Testing gems

    In order to test gems you can run

    rake test:plugins
    

    to test all plugins of your rails application (see more in chapter 6 of the testing guide), this only works when the gem is in the vendor directory of an application.

    Another possibility is to modify the Rakefile of the gem by including a testing task. For example this

    desc 'Test my custom made gem.'
    Rake::TestTask.new(:test) do |t|
      t.libs << 'lib'
      t.libs << 'test'
      t.pattern = 'test/**/*_test.rb'
      t.verbose = true
    end
    

    would run all available tests in the test directory ending with _test.rb. To execute this test you can type rake test (from the gem directory!).

    In order to run the tests for the gem by default (when typing just rake) you can add/modify this line:

    task :default => :test
    

    I used the second method in my ruby-bbcode gem, so you could take a look at it to see the complete example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a little program that use activemq embedded broker. Program run on one
i wrote a little addin, which does some formatting of my C# code. in
I wrote a little console application, and I want it to pause for a
I wrote a little script that check something, and i want a command to
I wrote a little program, which is working like a ping command(i use ICMPSendEcho2),
I wrote a little application that takes in some text and converts it to
Im trying to learn glib/gtk. I wrote little code which prints files in directory
I wrote a little powershell function that executes Get-EventLog against remote servers. On some
I wrote a little app, which has some locales and language options. When user
I wrote a little application using GAE and the playframework. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.