rails_best_practices 1.9.0 → 1.9.1
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/.travis.yml +4 -1
- data/Gemfile +0 -3
- data/Gemfile.lock +10 -9
- data/README.md +2 -0
- data/lib/rails_best_practices/analyzer.rb +40 -21
- data/lib/rails_best_practices/core.rb +1 -0
- data/lib/rails_best_practices/core/check.rb +12 -0
- data/lib/rails_best_practices/core/configs.rb +7 -0
- data/lib/rails_best_practices/core/error.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +11 -5
- data/lib/rails_best_practices/core/runner.rb +6 -2
- data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
- data/lib/rails_best_practices/prepares.rb +5 -0
- data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
- data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +1 -0
- data/spec/rails_best_practices/analyzer_spec.rb +52 -32
- data/spec/rails_best_practices/core/check_spec.rb +64 -45
- data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
- data/spec/rails_best_practices/core/configs_spec.rb +7 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
- data/spec/rails_best_practices/core/error_spec.rb +28 -22
- data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
- data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
- data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
- data/spec/rails_best_practices/core/methods_spec.rb +37 -35
- data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
- data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
- data/spec/rails_best_practices/core/models_spec.rb +4 -2
- data/spec/rails_best_practices/core/modules_spec.rb +21 -19
- data/spec/rails_best_practices/core/nil_spec.rb +23 -21
- data/spec/rails_best_practices/core/routes_spec.rb +21 -14
- data/spec/rails_best_practices/core/runner_spec.rb +17 -15
- data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
- data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
- data/spec/spec_helper.rb +11 -20
- metadata +42 -26
- data/.watchr.example +0 -65
@@ -1,65 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module RailsBestPractices
|
4
|
+
module Reviews
|
5
|
+
describe UseModelAssociationReview do
|
6
|
+
let(:runner) { Core::Runner.new(:reviews => UseModelAssociationReview.new) }
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
it "should use model association for instance variable" do
|
9
|
+
content = <<-EOF
|
10
|
+
class PostsController < ApplicationController
|
11
|
+
def create
|
12
|
+
@post = Post.new(params[:post])
|
13
|
+
@post.user_id = current_user.id
|
14
|
+
@post.save
|
15
|
+
end
|
16
|
+
end
|
17
|
+
EOF
|
18
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
19
|
+
runner.should have(1).errors
|
20
|
+
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - use model association (for @post)"
|
14
21
|
end
|
15
|
-
end
|
16
|
-
EOF
|
17
|
-
runner.review('app/controllers/posts_controller.rb', content)
|
18
|
-
runner.should have(1).errors
|
19
|
-
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - use model association (for @post)"
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
it "should not use model association without association assign" do
|
24
|
+
content = <<-EOF
|
25
|
+
class PostsController < ApplicationController
|
26
|
+
def create
|
27
|
+
@post = Post.new(params[:post])
|
28
|
+
@post.save
|
29
|
+
end
|
30
|
+
end
|
31
|
+
EOF
|
32
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
33
|
+
runner.should have(0).errors
|
29
34
|
end
|
30
|
-
end
|
31
|
-
EOF
|
32
|
-
runner.review('app/controllers/posts_controller.rb', content)
|
33
|
-
runner.should have(0).errors
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should use model association for local variable" do
|
37
|
-
content = <<-EOF
|
38
|
-
class PostsController < ApplicationController
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
it "should use model association for local variable" do
|
37
|
+
content = <<-EOF
|
38
|
+
class PostsController < ApplicationController
|
39
|
+
def create
|
40
|
+
post = Post.new(params[:post])
|
41
|
+
post.user_id = current_user.id
|
42
|
+
post.save
|
43
|
+
end
|
44
|
+
end
|
45
|
+
EOF
|
46
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
47
|
+
runner.should have(1).errors
|
48
|
+
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - use model association (for post)"
|
44
49
|
end
|
45
|
-
end
|
46
|
-
EOF
|
47
|
-
runner.review('app/controllers/posts_controller.rb', content)
|
48
|
-
runner.should have(1).errors
|
49
|
-
runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - use model association (for post)"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not use model association" do
|
53
|
-
content = <<-EOF
|
54
|
-
class PostsController < ApplicationController
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
51
|
+
it "should not use model association" do
|
52
|
+
content = <<-EOF
|
53
|
+
class PostsController < ApplicationController
|
54
|
+
def create
|
55
|
+
post = current_user.posts.buid(params[:post])
|
56
|
+
post.save
|
57
|
+
end
|
58
|
+
end
|
59
|
+
EOF
|
60
|
+
runner.review('app/controllers/posts_controller.rb', content)
|
61
|
+
runner.should have(0).errors
|
59
62
|
end
|
60
63
|
end
|
61
|
-
EOF
|
62
|
-
runner.review('app/controllers/posts_controller.rb', content)
|
63
|
-
runner.should have(0).errors
|
64
64
|
end
|
65
65
|
end
|
@@ -1,211 +1,213 @@
|
|
1
1
|
require 'spec_helper'
|
2
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
|
-
end
|
27
|
-
|
28
|
-
context "rails2" do
|
29
|
-
context "project_mailer" do
|
30
|
-
let(:content) {
|
31
|
-
<<-EOF
|
32
|
-
class ProjectMailer < ActionMailer::Base
|
33
|
-
def send_email(email)
|
34
|
-
subject email.subject
|
35
|
-
from email.from
|
36
|
-
recipients email.recipients
|
37
|
-
sent_on Time.now
|
38
|
-
body :email => email
|
39
|
-
end
|
40
|
-
end
|
41
|
-
EOF
|
42
|
-
}
|
43
|
-
|
44
|
-
context "erb" do
|
45
|
-
it "should use mulipart/alternative as content_type of email" do
|
46
|
-
mock_email_files(["send_email.text.html.erb"], "text.html.erb" => true)
|
47
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
48
|
-
runner.should have(1).errors
|
49
|
-
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not use multipart/alternative as content_type of email" do
|
53
|
-
mock_email_files(["send_email.text.html.erb"], "text.plain.erb" => true, "text.html.erb" => true)
|
54
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
55
|
-
runner.should have(0).errors
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should not use multiple/alternative as content_type of email when only plain text" do
|
59
|
-
mock_email_files(["send_email.text.plain.erb"], "text.plain.erb" => true)
|
60
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
61
|
-
runner.should have(0).errors
|
62
|
-
end
|
3
|
+
module RailsBestPractices
|
4
|
+
module Reviews
|
5
|
+
describe UseMultipartAlternativeAsContentTypeOfEmailReview do
|
6
|
+
let(:runner) { Core::Runner.new(:reviews => UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
|
7
|
+
|
8
|
+
before(:each) { Core::Runner.stub!(:base_path).and_return(".") }
|
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.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)
|
24
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.plain.rhtml").and_return(options["text.plain.rhtml"] || false)
|
25
|
+
File.stub!(:exist?).with("./app/views/project_mailer/send_email.text.html.rhtml").and_return(options["text.html.rhtml"] || false)
|
63
26
|
end
|
64
27
|
|
65
|
-
context "
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
107
|
-
context "rhtml" do
|
108
|
-
it "should use mulipart/alternative as content_type of email" do
|
109
|
-
mock_email_files(["send_email.text.html.rhtml"], "text.html.rhtml" => true)
|
110
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
111
|
-
runner.should have(1).errors
|
112
|
-
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should not use multipart/alternative as content_type of email" do
|
116
|
-
mock_email_files(["send_email.text.html.rhtml"], "text.plain.rhtml" => true, "text.html.rhtml" => true)
|
117
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
118
|
-
runner.should have(0).errors
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should not use multiple/alternative as content_type of email when only plain text" do
|
122
|
-
mock_email_files(["send_email.text.plain.rhtml"], "text.plain.rhtml" => true)
|
123
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
124
|
-
runner.should have(0).errors
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should not use mulipart/alternative as content_type of email for non deliver method" do
|
130
|
-
content =<<-EOF
|
131
|
-
class ProjectMailer < ActionMailer::Base
|
132
|
-
def no_deliver
|
133
|
-
end
|
134
|
-
end
|
135
|
-
EOF
|
136
|
-
mock_email_files(["send_email.text.html.erb"])
|
137
|
-
runner.review('app/mailers/project_mailer.rb', content)
|
138
|
-
runner.should have(0).errors
|
139
|
-
end
|
140
|
-
end
|
28
|
+
context "rails2" do
|
29
|
+
context "project_mailer" do
|
30
|
+
let(:content) {
|
31
|
+
<<-EOF
|
32
|
+
class ProjectMailer < ActionMailer::Base
|
33
|
+
def send_email(email)
|
34
|
+
subject email.subject
|
35
|
+
from email.from
|
36
|
+
recipients email.recipients
|
37
|
+
sent_on Time.now
|
38
|
+
body :email => email
|
39
|
+
end
|
40
|
+
end
|
41
|
+
EOF
|
42
|
+
}
|
43
|
+
|
44
|
+
context "erb" do
|
45
|
+
it "should use mulipart/alternative as content_type of email" do
|
46
|
+
mock_email_files(["send_email.text.html.erb"], "text.html.erb" => true)
|
47
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
48
|
+
runner.should have(1).errors
|
49
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not use multipart/alternative as content_type of email" do
|
53
|
+
mock_email_files(["send_email.text.html.erb"], "text.plain.erb" => true, "text.html.erb" => true)
|
54
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
55
|
+
runner.should have(0).errors
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
59
|
+
mock_email_files(["send_email.text.plain.erb"], "text.plain.erb" => true)
|
60
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
61
|
+
runner.should have(0).errors
|
62
|
+
end
|
63
|
+
end
|
141
64
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
65
|
+
context "haml" do
|
66
|
+
it "should use mulipart/alternative as content_type of email" do
|
67
|
+
mock_email_files(["send_email.text.html.haml"], "text.html.haml" => true)
|
68
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
69
|
+
runner.should have(1).errors
|
70
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should not use multipart/alternative as content_type of email" do
|
74
|
+
mock_email_files(["send_email.text.html.haml"], "text.plain.haml" => true, "text.html.haml" => true)
|
75
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
76
|
+
runner.should have(0).errors
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
80
|
+
mock_email_files(["send_email.text.plain.haml"], "text.plain.haml" => true)
|
81
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
82
|
+
runner.should have(0).errors
|
83
|
+
end
|
153
84
|
end
|
154
|
-
end
|
155
|
-
EOF
|
156
|
-
}
|
157
85
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
165
106
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
107
|
+
context "rhtml" do
|
108
|
+
it "should use mulipart/alternative as content_type of email" do
|
109
|
+
mock_email_files(["send_email.text.html.rhtml"], "text.html.rhtml" => true)
|
110
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
111
|
+
runner.should have(1).errors
|
112
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should not use multipart/alternative as content_type of email" do
|
116
|
+
mock_email_files(["send_email.text.html.rhtml"], "text.plain.rhtml" => true, "text.html.rhtml" => true)
|
117
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
118
|
+
runner.should have(0).errors
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
122
|
+
mock_email_files(["send_email.text.plain.rhtml"], "text.plain.rhtml" => true)
|
123
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
124
|
+
runner.should have(0).errors
|
125
|
+
end
|
126
|
+
end
|
170
127
|
end
|
171
128
|
|
172
|
-
it "should not use
|
173
|
-
|
129
|
+
it "should not use mulipart/alternative as content_type of email for non deliver method" do
|
130
|
+
content =<<-EOF
|
131
|
+
class ProjectMailer < ActionMailer::Base
|
132
|
+
def no_deliver
|
133
|
+
end
|
134
|
+
end
|
135
|
+
EOF
|
136
|
+
mock_email_files(["send_email.text.html.erb"])
|
174
137
|
runner.review('app/mailers/project_mailer.rb', content)
|
175
138
|
runner.should have(0).errors
|
176
139
|
end
|
177
140
|
end
|
178
141
|
|
179
|
-
context "
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
142
|
+
context "rails3" do
|
143
|
+
context "project_mailer" do
|
144
|
+
let(:content) {
|
145
|
+
<<-EOF
|
146
|
+
class ProjectMailer < ActionMailer::Base
|
147
|
+
def send_email(email)
|
148
|
+
subject email.subject
|
149
|
+
from email.from
|
150
|
+
recipients email.recipients
|
151
|
+
sent_on Time.now
|
152
|
+
body :email => email
|
153
|
+
end
|
154
|
+
end
|
155
|
+
EOF
|
156
|
+
}
|
157
|
+
|
158
|
+
context "erb" do
|
159
|
+
it "should use mulipart/alternative as content_type of email" do
|
160
|
+
mock_email_files(["send_email.html.erb"], "html.erb" => true)
|
161
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
162
|
+
runner.should have(1).errors
|
163
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should not use multipart/alternative as content_type of email" do
|
167
|
+
mock_email_files(["send_email.html.erb"], "text.erb" => true, "html.erb" => true)
|
168
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
169
|
+
runner.should have(0).errors
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
173
|
+
mock_email_files(["send_email.text.erb"], "text.erb" => true)
|
174
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
175
|
+
runner.should have(0).errors
|
176
|
+
end
|
177
|
+
end
|
192
178
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
179
|
+
context "haml" do
|
180
|
+
it "should use mulipart/alternative as content_type of email" do
|
181
|
+
mock_email_files(["send_email.html.haml"], "html.haml" => true)
|
182
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
183
|
+
runner.should have(1).errors
|
184
|
+
runner.errors[0].to_s.should == "app/mailers/project_mailer.rb:2 - use multipart/alternative as content_type of email"
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should not use multipart/alternative as content_type of email" do
|
188
|
+
mock_email_files(["send_email.html.haml", "send_email.text.haml"], "html.haml" => true, "text.haml" => true)
|
189
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
190
|
+
runner.should have(0).errors
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should not use multiple/alternative as content_type of email when only plain text" do
|
194
|
+
mock_email_files(["send_email.text.haml"], "text.haml" => true)
|
195
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
196
|
+
runner.should have(0).errors
|
197
|
+
end
|
198
|
+
end
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
200
|
+
context "haml/erb mix" do
|
201
|
+
it "should not suggest using multipart/alternative when mixing html.haml and text.erb" do
|
202
|
+
mock_email_files(["send_email.html.haml", "send_email.text.erb"], "html.haml" => true, "text.erb" => true)
|
203
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
204
|
+
runner.should have(0).errors
|
205
205
|
|
206
|
-
|
207
|
-
|
208
|
-
|
206
|
+
mock_email_files(["send_email.html.erb", "send_email.text.haml"], "html.erb" => true, "text.haml" => true)
|
207
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
208
|
+
runner.should have(0).errors
|
209
|
+
end
|
210
|
+
end
|
209
211
|
end
|
210
212
|
end
|
211
213
|
end
|