arca 2.0.1 → 2.1.0
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/arca.gemspec +1 -1
- data/lib/arca/callback_analysis.rb +3 -1
- data/lib/arca/report.rb +1 -1
- data/test/fixtures/ticket.rb +5 -0
- data/test/lib/arca/callback_analysis_test.rb +6 -6
- data/test/lib/arca/collector_test.rb +9 -0
- data/test/lib/arca/model_test.rb +4 -4
- data/test/lib/arca/report_test.rb +3 -3
- data/test/test_helper.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc4f919a7e79ca23f5ea8f1c37412bc40c181289
|
4
|
+
data.tar.gz: e6299619e24d39985a7f29f9809f043770cb9a30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 071f2a40b8184eea62932bc28b8e8d11988c8c68fcb742f9406c54fa576aca6695f5706db5fdd4215c8deba572a63408de27b21baa599298a644f7afb5bfe9f9
|
7
|
+
data.tar.gz: 265d6b69cd5c21a061191b08f035c40663ffe7e2062dd30222423048d5ba580e8ee6409e33bf2e0228a3f994b1019730bedfa6b6a88bedabe52cdcfe6be65f8a
|
data/arca.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "arca"
|
3
|
-
spec.version = "2.0
|
3
|
+
spec.version = "2.1.0"
|
4
4
|
spec.date = "2015-08-07"
|
5
5
|
spec.summary = "ActiveRecord callback analyzer"
|
6
6
|
spec.description = "Arca is a callback analyzer for ActiveRecord ideally suited for digging yourself out of callback hell"
|
@@ -113,7 +113,9 @@ module Arca
|
|
113
113
|
# Public: Boolean representing whether the conditional target is located in
|
114
114
|
# the same file where the callback is defined.
|
115
115
|
def external_conditional_target?
|
116
|
-
return if conditional_target_symbol.nil?
|
116
|
+
return false if conditional_target_symbol.nil?
|
117
|
+
return false if conditional_target_symbol.is_a?(Array)
|
118
|
+
return false if [:create, :update, :destroy].include?(conditional_target_symbol)
|
117
119
|
|
118
120
|
callback_file_path != conditional_target_file_path
|
119
121
|
end
|
data/lib/arca/report.rb
CHANGED
@@ -54,7 +54,7 @@ module Arca
|
|
54
54
|
number_of_unique_conditionals(model.analyzed_callbacks_array)
|
55
55
|
end
|
56
56
|
|
57
|
-
def_delegators
|
57
|
+
def_delegators :@model, :lines_between_count, :external_callbacks_count,
|
58
58
|
:external_targets_count, :external_conditionals_count
|
59
59
|
|
60
60
|
# Public: Integer representing the possible number of permutations stemming
|
data/test/fixtures/ticket.rb
CHANGED
@@ -3,6 +3,7 @@ class Ticket < ActiveRecord::Base
|
|
3
3
|
|
4
4
|
before_save :set_title, :set_body
|
5
5
|
before_save :upcase_title, :if => :title_is_a_shout?
|
6
|
+
after_commit :update_timeline, :on => [:create, :destroy]
|
6
7
|
|
7
8
|
def set_title
|
8
9
|
self.title ||= "Ticket id #{SecureRandom.hex(2)}"
|
@@ -19,4 +20,8 @@ class Ticket < ActiveRecord::Base
|
|
19
20
|
def title_is_a_shout?
|
20
21
|
self.title.split(" ").size == 1
|
21
22
|
end
|
23
|
+
|
24
|
+
def update_timeline
|
25
|
+
puts "Updating timeline"
|
26
|
+
end
|
22
27
|
end
|
@@ -85,8 +85,8 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
85
85
|
|
86
86
|
def test_target_line_number
|
87
87
|
assert_equal 9, announce_save.target_line_number
|
88
|
-
assert_equal
|
89
|
-
assert_equal
|
88
|
+
assert_equal 8, set_title.target_line_number
|
89
|
+
assert_equal 16, upcase_title.target_line_number
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_external_target?
|
@@ -97,8 +97,8 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
97
97
|
|
98
98
|
def test_lines_to_target
|
99
99
|
assert_equal 5, announce_save.lines_to_target
|
100
|
-
assert_equal
|
101
|
-
assert_equal
|
100
|
+
assert_equal 3, set_title.lines_to_target
|
101
|
+
assert_equal 10, upcase_title.lines_to_target
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_conditional_symbol
|
@@ -122,12 +122,12 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
122
122
|
def test_conditional_target_line_number
|
123
123
|
assert_nil announce_save.conditional_target_line_number
|
124
124
|
assert_nil set_title.conditional_target_line_number
|
125
|
-
assert_equal
|
125
|
+
assert_equal 20, upcase_title.conditional_target_line_number
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_lines_to_conditional_target
|
129
129
|
assert_nil announce_save.lines_to_conditional_target
|
130
130
|
assert_nil set_title.lines_to_conditional_target
|
131
|
-
assert_equal
|
131
|
+
assert_equal 14, upcase_title.lines_to_conditional_target
|
132
132
|
end
|
133
133
|
end
|
@@ -5,6 +5,7 @@ class Arca::CollectorTest < Minitest::Test
|
|
5
5
|
callbacks = Ticket.arca_callback_data
|
6
6
|
assert_equal 1, callbacks[:after_save].size
|
7
7
|
assert_equal 4, callbacks[:before_save].size
|
8
|
+
assert_equal 1, callbacks[:after_commit].size
|
8
9
|
|
9
10
|
callback = callbacks[:after_save][0]
|
10
11
|
assert_equal :after_save, callback[:callback_symbol]
|
@@ -45,6 +46,14 @@ class Arca::CollectorTest < Minitest::Test
|
|
45
46
|
assert_equal :upcase_title, callback[:target_symbol]
|
46
47
|
assert_equal :if, callback[:conditional_symbol]
|
47
48
|
assert_equal :title_is_a_shout?, callback[:conditional_target_symbol]
|
49
|
+
|
50
|
+
callback = callbacks[:after_commit][0]
|
51
|
+
assert_equal :after_commit, callback[:callback_symbol]
|
52
|
+
assert_match "test/fixtures/ticket.rb", callback[:callback_file_path]
|
53
|
+
assert_equal 6, callback[:callback_line_number]
|
54
|
+
assert_equal :update_timeline, callback[:target_symbol]
|
55
|
+
assert_equal :on, callback[:conditional_symbol]
|
56
|
+
assert_equal [:create, :destroy], callback[:conditional_target_symbol]
|
48
57
|
end
|
49
58
|
|
50
59
|
def test_callback_is_reapplied_with_original_args
|
data/test/lib/arca/model_test.rb
CHANGED
@@ -12,7 +12,7 @@ class Arca::ModelTest < Minitest::Test
|
|
12
12
|
def test_source_location
|
13
13
|
source_location = model.source_location(:set_title)
|
14
14
|
assert_match "test/fixtures/ticket.rb", source_location[:file_path]
|
15
|
-
assert_equal
|
15
|
+
assert_equal 8, source_location[:line_number]
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_source_location_with_method_symbol_with_no_associated_method
|
@@ -33,16 +33,16 @@ class Arca::ModelTest < Minitest::Test
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_analyzed_callbacks_array
|
36
|
-
assert_equal
|
36
|
+
assert_equal 6, model.analyzed_callbacks_array.size
|
37
37
|
assert model.analyzed_callbacks_array[0].is_a?(Arca::CallbackAnalysis)
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_analyzed_callbacks_count
|
41
|
-
assert_equal
|
41
|
+
assert_equal 6, model.analyzed_callbacks_count
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_lines_between_count
|
45
|
-
assert_equal
|
45
|
+
assert_equal 6, model.lines_between_count
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_external_callbacks_count
|
@@ -14,14 +14,14 @@ class Arca::ReportTest < Minitest::Test
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def callbacks_count
|
17
|
-
assert_equal
|
17
|
+
assert_equal 5, report.callbacks_count
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_conditionals_count
|
21
|
-
assert_equal
|
21
|
+
assert_equal 2, report.conditionals_count
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_calculated_permutations
|
25
|
-
assert_equal
|
25
|
+
assert_equal 3, report.calculated_permutations
|
26
26
|
end
|
27
27
|
end
|
data/test/test_helper.rb
CHANGED