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,118 +1,122 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::UseSayWithTimeInMigrationsReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseSayWithTimeInMigrationsReview.new) }
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe UseSayWithTimeInMigrationsReview do
6
+ let(:runner) { Core::Runner.new(:reviews => UseSayWithTimeInMigrationsReview.new) }
5
7
 
6
- it "should use say with time in migrations" do
7
- content =<<-EOF
8
- def self.up
9
- User.find_each do |user|
10
- user.first_name, user.last_name = user.full_name.split(' ')
11
- user.save
8
+ it "should use say with time in migrations" do
9
+ content =<<-EOF
10
+ def self.up
11
+ User.find_each do |user|
12
+ user.first_name, user.last_name = user.full_name.split(' ')
13
+ user.save
14
+ end
15
+ end
16
+ EOF
17
+ runner.review('db/migrate/20101010080658_update_users.rb', content)
18
+ runner.should have(1).errors
19
+ runner.errors[0].to_s.should == "db/migrate/20101010080658_update_users.rb:2 - use say with time in migrations"
12
20
  end
13
- end
14
- EOF
15
- runner.review('db/migrate/20101010080658_update_users.rb', content)
16
- runner.should have(1).errors
17
- runner.errors[0].to_s.should == "db/migrate/20101010080658_update_users.rb:2 - use say with time in migrations"
18
- end
19
21
 
20
- it "should use say with time in migrations with create_table" do
21
- content =<<-EOF
22
- def self.up
23
- create_table :users do |t|
24
- t.string :login
25
- t.timestamps
26
- end
22
+ it "should use say with time in migrations with create_table" do
23
+ content =<<-EOF
24
+ def self.up
25
+ create_table :users do |t|
26
+ t.string :login
27
+ t.timestamps
28
+ end
27
29
 
28
- User.find_each do |user|
29
- user.first_name, user.last_name = user.full_name.split(' ')
30
- user.save
30
+ User.find_each do |user|
31
+ user.first_name, user.last_name = user.full_name.split(' ')
32
+ user.save
33
+ end
34
+ end
35
+ EOF
36
+ runner.review('db/migrate/20101010080658_update_users.rb', content)
37
+ runner.should have(1).errors
38
+ runner.errors[0].to_s.should == "db/migrate/20101010080658_update_users.rb:7 - use say with time in migrations"
31
39
  end
32
- end
33
- EOF
34
- runner.review('db/migrate/20101010080658_update_users.rb', content)
35
- runner.should have(1).errors
36
- runner.errors[0].to_s.should == "db/migrate/20101010080658_update_users.rb:7 - use say with time in migrations"
37
- end
38
40
 
39
- it "should not use say with time in migrations" do
40
- content =<<-EOF
41
- def self.up
42
- say_with_time("Initialize first_name and last_name for users") do
43
- User.find_each do |user|
44
- user.first_name, user.last_name = user.full_name.split(' ')
45
- user.save
46
- say(user.id + " was updated.")
41
+ it "should not use say with time in migrations" do
42
+ content =<<-EOF
43
+ def self.up
44
+ say_with_time("Initialize first_name and last_name for users") do
45
+ User.find_each do |user|
46
+ user.first_name, user.last_name = user.full_name.split(' ')
47
+ user.save
48
+ say(user.id + " was updated.")
49
+ end
50
+ end
47
51
  end
52
+ EOF
53
+ runner.review('db/migrate/20101010080658_update_users.rb', content)
54
+ runner.should have(0).errors
48
55
  end
49
- end
50
- EOF
51
- runner.review('db/migrate/20101010080658_update_users.rb', content)
52
- runner.should have(0).errors
53
- end
54
56
 
55
- it "should not use say with time in migrations when not first code line" do
56
- content =<<-EOF
57
- def self.up
58
- User.find_each do |user|
59
- say_with_time 'Updating user with latest data' do
60
- user.do_time_consuming_stuff
57
+ it "should not use say with time in migrations when not first code line" do
58
+ content =<<-EOF
59
+ def self.up
60
+ User.find_each do |user|
61
+ say_with_time 'Updating user with latest data' do
62
+ user.do_time_consuming_stuff
63
+ end
64
+ end
61
65
  end
66
+ EOF
67
+ runner.review('db/migrate/20101010080658_update_users.rb', content)
68
+ runner.should have(0).errors
62
69
  end
63
- end
64
- EOF
65
- runner.review('db/migrate/20101010080658_update_users.rb', content)
66
- runner.should have(0).errors
67
- end
68
70
 
69
- it "should not use say with time when default migration message" do
70
- content =<<-EOF
71
- def self.up
72
- create_table :users do |t|
73
- t.string :login
74
- t.string :email
75
- t.timestamps
71
+ it "should not use say with time when default migration message" do
72
+ content =<<-EOF
73
+ def self.up
74
+ create_table :users do |t|
75
+ t.string :login
76
+ t.string :email
77
+ t.timestamps
78
+ end
79
+ end
80
+ EOF
81
+ runner.review('db/migrate/20101010080658_create_users.rb', content)
82
+ runner.should have(0).errors
76
83
  end
77
- end
78
- EOF
79
- runner.review('db/migrate/20101010080658_create_users.rb', content)
80
- runner.should have(0).errors
81
- end
82
84
 
83
- it "should not raise an error" do
84
- content =<<-EOF
85
- class AddAdmin < ActiveRecord::Migration
85
+ it "should not raise an error" do
86
+ content =<<-EOF
87
+ class AddAdmin < ActiveRecord::Migration
86
88
 
87
- class Person < ActiveRecord::Base
88
- end
89
+ class Person < ActiveRecord::Base
90
+ end
89
91
 
90
- class Blog < ActiveRecord::Base
91
- end
92
+ class Blog < ActiveRecord::Base
93
+ end
92
94
 
93
- def self.up
94
- add_column :people, :admin, :boolean, :default => false, :null => false
95
- add_column :people, :deactivated, :boolean,
96
- :default => false, :null => false
95
+ def self.up
96
+ add_column :people, :admin, :boolean, :default => false, :null => false
97
+ add_column :people, :deactivated, :boolean,
98
+ :default => false, :null => false
97
99
 
98
- key = Crypto::Key.from_file("\#{RAILS_ROOT}/rsa_key.pub")
99
- person = Person.new(:email => "admin@example.com",
100
- :name => "admin",
101
- :crypted_password => key.encrypt("admin"),
102
- :description => "")
103
- person.admin = true
104
- person.save!
105
- Blog.create(:person_id => person.id)
106
- end
100
+ key = Crypto::Key.from_file("\#{RAILS_ROOT}/rsa_key.pub")
101
+ person = Person.new(:email => "admin@example.com",
102
+ :name => "admin",
103
+ :crypted_password => key.encrypt("admin"),
104
+ :description => "")
105
+ person.admin = true
106
+ person.save!
107
+ Blog.create(:person_id => person.id)
108
+ end
107
109
 
108
- def self.down
109
- remove_column :people, :deactivated
110
- Person.delete(Person.find_by_name("admin"))
111
- remove_column :people, :admin
110
+ def self.down
111
+ remove_column :people, :deactivated
112
+ Person.delete(Person.find_by_name("admin"))
113
+ remove_column :people, :admin
114
+ end
115
+ end
116
+ EOF
117
+ runner.review('db/migrate/20101010080658_create_users.rb', content)
118
+ runner.should have(3).errors
112
119
  end
113
120
  end
114
- EOF
115
- runner.review('db/migrate/20101010080658_create_users.rb', content)
116
- runner.should have(3).errors
117
121
  end
118
122
  end
@@ -1,184 +1,179 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RailsBestPractices::Reviews::UseScopeAccessReview do
4
- let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::UseScopeAccessReview.new) }
5
-
6
- context "if" do
7
- it "shoud use scope access" do
8
- content = <<-EOF
9
- class PostsController < ApplicationController
10
-
11
- def edit
12
- @post = Post.find(params[:id])
13
-
14
- if @post.user != current_user
15
- flash[:warning] = 'Access Denied'
16
- redirect_to posts_url
3
+ module RailsBestPractices
4
+ module Reviews
5
+ describe UseScopeAccessReview do
6
+ let(:runner) { Core::Runner.new(:reviews => UseScopeAccessReview.new) }
7
+
8
+ context "if" do
9
+ it "shoud use scope access" do
10
+ content = <<-EOF
11
+ class PostsController < ApplicationController
12
+ def edit
13
+ @post = Post.find(params[:id])
14
+
15
+ if @post.user != current_user
16
+ flash[:warning] = 'Access Denied'
17
+ redirect_to posts_url
18
+ end
19
+ end
17
20
  end
21
+ EOF
22
+ runner.review('app/controllers/posts_controller.rb', content)
23
+ runner.should have(1).errors
24
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
18
25
  end
19
- end
20
- EOF
21
- runner.review('app/controllers/posts_controller.rb', content)
22
- runner.should have(1).errors
23
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
24
- end
25
26
 
26
- it "shoud use scope access by comparing with id" do
27
- content = <<-EOF
28
- class PostsController < ApplicationController
29
-
30
- def edit
31
- @post = Post.find(params[:id])
32
-
33
- if @post.user_id != current_user.id
34
- flash[:warning] = 'Access Denied'
35
- redirect_to posts_url
27
+ it "shoud use scope access by comparing with id" do
28
+ content = <<-EOF
29
+ class PostsController < ApplicationController
30
+ def edit
31
+ @post = Post.find(params[:id])
32
+
33
+ if @post.user_id != current_user.id
34
+ flash[:warning] = 'Access Denied'
35
+ redirect_to posts_url
36
+ end
37
+ end
36
38
  end
39
+ EOF
40
+ runner.review('app/controllers/posts_controller.rb', content)
41
+ runner.should have(1).errors
42
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
37
43
  end
38
- end
39
- EOF
40
- runner.review('app/controllers/posts_controller.rb', content)
41
- runner.should have(1).errors
42
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
43
- end
44
44
 
45
- it "shoud use scope access with current_user ==" do
46
- content = <<-EOF
47
- class PostsController < ApplicationController
48
-
49
- def edit
50
- @post = Post.find(params[:id])
51
-
52
- if current_user != @post.user
53
- flash[:warning] = 'Access Denied'
54
- redirect_to posts_url
45
+ it "shoud use scope access with current_user ==" do
46
+ content = <<-EOF
47
+ class PostsController < ApplicationController
48
+ def edit
49
+ @post = Post.find(params[:id])
50
+
51
+ if current_user != @post.user
52
+ flash[:warning] = 'Access Denied'
53
+ redirect_to posts_url
54
+ end
55
+ end
55
56
  end
57
+ EOF
58
+ runner.review('app/controllers/posts_controller.rb', content)
59
+ runner.should have(1).errors
60
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
56
61
  end
57
- end
58
- EOF
59
- runner.review('app/controllers/posts_controller.rb', content)
60
- runner.should have(1).errors
61
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
62
- end
63
62
 
64
- it "shoud use scope access by current_user.id ==" do
65
- content = <<-EOF
66
- class PostsController < ApplicationController
67
-
68
- def edit
69
- @post = Post.find(params[:id])
70
-
71
- if current_user.id != @post.user_id
72
- flash[:warning] = 'Access Denied'
73
- redirect_to posts_url
63
+ it "shoud use scope access by current_user.id ==" do
64
+ content = <<-EOF
65
+ class PostsController < ApplicationController
66
+ def edit
67
+ @post = Post.find(params[:id])
68
+
69
+ if current_user.id != @post.user_id
70
+ flash[:warning] = 'Access Denied'
71
+ redirect_to posts_url
72
+ end
73
+ end
74
74
  end
75
+ EOF
76
+ runner.review('app/controllers/posts_controller.rb', content)
77
+ runner.should have(1).errors
78
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
75
79
  end
76
80
  end
77
- EOF
78
- runner.review('app/controllers/posts_controller.rb', content)
79
- runner.should have(1).errors
80
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
81
- end
82
- end
83
81
 
84
- context "unless" do
85
- it "shoud use scope access" do
86
- content = <<-EOF
87
- class PostsController < ApplicationController
88
-
89
- def edit
90
- @post = Post.find(params[:id])
91
-
92
- unless @post.user == current_user
93
- flash[:warning] = 'Access Denied'
94
- redirect_to posts_url
82
+ context "unless" do
83
+ it "shoud use scope access" do
84
+ content = <<-EOF
85
+ class PostsController < ApplicationController
86
+ def edit
87
+ @post = Post.find(params[:id])
88
+
89
+ unless @post.user == current_user
90
+ flash[:warning] = 'Access Denied'
91
+ redirect_to posts_url
92
+ end
93
+ end
95
94
  end
95
+ EOF
96
+ runner.review('app/controllers/posts_controller.rb', content)
97
+ runner.should have(1).errors
98
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
96
99
  end
97
- end
98
- EOF
99
- runner.review('app/controllers/posts_controller.rb', content)
100
- runner.should have(1).errors
101
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
102
- end
103
-
104
- it "shoud use scope access by comparing with id" do
105
- content = <<-EOF
106
- class PostsController < ApplicationController
107
100
 
108
- def edit
109
- @post = Post.find(params[:id])
110
-
111
- unless @post.user_id == current_user.id
112
- flash[:warning] = 'Access Denied'
113
- redirect_to posts_url
101
+ it "shoud use scope access by comparing with id" do
102
+ content = <<-EOF
103
+ class PostsController < ApplicationController
104
+ def edit
105
+ @post = Post.find(params[:id])
106
+
107
+ unless @post.user_id == current_user.id
108
+ flash[:warning] = 'Access Denied'
109
+ redirect_to posts_url
110
+ end
111
+ end
114
112
  end
113
+ EOF
114
+ runner.review('app/controllers/posts_controller.rb', content)
115
+ runner.should have(1).errors
116
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
115
117
  end
116
- end
117
- EOF
118
- runner.review('app/controllers/posts_controller.rb', content)
119
- runner.should have(1).errors
120
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
121
- end
122
-
123
- it "shoud use scope access with current_user ==" do
124
- content = <<-EOF
125
- class PostsController < ApplicationController
126
118
 
127
- def edit
128
- @post = Post.find(params[:id])
129
-
130
- unless current_user == @post.user
131
- flash[:warning] = 'Access Denied'
132
- redirect_to posts_url
119
+ it "shoud use scope access with current_user ==" do
120
+ content = <<-EOF
121
+ class PostsController < ApplicationController
122
+ def edit
123
+ @post = Post.find(params[:id])
124
+
125
+ unless current_user == @post.user
126
+ flash[:warning] = 'Access Denied'
127
+ redirect_to posts_url
128
+ end
129
+ end
133
130
  end
131
+ EOF
132
+ runner.review('app/controllers/posts_controller.rb', content)
133
+ runner.should have(1).errors
134
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
134
135
  end
135
- end
136
- EOF
137
- runner.review('app/controllers/posts_controller.rb', content)
138
- runner.should have(1).errors
139
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
140
- end
141
-
142
- it "shoud use scope access by current_user.id ==" do
143
- content = <<-EOF
144
- class PostsController < ApplicationController
145
136
 
146
- def edit
147
- @post = Post.find(params[:id])
148
-
149
- unless current_user.id == @post.user_id
150
- flash[:warning] = 'Access Denied'
151
- redirect_to posts_url
137
+ it "shoud use scope access by current_user.id ==" do
138
+ content = <<-EOF
139
+ class PostsController < ApplicationController
140
+ def edit
141
+ @post = Post.find(params[:id])
142
+
143
+ unless current_user.id == @post.user_id
144
+ flash[:warning] = 'Access Denied'
145
+ redirect_to posts_url
146
+ end
147
+ end
152
148
  end
149
+ EOF
150
+ runner.review('app/controllers/posts_controller.rb', content)
151
+ runner.should have(1).errors
152
+ runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
153
153
  end
154
- end
155
- EOF
156
- runner.review('app/controllers/posts_controller.rb', content)
157
- runner.should have(1).errors
158
- runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:6 - use scope access"
159
- end
160
154
 
161
- it "should no error in use_scope_access_review" do
162
- content = <<-EOF
163
- class CommentsController < ApplicationController
164
-
165
- def add_comment
166
- @current_user = User.find_by_id(session[:user_id])
167
- @id = params[:post_id]
168
- @error = ""
169
- if (@text = params[:text]) == ""
170
- @error = "Please enter a comment!"
171
- else
172
- @comment = Comment.create_object(@text, @id, @current_user.id)
173
- end
174
- unless @comment
175
- @error = "Comment could not be saved."
155
+ it "should no error in use_scope_access_review" do
156
+ content = <<-EOF
157
+ class CommentsController < ApplicationController
158
+ def add_comment
159
+ @current_user = User.find_by_id(session[:user_id])
160
+ @id = params[:post_id]
161
+ @error = ""
162
+ if (@text = params[:text]) == ""
163
+ @error = "Please enter a comment!"
164
+ else
165
+ @comment = Comment.create_object(@text, @id, @current_user.id)
166
+ end
167
+ unless @comment
168
+ @error = "Comment could not be saved."
169
+ end
170
+ end
176
171
  end
172
+ EOF
173
+ runner.review('app/controllers/comments_controller.rb', content)
174
+ runner.should have(0).errors
177
175
  end
178
176
  end
179
- EOF
180
- runner.review('app/controllers/comments_controller.rb', content)
181
- runner.should have(0).errors
182
177
  end
183
178
  end
184
179
  end