Rails本体の、testを実行する(3)
昨日 (http://d.hatena.ne.jp/kouji0625/20130612/p1) の続きです。
昨日の時点で、あとは activerecord のみという状態でした。さぁ、今日もはりきっていってみよ〜♪
activerecord
MySQL のセットアップ
事前に MySQL そのものは公式サイト (http://dev.mysql.com/downloads/mysql/) からダウンロードして、インストールしていました。しかしながら、設定で自動起動を OFF にしていたみたいなので、環境設定.app を操作して MySQL サーバを起動しました。
あと、以下のように MySQL の権限の設定が必要みたいです。 activerecord/test/connections/native_mysql/connection.rb に権限を設定するためのコマンドが書いてありました。なお、このファイルを修正して既存のアカウント情報を設定するという方法でもいいようです。
GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost'; GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
PostgreSQL のセットアップ
事前に PostgreSQL そのものは MacPorts でインストールしていました。
$ sudo port install postgresql92-server $ sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb $ sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb $ sudo su postgres -c '/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql92/defaultdb' $ sudo -u postgres /opt/local/lib/postgresql92/bin/pg_ctl -D /opt/local/var/db/postgresql92/defaultdb start
しかしエラーが発生。ログインユーザと同じ名前のPostgreSQLのユーザを作成しておく必要があるみたい。
$ sudo -u postgres createuser kouji Shall the new role be a superuser? (y/n) y
linecache の警告の抑制
Gemfile に以下を追加した。
gem "linecache", "0.43"
追加後は linecache のアップデート。
$ bundle update linecache
「joins is deprecated」の警告の抑制
該当するのは3箇所。Rails のソースコードを修正する。
パッチは以下のコマンド + 目視で取得した。
$ git diff v3.0.3..v3.0.20 -- path/to/target_file.rb
please remove your call to joins from /Users/kouji/work/rails/rails/activerecord/lib/active_record/relation/calculations.rb:169:in `perform_calculation'
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/activ e_record/relation/calculations.rb index 6bf698f..848b7d3 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -166,7 +166,7 @@ module ActiveRecord if operation == "count" column_name ||= (select_for_count || :all) - if arel.joins(arel) =~ /LEFT OUTER/i + if arel.join_sql =~ /LEFT OUTER/i distinct = true column_name = @klass.primary_key if column_name == :all end
please remove your call to joins from /Users/kouji/work/rails/rails/activerecord/lib/active_record/relation/query_methods.rb:171:in `custom_join_sql'
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 926f471..eb62750 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -168,7 +167,7 @@ module ActiveRecord arel.join(join) end - arel.joins(arel) + arel.join_sql end def build_arel
please remove your call to joins from /Users/kouji/work/rails/rails/activerecord/lib/active_record/relation.rb:379:in `references_eager_loaded_tables?'
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 49cdde5..07eb572 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -376,7 +376,7 @@ module ActiveRecord 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{ |t| t.downcase }.uniq + joined_tables = (tables_in_string(arel.join_sql) + [table.name, table.table_alias]).compact.map{ |t| t.downcase }.uniq (tables_in_string(to_sql) - joined_tables).any? end
please remove your call to joins from /Users/kouji/work/rails/rails/activerecord/lib/active_record/relation/finder_methods.rb:197:in `construct_relation_for_association_calculations'
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index e950dce..fadb6c5 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -194,7 +194,7 @@ module ActiveRecord def construct_relation_for_association_calculations including = (@eager_load_values + @includes_values).uniq - join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, arel.joins(arel)) + join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, arel.join_sql) relation = except(:includes, :eager_load, :preload) apply_join_dependency(relation, join_dependency) end
「reorder」の警告
警告の内容に従って修正した。
diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 947583a..3083de7 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -88,7 +88,7 @@ class DeveloperOrderedBySalary < ActiveRecord::Base self.table_name = 'developers' default_scope :order => 'salary DESC' scope :by_name, order('name DESC') - scope :reordered_by_name, reorder('name') + scope :reordered_by_name, except(:order).order('name') def self.all_ordered_by_name with_scope(:find => { :order => 'name DESC' }) do
「to_a is deprecated...」の警告
この対応は無理っぽい。あきらめる。
「test_except_and_order_overrides_default_scope_order」の警告
修正漏れっぽい。
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index e2abe3b..1575cc5 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -415,12 +415,6 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal expected, received end - def test_except_and_order_overrides_default_scope_order - expected = Developer.order('name DESC').collect { |dev| dev.name } - received = DeveloperOrderedBySalary.except(:order).order('name DESC').collect { |dev| dev.name } - assert_equal expected, received - end - def test_reordered_scope_overrides_default_scope_order not_expected = DeveloperOrderedBySalary.first # Jamis -> name DESC received = DeveloperOrderedBySalary.reordered_by_name.first # David -> name
rack のバージョンダウン (「discarding old bytesize」の警告の抑制)
rack のバージョンを 1.2.1 に固定する。
$ vi Gemfile (以下のように修正する) gem "rack", "1.2.1" $ bundle update rack
と、今日はここまで...
(つづく...)
--- 参考URL
--- PR広告
記事を読んでくださり、ありがとうございます。もしよろしければ、この記事の著者が提供している無料のサービス「かくってる?」をお試しください。
- かくってる?: http://cocktailq.herokuapp.com/