From e7b7b4412380e7ce2d8e6ae402cb7fe02d7666b8 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 20 Sep 2011 10:50:08 -0700 Subject: implements AR::Relation#explain This is a first implementation, EXPLAIN is highly dependent on the database and I have made some compromises. On one hand, the method allows you to run the most common EXPLAIN and that's it. If you want EXPLAIN ANALYZE in PostgreSQL you need to do it by hand. On the other hand, I've tried to construct a string as close as possible to the ones built by the respective shells. The rationale is that IMO the user should feel at home with the output and recognize it at first sight. Per database. I don't know whether this implementation is going to work well. Let's see whether people like it. --- .../test/cases/adapters/mysql2/explain_test.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 activerecord/test/cases/adapters/mysql2/explain_test.rb (limited to 'activerecord/test/cases/adapters/mysql2') diff --git a/activerecord/test/cases/adapters/mysql2/explain_test.rb b/activerecord/test/cases/adapters/mysql2/explain_test.rb new file mode 100644 index 0000000000..8ea777b72b --- /dev/null +++ b/activerecord/test/cases/adapters/mysql2/explain_test.rb @@ -0,0 +1,23 @@ +require "cases/helper" +require 'models/developer' + +module ActiveRecord + module ConnectionAdapters + class Mysql2Adapter + class ExplainTest < ActiveRecord::TestCase + fixtures :developers + + def test_explain_for_one_query + explain = Developer.where(:id => 1).explain + assert_match %(developers | const), explain + end + + def test_explain_with_eager_loading + explain = Developer.where(:id => 1).includes(:audit_logs).explain + assert_match %(developers | const), explain + assert_match %(audit_logs | ALL), explain + end + end + end + end +end -- cgit v1.2.3 From 9c37416a3eaa446ec59cde1e7f8a913f62de3265 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 19 Nov 2011 12:34:15 +0000 Subject: Verify that #3690 has been closed by previous changes to the mysql adapters. These tests fail on the v3.1.2 tag. Closes #3690. --- activerecord/test/cases/adapters/mysql2/schema_test.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/adapters/mysql2') diff --git a/activerecord/test/cases/adapters/mysql2/schema_test.rb b/activerecord/test/cases/adapters/mysql2/schema_test.rb index 858d1da2dd..49514e1539 100644 --- a/activerecord/test/cases/adapters/mysql2/schema_test.rb +++ b/activerecord/test/cases/adapters/mysql2/schema_test.rb @@ -13,7 +13,7 @@ module ActiveRecord table = Post.table_name @db_name = db - @omgpost = Class.new(Post) do + @omgpost = Class.new(ActiveRecord::Base) do set_table_name "#{db}.#{table}" def self.name; 'Post'; end end @@ -23,6 +23,10 @@ module ActiveRecord assert @omgpost.find(:first) end + def test_primary_key + assert_equal 'id', @omgpost.primary_key + end + def test_table_exists? name = @omgpost.table_name assert @connection.table_exists?(name), "#{name} table should exist" -- cgit v1.2.3