From c40cfd39bbef682930a2d5627e36f7493e81aa74 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 27 Jan 2011 15:37:05 -0300 Subject: [PATCH] Fixing ActionTracker::Record.user validation --- db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb | 9 +++++++++ vendor/plugins/action_tracker/lib/action_tracker_model.rb | 3 +-- vendor/plugins/action_tracker/test/action_tracker_model_test.rb | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb diff --git a/db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb b/db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb new file mode 100644 index 0000000..7afe586 --- /dev/null +++ b/db/migrate/20110127174236_remove_action_tracker_record_with_nil_users.rb @@ -0,0 +1,9 @@ +class RemoveActionTrackerRecordWithNilUsers < ActiveRecord::Migration + def self.up + ActionTracker::Record.all.map {|record| record.destroy if record.user.nil?} + end + + def self.down + say "this migration can't be reverted" + end +end diff --git a/vendor/plugins/action_tracker/lib/action_tracker_model.rb b/vendor/plugins/action_tracker/lib/action_tracker_model.rb index 080a69c..4ce5097 100644 --- a/vendor/plugins/action_tracker/lib/action_tracker_model.rb +++ b/vendor/plugins/action_tracker/lib/action_tracker_model.rb @@ -11,8 +11,7 @@ module ActionTracker before_validation :stringify_verb validates_presence_of :verb - validates_presence_of :user_id - validates_presence_of :user_type + validates_presence_of :user alias_method :subject, :user diff --git a/vendor/plugins/action_tracker/test/action_tracker_model_test.rb b/vendor/plugins/action_tracker/test/action_tracker_model_test.rb index 16552f8..bf88d06 100644 --- a/vendor/plugins/action_tracker/test/action_tracker_model_test.rb +++ b/vendor/plugins/action_tracker/test/action_tracker_model_test.rb @@ -67,6 +67,11 @@ class ActionTrackerModelTest < ActiveSupport::TestCase end end + def test_user_exists_indeed + ta = ActionTracker::Record.new(:user_id => -1, :user_type => "SomeModel", :verb => :some_verb) + assert !ta.valid? + end + def test_verb_must_be_declared_previously ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something" } } assert_raise ActiveRecord::RecordInvalid do -- libgit2 0.21.2