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,154 +1,147 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::UseObserverReview do
4
- let(:runner) {
5
- RailsBestPractices::Core::Runner.new(
6
- :prepares => RailsBestPractices::Prepares::MailerPrepare.new,
7
- :reviews => RailsBestPractices::Reviews::UseObserverReview.new
8
- )
9
- }
10
-
11
- before :each do
12
- content =<<-EOF
13
- class ProjectMailer < ActionMailer::Base
14
- end
15
- EOF
16
- runner.prepare('app/models/project_mailer.rb', content)
17
- end
18
-
19
- describe "rails2" do
20
- it "should use observer" do
21
- content =<<-EOF
22
- class Project < ActiveRecord::Base
23
- after_create :send_create_notification
24
-
25
- private
26
-
27
- def send_create_notification
28
- self.members.each do |member|
29
- ProjectMailer.deliver_notification(self, member)
30
- end
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe UseObserverReview do
6
+ let(:runner) { Core::Runner.new(:prepares => Prepares::MailerPrepare.new, :reviews => UseObserverReview.new) }
7
+
8
+ before :each do
9
+ content =<<-EOF
10
+ class ProjectMailer < ActionMailer::Base
31
11
  end
12
+ EOF
13
+ runner.prepare('app/models/project_mailer.rb', content)
32
14
  end
33
- EOF
34
- runner.review('app/models/project.rb', content)
35
- runner.should have(1).errors
36
- runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
37
- end
38
15
 
39
- it "should not use observer without callback" do
40
- content =<<-EOF
41
- class Project < ActiveRecord::Base
42
- private
16
+ describe "rails2" do
17
+ it "should use observer" do
18
+ content =<<-EOF
19
+ class Project < ActiveRecord::Base
20
+ after_create :send_create_notification
21
+
22
+ private
23
+ def send_create_notification
24
+ self.members.each do |member|
25
+ ProjectMailer.deliver_notification(self, member)
26
+ end
27
+ end
28
+ end
29
+ EOF
30
+ runner.review('app/models/project.rb', content)
31
+ runner.should have(1).errors
32
+ runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
33
+ end
43
34
 
44
- def send_create_notification
45
- self.members.each do |member|
46
- ProjectMailer.deliver_notification(self, member)
35
+ it "should not use observer without callback" do
36
+ content =<<-EOF
37
+ class Project < ActiveRecord::Base
38
+ private
39
+ def send_create_notification
40
+ self.members.each do |member|
41
+ ProjectMailer.deliver_notification(self, member)
42
+ end
43
+ end
47
44
  end
45
+ EOF
46
+ runner.review('app/models/project.rb', content)
47
+ runner.should have(0).errors
48
48
  end
49
- end
50
- EOF
51
- runner.review('app/models/project.rb', content)
52
- runner.should have(0).errors
53
- end
54
49
 
55
- it "should use observer with two after_create" do
56
- content =<<-EOF
57
- class Project < ActiveRecord::Base
58
- after_create :send_create_notification, :update_author
50
+ it "should use observer with two after_create" do
51
+ content =<<-EOF
52
+ class Project < ActiveRecord::Base
53
+ after_create :send_create_notification, :update_author
59
54
 
60
- private
55
+ private
56
+ def send_create_notification
57
+ self.members.each do |member|
58
+ ProjectMailer.deliver_notification(self, member)
59
+ end
60
+ end
61
61
 
62
- def send_create_notification
63
- self.members.each do |member|
64
- ProjectMailer.deliver_notification(self, member)
62
+ def update_author
63
+ end
65
64
  end
65
+ EOF
66
+ runner.review('app/models/project.rb', content)
67
+ runner.should have(1).errors
68
+ runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
66
69
  end
67
70
 
68
- def update_author
71
+ it "should not raise when initiate an object in callback" do
72
+ content =<<-EOF
73
+ class Project < ActiveRecord::Base
74
+ after_create ProjectMailer.new
75
+ end
76
+ EOF
77
+ lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
69
78
  end
70
79
  end
71
- EOF
72
- runner.review('app/models/project.rb', content)
73
- runner.should have(1).errors
74
- runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
75
- end
76
-
77
- it "should not raise when initiate an object in callback" do
78
- content =<<-EOF
79
- class Project < ActiveRecord::Base
80
- after_create ProjectMailer.new
81
- end
82
- EOF
83
- lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
84
- end
85
- end
86
-
87
- describe "rails3" do
88
- it "should use observer" do
89
- content =<<-EOF
90
- class Project < ActiveRecord::Base
91
- after_create :send_create_notification
92
80
 
93
- private
94
-
95
- def send_create_notification
96
- self.members.each do |member|
97
- ProjectMailer.notification(self, member).deliver
81
+ describe "rails3" do
82
+ it "should use observer" do
83
+ content =<<-EOF
84
+ class Project < ActiveRecord::Base
85
+ after_create :send_create_notification
86
+
87
+ private
88
+ def send_create_notification
89
+ self.members.each do |member|
90
+ ProjectMailer.notification(self, member).deliver
91
+ end
92
+ end
98
93
  end
94
+ EOF
95
+ runner.review('app/models/project.rb', content)
96
+ runner.should have(1).errors
97
+ runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
99
98
  end
100
- end
101
- EOF
102
- runner.review('app/models/project.rb', content)
103
- runner.should have(1).errors
104
- runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
105
- end
106
99
 
107
- it "should not use observer without callback" do
108
- content =<<-EOF
109
- class Project < ActiveRecord::Base
110
- private
111
-
112
- def send_create_notification
113
- self.members.each do |member|
114
- ProjectMailer.notification(self, member).deliver
100
+ it "should not use observer without callback" do
101
+ content =<<-EOF
102
+ class Project < ActiveRecord::Base
103
+ private
104
+ def send_create_notification
105
+ self.members.each do |member|
106
+ ProjectMailer.notification(self, member).deliver
107
+ end
108
+ end
115
109
  end
110
+ EOF
111
+ runner.review('app/models/project.rb', content)
112
+ runner.should have(0).errors
116
113
  end
117
- end
118
- EOF
119
- runner.review('app/models/project.rb', content)
120
- runner.should have(0).errors
121
- end
122
114
 
123
- it "should use observer with two after_create" do
124
- content =<<-EOF
125
- class Project < ActiveRecord::Base
126
- after_create :send_create_notification, :update_author
115
+ it "should use observer with two after_create" do
116
+ content =<<-EOF
117
+ class Project < ActiveRecord::Base
118
+ after_create :send_create_notification, :update_author
127
119
 
128
- private
120
+ private
121
+ def send_create_notification
122
+ self.members.each do |member|
123
+ ProjectMailer.notification(self, member).deliver
124
+ end
125
+ end
129
126
 
130
- def send_create_notification
131
- self.members.each do |member|
132
- ProjectMailer.notification(self, member).deliver
127
+ def update_author
128
+ end
133
129
  end
130
+ EOF
131
+ runner.review('app/models/project.rb', content)
132
+ runner.should have(1).errors
133
+ runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
134
134
  end
135
135
 
136
- def update_author
136
+ it "should not raise when initiate an object in callback" do
137
+ content =<<-EOF
138
+ class Project < ActiveRecord::Base
139
+ after_create ProjectMailer.new
140
+ end
141
+ EOF
142
+ lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
137
143
  end
138
144
  end
139
- EOF
140
- runner.review('app/models/project.rb', content)
141
- runner.should have(1).errors
142
- runner.errors[0].to_s.should == "app/models/project.rb:6 - use observer"
143
- end
144
-
145
- it "should not raise when initiate an object in callback" do
146
- content =<<-EOF
147
- class Project < ActiveRecord::Base
148
- after_create ProjectMailer.new
149
- end
150
- EOF
151
- lambda { runner.review('app/models/project.rb', content) }.should_not raise_error
152
145
  end
153
146
  end
154
147
  end
@@ -1,210 +1,209 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::UseQueryAttributeReview do
4
- let(:runner) {
5
- RailsBestPractices::Core::Runner.new(
6
- :prepares => [RailsBestPractices::Prepares::ModelPrepare.new, RailsBestPractices::Prepares::SchemaPrepare.new],
7
- :reviews => RailsBestPractices::Reviews::UseQueryAttributeReview.new
8
- )
9
- }
10
-
11
- before :each do
12
- content = <<-EOF
13
- class User < ActiveRecord::Base
14
- has_many :projects
15
- belongs_to :location
16
- has_one :phone
17
-
18
- belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
19
- end
20
- EOF
21
- runner.prepare('app/models/user.rb', content)
22
-
23
- content = <<-EOF
24
- ActiveRecord::Schema.define(:version => 20110216150853) do
25
- create_table "users", force => true do |t|
26
- t.string :login
27
- t.integer :age
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe UseQueryAttributeReview do
6
+ let(:runner) { Core::Runner.new(:prepares => [Prepares::ModelPrepare.new, Prepares::SchemaPrepare.new], :reviews => UseQueryAttributeReview.new) }
7
+
8
+ before :each do
9
+ content = <<-EOF
10
+ class User < ActiveRecord::Base
11
+ has_many :projects
12
+ belongs_to :location
13
+ has_one :phone
14
+
15
+ belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
16
+ end
17
+ EOF
18
+ runner.prepare('app/models/user.rb', content)
19
+
20
+ content = <<-EOF
21
+ ActiveRecord::Schema.define(:version => 20110216150853) do
22
+ create_table "users", force => true do |t|
23
+ t.string :login
24
+ t.integer :age
25
+ end
26
+ end
27
+ EOF
28
+ runner.prepare('db/schema.rb', content)
28
29
  end
29
- end
30
- EOF
31
- runner.prepare('db/schema.rb', content)
32
- end
33
-
34
- it "should use query attribute by blank call" do
35
- content = <<-EOF
36
- <% if @user.login.blank? %>
37
- <%= link_to 'login', new_session_path %>
38
- <% end %>
39
- EOF
40
- runner.review('app/views/users/show.html.erb', content)
41
- runner.should have(1).errors
42
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
43
- end
44
30
 
45
- it "should use query attribute by comparing empty string" do
46
- content = <<-EOF
47
- <% if @user.login == "" %>
48
- <%= link_to 'login', new_session_path %>
49
- <% end %>
50
- EOF
51
- runner.review('app/views/users/show.html.erb', content)
52
- runner.should have(1).errors
53
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
54
- end
55
-
56
- it "should use query attribute by nil call" do
57
- content = <<-EOF
58
- <% if @user.login.nil? %>
59
- <%= link_to 'login', new_session_path %>
60
- <% end %>
61
- EOF
62
- runner.review('app/views/users/show.html.erb', content)
63
- runner.should have(1).errors
64
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
65
- end
66
-
67
- it "should use query attribute by present call" do
68
- content = <<-EOF
69
- <% if @user.login.present? %>
70
- <%= @user.login %>
71
- <% end %>
72
- EOF
73
- runner.review('app/views/users/show.html.erb', content)
74
- runner.should have(1).errors
75
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
76
- end
31
+ it "should use query attribute by blank call" do
32
+ content = <<-EOF
33
+ <% if @user.login.blank? %>
34
+ <%= link_to 'login', new_session_path %>
35
+ <% end %>
36
+ EOF
37
+ runner.review('app/views/users/show.html.erb', content)
38
+ runner.should have(1).errors
39
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
40
+ end
77
41
 
78
- it "should use query attribute within and conditions" do
79
- content = <<-EOF
80
- <% if @user.active? && @user.login.present? %>
81
- <%= @user.login %>
82
- <% end %>
83
- EOF
84
- runner.review('app/views/users/show.html.erb', content)
85
- runner.should have(1).errors
86
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
87
- end
42
+ it "should use query attribute by comparing empty string" do
43
+ content = <<-EOF
44
+ <% if @user.login == "" %>
45
+ <%= link_to 'login', new_session_path %>
46
+ <% end %>
47
+ EOF
48
+ runner.review('app/views/users/show.html.erb', content)
49
+ runner.should have(1).errors
50
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
51
+ end
88
52
 
89
- it "should use query attribute within or conditions" do
90
- content = <<-EOF
91
- <% if @user.active? or @user.login != "" %>
92
- <%= @user.login %>
93
- <% end %>
94
- EOF
95
- runner.review('app/views/users/show.html.erb', content)
96
- runner.should have(1).errors
97
- runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
98
- end
53
+ it "should use query attribute by nil call" do
54
+ content = <<-EOF
55
+ <% if @user.login.nil? %>
56
+ <%= link_to 'login', new_session_path %>
57
+ <% end %>
58
+ EOF
59
+ runner.review('app/views/users/show.html.erb', content)
60
+ runner.should have(1).errors
61
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
62
+ end
99
63
 
100
- it "should not use query attribute" do
101
- content = <<-EOF
102
- <% if @user.login? %>
103
- <%= @user.login %>
104
- <% end %>
105
- EOF
106
- runner.review('app/views/users/show.html.erb', content)
107
- runner.should have(0).errors
108
- end
64
+ it "should use query attribute by present call" do
65
+ content = <<-EOF
66
+ <% if @user.login.present? %>
67
+ <%= @user.login %>
68
+ <% end %>
69
+ EOF
70
+ runner.review('app/views/users/show.html.erb', content)
71
+ runner.should have(1).errors
72
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
73
+ end
109
74
 
110
- it "should not use query attribute for number" do
111
- content =<<-EOF
112
- <% unless @user.age.blank? %>
113
- <%= @user.age %>
114
- <% end %>
115
- EOF
116
- runner.review('app/views/users/show.html.erb', content)
117
- runner.should have(0).errors
118
- end
75
+ it "should use query attribute within and conditions" do
76
+ content = <<-EOF
77
+ <% if @user.active? && @user.login.present? %>
78
+ <%= @user.login %>
79
+ <% end %>
80
+ EOF
81
+ runner.review('app/views/users/show.html.erb', content)
82
+ runner.should have(1).errors
83
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
84
+ end
119
85
 
120
- it "should not review for pluralize attribute" do
121
- content = <<-EOF
122
- <% if @user.roles.blank? %>
123
- <%= @user.login %>
124
- <% end %>
125
- EOF
126
- runner.review('app/views/users/show.html.erb', content)
127
- runner.should have(0).errors
128
- end
86
+ it "should use query attribute within or conditions" do
87
+ content = <<-EOF
88
+ <% if @user.active? or @user.login != "" %>
89
+ <%= @user.login %>
90
+ <% end %>
91
+ EOF
92
+ runner.review('app/views/users/show.html.erb', content)
93
+ runner.should have(1).errors
94
+ runner.errors[0].to_s.should == "app/views/users/show.html.erb:1 - use query attribute (@user.login?)"
95
+ end
129
96
 
130
- it "should not review non model class" do
131
- content = <<-EOF
132
- <% if @person.login.present? %>
133
- <%= @person.login %>
134
- <% end %>
135
- EOF
136
- runner.review('app/views/users/show.html.erb', content)
137
- runner.should have(0).errors
138
- end
97
+ it "should not use query attribute" do
98
+ content = <<-EOF
99
+ <% if @user.login? %>
100
+ <%= @user.login %>
101
+ <% end %>
102
+ EOF
103
+ runner.review('app/views/users/show.html.erb', content)
104
+ runner.should have(0).errors
105
+ end
139
106
 
140
- context "association" do
141
- it "should not review belongs_to association" do
142
- content = <<-EOF
143
- <% if @user.location.present? %>
144
- <%= @user.location.name %>
145
- <% end %>
146
- EOF
147
- runner.review('app/views/users/show.html.erb', content)
148
- runner.should have(0).errors
149
- end
107
+ it "should not use query attribute for number" do
108
+ content =<<-EOF
109
+ <% unless @user.age.blank? %>
110
+ <%= @user.age %>
111
+ <% end %>
112
+ EOF
113
+ runner.review('app/views/users/show.html.erb', content)
114
+ runner.should have(0).errors
115
+ end
150
116
 
151
- it "should not review belongs_to category" do
152
- content = <<-EOF
153
- <% if @user.category.present? %>
154
- <%= @user.category.name %>
155
- <% end %>
156
- EOF
157
- runner.review('app/views/users/show.html.erb', content)
158
- runner.should have(0).errors
159
- end
117
+ it "should not review for pluralize attribute" do
118
+ content = <<-EOF
119
+ <% if @user.roles.blank? %>
120
+ <%= @user.login %>
121
+ <% end %>
122
+ EOF
123
+ runner.review('app/views/users/show.html.erb', content)
124
+ runner.should have(0).errors
125
+ end
160
126
 
161
- it "should not review has_one association" do
162
- content = <<-EOF
163
- <% if @user.phone.present? %>
164
- <%= @user.phone.number %>
165
- <% end %>
166
- EOF
167
- runner.review('app/views/users/show.html.erb', content)
168
- runner.should have(0).errors
169
- end
127
+ it "should not review non model class" do
128
+ content = <<-EOF
129
+ <% if @person.login.present? %>
130
+ <%= @person.login %>
131
+ <% end %>
132
+ EOF
133
+ runner.review('app/views/users/show.html.erb', content)
134
+ runner.should have(0).errors
135
+ end
170
136
 
171
- it "should not review has_many association" do
172
- content = <<-EOF
173
- <% if @user.projects.present? %>
174
- <%= @user.projects.first.name %>
175
- <% end %>
176
- EOF
177
- runner.review('app/views/users/show.html.erb', content)
178
- runner.should have(0).errors
179
- end
180
- end
137
+ context "association" do
138
+ it "should not review belongs_to association" do
139
+ content = <<-EOF
140
+ <% if @user.location.present? %>
141
+ <%= @user.location.name %>
142
+ <% end %>
143
+ EOF
144
+ runner.review('app/views/users/show.html.erb', content)
145
+ runner.should have(0).errors
146
+ end
147
+
148
+ it "should not review belongs_to category" do
149
+ content = <<-EOF
150
+ <% if @user.category.present? %>
151
+ <%= @user.category.name %>
152
+ <% end %>
153
+ EOF
154
+ runner.review('app/views/users/show.html.erb', content)
155
+ runner.should have(0).errors
156
+ end
157
+
158
+ it "should not review has_one association" do
159
+ content = <<-EOF
160
+ <% if @user.phone.present? %>
161
+ <%= @user.phone.number %>
162
+ <% end %>
163
+ EOF
164
+ runner.review('app/views/users/show.html.erb', content)
165
+ runner.should have(0).errors
166
+ end
167
+
168
+ it "should not review has_many association" do
169
+ content = <<-EOF
170
+ <% if @user.projects.present? %>
171
+ <%= @user.projects.first.name %>
172
+ <% end %>
173
+ EOF
174
+ runner.review('app/views/users/show.html.erb', content)
175
+ runner.should have(0).errors
176
+ end
177
+ end
181
178
 
182
- it "should not review for class method" do
183
- content = <<-EOF
184
- <% if User.name.present? %>
185
- <%= User.name %>
186
- <% end %>
187
- EOF
188
- runner.review('app/views/users/show.html.erb', content)
189
- runner.should have(0).errors
190
- end
179
+ it "should not review for class method" do
180
+ content = <<-EOF
181
+ <% if User.name.present? %>
182
+ <%= User.name %>
183
+ <% end %>
184
+ EOF
185
+ runner.review('app/views/users/show.html.erb', content)
186
+ runner.should have(0).errors
187
+ end
191
188
 
192
- it "should not review for non attribute call" do
193
- content = <<-EOF
194
- if @user.login(false).nil?
195
- puts @user.login(false)
196
- end
197
- EOF
198
- runner.review('app/models/users_controller.rb', content)
199
- runner.should have(0).errors
200
- end
189
+ it "should not review for non attribute call" do
190
+ content = <<-EOF
191
+ if @user.login(false).nil?
192
+ puts @user.login(false)
193
+ end
194
+ EOF
195
+ runner.review('app/models/users_controller.rb', content)
196
+ runner.should have(0).errors
197
+ end
201
198
 
202
- it "should not raise error for common conditional statement" do
203
- content = <<-EOF
204
- if voteable.is_a? Answer
205
- puts voteable.title
199
+ it "should not raise error for common conditional statement" do
200
+ content = <<-EOF
201
+ if voteable.is_a? Answer
202
+ puts voteable.title
203
+ end
204
+ EOF
205
+ lambda { runner.review('app/models/users_controller.rb', content) }.should_not raise_error
206
+ end
206
207
  end
207
- EOF
208
- lambda { runner.review('app/models/users_controller.rb', content) }.should_not raise_error
209
208
  end
210
209
  end