nay-record_with_operator 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/record_with_operator.rb +2 -1
- data/test/record_with_operator_test.rb +19 -8
- metadata +4 -2
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ DESCRIPTION = "Rails plugin to set created_by, updated_by, deleted_by to ActiveR
|
|
12
12
|
GITHUB_PROJECT = "record_with_operator"
|
13
13
|
HOMEPAGE = "http://github.com/nay/#{GITHUB_PROJECT}/tree"
|
14
14
|
BIN_FILES = %w( )
|
15
|
-
VER = "0.0.
|
15
|
+
VER = "0.0.5"
|
16
16
|
CLEAN.include ['pkg']
|
17
17
|
|
18
18
|
desc 'Default: run unit tests.'
|
data/lib/record_with_operator.rb
CHANGED
@@ -9,16 +9,25 @@ class NoteWithUser < ActiveRecord::Base
|
|
9
9
|
|
10
10
|
named_scope :new_arrivals, {:order => "updated_at desc"}
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def destroy_without_callbacks
|
13
|
+
unless new_record?
|
14
|
+
self.class.update_all self.class.send(:sanitize_sql, ["deleted_at = ?", (self.deleted_at = default_timezone == :utc ? Time.now.utc : Time.now)]), ["#{self.class.primary_key} = ?", id]
|
15
|
+
end
|
16
|
+
freeze
|
14
17
|
end
|
15
|
-
|
16
|
-
def
|
17
|
-
|
18
|
+
|
19
|
+
def destroy_with_callbacks!
|
20
|
+
return false if callback(:before_destroy) == false
|
21
|
+
result = destroy_without_callbacks!
|
22
|
+
callback(:after_destroy)
|
23
|
+
result
|
24
|
+
end
|
25
|
+
def destroy!
|
26
|
+
transaction { destroy_with_callbacks! }
|
18
27
|
end
|
19
28
|
|
20
29
|
def deleted?
|
21
|
-
self.deleted_at <= Time.now
|
30
|
+
self.deleted_at.to_time <= Time.now
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
@@ -46,7 +55,9 @@ class RecordWithOperatorTest < ActiveSupport::TestCase
|
|
46
55
|
def setup
|
47
56
|
RecordWithOperator.config[:user_class_name] = "User"
|
48
57
|
@user1 = User.create!(:name => "user1")
|
58
|
+
raise "@user1.id is nil" unless @user1.id
|
49
59
|
@user2 = User.create!(:name => "user2")
|
60
|
+
raise "@user2.id is nil" unless @user2.id
|
50
61
|
@note_created_by_user1 = NoteWithUser.create!(:body => "test", :operator => @user1)
|
51
62
|
end
|
52
63
|
|
@@ -137,9 +148,9 @@ class RecordWithOperatorTest < ActiveSupport::TestCase
|
|
137
148
|
def test_note_should_be_destroyed_with_deleted_by
|
138
149
|
note = NoteWithUser.find(@note_created_by_user1.id, :for => @user2)
|
139
150
|
note.destroy # logically
|
140
|
-
note.
|
151
|
+
note = NoteWithUser.find(@note_created_by_user1.id)
|
141
152
|
raise "not deleted" unless note.deleted?
|
142
|
-
|
153
|
+
assert_equal @user2.id, note.deleted_by
|
143
154
|
end
|
144
155
|
|
145
156
|
# reload
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nay-record_with_operator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yasuko Ohba
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/record_with_operator.rb
|
43
43
|
- tasks/record_with_operator_tasks.rake
|
44
44
|
- test/database.yml
|
45
|
+
- test/debug.log
|
45
46
|
- test/record_with_operator_belongs_to_association_test.rb
|
46
47
|
- test/record_with_operator_has_one_association_test.rb
|
47
48
|
- test/record_with_operator_test.rb
|
@@ -78,6 +79,7 @@ specification_version: 2
|
|
78
79
|
summary: Rails plugin to set created_by, updated_by, deleted_by to ActiveRecord objects. Supports associations.
|
79
80
|
test_files:
|
80
81
|
- test/database.yml
|
82
|
+
- test/debug.log
|
81
83
|
- test/record_with_operator_belongs_to_association_test.rb
|
82
84
|
- test/record_with_operator_has_one_association_test.rb
|
83
85
|
- test/record_with_operator_test.rb
|