rails_best_practices 0.2.5 → 0.2.6
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/VERSION +1 -1
- data/lib/rails_best_practices/checks/use_observer_check.rb +3 -1
- data/lib/rails_best_practices/command.rb +7 -2
- data/lib/rails_best_practices/core/runner.rb +1 -1
- data/rails_best_practices.gemspec +1 -1
- data/spec/rails_best_practices/checks/use_observer_check_spec.rb +23 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
3
|
def expand_dirs_to_files *dirs
|
4
|
+
# extensions = ['rb', 'erb', 'builder']
|
4
5
|
extensions = ['rb', 'builder']
|
5
6
|
|
6
7
|
dirs.flatten.map { |p|
|
7
8
|
if File.directory? p
|
8
|
-
Dir[File.join(p, '**', "
|
9
|
+
Dir[File.join(p, '**', "*.{#{extensions.join(',')}}")]
|
9
10
|
else
|
10
11
|
p
|
11
12
|
end
|
@@ -27,6 +28,10 @@ def add_duplicate_migration_files files
|
|
27
28
|
(files << migration_files).flatten
|
28
29
|
end
|
29
30
|
|
31
|
+
def ignore_vendor_directories files
|
32
|
+
files.reject { |file| file.index("vendor/") }
|
33
|
+
end
|
34
|
+
|
30
35
|
options = {}
|
31
36
|
OptionParser.new do |opts|
|
32
37
|
opts.banner = "Usage: rails_best_practices [options]"
|
@@ -40,7 +45,7 @@ OptionParser.new do |opts|
|
|
40
45
|
end
|
41
46
|
|
42
47
|
runner = RailsBestPractices::Core::Runner.new
|
43
|
-
add_duplicate_migration_files(expand_dirs_to_files(ARGV)).each { |file| runner.check_file(file) }
|
48
|
+
ignore_vendor_directories(add_duplicate_migration_files(expand_dirs_to_files(ARGV))).each { |file| runner.check_file(file) }
|
44
49
|
runner.errors.each {|error| puts error}
|
45
50
|
puts "\nFound #{runner.errors.size} errors."
|
46
51
|
|
@@ -49,7 +49,7 @@ module RailsBestPractices
|
|
49
49
|
begin
|
50
50
|
@parser.parse(content, filename)
|
51
51
|
rescue Exception => e
|
52
|
-
puts "#{filename} looks like it's not a valid Ruby file. Skipping..."
|
52
|
+
puts "#{filename} looks like it's not a valid Ruby file. Skipping..."
|
53
53
|
nil
|
54
54
|
end
|
55
55
|
end
|
@@ -41,4 +41,27 @@ describe RailsBestPractices::Checks::UseObserverCheck do
|
|
41
41
|
errors = @runner.errors
|
42
42
|
errors.should be_empty
|
43
43
|
end
|
44
|
+
|
45
|
+
it "should use observer with two after_create" do
|
46
|
+
content =<<-EOF
|
47
|
+
class Project < ActiveRecord::Base
|
48
|
+
after_create :send_create_notification, :update_author
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def send_create_notification
|
53
|
+
self.members.each do |member|
|
54
|
+
ProjectMailer.deliver_notification(self, member)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def update_author
|
59
|
+
end
|
60
|
+
end
|
61
|
+
EOF
|
62
|
+
@runner.check('app/models/project.rb', content)
|
63
|
+
errors = @runner.errors
|
64
|
+
errors.should_not be_empty
|
65
|
+
errors[0].to_s.should == "app/models/project.rb:6 - use observer"
|
66
|
+
end
|
44
67
|
end
|