テストが通らない件
rake test:units だと通らず、test ファイルを直接指定すると通る、という状態。
rake test:units だと
C:\Work\drweb_office>rake test:units (in C:/Work/drweb_office) C:/Program Files/ruby-1.8/bin/ruby -Ilib;test "C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" "test/unit/customer_test.rb" "test/unit/customer_type_test.rb" "test/unit/distributor_staff_test.rb" "test/unit/distributor_test.rb" "test/unit/distributor_type_test.rb" "test/unit/license_test.rb" "test/unit/license_type_test.rb" "test/unit/payment_term_test.rb" Loaded suite C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader Started ..............E.............................. Finished in 6.539 seconds. 1) Error: test_success(DistributorStaffTest): ActiveRecord::RecordInvalid: Validation failed: Distributor が不正です。 C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:764:in `save_w ithout_transactions!' C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:133:in `save!' C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction' C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction' C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction' C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:133:in `save!' ./test/unit/distributor_staff_test.rb:16:in `test_success' 45 tests, 118 assertions, 0 failures, 1 errors rake aborted! Command failed with status (1): [C:/Program Files/ruby-1.8/bin/ruby -Ilib;t...] (See full trace by running task with --trace)
で、単独で実行すると
C:\Work\drweb_office> ruby test\unit\distributor_staff_test..rb Loaded suite test/unit/distributor_staff_test Started ..... Finished in 1.593 seconds. 5 tests, 10 assertions, 0 failures, 0 errors
と 0F0E になります。
以前にも同様の問題に遭遇したことがあった気がするけど思い出せない --;)。なんだろうなぁ...
モデルはこんな感じ。
class DistributorStaff < ActiveRecord::Base acts_as_list :scope => :distributor_id belongs_to :distributor ROLE = [['販売', 1], ['経理', 2], ['技術', 3], ['その他', 9]].freeze [:distributor_id, :role, :name, :name_in_kana, :email].each do |key| validates_presence_of(key, :message => 'は必須項目です。') end validates_format_of(:email, :with => /^[-\.\w]{1,}@([-\w]{1,}\.){1,}([-\w]{1,})$/, :message => 'の書式が正しくありません。') validates_inclusion_of(:role, :in => ROLE.map {|role| role[1]}, :message => 'が不正です。') validates_inclusion_of(:distributor_id, :in => Distributor.find(:all, :select => 'id').collect {|db| db.id}, :message => "が不正です。") end
あまり悩んでいても仕方ないから、先に進むかな...