rails_best_practices 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -1
- data/README.md +21 -10
- data/lib/rails_best_practices/analyzer.rb +2 -2
- data/lib/rails_best_practices/core/check.rb +2 -2
- data/lib/rails_best_practices/core/runner.rb +14 -5
- data/lib/rails_best_practices/prepares/model_prepare.rb +4 -1
- data/lib/rails_best_practices/prepares/route_prepare.rb +1 -0
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +7 -5
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +4 -4
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +49 -1
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +13 -2
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +10 -0
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +9 -0
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +25 -0
- metadata +34 -23
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails_best_practices (1.
|
4
|
+
rails_best_practices (1.7.0)
|
5
5
|
activesupport
|
6
6
|
colored
|
7
7
|
erubis
|
@@ -36,8 +36,13 @@ GEM
|
|
36
36
|
diff-lcs (~> 1.1.2)
|
37
37
|
rspec-mocks (2.7.0)
|
38
38
|
sexp_processor (3.0.5)
|
39
|
+
slim (1.0.4)
|
40
|
+
temple (~> 0.3.4)
|
41
|
+
tilt (~> 1.3.2)
|
39
42
|
spork (0.9.0.rc9)
|
43
|
+
temple (0.3.4)
|
40
44
|
thor (0.14.6)
|
45
|
+
tilt (1.3.3)
|
41
46
|
|
42
47
|
PLATFORMS
|
43
48
|
ruby
|
@@ -53,4 +58,5 @@ DEPENDENCIES
|
|
53
58
|
rb-fsevent
|
54
59
|
ripper
|
55
60
|
rspec
|
61
|
+
slim
|
56
62
|
spork (= 0.9.0.rc9)
|
data/README.md
CHANGED
@@ -5,7 +5,17 @@ rails_best_practices
|
|
5
5
|
|
6
6
|
[![Click here to lend your support to: rails-bestpractices.com and make a donation at www.pledgie.com !](https://www.pledgie.com/campaigns/12057.png?skin_name=chrome)](http://www.pledgie.com/campaigns/12057)
|
7
7
|
|
8
|
-
rails_best_practices is a code metric tool to check the quality of rails codes.
|
8
|
+
rails_best_practices is a code metric tool to check the quality of rails codes.
|
9
|
+
|
10
|
+
rails_best_practices supports
|
11
|
+
|
12
|
+
activerecord
|
13
|
+
mongoid
|
14
|
+
mongomapper
|
15
|
+
|
16
|
+
erb
|
17
|
+
haml
|
18
|
+
slim
|
9
19
|
|
10
20
|
Usage
|
11
21
|
-----
|
@@ -22,24 +32,25 @@ By default rails_best_practices will do parse codes in vendor, spec, test and fe
|
|
22
32
|
|
23
33
|
$ rails_best_practices -h
|
24
34
|
Usage: rails_best_practices [options]
|
25
|
-
-d, --debug
|
26
|
-
--silent silent mode
|
35
|
+
-d, --debug Debug mode
|
27
36
|
-f, --format FORMAT output format
|
28
37
|
--without-color only output plain text without color
|
29
38
|
--with-textmate open file by textmate in html format
|
30
39
|
--with-mvim open file by mvim in html format
|
31
|
-
--with-
|
32
|
-
--with-git display git commit and
|
33
|
-
--
|
40
|
+
--with-hg display hg commit and username, only support html format
|
41
|
+
--with-git display git commit and username, only support html format
|
42
|
+
--template TEMPLATE customize erb template
|
43
|
+
--output-file OUTPUT_FILE output html file for the analyzing result
|
44
|
+
--silent silent mode
|
34
45
|
--vendor include vendor files
|
35
46
|
--spec include spec files
|
36
47
|
--test include test files
|
37
48
|
--features include features files
|
38
|
-
-x, --exclude PATTERNS
|
49
|
+
-x, --exclude PATTERNS Don't analyze files matching a pattern
|
39
50
|
(comma-separated regexp list)
|
40
|
-
-g, --generate
|
41
|
-
-v, --version
|
42
|
-
-h, --help
|
51
|
+
-g, --generate Generate configuration yaml
|
52
|
+
-v, --version Show this version
|
53
|
+
-h, --help Show this message
|
43
54
|
|
44
55
|
Resources
|
45
56
|
---------
|
@@ -112,12 +112,12 @@ module RailsBestPractices
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
# expand all files with extenstion rb, erb, haml
|
115
|
+
# expand all files with extenstion rb, erb, haml, slim, builder and rxml under the dirs
|
116
116
|
#
|
117
117
|
# @param [Array] dirs what directories to expand
|
118
118
|
# @return [Array] all files expanded
|
119
119
|
def expand_dirs_to_files *dirs
|
120
|
-
extensions = ['rb', 'erb', 'rake', 'rhtml', 'haml', 'builder']
|
120
|
+
extensions = ['rb', 'erb', 'rake', 'rhtml', 'haml', 'slim', 'builder', 'rxml']
|
121
121
|
|
122
122
|
dirs.flatten.map { |entry|
|
123
123
|
next unless File.exist? entry
|
@@ -8,8 +8,8 @@ module RailsBestPractices
|
|
8
8
|
MIGRATION_FILES = /db\/migrate\/.*\.rb$/
|
9
9
|
MODEL_FILES = /models\/.*\.rb$/
|
10
10
|
MAILER_FILES = /models\/.*mailer\.rb$|mailers\/.*mailer\.rb/
|
11
|
-
VIEW_FILES = /(views|cells)\/.*\.(erb|haml|builder)$/
|
12
|
-
PARTIAL_VIEW_FILES = /(views|cells)\/.*\/_.*\.(erb|haml|builder)$/
|
11
|
+
VIEW_FILES = /(views|cells)\/.*\.(erb|haml|slim|builder|rxml)$/
|
12
|
+
PARTIAL_VIEW_FILES = /(views|cells)\/.*\/_.*\.(erb|haml|slim|builder|rxml)$/
|
13
13
|
ROUTE_FILES = /config\/routes.*\.rb/
|
14
14
|
SCHEMA_FILE = /db\/schema\.rb/
|
15
15
|
HELPER_FILES = /helpers\/.*\.rb$/
|
@@ -93,7 +93,7 @@ module RailsBestPractices
|
|
93
93
|
# @param [String] content content of the file
|
94
94
|
def review(filename, content)
|
95
95
|
puts filename if @debug
|
96
|
-
content =
|
96
|
+
content = parse_html_template(filename, content)
|
97
97
|
node = parse_ruby(filename, content)
|
98
98
|
if node
|
99
99
|
node.file = filename
|
@@ -154,11 +154,11 @@ module RailsBestPractices
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
-
# parse erb
|
157
|
+
# parse html tempalte code, erb, haml and slim.
|
158
158
|
#
|
159
|
-
# @param [String] filename is the filename of the erb or
|
160
|
-
# @param [String] content is the source code of erb or
|
161
|
-
def
|
159
|
+
# @param [String] filename is the filename of the erb, haml or slim code.
|
160
|
+
# @param [String] content is the source code of erb, haml or slim file.
|
161
|
+
def parse_html_template(filename, content)
|
162
162
|
if filename =~ /.*\.erb$|.*\.rhtml$/
|
163
163
|
content = Erubis::OnlyRuby.new(content).src
|
164
164
|
elsif filename =~ /.*\.haml$/
|
@@ -172,6 +172,15 @@ module RailsBestPractices
|
|
172
172
|
rescue Haml::Error, SyntaxError
|
173
173
|
# do nothing, just ignore the wrong haml files.
|
174
174
|
end
|
175
|
+
elsif filename =~ /.*\.slim$/
|
176
|
+
begin
|
177
|
+
require 'slim'
|
178
|
+
content = Slim::Engine.new.call(content)
|
179
|
+
rescue LoadError
|
180
|
+
raise "In order to parse #{filename}, please install the slim gem"
|
181
|
+
rescue SyntaxError
|
182
|
+
# do nothing, just ignore the wrong slim files
|
183
|
+
end
|
175
184
|
end
|
176
185
|
content
|
177
186
|
end
|
@@ -11,7 +11,7 @@ module RailsBestPractices
|
|
11
11
|
interesting_nodes :class, :def, :command, :var_ref, :alias
|
12
12
|
interesting_files MODEL_FILES
|
13
13
|
|
14
|
-
ASSOCIATION_METHODS = %w(belongs_to has_one has_many has_and_belongs_to_many embeds_many embeds_one embedded_in)
|
14
|
+
ASSOCIATION_METHODS = %w(belongs_to has_one has_many has_and_belongs_to_many embeds_many embeds_one embedded_in many one)
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@models = Prepares.models
|
@@ -71,6 +71,9 @@ module RailsBestPractices
|
|
71
71
|
attribute_name = arguments.first.to_s
|
72
72
|
attribute_type = arguments.last.hash_value("type").present? ? arguments.last.hash_value("type").to_s : "String"
|
73
73
|
@model_attributes.add_attribute(current_class_name, attribute_name, attribute_type)
|
74
|
+
when "key"
|
75
|
+
attribute_name, attribute_type = node.arguments.all.map(&:to_s)
|
76
|
+
@model_attributes.add_attribute(current_class_name, attribute_name, attribute_type)
|
74
77
|
when *ASSOCIATION_METHODS
|
75
78
|
remember_association(node)
|
76
79
|
else
|
@@ -41,6 +41,7 @@ module RailsBestPractices
|
|
41
41
|
options = node.arguments.all.last
|
42
42
|
return if :string_literal == options.sexp_type
|
43
43
|
if options.hash_value("controller").present?
|
44
|
+
return if :regexp_literal == options.hash_value("controller").sexp_type
|
44
45
|
controller_name = options.hash_value("controller").to_s
|
45
46
|
action_name = options.hash_value("action").present? ? options.hash_value("action").to_s : "*"
|
46
47
|
@routes.add_route(current_namespaces, controller_name, action_name)
|
data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb
CHANGED
@@ -42,6 +42,7 @@ module RailsBestPractices
|
|
42
42
|
def rails2_canonical_mailer_views?(name)
|
43
43
|
(exist?("#{name}.text.html.erb") && !exist?("#{name}.text.plain.erb")) ||
|
44
44
|
(exist?("#{name}.text.html.haml") && !exist?("#{name}.text.plain.haml")) ||
|
45
|
+
(exist?("#{name}.text.html.slim") && !exist?("#{name}.text.plain.slim")) ||
|
45
46
|
(exist?("#{name}.text.html.rhtml") && !exist?("#{name}.text.plain.rhtml"))
|
46
47
|
end
|
47
48
|
|
@@ -49,8 +50,9 @@ module RailsBestPractices
|
|
49
50
|
#
|
50
51
|
# @param [String] name method name in action_mailer
|
51
52
|
def rails3_canonical_mailer_views?(name)
|
52
|
-
(exist?("#{name}.html.erb") && !
|
53
|
-
(exist?("#{name}.html.haml") && !
|
53
|
+
(exist?("#{name}.html.erb") && !html_tempalte_exists?("#{name}.text")) ||
|
54
|
+
(exist?("#{name}.html.haml") && !html_tempalte_exists?("#{name}.text")) ||
|
55
|
+
(exist?("#{name}.html.slim") && !html_tempalte_exists?("#{name}.text"))
|
54
56
|
end
|
55
57
|
|
56
58
|
# check if the filename existed in the mailer directory.
|
@@ -58,9 +60,9 @@ module RailsBestPractices
|
|
58
60
|
File.exist? File.join(mailer_directory, filename)
|
59
61
|
end
|
60
62
|
|
61
|
-
# check if haml or
|
62
|
-
def
|
63
|
-
exist?("#{filename}.erb") || exist?("#{filename}.haml")
|
63
|
+
# check if erb, haml or slim exists
|
64
|
+
def html_tempalte_exists?(filename)
|
65
|
+
exist?("#{filename}.erb") || exist?("#{filename}.haml") || exist?("#{filename}.slim")
|
64
66
|
end
|
65
67
|
|
66
68
|
# check if the method is a deliver_method.
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency("rake")
|
24
24
|
s.add_development_dependency("rspec")
|
25
25
|
s.add_development_dependency("haml")
|
26
|
+
s.add_development_dependency("slim")
|
26
27
|
s.add_development_dependency("bundler")
|
27
28
|
|
28
29
|
s.files = `git ls-files`.split("\n")
|
@@ -12,15 +12,15 @@ describe RailsBestPractices::Analyzer do
|
|
12
12
|
|
13
13
|
describe "file_sort" do
|
14
14
|
it "should get models first, mailers, helpers and then others" do
|
15
|
-
files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/models/user.rb", "app/views/users/index.html.haml", "lib/user.rb"]
|
16
|
-
subject.file_sort(files).should == ["app/models/user.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/controllers/users_controller.rb", "app/views/users/index.html.haml", "lib/user.rb"]
|
15
|
+
files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
|
16
|
+
subject.file_sort(files).should == ["app/models/user.rb", "app/mailers/user_mailer.rb", "app/helpers/users_helper.rb", "app/controllers/users_controller.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "file_ignore" do
|
21
21
|
it "should ignore lib" do
|
22
|
-
files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "lib/user.rb"]
|
23
|
-
subject.file_ignore(files, 'lib/').should == ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml"]
|
22
|
+
files = ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim", "lib/user.rb"]
|
23
|
+
subject.file_ignore(files, 'lib/').should == ["app/controllers/users_controller.rb", "app/mailers/user_mailer.rb", "app/models/user.rb", "app/views/users/index.html.haml", "app/views/users/show.html.slim"]
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -95,7 +95,7 @@ describe RailsBestPractices::Prepares::ModelPrepare do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
context "mongoid
|
98
|
+
context "mongoid embeds" do
|
99
99
|
it "should parse embeds_many" do
|
100
100
|
content =<<-EOF
|
101
101
|
class Person
|
@@ -132,6 +132,32 @@ describe RailsBestPractices::Prepares::ModelPrepare do
|
|
132
132
|
model_associations.get_association("Drink", "alcoholic").should == {"meta" => "embedded_in", "class_name" => "Lush"}
|
133
133
|
end
|
134
134
|
end
|
135
|
+
|
136
|
+
context "mongomapper many/one" do
|
137
|
+
it "should parse one" do
|
138
|
+
content =<<-EOF
|
139
|
+
class Employee
|
140
|
+
include MongoMapper::Document
|
141
|
+
one :desk
|
142
|
+
end
|
143
|
+
EOF
|
144
|
+
runner.prepare("app/models/employee.rb", content)
|
145
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
146
|
+
model_associations.get_association("Employee", "desk").should == {"meta" => "one", "class_name" => "Desk"}
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should parse many" do
|
150
|
+
content =<<-EOF
|
151
|
+
class Tree
|
152
|
+
include MongoMapper::Document
|
153
|
+
many :birds
|
154
|
+
end
|
155
|
+
EOF
|
156
|
+
runner.prepare("app/models/tree.rb", content)
|
157
|
+
model_associations = RailsBestPractices::Prepares.model_associations
|
158
|
+
model_associations.get_association("Tree", "birds").should == {"meta" => "many", "class_name" => "Bird"}
|
159
|
+
end
|
160
|
+
end
|
135
161
|
end
|
136
162
|
|
137
163
|
context "methods" do
|
@@ -274,6 +300,28 @@ describe RailsBestPractices::Prepares::ModelPrepare do
|
|
274
300
|
model_attributes.get_attribute_type("Post", "deleted_at").should == "DateTime"
|
275
301
|
model_attributes.get_attribute_type("Post", "active").should == "Boolean"
|
276
302
|
end
|
303
|
+
|
304
|
+
it "should parse mongomapper field" do
|
305
|
+
content =<<-EOF
|
306
|
+
class Post
|
307
|
+
include MongoMapper::Document
|
308
|
+
key :first_name, String
|
309
|
+
key :last_name, String
|
310
|
+
key :age, Integer
|
311
|
+
key :born_at, Time
|
312
|
+
key :active, Boolean
|
313
|
+
key :fav_colors, Array
|
314
|
+
end
|
315
|
+
EOF
|
316
|
+
runner.prepare("app/models/post.rb", content)
|
317
|
+
model_attributes = RailsBestPractices::Prepares.model_attributes
|
318
|
+
model_attributes.get_attribute_type("Post", "first_name").should == "String"
|
319
|
+
model_attributes.get_attribute_type("Post", "last_name").should == "String"
|
320
|
+
model_attributes.get_attribute_type("Post", "age").should == "Integer"
|
321
|
+
model_attributes.get_attribute_type("Post", "born_at").should == "Time"
|
322
|
+
model_attributes.get_attribute_type("Post", "active").should == "Boolean"
|
323
|
+
model_attributes.get_attribute_type("Post", "fav_colors").should == "Array"
|
324
|
+
end
|
277
325
|
end
|
278
326
|
|
279
327
|
context "no error" do
|
@@ -123,7 +123,7 @@ describe RailsBestPractices::Prepares::RoutePrepare do
|
|
123
123
|
routes.size.should == 14
|
124
124
|
end
|
125
125
|
|
126
|
-
it "should add
|
126
|
+
it "should add route with namespace" do
|
127
127
|
content =<<-EOF
|
128
128
|
ActionController::Routing::Routes.draw do |map|
|
129
129
|
map.namespace :admin do |admin|
|
@@ -463,7 +463,7 @@ describe RailsBestPractices::Prepares::RoutePrepare do
|
|
463
463
|
routes.size.should == 14
|
464
464
|
end
|
465
465
|
|
466
|
-
it "should add
|
466
|
+
it "should add route with namespace" do
|
467
467
|
content =<<-EOF
|
468
468
|
RailsBestPracticesCom::Application.routes.draw do
|
469
469
|
namespace :admin do
|
@@ -30,7 +30,7 @@ describe RailsBestPractices::Reviews::LawOfDemeterReview do
|
|
30
30
|
runner.prepare('db/schema.rb', content)
|
31
31
|
end
|
32
32
|
|
33
|
-
it "should law of demeter" do
|
33
|
+
it "should law of demeter with erb" do
|
34
34
|
content = <<-EOF
|
35
35
|
<%= @invoice.user.name %>
|
36
36
|
<%= @invoice.user.address %>
|
@@ -41,7 +41,7 @@ describe RailsBestPractices::Reviews::LawOfDemeterReview do
|
|
41
41
|
runner.errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should law of demeter" do
|
44
|
+
it "should law of demeter with haml" do
|
45
45
|
content = <<-EOF
|
46
46
|
= @invoice.user.name
|
47
47
|
= @invoice.user.address
|
@@ -52,6 +52,17 @@ describe RailsBestPractices::Reviews::LawOfDemeterReview do
|
|
52
52
|
runner.errors[0].to_s.should == "app/views/invoices/show.html.haml:1 - law of demeter"
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should law of demeter with slim" do
|
56
|
+
content = <<-EOF
|
57
|
+
= @invoice.user.name
|
58
|
+
= @invoice.user.address
|
59
|
+
= @invoice.user.cellphone
|
60
|
+
EOF
|
61
|
+
runner.review('app/views/invoices/show.html.slim', content)
|
62
|
+
runner.should have(3).errors
|
63
|
+
runner.errors[0].to_s.should == "app/views/invoices/show.html.slim:1 - law of demeter"
|
64
|
+
end
|
65
|
+
|
55
66
|
it "should no law of demeter" do
|
56
67
|
content = <<-EOF
|
57
68
|
<%= @invoice.user_name %>
|
@@ -24,6 +24,16 @@ describe RailsBestPractices::Reviews::MoveCodeIntoModelReview do
|
|
24
24
|
runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should move code into model with slim" do
|
28
|
+
content =<<-EOF
|
29
|
+
- if current_user && @post.user && (current_user == @post.user || @post.editors.include?(current_user))
|
30
|
+
= link_to 'Edit this post', edit_post_url(@post)
|
31
|
+
EOF
|
32
|
+
runner.review('app/views/posts/show.html.slim', content)
|
33
|
+
runner.should have(1).errors
|
34
|
+
runner.errors[0].to_s.should == "app/views/posts/show.html.slim:1 - move code into model (@post use_count > 2)"
|
35
|
+
end
|
36
|
+
|
27
37
|
it "should move code into model only review for current if conditional statement" do
|
28
38
|
content =<<-EOF
|
29
39
|
<% if @post.title %>
|
data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
CHANGED
@@ -21,6 +21,15 @@ describe RailsBestPractices::Reviews::ReplaceInstanceVariableWithLocalVariableRe
|
|
21
21
|
runner.errors[0].to_s.should == "app/views/posts/_post.html.haml:1 - replace instance variable with local variable"
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should replace instance variable with local varialbe in slim file" do
|
25
|
+
content = <<-EOF
|
26
|
+
= @post.title
|
27
|
+
EOF
|
28
|
+
runner.review('app/views/posts/_post.html.slim', content)
|
29
|
+
runner.should have(1).errors
|
30
|
+
runner.errors[0].to_s.should == "app/views/posts/_post.html.slim:1 - replace instance variable with local variable"
|
31
|
+
end
|
32
|
+
|
24
33
|
it "should not replace instance variable with local varialbe" do
|
25
34
|
content = <<-EOF
|
26
35
|
<%= post.title %>
|
@@ -17,6 +17,10 @@ describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmai
|
|
17
17
|
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.haml").and_return(options["text.html.haml"] || false)
|
18
18
|
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.haml").and_return(options["text.haml"] || false)
|
19
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.slim").and_return(options["text.plain.slim"] || false)
|
21
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.slim").and_return(options["text.html.slim"] || false)
|
22
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.slim").and_return(options["text.slim"] || false)
|
23
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.html.slim").and_return(options["html.slim"] || false)
|
20
24
|
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(options["text.plain.rhtml"] || false)
|
21
25
|
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(options["text.html.rhtml"] || false)
|
22
26
|
end
|
@@ -79,6 +83,27 @@ describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmai
|
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
86
|
+
context "slim" do
|
87
|
+
it "should use mulipart/alternative as content_type of email" do
|
88
|
+
mock_email_files(["send_email.text.html.slim"], "text.html.slim" => true)
|
89
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
90
|
+
runner.should have(1).errors
|
91
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should not use multipart/alternative as content_type of email" do
|
95
|
+
mock_email_files(["send_email.text.html.slim"], "text.plain.slim" => true, "text.html.slim" => true)
|
96
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
97
|
+
runner.should have(0).errors
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
101
|
+
mock_email_files(["send_email.text.plain.slim"], "text.plain.slim" => true)
|
102
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
103
|
+
runner.should have(0).errors
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
82
107
|
context "rhtml" do
|
83
108
|
it "should use mulipart/alternative as content_type of email" do
|
84
109
|
mock_email_files(["send_email.text.html.rhtml"], "text.html.rhtml" => true)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sexp_processor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70336822187040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70336822187040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: progressbar
|
27
|
-
requirement: &
|
27
|
+
requirement: &70336822186240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70336822186240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: colored
|
38
|
-
requirement: &
|
38
|
+
requirement: &70336822184720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70336822184720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: erubis
|
49
|
-
requirement: &
|
49
|
+
requirement: &70336822184080 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70336822184080
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: i18n
|
60
|
-
requirement: &
|
60
|
+
requirement: &70336822183280 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70336822183280
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
|
-
requirement: &
|
71
|
+
requirement: &70336822182380 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70336822182380
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &70336822181360 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70336822181360
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70336822180700 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70336822180700
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: haml
|
104
|
-
requirement: &
|
104
|
+
requirement: &70336822179980 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,21 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70336822179980
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: slim
|
115
|
+
requirement: &70336822179300 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70336822179300
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: bundler
|
115
|
-
requirement: &
|
126
|
+
requirement: &70336822178600 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ! '>='
|
@@ -120,7 +131,7 @@ dependencies:
|
|
120
131
|
version: '0'
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *70336822178600
|
124
135
|
description: a code metric tool for rails codes, written in Ruby.
|
125
136
|
email:
|
126
137
|
- flyerhzm@gmail.com
|
@@ -292,7 +303,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
292
303
|
version: '0'
|
293
304
|
segments:
|
294
305
|
- 0
|
295
|
-
hash:
|
306
|
+
hash: -2040907872987852778
|
296
307
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
297
308
|
none: false
|
298
309
|
requirements:
|