Sha256: af5c8de6f12efb29af3a9e6b7c9d4422aaba05c3c5d67adfca25da71cbab7fde
Contents?: true
Size: 1.72 KB
Versions: 18
Compression:
Stored size: 1.72 KB
Contents
require 'test_helper' class NoteWithAdminUser < ActiveRecord::Base set_table_name "notes" def destroy_with_deleted_at NoteWithAdminUser.update_all("deleted_at = '#{Time.now.to_s(:db)}'", "id = #{self.id}") end alias_method_chain :destroy, :deleted_at def destory! destory_without_deleted_at end def deleted? self.deleted_at <= Time.now end end class AdminUser < ActiveRecord::Base set_table_name "users" end class RecordWithOperatorUserClassNameTest < ActiveSupport::TestCase def setup RecordWithOperator.config[:user_class_name] = "AdminUser" @user1 = AdminUser.create!(:name => "user1") @user2 = AdminUser.create!(:name => "user2") @note_created_by_user1 = NoteWithAdminUser.create!(:body => "test", :operator => @user1) end def test_note_should_be_created_with_operator assert_equal @user1, @note_created_by_user1.operator end def test_note_should_be_created_with_created_by_and_updated_by assert_equal @user1.id, @note_created_by_user1.created_by assert_equal @user1.id, @note_created_by_user1.updated_by @note_created_by_user1.reload assert_equal @user1.id, @note_created_by_user1.created_by assert_equal @user1.id, @note_created_by_user1.updated_by assert @note_created_by_user1.creator.kind_of?(AdminUser) end def test_note_should_be_found_with_for note = NoteWithAdminUser.find(@note_created_by_user1.id, :for => @user2) assert_equal(@user2, note.operator) end def test_note_should_be_updated_with_updated_by note = NoteWithAdminUser.find(@note_created_by_user1.id, :for => @user2) note.body = "changed" note.save! assert_equal(@user2.id, note.updated_by) note.reload assert_equal(@user2.id, note.updated_by) end end
Version data entries
18 entries across 18 versions & 2 rubygems