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.
Files changed (81) hide show
  1. data/.travis.yml +4 -1
  2. data/Gemfile +0 -3
  3. data/Gemfile.lock +10 -9
  4. data/README.md +2 -0
  5. data/lib/rails_best_practices/analyzer.rb +40 -21
  6. data/lib/rails_best_practices/core.rb +1 -0
  7. data/lib/rails_best_practices/core/check.rb +12 -0
  8. data/lib/rails_best_practices/core/configs.rb +7 -0
  9. data/lib/rails_best_practices/core/error.rb +2 -1
  10. data/lib/rails_best_practices/core/routes.rb +11 -5
  11. data/lib/rails_best_practices/core/runner.rb +6 -2
  12. data/lib/rails_best_practices/core_ext/sexp.rb +3 -1
  13. data/lib/rails_best_practices/prepares.rb +5 -0
  14. data/lib/rails_best_practices/prepares/config_prepare.rb +21 -0
  15. data/lib/rails_best_practices/prepares/route_prepare.rb +24 -7
  16. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +11 -3
  17. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +7 -3
  18. data/lib/rails_best_practices/version.rb +1 -1
  19. data/rails_best_practices.gemspec +1 -0
  20. data/spec/rails_best_practices/analyzer_spec.rb +52 -32
  21. data/spec/rails_best_practices/core/check_spec.rb +64 -45
  22. data/spec/rails_best_practices/core/checking_visitor_spec.rb +65 -64
  23. data/spec/rails_best_practices/core/configs_spec.rb +7 -0
  24. data/spec/rails_best_practices/core/controllers_spec.rb +4 -2
  25. data/spec/rails_best_practices/core/error_spec.rb +28 -22
  26. data/spec/rails_best_practices/core/helpers_spec.rb +4 -2
  27. data/spec/rails_best_practices/core/klasses_spec.rb +8 -6
  28. data/spec/rails_best_practices/core/mailers_spec.rb +4 -2
  29. data/spec/rails_best_practices/core/methods_spec.rb +37 -35
  30. data/spec/rails_best_practices/core/model_associations_spec.rb +17 -15
  31. data/spec/rails_best_practices/core/model_attributes_spec.rb +17 -15
  32. data/spec/rails_best_practices/core/models_spec.rb +4 -2
  33. data/spec/rails_best_practices/core/modules_spec.rb +21 -19
  34. data/spec/rails_best_practices/core/nil_spec.rb +23 -21
  35. data/spec/rails_best_practices/core/routes_spec.rb +21 -14
  36. data/spec/rails_best_practices/core/runner_spec.rb +17 -15
  37. data/spec/rails_best_practices/core_ext/sexp_spec.rb +32 -7
  38. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +35 -31
  39. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +35 -31
  40. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +24 -0
  41. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +122 -123
  42. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +36 -32
  43. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +12 -8
  44. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +326 -322
  45. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +619 -573
  46. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +25 -21
  47. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +85 -87
  48. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +224 -222
  49. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +30 -26
  50. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +79 -75
  51. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +76 -72
  52. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +138 -140
  53. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +38 -34
  54. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +22 -18
  55. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +57 -53
  56. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +62 -63
  57. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +51 -50
  58. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +140 -136
  59. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +48 -44
  60. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +42 -38
  61. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +151 -149
  62. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +86 -55
  63. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +23 -19
  64. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +290 -286
  65. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +76 -72
  66. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +601 -597
  67. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +55 -54
  68. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +34 -30
  69. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +288 -289
  70. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +59 -55
  71. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +73 -69
  72. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +89 -98
  73. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +52 -52
  74. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +192 -190
  75. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +114 -121
  76. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +189 -190
  77. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +97 -93
  78. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +146 -151
  79. data/spec/spec_helper.rb +11 -20
  80. metadata +42 -26
  81. data/.watchr.example +0 -65
@@ -1,65 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::UseModelAssociationReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseModelAssociationReview.new) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe UseModelAssociationReview do
6
+ let(:runner) { Core::Runner.new(:reviews => UseModelAssociationReview.new) }
5
7
 
6
- it "should use model association for instance variable" do
7
- content = <<-EOF
8
- class PostsController < ApplicationController
9
-
10
- def create
11
- @post = Post.new(params[:post])
12
- @post.user_id = current_user.id
13
- @post.save
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
- it "should not use model association without association assign" do
23
- content = <<-EOF
24
- class PostsController < ApplicationController
25
-
26
- def create
27
- @post = Post.new(params[:post])
28
- @post.save
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
- def create
41
- post = Post.new(params[:post])
42
- post.user_id = current_user.id
43
- post.save
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
- def create
57
- post = current_user.posts.buid(params[:post])
58
- post.save
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
- describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmailReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmailReview.new) }
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.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)
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 "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
84
- end
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
-
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
- 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
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
- 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
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
- 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
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 multiple/alternative as content_type of email when only plain text" do
173
- mock_email_files(["send_email.text.erb"], "text.erb" => true)
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 "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
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
- 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
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
- 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
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
- 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
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