-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathattribute_generated_spec.rb
More file actions
57 lines (51 loc) · 1.76 KB
/
attribute_generated_spec.rb
File metadata and controls
57 lines (51 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
RSpec.describe CallbackHell, "with attribute-generated callbacks and validations" do
def normalization_supported?
ActiveRecord::Base.respond_to?(:normalizes)
end
subject(:foo) { CallbackHell::Collector.new(Foo, mode: :full).collect }
subject(:bar) { CallbackHell::Collector.new(Bar, mode: :full).collect }
it "correctly marks the callbacks generated by attributes" do
skip "Normalization not supported in this Rails version" unless normalization_supported?
expect(foo).to have_callback(
callback_name: :before_validate,
method_name: :cant_modify_encrypted_attributes_when_frozen,
attribute_generated: true,
origin: :rails
)
expect(foo).to have_callback(
callback_name: :before_validation,
method_name: :normalize_changed_in_place_attributes,
attribute_generated: true,
origin: :rails
)
end
it "does not cause false positives when it comes to attribute callbacks" do
expect(foo).to have_callback(
callback_name: :after_validation,
method_name: :noop,
attribute_generated: false,
origin: :own
)
expect(foo).to have_callback(
callback_name: :after_create,
method_name: :noop,
attribute_generated: false,
origin: :own
)
end
it "correctly marks the validations generated by attributes" do
expect(foo).to have_validation(
type: :custom,
method_name: :cant_modify_encrypted_attributes_when_frozen,
attribute_generated: true,
origin: :rails
)
end
context "with mode=default" do
subject(:foo) { CallbackHell::Collector.new(Foo, mode: :default).collect }
it "has no attribute callbacks" do
expect(foo).not_to have_callback(attribute_generated: true)
end
end
end