rails_best_practices 0.7.1 → 0.7.2
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/README.md +9 -1
- data/lib/rails_best_practices.rb +2 -0
- data/lib/rails_best_practices/core.rb +3 -1
- data/lib/rails_best_practices/core/check.rb +1 -1
- data/lib/rails_best_practices/core/model_associations.rb +25 -0
- data/lib/rails_best_practices/core/models.rb +7 -0
- data/lib/rails_best_practices/core/nil.rb +15 -0
- data/lib/rails_best_practices/core/runner.rb +17 -0
- data/lib/rails_best_practices/core/visitable_sexp.rb +12 -0
- data/lib/rails_best_practices/prepares.rb +1 -1
- data/lib/rails_best_practices/prepares/model_prepare.rb +15 -9
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -3
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +2 -1
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -4
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +1 -1
- data/lib/rails_best_practices/reviews/review.rb +11 -0
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +6 -1
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +11 -10
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +6 -2
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +6 -6
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.yml +1 -1
- data/spec/rails_best_practices/core/check_spec.rb +1 -1
- data/spec/rails_best_practices/core/model_associations_spec.rb +22 -0
- data/spec/rails_best_practices/core/models_spec.rb +5 -0
- data/spec/rails_best_practices/core/nil_spec.rb +17 -0
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +50 -4
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +18 -1
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +134 -154
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +14 -0
- data/spec/rails_best_practices_spec.rb +1 -0
- metadata +13 -7
- data/lib/rails_best_practices/core_ext/nil_class.rb +0 -8
- data/spec/rails_best_practices/core_ext/nil_class_spec.rb +0 -11
data/README.md
CHANGED
@@ -98,7 +98,7 @@ Now you can customize this configuration file, the default configuration is as f
|
|
98
98
|
UseObserverCheck: { }
|
99
99
|
IsolateSeedDataCheck: { }
|
100
100
|
AlwaysAddDbIndexCheck: { }
|
101
|
-
UseBeforeFilterCheck: { }
|
101
|
+
UseBeforeFilterCheck: { customize_count: 1 }
|
102
102
|
MoveCodeIntoControllerCheck: { }
|
103
103
|
MoveCodeIntoModelCheck: { use_count: 2 }
|
104
104
|
MoveCodeIntoHelperCheck: { array_count: 3 }
|
@@ -165,6 +165,11 @@ Other
|
|
165
165
|
|
166
166
|
1. Remove Trailing Whitespace
|
167
167
|
|
168
|
+
Write Your Own Check List
|
169
|
+
-------------------------
|
170
|
+
|
171
|
+
If you want to write your own check list (some check list only for your rails projects), please read this first, [How to write your own check list?][1]
|
172
|
+
|
168
173
|
Contribute
|
169
174
|
----------
|
170
175
|
|
@@ -181,3 +186,6 @@ Send us email: <team@rails-bestpractices.com>
|
|
181
186
|
|
182
187
|
|
183
188
|
Copyright © 2009 - 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license
|
189
|
+
|
190
|
+
|
191
|
+
[1]:https://github.com/flyerhzm/rails_best_practices/wiki/How-to-write-your-own-check-list
|
data/lib/rails_best_practices.rb
CHANGED
@@ -3,7 +3,9 @@ require 'rails_best_practices/core/check'
|
|
3
3
|
require 'rails_best_practices/core/runner'
|
4
4
|
require 'rails_best_practices/core/checking_visitor'
|
5
5
|
require 'rails_best_practices/core/error'
|
6
|
+
require 'rails_best_practices/core/nil'
|
6
7
|
require 'rails_best_practices/core/visitable_sexp'
|
8
|
+
require 'rails_best_practices/core/models'
|
9
|
+
require 'rails_best_practices/core/model_associations'
|
7
10
|
|
8
11
|
require 'rails_best_practices/core_ext/enumerable'
|
9
|
-
require 'rails_best_practices/core_ext/nil_class'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module RailsBestPractices
|
3
|
+
module Core
|
4
|
+
class ModelAssociations
|
5
|
+
def initialize
|
6
|
+
@associations = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_association(model_name, association_name, association_meta, association_class=nil)
|
10
|
+
@associations[model_name] ||= {}
|
11
|
+
@associations[model_name][association_name] = {:meta => association_meta, :class_name => association_class || association_name.classify}
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_association(model_name, association_name)
|
15
|
+
associations = @associations[model_name]
|
16
|
+
associations and associations[association_name]
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_association?(model_name, association_name)
|
20
|
+
associations = @associations[model_name]
|
21
|
+
associations && associations[association_name]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -44,6 +44,8 @@ module RailsBestPractices
|
|
44
44
|
@prepares = prepares.empty? ? load_prepares : prepares
|
45
45
|
@reviews = reviews.empty? ? load_reviews : reviews
|
46
46
|
|
47
|
+
load_plugin_reviews
|
48
|
+
|
47
49
|
@checker ||= CheckingVisitor.new(:prepares => @prepares, :reviews => @reviews, :lexicals => @lexicals)
|
48
50
|
@debug = false
|
49
51
|
end
|
@@ -161,6 +163,21 @@ module RailsBestPractices
|
|
161
163
|
}
|
162
164
|
end
|
163
165
|
|
166
|
+
# load all plugin reviews.
|
167
|
+
def load_plugin_reviews
|
168
|
+
begin
|
169
|
+
plugins = "lib/rails_best_practices/plugins/reviews"
|
170
|
+
if File.directory?(plugins)
|
171
|
+
Dir[File.expand_path(File.join(plugins, "*.rb"))].each do |review|
|
172
|
+
require review
|
173
|
+
end
|
174
|
+
RailsBestPractices::Plugins::Reviews.constants.each do |review|
|
175
|
+
@reviews << RailsBestPractices::Plugins::Reviews.const_get(review).new
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
164
181
|
# read the checks from yaml config.
|
165
182
|
def checks_from_config
|
166
183
|
@checks ||= YAML.load_file @config
|
@@ -427,4 +427,16 @@ class Sexp
|
|
427
427
|
""
|
428
428
|
end
|
429
429
|
end
|
430
|
+
|
431
|
+
# if the return value of these methods is nil, then return RailsBestPractices::Core::Nil.new instead
|
432
|
+
[:node_type, :subject, :message, :arguments, :class_name, :base_class, :method_name, :body, :conditional_statement, :true_node, :false_node, :left_value, :right_value].each do |method|
|
433
|
+
class_eval <<-EOS
|
434
|
+
alias_method :origin_#{method}, :#{method}
|
435
|
+
|
436
|
+
def #{method}
|
437
|
+
ret = origin_#{method}
|
438
|
+
ret.nil? ? RailsBestPractices::Core::Nil.new : ret
|
439
|
+
end
|
440
|
+
EOS
|
441
|
+
end
|
430
442
|
end
|
@@ -15,17 +15,20 @@ module RailsBestPractices
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
@
|
18
|
+
@models = Core::Models.new
|
19
|
+
@model_associations = Core::ModelAssociations.new
|
19
20
|
end
|
20
21
|
|
21
22
|
# check class node to remember the last class name.
|
22
23
|
def start_class(class_node)
|
23
24
|
@last_klazz = class_node.class_name.to_s
|
25
|
+
@models << @last_klazz
|
24
26
|
end
|
25
27
|
|
26
|
-
# assign @
|
28
|
+
# assign @model_associations to Prepare.model_associations.
|
27
29
|
def end_class(class_node)
|
28
|
-
Prepares.
|
30
|
+
Prepares.models = @models
|
31
|
+
Prepares.model_associations = @model_associations
|
29
32
|
end
|
30
33
|
|
31
34
|
# check call node to remember all assoications.
|
@@ -33,10 +36,10 @@ module RailsBestPractices
|
|
33
36
|
# the remembered association names (@associations) are like
|
34
37
|
# {
|
35
38
|
# :Project=>{
|
36
|
-
# "categories"
|
37
|
-
# "project_manager"
|
38
|
-
# "portfolio"
|
39
|
-
# "milestones
|
39
|
+
# "categories" => {:has_and_belongs_to_many => "Category"},
|
40
|
+
# "project_manager" => {:has_one => "ProjectManager"},
|
41
|
+
# "portfolio" => {:belongs_to => "Portfolio"},
|
42
|
+
# "milestones => {:has_many" => "Milestone"}
|
40
43
|
# }
|
41
44
|
# }
|
42
45
|
def start_call(node)
|
@@ -47,8 +50,11 @@ module RailsBestPractices
|
|
47
50
|
def remember_association(association_node)
|
48
51
|
association_meta = association_node.message
|
49
52
|
association_name = association_node.arguments[1].to_s
|
50
|
-
|
51
|
-
|
53
|
+
if association_node.arguments[2] && :hash == association_node.arguments[2].node_type
|
54
|
+
association_options = eval(association_node.arguments[2].to_s)
|
55
|
+
association_class = association_options["class_name"]
|
56
|
+
end
|
57
|
+
@model_associations.add_association(@last_klazz, association_name, association_meta, association_class)
|
52
58
|
end
|
53
59
|
|
54
60
|
# default rails association methods.
|
@@ -94,8 +94,7 @@ module RailsBestPractices
|
|
94
94
|
subject = node.subject
|
95
95
|
arguments_node = node.arguments.grep_node(:message => :[])
|
96
96
|
return if subject.nil? or arguments_node.nil?
|
97
|
-
|
98
|
-
@attrasgns[subject] << {:message => node.message, :arguments => arguments_node}
|
97
|
+
attrasgns(subject) << {:message => node.message, :arguments => arguments_node}
|
99
98
|
end
|
100
99
|
|
101
100
|
# check a call node with message :save or :save!,
|
@@ -123,7 +122,7 @@ module RailsBestPractices
|
|
123
122
|
def call_assignment(node)
|
124
123
|
if [:save, :save!].include? node.message
|
125
124
|
subject = node.subject
|
126
|
-
add_error "add model virtual attribute (for #{subject})" if params_dup?(
|
125
|
+
add_error "add model virtual attribute (for #{subject})" if params_dup?(attrasgns(subject).collect {|h| h[:arguments]})
|
127
126
|
end
|
128
127
|
end
|
129
128
|
|
@@ -132,6 +131,11 @@ module RailsBestPractices
|
|
132
131
|
return false if nodes.nil?
|
133
132
|
!nodes.dups.empty?
|
134
133
|
end
|
134
|
+
|
135
|
+
# get the attrasgns of subject, or empty array.
|
136
|
+
def attrasgns(subject)
|
137
|
+
@attrasgns[subject] ||= []
|
138
|
+
end
|
135
139
|
end
|
136
140
|
end
|
137
141
|
end
|
@@ -63,7 +63,8 @@ module RailsBestPractices
|
|
63
63
|
# and the message of subject of the call node is :user
|
64
64
|
def need_delegate?(node)
|
65
65
|
class_name = node.subject.subject.to_s(:remove_at => true).classify
|
66
|
-
|
66
|
+
association = model_associations.get_association(class_name, node.subject.message.to_s)
|
67
|
+
association && association_methods.include?(association[:meta])
|
67
68
|
end
|
68
69
|
|
69
70
|
# only check belongs_to and has_one association.
|
@@ -114,7 +114,7 @@ module RailsBestPractices
|
|
114
114
|
def recursively_check(node)
|
115
115
|
if :iter == node.node_type && :resources == node.subject.message
|
116
116
|
options = eval(node.subject.arguments[2].to_s)
|
117
|
-
return if options["shallow"] == true
|
117
|
+
return if options && options["shallow"] == true
|
118
118
|
@counter += 1
|
119
119
|
recursively_check(node.body)
|
120
120
|
@counter -= 1
|
@@ -127,9 +127,10 @@ module RailsBestPractices
|
|
127
127
|
if :resources == node.message
|
128
128
|
hash_node = node.arguments[2]
|
129
129
|
if hash_node
|
130
|
-
(hash_node.grep_nodes_count(:node_type => :lit) - hash_node.grep_nodes_count(:node_type => :hash)) / 2
|
130
|
+
return (hash_node.grep_nodes_count(:node_type => :lit) - hash_node.grep_nodes_count(:node_type => :hash)) / 2
|
131
131
|
end
|
132
132
|
end
|
133
|
+
0
|
133
134
|
end
|
134
135
|
|
135
136
|
# check iter node to calculate the count of member and collection custom routes.
|
@@ -160,9 +161,7 @@ module RailsBestPractices
|
|
160
161
|
# )
|
161
162
|
# )
|
162
163
|
def member_and_collection_count_for_rails3(node)
|
163
|
-
|
164
|
-
node.grep_nodes_count(:node_type => :call, :message => VERBS)
|
165
|
-
end
|
164
|
+
:resources == node.subject.message ? node.grep_nodes_count(:node_type => :call, :message => VERBS) : 0
|
166
165
|
end
|
167
166
|
end
|
168
167
|
end
|
data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb
CHANGED
@@ -60,7 +60,7 @@ module RailsBestPractices
|
|
60
60
|
def check_variable_save(node)
|
61
61
|
if [:save, :save!].include? node.message
|
62
62
|
variable = node.subject
|
63
|
-
if variable_use_count[variable] > @attrasgn_count
|
63
|
+
if variable_use_count[variable].to_i > @attrasgn_count
|
64
64
|
add_error "replace complex creation with factory method (#{variable} attribute_assignment_count > #{@attrasgn_count})"
|
65
65
|
end
|
66
66
|
end
|
@@ -6,6 +6,10 @@ module RailsBestPractices
|
|
6
6
|
module Reviews
|
7
7
|
# A Review class that takes charge of reviewing one rails best practice.
|
8
8
|
class Review < Core::Check
|
9
|
+
# default url.
|
10
|
+
def url
|
11
|
+
"#"
|
12
|
+
end
|
9
13
|
# remember use count for the local or instance variable in the call or attrasgn node.
|
10
14
|
#
|
11
15
|
# find the local variable or instance variable in the call or attrasgn node,
|
@@ -56,6 +60,13 @@ module RailsBestPractices
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
63
|
+
# get the models from Prepares.
|
64
|
+
#
|
65
|
+
# @return [Array]
|
66
|
+
def models
|
67
|
+
@models ||= Prepares.models
|
68
|
+
end
|
69
|
+
|
59
70
|
# get the model associations from Prepares.
|
60
71
|
#
|
61
72
|
# @return [Hash]
|
@@ -28,6 +28,11 @@ module RailsBestPractices
|
|
28
28
|
CONTROLLER_FILES
|
29
29
|
end
|
30
30
|
|
31
|
+
def initialize(options = {})
|
32
|
+
super()
|
33
|
+
@customize_count = options['customize_count'] || 1
|
34
|
+
end
|
35
|
+
|
31
36
|
# check class define node to see if there are method define nodes whose first code line are duplicated.
|
32
37
|
#
|
33
38
|
# it will check every defn nodes in the class node until protected or private identification,
|
@@ -79,7 +84,7 @@ module RailsBestPractices
|
|
79
84
|
remember_first_sentence(child_node) if :defn == child_node.node_type
|
80
85
|
end
|
81
86
|
@first_sentences.each do |first_sentence, defn_nodes|
|
82
|
-
if defn_nodes.size >
|
87
|
+
if defn_nodes.size > @customize_count
|
83
88
|
add_error "use before_filter for #{defn_nodes.collect(&:method_name).join(',')}", class_node.file, defn_nodes.collect(&:line).join(',')
|
84
89
|
end
|
85
90
|
end
|
data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb
CHANGED
@@ -35,26 +35,27 @@ module RailsBestPractices
|
|
35
35
|
def start_defn(node)
|
36
36
|
name = node.method_name
|
37
37
|
return unless deliver_method?(name)
|
38
|
-
if
|
38
|
+
if rails2_canonical_mailer_views?(name) || rails3_canonical_mailer_views?(name)
|
39
39
|
add_error("use multipart/alternative as content_type of email")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
|
-
# check if rails2's syntax mailer views
|
44
|
+
# check if rails2's syntax mailer views are canonical.
|
45
|
+
#
|
45
46
|
# @param [String] name method name in action_mailer
|
46
|
-
def
|
47
|
-
(exist?("#{name}.text.
|
48
|
-
(exist?("#{name}.text.
|
49
|
-
(exist?("#{name}.text.
|
47
|
+
def rails2_canonical_mailer_views?(name)
|
48
|
+
(exist?("#{name}.text.html.erb") && !exist?("#{name}.text.plain.erb")) ||
|
49
|
+
(exist?("#{name}.text.html.haml") && !exist?("#{name}.text.plain.haml")) ||
|
50
|
+
(exist?("#{name}.text.html.rhtml") && !exist?("#{name}.text.plain.rhtml"))
|
50
51
|
end
|
51
52
|
|
52
|
-
# check if rails3's syntax mailer views
|
53
|
+
# check if rails3's syntax mailer views are canonical.
|
53
54
|
#
|
54
55
|
# @param [String] name method name in action_mailer
|
55
|
-
def
|
56
|
-
(exist?("#{name}.
|
57
|
-
(exist?("#{name}.
|
56
|
+
def rails3_canonical_mailer_views?(name)
|
57
|
+
(exist?("#{name}.html.erb") && !exist?("#{name}.text.erb")) ||
|
58
|
+
(exist?("#{name}.html.haml") && !exist?("#{name}.text.haml"))
|
58
59
|
end
|
59
60
|
|
60
61
|
# check if the filename existed in the mailer directory.
|
@@ -85,10 +85,14 @@ module RailsBestPractices
|
|
85
85
|
!pluralize?(message.to_s) && (QUERY_METHODS.include?(node.message) || compare_with_empty_string?(node))
|
86
86
|
end
|
87
87
|
|
88
|
+
# check if the subject is one of the models.
|
89
|
+
#
|
90
|
+
# subject, subject of call node, like
|
91
|
+
# s(:ivar, @user)
|
88
92
|
def is_model?(subject)
|
89
93
|
return false if :const == subject.node_type
|
90
94
|
class_name = subject.to_s(:remove_at => true).classify
|
91
|
-
|
95
|
+
models.include?(class_name)
|
92
96
|
end
|
93
97
|
|
94
98
|
# check if the subject and message is one of the model's aassociation.
|
@@ -101,7 +105,7 @@ module RailsBestPractices
|
|
101
105
|
# :login
|
102
106
|
def model_association?(subject, message)
|
103
107
|
class_name = subject.to_s(:remove_at => true).classify
|
104
|
-
|
108
|
+
model_associations.is_association?(class_name, message.to_s)
|
105
109
|
end
|
106
110
|
|
107
111
|
|
@@ -17,7 +17,7 @@ module RailsBestPractices
|
|
17
17
|
class UseSayWithTimeInMigrationsReview < Review
|
18
18
|
|
19
19
|
DEFAULT_MIGRATION_METHODS = [:add_column, :add_index, :add_timestamps, :change_column, :change_column_default, :change_table, :create_table, :drop_table, :remove_column, :remove_index, :remove_timestamps, :rename_column, :rename_index, :rename_table]
|
20
|
-
WITH_SAY_METHODS =
|
20
|
+
WITH_SAY_METHODS = [:say, :say_with_time]
|
21
21
|
|
22
22
|
def url
|
23
23
|
"http://rails-bestpractices.com/posts/46-use-say-and-say_with_time-in-migrations-to-make-a-useful-migration-log"
|
@@ -67,11 +67,11 @@ module RailsBestPractices
|
|
67
67
|
def start_defs(node)
|
68
68
|
block_node = node.grep_node(:node_type => :block)
|
69
69
|
block_node.children.each do |child_node|
|
70
|
-
if :iter
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
next if :iter != child_node.node_type || child_node.grep_nodes_count(:node_type => :call, :message => WITH_SAY_METHODS) > 0
|
71
|
+
|
72
|
+
subject_node = child_node.subject
|
73
|
+
if :call == subject_node.node_type && !DEFAULT_MIGRATION_METHODS.include?(subject_node.message)
|
74
|
+
add_error("use say with time in migrations", subject_node.file, subject_node.line)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/rails_best_practices.yml
CHANGED
@@ -12,7 +12,7 @@ LawOfDemeterCheck: { }
|
|
12
12
|
UseObserverCheck: { }
|
13
13
|
IsolateSeedDataCheck: { }
|
14
14
|
AlwaysAddDbIndexCheck: { }
|
15
|
-
UseBeforeFilterCheck: { }
|
15
|
+
UseBeforeFilterCheck: { customize_count: 1 }
|
16
16
|
MoveCodeIntoControllerCheck: { }
|
17
17
|
MoveCodeIntoModelCheck: { use_count: 2 }
|
18
18
|
MoveCodeIntoHelperCheck: { array_count: 3 }
|
@@ -4,7 +4,7 @@ describe RailsBestPractices::Core::Check do
|
|
4
4
|
let(:check) { RailsBestPractices::Core::Check.new }
|
5
5
|
|
6
6
|
it "should get empty interesting nodes" do
|
7
|
-
check.interesting_nodes.should ==
|
7
|
+
check.interesting_nodes.should == RailsBestPractices::Core::Check::NODE_TYPES
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should match all files of interesting files" do
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsBestPractices::Core::ModelAssociations do
|
4
|
+
let(:model_associations) { RailsBestPractices::Core::ModelAssociations.new }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
model_associations.add_association("Project", "project_manager", :belongs_to)
|
8
|
+
model_associations.add_association("Project", "people", :has_many, "Person")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should get model associations" do
|
12
|
+
model_associations.get_association("Project", "project_manager").should == {:meta => :belongs_to, :class_name => "ProjectManager"}
|
13
|
+
model_associations.get_association("Project", "people").should == {:meta => :has_many, :class_name => "Person"}
|
14
|
+
model_associations.get_association("Project", "unknown").should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should check is model associatiosn" do
|
18
|
+
model_associations.get_association("Project", "project_manager").should be_true
|
19
|
+
model_associations.get_association("Project", "people").should be_true
|
20
|
+
model_associations.get_association("Project", "unknown").should be_false
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsBestPractices::Core::Nil do
|
4
|
+
let(:core_nil) { RailsBestPractices::Core::Nil.new }
|
5
|
+
|
6
|
+
context "to_s" do
|
7
|
+
it "should return self" do
|
8
|
+
core_nil.to_s.should == core_nil
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "method_missing" do
|
13
|
+
it "should return self" do
|
14
|
+
core_nil.undefined.should == core_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -14,9 +14,55 @@ describe RailsBestPractices::Prepares::ModelPrepare do
|
|
14
14
|
EOF
|
15
15
|
runner.prepare('app/models/project.rb', content)
|
16
16
|
model_associations = RailsBestPractices::Prepares.model_associations
|
17
|
-
model_associations
|
18
|
-
model_associations
|
19
|
-
model_associations
|
20
|
-
model_associations
|
17
|
+
model_associations.get_association("Project", "portfolio").should == {:meta => :belongs_to, :class_name => "Portfolio"}
|
18
|
+
model_associations.get_association("Project", "project_manager").should == {:meta => :has_one, :class_name => "ProjectManager"}
|
19
|
+
model_associations.get_association("Project", "milestones").should == {:meta => :has_many, :class_name => "Milestone"}
|
20
|
+
model_associations.get_association("Project", "categories").should == {:meta => :has_and_belongs_to_many, :class_name => "Category"}
|
21
|
+
end
|
22
|
+
|
23
|
+
context "class_name" do
|
24
|
+
it "should parse belongs_to" do
|
25
|
+
content =<<-EOF
|
26
|
+
class Post < ActiveRecord::Base
|
27
|
+
belongs_to :author, :class_name => "Person"
|
28
|
+
end
|
29
|
+
EOF
|
30
|
+
runner.prepare("app/models/post.rb", content)
|
31
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
32
|
+
model_associations.get_association("Post", "author").should == {:meta => :belongs_to, :class_name => "Person"}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should parse has_one" do
|
36
|
+
content =<<-EOF
|
37
|
+
class Project < ActiveRecord::Base
|
38
|
+
has_one :project_manager, :class_name => "Person"
|
39
|
+
end
|
40
|
+
EOF
|
41
|
+
runner.prepare("app/models/post.rb", content)
|
42
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
43
|
+
model_associations.get_association("Project", "project_manager").should == {:meta => :has_one, :class_name => "Person"}
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should parse has_many" do
|
47
|
+
content =<<-EOF
|
48
|
+
class Project < ActiveRecord::Base
|
49
|
+
has_many :people, :class_name => "Person"
|
50
|
+
end
|
51
|
+
EOF
|
52
|
+
runner.prepare("app/models/project.rb", content)
|
53
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
54
|
+
model_associations.get_association("Project", "people").should == {:meta => :has_many, :class_name => "Person"}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should parse has_and_belongs_to_many" do
|
58
|
+
content =<<-EOF
|
59
|
+
class Citizen < ActiveRecord::Base
|
60
|
+
has_and_belongs_to_many :nations, :class_name => "Country"
|
61
|
+
end
|
62
|
+
EOF
|
63
|
+
runner.prepare("app/models/citizen.rb", content)
|
64
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
65
|
+
model_associations.get_association("Citizen", "nations").should == {:meta => :has_and_belongs_to_many, :class_name => "Country"}
|
66
|
+
end
|
21
67
|
end
|
22
68
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RailsBestPractices::Reviews::UseBeforeFilterReview do
|
4
|
-
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseBeforeFilterReview.new) }
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseBeforeFilterReview.new('customize_count' => 2)) }
|
5
5
|
|
6
6
|
it "should use before_filter" do
|
7
7
|
content = <<-EOF
|
@@ -32,6 +32,23 @@ describe RailsBestPractices::Reviews::UseBeforeFilterReview do
|
|
32
32
|
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3,7,11,16 - use before_filter for show,edit,update,destroy"
|
33
33
|
end
|
34
34
|
|
35
|
+
it "should not use before_filter when equal to customize count" do
|
36
|
+
content = <<-EOF
|
37
|
+
class PostsController < ApplicationController
|
38
|
+
|
39
|
+
def show
|
40
|
+
@post = Post.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
def edit
|
44
|
+
@post = Post.find(params[:id])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
EOF
|
48
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
49
|
+
runner.should have(0).errors
|
50
|
+
end
|
51
|
+
|
35
52
|
it "should not use before_filter" do
|
36
53
|
content = <<-EOF
|
37
54
|
class PostsController < ApplicationController
|
@@ -3,108 +3,102 @@ require 'spec_helper'
|
|
3
3
|
describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmailReview do
|
4
4
|
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
|
5
5
|
|
6
|
+
before :each do
|
7
|
+
RailsBestPractices::Core::Runner.stub!(:base_path).and_return(".")
|
8
|
+
end
|
9
|
+
|
10
|
+
def mock_email_files(entry_files, options={})
|
11
|
+
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(entry_files)
|
12
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(options["text.plain.erb"] || false)
|
13
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(options["text.html.erb"] || false)
|
14
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(options["text.erb"] || false)
|
15
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(options["html.erb"] || false)
|
16
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(options["text.plain.haml"] || false)
|
17
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(options["text.html.haml"] || false)
|
18
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(options["text.haml"] || false)
|
19
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(options["html.haml"] || false)
|
20
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(options["text.plain.rhtml"] || false)
|
21
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(options["text.html.rhtml"] || false)
|
22
|
+
end
|
23
|
+
|
6
24
|
context "rails2" do
|
7
|
-
|
8
|
-
|
9
|
-
|
25
|
+
context "project_mailer" do
|
26
|
+
let(:content) {
|
27
|
+
<<-EOF
|
28
|
+
class ProjectMailer < ActionMailer::Base
|
29
|
+
def send_email(email)
|
30
|
+
subject email.subject
|
31
|
+
from email.from
|
32
|
+
recipients email.recipients
|
33
|
+
sent_on Time.now
|
34
|
+
body :email => email
|
35
|
+
end
|
36
|
+
end
|
37
|
+
EOF
|
38
|
+
}
|
10
39
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
recipients email.recipients
|
18
|
-
sent_on Time.now
|
19
|
-
body :email => email
|
40
|
+
context "erb" do
|
41
|
+
it "should use mulipart/alternative as content_type of email" do
|
42
|
+
mock_email_files(["send_email.text.html.erb"], "text.html.erb" => true)
|
43
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
44
|
+
runner.should have(1).errors
|
45
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
20
46
|
end
|
21
|
-
end
|
22
|
-
EOF
|
23
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
24
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
25
|
-
runner.should have(1).errors
|
26
|
-
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
27
|
-
end
|
28
47
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
48
|
+
it "should not use multipart/alternative as content_type of email" do
|
49
|
+
mock_email_files(["send_email.text.html.erb"], "text.plain.erb" => true, "text.html.erb" => true)
|
50
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
51
|
+
runner.should have(0).errors
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
55
|
+
mock_email_files(["send_email.text.plain.erb"], "text.plain.erb" => true)
|
56
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
57
|
+
runner.should have(0).errors
|
38
58
|
end
|
39
59
|
end
|
40
|
-
EOF
|
41
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
42
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(true)
|
43
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(true)
|
44
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(false)
|
45
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(false)
|
46
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(false)
|
47
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(false)
|
48
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(false)
|
49
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(false)
|
50
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(false)
|
51
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(false)
|
52
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
53
|
-
runner.should have(0).errors
|
54
|
-
end
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
context "haml" do
|
62
|
+
it "should use mulipart/alternative as content_type of email" do
|
63
|
+
mock_email_files(["send_email.text.html.haml"], "text.html.haml" => true)
|
64
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
65
|
+
runner.should have(1).errors
|
66
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not use multipart/alternative as content_type of email" do
|
70
|
+
mock_email_files(["send_email.text.html.haml"], "text.plain.haml" => true, "text.html.haml" => true)
|
71
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
72
|
+
runner.should have(0).errors
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
76
|
+
mock_email_files(["send_email.text.plain.haml"], "text.plain.haml" => true)
|
77
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
78
|
+
runner.should have(0).errors
|
65
79
|
end
|
66
80
|
end
|
67
|
-
EOF
|
68
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
69
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(false)
|
70
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(false)
|
71
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(false)
|
72
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(false)
|
73
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(true)
|
74
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(true)
|
75
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(false)
|
76
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(false)
|
77
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(false)
|
78
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(false)
|
79
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
80
|
-
runner.should have(0).errors
|
81
|
-
end
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
82
|
+
context "rhtml" do
|
83
|
+
it "should use mulipart/alternative as content_type of email" do
|
84
|
+
mock_email_files(["send_email.text.html.rhtml"], "text.html.rhtml" => true)
|
85
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
86
|
+
runner.should have(1).errors
|
87
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not use multipart/alternative as content_type of email" do
|
91
|
+
mock_email_files(["send_email.text.html.rhtml"], "text.plain.rhtml" => true, "text.html.rhtml" => true)
|
92
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
93
|
+
runner.should have(0).errors
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
97
|
+
mock_email_files(["send_email.text.plain.rhtml"], "text.plain.rhtml" => true)
|
98
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
99
|
+
runner.should have(0).errors
|
92
100
|
end
|
93
101
|
end
|
94
|
-
EOF
|
95
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
96
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(false)
|
97
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(false)
|
98
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(false)
|
99
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(false)
|
100
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(false)
|
101
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(false)
|
102
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(false)
|
103
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(false)
|
104
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(true)
|
105
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(true)
|
106
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
107
|
-
runner.should have(0).errors
|
108
102
|
end
|
109
103
|
|
110
104
|
it "should not use mulipart/alternative as content_type of email for non deliver method" do
|
@@ -114,83 +108,69 @@ describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmai
|
|
114
108
|
end
|
115
109
|
end
|
116
110
|
EOF
|
117
|
-
|
111
|
+
mock_email_files(["send_email.text.html.erb"])
|
118
112
|
runner.review('app/mailers/project_mailer.rb', content)
|
119
113
|
runner.should have(0).errors
|
120
114
|
end
|
121
115
|
end
|
122
116
|
|
123
117
|
context "rails3" do
|
124
|
-
|
125
|
-
content
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
118
|
+
context "project_mailer" do
|
119
|
+
let(:content) {
|
120
|
+
<<-EOF
|
121
|
+
class ProjectMailer < ActionMailer::Base
|
122
|
+
def send_email(email)
|
123
|
+
subject email.subject
|
124
|
+
from email.from
|
125
|
+
recipients email.recipients
|
126
|
+
sent_on Time.now
|
127
|
+
body :email => email
|
128
|
+
end
|
133
129
|
end
|
134
|
-
|
135
|
-
|
136
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
137
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
138
|
-
runner.should have(1).errors
|
139
|
-
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
140
|
-
end
|
130
|
+
EOF
|
131
|
+
}
|
141
132
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
133
|
+
context "erb" do
|
134
|
+
it "should use mulipart/alternative as content_type of email" do
|
135
|
+
mock_email_files(["send_email.html.erb"], "html.erb" => true)
|
136
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
137
|
+
runner.should have(1).errors
|
138
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should not use multipart/alternative as content_type of email" do
|
142
|
+
mock_email_files(["send_email.html.erb"], "text.erb" => true, "html.erb" => true)
|
143
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
144
|
+
runner.should have(0).errors
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
148
|
+
mock_email_files(["send_email.text.erb"], "text.erb" => true)
|
149
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
150
|
+
runner.should have(0).errors
|
151
151
|
end
|
152
152
|
end
|
153
|
-
EOF
|
154
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
155
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(false)
|
156
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(false)
|
157
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(true)
|
158
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(true)
|
159
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(false)
|
160
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(false)
|
161
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(false)
|
162
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(false)
|
163
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(false)
|
164
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(false)
|
165
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
166
|
-
runner.should have(0).errors
|
167
|
-
end
|
168
153
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
154
|
+
context "haml" do
|
155
|
+
it "should use mulipart/alternative as content_type of email" do
|
156
|
+
mock_email_files(["send_email.html.haml"], "html.haml" => true)
|
157
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
158
|
+
runner.should have(1).errors
|
159
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should not use multipart/alternative as content_type of email" do
|
163
|
+
mock_email_files(["send_email.html.haml"], "text.haml" => true, "html.haml" => true)
|
164
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
165
|
+
runner.should have(0).errors
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
169
|
+
mock_email_files(["send_email.text.haml"], "text.haml" => true)
|
170
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
171
|
+
runner.should have(0).errors
|
178
172
|
end
|
179
173
|
end
|
180
|
-
EOF
|
181
|
-
Dir.stub!(:entries).with("./app/views/project_mailer").and_return(["send_email.html.erb"])
|
182
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.erb").and_return(false)
|
183
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.erb").and_return(false)
|
184
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.erb").and_return(false)
|
185
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.erb").and_return(false)
|
186
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.haml").and_return(false)
|
187
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(false)
|
188
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(true)
|
189
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.haml").and_return(true)
|
190
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(false)
|
191
|
-
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(false)
|
192
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
193
|
-
runner.should have(0).errors
|
194
174
|
end
|
195
175
|
end
|
196
176
|
end
|
@@ -52,6 +52,20 @@ describe RailsBestPractices::Reviews::UseSayWithTimeInMigrationsReview do
|
|
52
52
|
runner.should have(0).errors
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should not use say with time in migrations when not first code line" do
|
56
|
+
content =<<-EOF
|
57
|
+
def self.up
|
58
|
+
User.find_each do |user|
|
59
|
+
say_with_time 'Updating user with latest data' do
|
60
|
+
user.do_time_consuming_stuff
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
EOF
|
65
|
+
runner.review('db/migrate/20101010080658_update_users.rb', content)
|
66
|
+
runner.should have(0).errors
|
67
|
+
end
|
68
|
+
|
55
69
|
it "should not use say with time when default migration message" do
|
56
70
|
content =<<-EOF
|
57
71
|
def self.up
|
@@ -33,6 +33,7 @@ describe RailsBestPractices do
|
|
33
33
|
check1.add_error "law of demeter", "app/models/user.rb", 10
|
34
34
|
check2.add_error "use query attribute", "app/models/post.rb", 100
|
35
35
|
RailsBestPractices.runner = runner
|
36
|
+
RailsBestPractices.instance_variable_set("@options", {"without-color" => false})
|
36
37
|
|
37
38
|
$origin_stdout = $stdout
|
38
39
|
$stdout = StringIO.new
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-17 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -216,10 +216,12 @@ files:
|
|
216
216
|
- lib/rails_best_practices/core/check.rb
|
217
217
|
- lib/rails_best_practices/core/checking_visitor.rb
|
218
218
|
- lib/rails_best_practices/core/error.rb
|
219
|
+
- lib/rails_best_practices/core/model_associations.rb
|
220
|
+
- lib/rails_best_practices/core/models.rb
|
221
|
+
- lib/rails_best_practices/core/nil.rb
|
219
222
|
- lib/rails_best_practices/core/runner.rb
|
220
223
|
- lib/rails_best_practices/core/visitable_sexp.rb
|
221
224
|
- lib/rails_best_practices/core_ext/enumerable.rb
|
222
|
-
- lib/rails_best_practices/core_ext/nil_class.rb
|
223
225
|
- lib/rails_best_practices/lexicals.rb
|
224
226
|
- lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
|
225
227
|
- lib/rails_best_practices/prepares.rb
|
@@ -257,9 +259,11 @@ files:
|
|
257
259
|
- spec/rails_best_practices/core/check_spec.rb
|
258
260
|
- spec/rails_best_practices/core/checking_visitor_spec.rb
|
259
261
|
- spec/rails_best_practices/core/error_spec.rb
|
262
|
+
- spec/rails_best_practices/core/model_associations_spec.rb
|
263
|
+
- spec/rails_best_practices/core/models_spec.rb
|
264
|
+
- spec/rails_best_practices/core/nil_spec.rb
|
260
265
|
- spec/rails_best_practices/core/visitable_sexp_spec.rb
|
261
266
|
- spec/rails_best_practices/core_ext/enumerable_spec.rb
|
262
|
-
- spec/rails_best_practices/core_ext/nil_class_spec.rb
|
263
267
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
264
268
|
- spec/rails_best_practices/prepares/mailer_prepare_spec.rb
|
265
269
|
- spec/rails_best_practices/prepares/model_prepare_spec.rb
|
@@ -343,9 +347,11 @@ test_files:
|
|
343
347
|
- spec/rails_best_practices/core/check_spec.rb
|
344
348
|
- spec/rails_best_practices/core/checking_visitor_spec.rb
|
345
349
|
- spec/rails_best_practices/core/error_spec.rb
|
350
|
+
- spec/rails_best_practices/core/model_associations_spec.rb
|
351
|
+
- spec/rails_best_practices/core/models_spec.rb
|
352
|
+
- spec/rails_best_practices/core/nil_spec.rb
|
346
353
|
- spec/rails_best_practices/core/visitable_sexp_spec.rb
|
347
354
|
- spec/rails_best_practices/core_ext/enumerable_spec.rb
|
348
|
-
- spec/rails_best_practices/core_ext/nil_class_spec.rb
|
349
355
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
350
356
|
- spec/rails_best_practices/prepares/mailer_prepare_spec.rb
|
351
357
|
- spec/rails_best_practices/prepares/model_prepare_spec.rb
|