Commit c40cfd39bbef682930a2d5627e36f7493e81aa74

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 0d4ff218

Fixing ActionTracker::Record.user validation

* Also creating a migration to remove the broken records.

(ActionItem1785)
db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +class RemoveActionTrackerRecordWithNilUsers < ActiveRecord::Migration
  2 + def self.up
  3 + ActionTracker::Record.all.map {|record| record.destroy if record.user.nil?}
  4 + end
  5 +
  6 + def self.down
  7 + say "this migration can't be reverted"
  8 + end
  9 +end
vendor/plugins/action_tracker/lib/action_tracker_model.rb
@@ -11,8 +11,7 @@ module ActionTracker @@ -11,8 +11,7 @@ module ActionTracker
11 before_validation :stringify_verb 11 before_validation :stringify_verb
12 12
13 validates_presence_of :verb 13 validates_presence_of :verb
14 - validates_presence_of :user_id  
15 - validates_presence_of :user_type 14 + validates_presence_of :user
16 15
17 alias_method :subject, :user 16 alias_method :subject, :user
18 17
vendor/plugins/action_tracker/test/action_tracker_model_test.rb
@@ -67,6 +67,11 @@ class ActionTrackerModelTest &lt; ActiveSupport::TestCase @@ -67,6 +67,11 @@ class ActionTrackerModelTest &lt; ActiveSupport::TestCase
67 end 67 end
68 end 68 end
69 69
  70 + def test_user_exists_indeed
  71 + ta = ActionTracker::Record.new(:user_id => -1, :user_type => "SomeModel", :verb => :some_verb)
  72 + assert !ta.valid?
  73 + end
  74 +
70 def test_verb_must_be_declared_previously 75 def test_verb_must_be_declared_previously
71 ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something" } } 76 ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something" } }
72 assert_raise ActiveRecord::RecordInvalid do 77 assert_raise ActiveRecord::RecordInvalid do