activerecord-userstamp 3.0.2 → 3.0.3
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.
- checksums.yaml +4 -4
- data/.gitignore +5 -5
- data/.rspec +2 -2
- data/CHANGELOG.md +103 -99
- data/Gemfile +3 -3
- data/LICENSE +21 -21
- data/README.md +189 -189
- data/Rakefile +17 -17
- data/activerecord-userstamp.gemspec +34 -34
- data/lib/active_record/userstamp.rb +30 -30
- data/lib/active_record/userstamp/configuration.rb +49 -49
- data/lib/active_record/userstamp/controller_additions.rb +50 -50
- data/lib/active_record/userstamp/migration_additions.rb +14 -14
- data/lib/active_record/userstamp/model_additions.rb +10 -10
- data/lib/active_record/userstamp/stampable.rb +123 -123
- data/lib/active_record/userstamp/stamper.rb +54 -54
- data/lib/active_record/userstamp/utilities.rb +55 -54
- data/lib/active_record/userstamp/version.rb +4 -4
- data/lib/activerecord/userstamp.rb +1 -1
- data/spec/controllers/posts_controller_spec.rb +44 -44
- data/spec/controllers/users_controller_spec.rb +50 -50
- data/spec/dummy/README.rdoc +28 -28
- data/spec/dummy/Rakefile +6 -6
- data/spec/dummy/app/assets/javascripts/application.js +13 -13
- data/spec/dummy/app/assets/stylesheets/application.css +15 -15
- data/spec/dummy/app/controllers/application_controller.rb +13 -13
- data/spec/dummy/app/controllers/posts_controller.rb +36 -36
- data/spec/dummy/app/controllers/users_controller.rb +22 -22
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/models/comment.rb +5 -5
- data/spec/dummy/app/models/person.rb +3 -3
- data/spec/dummy/app/models/post.rb +14 -14
- data/spec/dummy/app/models/tag.rb +3 -0
- data/spec/dummy/app/models/user.rb +3 -3
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +4 -4
- data/spec/dummy/bin/rake +4 -4
- data/spec/dummy/bin/setup +29 -29
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/config/application.rb +30 -30
- data/spec/dummy/config/boot.rb +5 -5
- data/spec/dummy/config/database.yml +23 -23
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +41 -41
- data/spec/dummy/config/environments/production.rb +79 -79
- data/spec/dummy/config/environments/test.rb +37 -37
- data/spec/dummy/config/initializers/assets.rb +11 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/mime_types.rb +4 -4
- data/spec/dummy/config/initializers/session_store.rb +3 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +23 -23
- data/spec/dummy/config/routes.rb +56 -56
- data/spec/dummy/config/secrets.yml +22 -22
- data/spec/dummy/db/schema.rb +54 -45
- data/spec/dummy/public/404.html +67 -67
- data/spec/dummy/public/422.html +67 -67
- data/spec/dummy/public/500.html +66 -66
- data/spec/lib/configuration_spec.rb +20 -20
- data/spec/lib/migration_spec.rb +71 -71
- data/spec/lib/stamper_spec.rb +66 -66
- data/spec/lib/stamping_spec.rb +250 -238
- data/spec/lib/userstamp_spec.rb +7 -7
- data/spec/rails_helper.rb +7 -7
- data/spec/spec_helper.rb +97 -97
- data/spec/support/database_helpers.rb +22 -22
- data/spec/support/with_temporary_table.rb +51 -51
- metadata +3 -2
data/spec/lib/stamper_spec.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Stamper' do
|
4
|
-
describe '.model_stamper' do
|
5
|
-
it 'can only be included once' do
|
6
|
-
expect(User.singleton_class.included_modules.count(
|
7
|
-
ActiveRecord::Userstamp::Stamper::InstanceMethods)).to eq(1)
|
8
|
-
|
9
|
-
User.class_eval do
|
10
|
-
stamper
|
11
|
-
end
|
12
|
-
|
13
|
-
expect(User.singleton_class.included_modules.count(
|
14
|
-
ActiveRecord::Userstamp::Stamper::InstanceMethods)).to eq(1)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.stamper' do
|
19
|
-
it 'defaults to nil' do
|
20
|
-
User.reset_stamper
|
21
|
-
expect(User.stamper).to be_nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '.stamper=' do
|
26
|
-
it 'assigns the stamper' do
|
27
|
-
stamper = User.new
|
28
|
-
User.stamper = stamper
|
29
|
-
expect(User.stamper).to eq(stamper)
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when the stamper is nil' do
|
33
|
-
it 'resets the stamper' do
|
34
|
-
User.stamper = nil
|
35
|
-
expect(User.stamper).to be(nil)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '.reset_stamper' do
|
41
|
-
it 'resets the stamper' do
|
42
|
-
User.reset_stamper
|
43
|
-
expect(User.stamper).to be_nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe '.with_stamper' do
|
48
|
-
context 'when within the block' do
|
49
|
-
it 'uses the correct stamper' do
|
50
|
-
stamper = User.create(name: 'Joel')
|
51
|
-
User.with_stamper(stamper) do
|
52
|
-
expect(User.stamper).to eq(stamper)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when exiting the block' do
|
58
|
-
it 'restores the stamper' do
|
59
|
-
expect do
|
60
|
-
User.with_stamper(User.create(name: 'Joel')) do
|
61
|
-
end
|
62
|
-
end.not_to change { User.stamper }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Stamper' do
|
4
|
+
describe '.model_stamper' do
|
5
|
+
it 'can only be included once' do
|
6
|
+
expect(User.singleton_class.included_modules.count(
|
7
|
+
ActiveRecord::Userstamp::Stamper::InstanceMethods)).to eq(1)
|
8
|
+
|
9
|
+
User.class_eval do
|
10
|
+
stamper
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(User.singleton_class.included_modules.count(
|
14
|
+
ActiveRecord::Userstamp::Stamper::InstanceMethods)).to eq(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.stamper' do
|
19
|
+
it 'defaults to nil' do
|
20
|
+
User.reset_stamper
|
21
|
+
expect(User.stamper).to be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.stamper=' do
|
26
|
+
it 'assigns the stamper' do
|
27
|
+
stamper = User.new
|
28
|
+
User.stamper = stamper
|
29
|
+
expect(User.stamper).to eq(stamper)
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when the stamper is nil' do
|
33
|
+
it 'resets the stamper' do
|
34
|
+
User.stamper = nil
|
35
|
+
expect(User.stamper).to be(nil)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '.reset_stamper' do
|
41
|
+
it 'resets the stamper' do
|
42
|
+
User.reset_stamper
|
43
|
+
expect(User.stamper).to be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.with_stamper' do
|
48
|
+
context 'when within the block' do
|
49
|
+
it 'uses the correct stamper' do
|
50
|
+
stamper = User.create(name: 'Joel')
|
51
|
+
User.with_stamper(stamper) do
|
52
|
+
expect(User.stamper).to eq(stamper)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when exiting the block' do
|
58
|
+
it 'restores the stamper' do
|
59
|
+
expect do
|
60
|
+
User.with_stamper(User.create(name: 'Joel')) do
|
61
|
+
end
|
62
|
+
end.not_to change { User.stamper }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/lib/stamping_spec.rb
CHANGED
@@ -1,238 +1,250 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Stamping', type: :model do
|
4
|
-
before(:each) do
|
5
|
-
define_first_post
|
6
|
-
User.stamper = @zeus
|
7
|
-
Person.stamper = @delynn
|
8
|
-
end
|
9
|
-
|
10
|
-
context 'when creating a Person' do
|
11
|
-
context 'when the stamper is an object' do
|
12
|
-
it 'sets using the the association' do
|
13
|
-
User.stamper = @zeus
|
14
|
-
expect(User.stamper).to eq(@zeus)
|
15
|
-
|
16
|
-
person = Person.new
|
17
|
-
expect(person).to receive(:creator=)
|
18
|
-
person.valid?
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets the correct creator and updater' do
|
22
|
-
expect(User.stamper).to eq(@zeus)
|
23
|
-
|
24
|
-
person = Person.create(name: 'David')
|
25
|
-
expect(person.creator_id).to eq(@zeus.id)
|
26
|
-
expect(person.updater_id).to eq(@zeus.id)
|
27
|
-
expect(person.creator).to eq(@zeus)
|
28
|
-
expect(person.updater).to eq(@zeus)
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when a creator is specified' do
|
32
|
-
it 'does not reset the creator' do
|
33
|
-
expect(User.stamper).to eq(@zeus)
|
34
|
-
|
35
|
-
person = Person.create(name: 'David', creator: @hera)
|
36
|
-
expect(person.creator_id).to eq(@hera.id)
|
37
|
-
expect(person.updater_id).to eq(@zeus.id)
|
38
|
-
expect(person.creator).to eq(@hera)
|
39
|
-
expect(person.updater).to eq(@zeus)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'does not reset the creator' do
|
43
|
-
expect(User.stamper).to eq(@zeus)
|
44
|
-
|
45
|
-
person = Person.create(name: 'David', creator_id: @hera.id)
|
46
|
-
expect(person.creator_id).to eq(@hera.id)
|
47
|
-
expect(person.updater_id).to eq(@zeus.id)
|
48
|
-
expect(person.creator).to eq(@hera)
|
49
|
-
expect(person.updater).to eq(@zeus)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when saving without validations' do
|
54
|
-
it 'sets the correct creator and updater' do
|
55
|
-
expect(User.stamper).to eq(@zeus)
|
56
|
-
|
57
|
-
person = Person.new(name: 'David')
|
58
|
-
person.save(validate: false)
|
59
|
-
expect(person.creator_id).to eq(@zeus.id)
|
60
|
-
expect(person.updater_id).to eq(@zeus.id)
|
61
|
-
expect(person.creator).to eq(@zeus)
|
62
|
-
expect(person.updater).to eq(@zeus)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when temporarily disabling stampng' do
|
67
|
-
it 'does not set the creator and updater' do
|
68
|
-
expect(User.stamper).to eq(@zeus)
|
69
|
-
|
70
|
-
Person.without_stamps do
|
71
|
-
person = Person.create(name: 'David')
|
72
|
-
expect(person.creator_id).to be_nil
|
73
|
-
expect(person.updater_id).to be_nil
|
74
|
-
expect(person.creator).to be_nil
|
75
|
-
expect(person.updater).to be_nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when the stamper is an ID' do
|
82
|
-
it 'sets using the the association ID' do
|
83
|
-
User.stamper = @zeus.id
|
84
|
-
expect(User.stamper).to eq(@zeus.id)
|
85
|
-
|
86
|
-
person = Person.new
|
87
|
-
expect(person).to receive(:creator_id=)
|
88
|
-
person.valid?
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'sets the correct creator and updater' do
|
92
|
-
User.stamper = @hera.id
|
93
|
-
expect(User.stamper).to eq(@hera.id)
|
94
|
-
|
95
|
-
person = Person.create(name: 'Daniel')
|
96
|
-
expect(person.creator_id).to eq(@hera.id)
|
97
|
-
expect(person.updater_id).to eq(@hera.id)
|
98
|
-
expect(person.creator).to eq(@hera)
|
99
|
-
expect(person.updater).to eq(@hera)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'when creating a Post' do
|
105
|
-
context 'when the stamper is an object' do
|
106
|
-
it 'sets the correct creator and updater' do
|
107
|
-
expect(Person.stamper).to eq(@delynn)
|
108
|
-
|
109
|
-
post = Post.create(title: 'Test Post - 1')
|
110
|
-
expect(post.creator_id).to eq(@delynn.id)
|
111
|
-
expect(post.updater_id).to eq(@delynn.id)
|
112
|
-
expect(post.creator).to eq(@delynn)
|
113
|
-
expect(post.updater).to eq(@delynn)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context 'when the stamper is an ID' do
|
118
|
-
it 'sets the correct creator and updater' do
|
119
|
-
Person.stamper = @nicole.id
|
120
|
-
expect(Person.stamper).to eq(@nicole.id)
|
121
|
-
|
122
|
-
post = Post.create(title: 'Test Post - 2')
|
123
|
-
expect(post.creator_id).to eq(@nicole.id)
|
124
|
-
expect(post.updater_id).to eq(@nicole.id)
|
125
|
-
expect(post.creator).to eq(@nicole)
|
126
|
-
expect(post.updater).to eq(@nicole)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'when updating a Person' do
|
132
|
-
context 'when the stamper is an object' do
|
133
|
-
it 'sets the correct updater' do
|
134
|
-
User.stamper = @hera
|
135
|
-
expect(User.stamper).to eq(@hera)
|
136
|
-
|
137
|
-
@delynn.name << " Berry"
|
138
|
-
@delynn.save
|
139
|
-
@delynn.reload
|
140
|
-
expect(@delynn.creator).to eq(@zeus)
|
141
|
-
expect(@delynn.updater).to eq(@hera)
|
142
|
-
expect(@delynn.creator_id).to eq(@zeus.id)
|
143
|
-
expect(@delynn.updater_id).to eq(@hera.id)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when the stamper is an ID' do
|
148
|
-
it 'sets the correct updater' do
|
149
|
-
User.stamper = @hera.id
|
150
|
-
expect(User.stamper).to eq(@hera.id)
|
151
|
-
|
152
|
-
@delynn.name << " Berry"
|
153
|
-
@delynn.save
|
154
|
-
@delynn.reload
|
155
|
-
expect(@delynn.creator_id).to eq(@zeus.id)
|
156
|
-
expect(@delynn.updater_id).to eq(@hera.id)
|
157
|
-
expect(@delynn.creator).to eq(@zeus)
|
158
|
-
expect(@delynn.updater).to eq(@hera)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'when temporarily disabling stamping' do
|
163
|
-
it 'does not set the updater' do
|
164
|
-
User.stamper = @zeus
|
165
|
-
expect(User.stamper).to eq(@zeus)
|
166
|
-
|
167
|
-
original_updater = @delynn.updater
|
168
|
-
Person.without_stamps do
|
169
|
-
@delynn.name << " Berry"
|
170
|
-
@delynn.save
|
171
|
-
@delynn.reload
|
172
|
-
expect(@delynn.creator).to eq(@zeus)
|
173
|
-
expect(@delynn.updater).to eq(original_updater)
|
174
|
-
expect(@delynn.creator_id).to eq(@zeus.id)
|
175
|
-
expect(@delynn.updater_id).to eq(original_updater.id)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'when updating a Post' do
|
182
|
-
context 'when the stamper is an ID' do
|
183
|
-
it 'sets the correct updater' do
|
184
|
-
Person.stamper = @nicole.id
|
185
|
-
expect(Person.stamper).to eq(@nicole.id)
|
186
|
-
|
187
|
-
@first_post.title << " - Updated"
|
188
|
-
@first_post.save
|
189
|
-
@first_post.reload
|
190
|
-
expect(@first_post.creator_id).to eq(@delynn.id)
|
191
|
-
expect(@first_post.updater_id).to eq(@nicole.id)
|
192
|
-
expect(@first_post.creator).to eq(@delynn)
|
193
|
-
expect(@first_post.updater).to eq(@nicole)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'when the stamper is an object' do
|
198
|
-
it 'sets the correct updater' do
|
199
|
-
Person.stamper = @nicole
|
200
|
-
expect(Person.stamper).to eq(@nicole)
|
201
|
-
|
202
|
-
@first_post.title << " - Updated"
|
203
|
-
@first_post.save
|
204
|
-
@first_post.reload
|
205
|
-
expect(@first_post.creator_id).to eq(@delynn.id)
|
206
|
-
expect(@first_post.updater_id).to eq(@nicole.id)
|
207
|
-
expect(@first_post.creator).to eq(@delynn)
|
208
|
-
expect(@first_post.updater).to eq(@nicole)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'when destroying a Post' do
|
214
|
-
context 'when the stamper is an ID' do
|
215
|
-
it 'sets the deleter' do
|
216
|
-
expect(@first_post.deleted_at).to be_nil
|
217
|
-
|
218
|
-
Person.stamper = @nicole.id
|
219
|
-
expect(Person.stamper).to eq(@nicole.id)
|
220
|
-
|
221
|
-
@first_post.destroy
|
222
|
-
@first_post.save
|
223
|
-
@first_post.reload
|
224
|
-
|
225
|
-
expect(@first_post.deleted_at).to be_present
|
226
|
-
expect(@first_post.deleter_id).to eq(@nicole.id)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context 'when a
|
232
|
-
it '
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Stamping', type: :model do
|
4
|
+
before(:each) do
|
5
|
+
define_first_post
|
6
|
+
User.stamper = @zeus
|
7
|
+
Person.stamper = @delynn
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when creating a Person' do
|
11
|
+
context 'when the stamper is an object' do
|
12
|
+
it 'sets using the the association' do
|
13
|
+
User.stamper = @zeus
|
14
|
+
expect(User.stamper).to eq(@zeus)
|
15
|
+
|
16
|
+
person = Person.new
|
17
|
+
expect(person).to receive(:creator=)
|
18
|
+
person.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the correct creator and updater' do
|
22
|
+
expect(User.stamper).to eq(@zeus)
|
23
|
+
|
24
|
+
person = Person.create(name: 'David')
|
25
|
+
expect(person.creator_id).to eq(@zeus.id)
|
26
|
+
expect(person.updater_id).to eq(@zeus.id)
|
27
|
+
expect(person.creator).to eq(@zeus)
|
28
|
+
expect(person.updater).to eq(@zeus)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when a creator is specified' do
|
32
|
+
it 'does not reset the creator' do
|
33
|
+
expect(User.stamper).to eq(@zeus)
|
34
|
+
|
35
|
+
person = Person.create(name: 'David', creator: @hera)
|
36
|
+
expect(person.creator_id).to eq(@hera.id)
|
37
|
+
expect(person.updater_id).to eq(@zeus.id)
|
38
|
+
expect(person.creator).to eq(@hera)
|
39
|
+
expect(person.updater).to eq(@zeus)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not reset the creator' do
|
43
|
+
expect(User.stamper).to eq(@zeus)
|
44
|
+
|
45
|
+
person = Person.create(name: 'David', creator_id: @hera.id)
|
46
|
+
expect(person.creator_id).to eq(@hera.id)
|
47
|
+
expect(person.updater_id).to eq(@zeus.id)
|
48
|
+
expect(person.creator).to eq(@hera)
|
49
|
+
expect(person.updater).to eq(@zeus)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when saving without validations' do
|
54
|
+
it 'sets the correct creator and updater' do
|
55
|
+
expect(User.stamper).to eq(@zeus)
|
56
|
+
|
57
|
+
person = Person.new(name: 'David')
|
58
|
+
person.save(validate: false)
|
59
|
+
expect(person.creator_id).to eq(@zeus.id)
|
60
|
+
expect(person.updater_id).to eq(@zeus.id)
|
61
|
+
expect(person.creator).to eq(@zeus)
|
62
|
+
expect(person.updater).to eq(@zeus)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when temporarily disabling stampng' do
|
67
|
+
it 'does not set the creator and updater' do
|
68
|
+
expect(User.stamper).to eq(@zeus)
|
69
|
+
|
70
|
+
Person.without_stamps do
|
71
|
+
person = Person.create(name: 'David')
|
72
|
+
expect(person.creator_id).to be_nil
|
73
|
+
expect(person.updater_id).to be_nil
|
74
|
+
expect(person.creator).to be_nil
|
75
|
+
expect(person.updater).to be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when the stamper is an ID' do
|
82
|
+
it 'sets using the the association ID' do
|
83
|
+
User.stamper = @zeus.id
|
84
|
+
expect(User.stamper).to eq(@zeus.id)
|
85
|
+
|
86
|
+
person = Person.new
|
87
|
+
expect(person).to receive(:creator_id=)
|
88
|
+
person.valid?
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'sets the correct creator and updater' do
|
92
|
+
User.stamper = @hera.id
|
93
|
+
expect(User.stamper).to eq(@hera.id)
|
94
|
+
|
95
|
+
person = Person.create(name: 'Daniel')
|
96
|
+
expect(person.creator_id).to eq(@hera.id)
|
97
|
+
expect(person.updater_id).to eq(@hera.id)
|
98
|
+
expect(person.creator).to eq(@hera)
|
99
|
+
expect(person.updater).to eq(@hera)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when creating a Post' do
|
105
|
+
context 'when the stamper is an object' do
|
106
|
+
it 'sets the correct creator and updater' do
|
107
|
+
expect(Person.stamper).to eq(@delynn)
|
108
|
+
|
109
|
+
post = Post.create(title: 'Test Post - 1')
|
110
|
+
expect(post.creator_id).to eq(@delynn.id)
|
111
|
+
expect(post.updater_id).to eq(@delynn.id)
|
112
|
+
expect(post.creator).to eq(@delynn)
|
113
|
+
expect(post.updater).to eq(@delynn)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when the stamper is an ID' do
|
118
|
+
it 'sets the correct creator and updater' do
|
119
|
+
Person.stamper = @nicole.id
|
120
|
+
expect(Person.stamper).to eq(@nicole.id)
|
121
|
+
|
122
|
+
post = Post.create(title: 'Test Post - 2')
|
123
|
+
expect(post.creator_id).to eq(@nicole.id)
|
124
|
+
expect(post.updater_id).to eq(@nicole.id)
|
125
|
+
expect(post.creator).to eq(@nicole)
|
126
|
+
expect(post.updater).to eq(@nicole)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'when updating a Person' do
|
132
|
+
context 'when the stamper is an object' do
|
133
|
+
it 'sets the correct updater' do
|
134
|
+
User.stamper = @hera
|
135
|
+
expect(User.stamper).to eq(@hera)
|
136
|
+
|
137
|
+
@delynn.name << " Berry"
|
138
|
+
@delynn.save
|
139
|
+
@delynn.reload
|
140
|
+
expect(@delynn.creator).to eq(@zeus)
|
141
|
+
expect(@delynn.updater).to eq(@hera)
|
142
|
+
expect(@delynn.creator_id).to eq(@zeus.id)
|
143
|
+
expect(@delynn.updater_id).to eq(@hera.id)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when the stamper is an ID' do
|
148
|
+
it 'sets the correct updater' do
|
149
|
+
User.stamper = @hera.id
|
150
|
+
expect(User.stamper).to eq(@hera.id)
|
151
|
+
|
152
|
+
@delynn.name << " Berry"
|
153
|
+
@delynn.save
|
154
|
+
@delynn.reload
|
155
|
+
expect(@delynn.creator_id).to eq(@zeus.id)
|
156
|
+
expect(@delynn.updater_id).to eq(@hera.id)
|
157
|
+
expect(@delynn.creator).to eq(@zeus)
|
158
|
+
expect(@delynn.updater).to eq(@hera)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when temporarily disabling stamping' do
|
163
|
+
it 'does not set the updater' do
|
164
|
+
User.stamper = @zeus
|
165
|
+
expect(User.stamper).to eq(@zeus)
|
166
|
+
|
167
|
+
original_updater = @delynn.updater
|
168
|
+
Person.without_stamps do
|
169
|
+
@delynn.name << " Berry"
|
170
|
+
@delynn.save
|
171
|
+
@delynn.reload
|
172
|
+
expect(@delynn.creator).to eq(@zeus)
|
173
|
+
expect(@delynn.updater).to eq(original_updater)
|
174
|
+
expect(@delynn.creator_id).to eq(@zeus.id)
|
175
|
+
expect(@delynn.updater_id).to eq(original_updater.id)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when updating a Post' do
|
182
|
+
context 'when the stamper is an ID' do
|
183
|
+
it 'sets the correct updater' do
|
184
|
+
Person.stamper = @nicole.id
|
185
|
+
expect(Person.stamper).to eq(@nicole.id)
|
186
|
+
|
187
|
+
@first_post.title << " - Updated"
|
188
|
+
@first_post.save
|
189
|
+
@first_post.reload
|
190
|
+
expect(@first_post.creator_id).to eq(@delynn.id)
|
191
|
+
expect(@first_post.updater_id).to eq(@nicole.id)
|
192
|
+
expect(@first_post.creator).to eq(@delynn)
|
193
|
+
expect(@first_post.updater).to eq(@nicole)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'when the stamper is an object' do
|
198
|
+
it 'sets the correct updater' do
|
199
|
+
Person.stamper = @nicole
|
200
|
+
expect(Person.stamper).to eq(@nicole)
|
201
|
+
|
202
|
+
@first_post.title << " - Updated"
|
203
|
+
@first_post.save
|
204
|
+
@first_post.reload
|
205
|
+
expect(@first_post.creator_id).to eq(@delynn.id)
|
206
|
+
expect(@first_post.updater_id).to eq(@nicole.id)
|
207
|
+
expect(@first_post.creator).to eq(@delynn)
|
208
|
+
expect(@first_post.updater).to eq(@nicole)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'when destroying a Post' do
|
214
|
+
context 'when the stamper is an ID' do
|
215
|
+
it 'sets the deleter' do
|
216
|
+
expect(@first_post.deleted_at).to be_nil
|
217
|
+
|
218
|
+
Person.stamper = @nicole.id
|
219
|
+
expect(Person.stamper).to eq(@nicole.id)
|
220
|
+
|
221
|
+
@first_post.destroy
|
222
|
+
@first_post.save
|
223
|
+
@first_post.reload
|
224
|
+
|
225
|
+
expect(@first_post.deleted_at).to be_present
|
226
|
+
expect(@first_post.deleter_id).to eq(@nicole.id)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context 'when using a generated model' do
|
232
|
+
it 'does not query the model on the columns' do
|
233
|
+
class self.class::Post2 < Post
|
234
|
+
end
|
235
|
+
allow(self.class::Post2).to receive(:column_names).and_raise(StandardError)
|
236
|
+
|
237
|
+
class self.class::Post2
|
238
|
+
has_and_belongs_to_many :tags
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context 'when a deleter attribute is specified' do
|
244
|
+
it 'creates a deleter relation' do
|
245
|
+
expect(@first_post.respond_to?('creator')).to eq(true)
|
246
|
+
expect(@first_post.respond_to?('updater')).to eq(true)
|
247
|
+
expect(@first_post.respond_to?('deleter')).to eq(true)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|