rails_best_practices 0.2.12 → 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -0
- data/VERSION +1 -1
- data/lib/rails_best_practices/checks/isolate_seed_data_check.rb +20 -7
- data/lib/rails_best_practices/core/runner.rb +1 -1
- data/rails_best_practices.gemspec +15 -15
- data/spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb +10 -5
- metadata +14 -14
data/README.textile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.13
|
@@ -8,7 +8,7 @@ module RailsBestPractices
|
|
8
8
|
class IsolateSeedDataCheck < Check
|
9
9
|
|
10
10
|
def interesting_nodes
|
11
|
-
[:call, :lasgn]
|
11
|
+
[:defs, :call, :lasgn]
|
12
12
|
end
|
13
13
|
|
14
14
|
def interesting_files
|
@@ -18,15 +18,28 @@ module RailsBestPractices
|
|
18
18
|
def initialize
|
19
19
|
super
|
20
20
|
@new_variables = []
|
21
|
+
@files = []
|
22
|
+
@parse = false
|
21
23
|
end
|
22
24
|
|
23
25
|
def evaluate_start(node)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
# check duplicate migration because of always_add_db_index_check.
|
27
|
+
if :defs == node.node_type
|
28
|
+
if @files.include? node.file
|
29
|
+
@parse = true if :up == node.message
|
30
|
+
else
|
31
|
+
@files << node.file
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if @parse
|
36
|
+
if [:create, :create!].include? node.message
|
37
|
+
add_error("isolate seed data")
|
38
|
+
elsif :lasgn == node.node_type
|
39
|
+
remember_new_variable(node)
|
40
|
+
elsif [:save, :save!].include? node.message
|
41
|
+
add_error("isolate seed data") if new_record?(node)
|
42
|
+
end
|
30
43
|
end
|
31
44
|
end
|
32
45
|
|
@@ -54,7 +54,7 @@ module RailsBestPractices
|
|
54
54
|
begin
|
55
55
|
RubyParser.new.parse(content, filename)
|
56
56
|
rescue Exception => e
|
57
|
-
puts "#{filename} looks like it's not a valid Ruby file. Skipping..."
|
57
|
+
puts "#{filename} looks like it's not a valid Ruby file. Skipping..." if @debug
|
58
58
|
nil
|
59
59
|
end
|
60
60
|
end
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_best_practices}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Richard Huang"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-10}
|
13
13
|
s.default_executable = %q{rails_best_practices}
|
14
14
|
s.description = %q{check rails files according to ihower's presentation 'rails best practices'}
|
15
15
|
s.email = %q{flyerhzm@gmail.com}
|
@@ -82,24 +82,24 @@ Gem::Specification.new do |s|
|
|
82
82
|
s.rubygems_version = %q{1.3.5}
|
83
83
|
s.summary = %q{check rails files according to ihower's presentation 'rails best practices'}
|
84
84
|
s.test_files = [
|
85
|
-
"spec/rails_best_practices/checks/
|
86
|
-
"spec/rails_best_practices/checks/
|
87
|
-
"spec/rails_best_practices/checks/use_filter_check_spec.rb",
|
88
|
-
"spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
|
89
|
-
"spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
|
90
|
-
"spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
|
85
|
+
"spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb",
|
86
|
+
"spec/rails_best_practices/checks/always_add_db_index_check_spec.rb",
|
91
87
|
"spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb",
|
92
|
-
"spec/rails_best_practices/checks/
|
93
|
-
"spec/rails_best_practices/checks/use_model_association_check_spec.rb",
|
94
|
-
"spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
|
88
|
+
"spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb",
|
95
89
|
"spec/rails_best_practices/checks/law_of_demeter_check_spec.rb",
|
96
|
-
"spec/rails_best_practices/checks/
|
97
|
-
"spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
|
98
|
-
"spec/rails_best_practices/checks/use_observer_check_spec.rb",
|
90
|
+
"spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb",
|
99
91
|
"spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb",
|
92
|
+
"spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb",
|
100
93
|
"spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb",
|
94
|
+
"spec/rails_best_practices/checks/nested_model_forms_check_spec.rb",
|
95
|
+
"spec/rails_best_practices/checks/not_use_default_route_check_spec.rb",
|
101
96
|
"spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb",
|
102
|
-
"spec/rails_best_practices/checks/
|
97
|
+
"spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb",
|
98
|
+
"spec/rails_best_practices/checks/use_filter_check_spec.rb",
|
99
|
+
"spec/rails_best_practices/checks/use_model_association_check_spec.rb",
|
100
|
+
"spec/rails_best_practices/checks/use_model_callback_check_spec.rb",
|
101
|
+
"spec/rails_best_practices/checks/use_observer_check_spec.rb",
|
102
|
+
"spec/rails_best_practices/checks/use_scope_access_check_spec.rb",
|
103
103
|
"spec/spec_helper.rb"
|
104
104
|
]
|
105
105
|
|
@@ -24,11 +24,14 @@ describe RailsBestPractices::Checks::IsolateSeedDataCheck do
|
|
24
24
|
end
|
25
25
|
EOF
|
26
26
|
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
27
|
+
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
27
28
|
errors = @runner.errors
|
28
29
|
errors.should_not be_empty
|
29
30
|
errors[0].to_s.should == "db/migrate/20090818130258_create_roles.rb:8 - isolate seed data"
|
31
|
+
puts errors.inspect
|
32
|
+
errors.size.should == 1
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
it "should isolate seed data with new and save" do
|
33
36
|
content = <<-EOF
|
34
37
|
class CreateRoles < ActiveRecord::Migration
|
@@ -36,24 +39,25 @@ describe RailsBestPractices::Checks::IsolateSeedDataCheck do
|
|
36
39
|
create_table "roles", :force => true do |t|
|
37
40
|
t.string :name
|
38
41
|
end
|
39
|
-
|
42
|
+
|
40
43
|
["admin", "author", "editor", "account"].each do |name|
|
41
44
|
role = Role.new(:name => name)
|
42
45
|
role.save!
|
43
46
|
end
|
44
47
|
end
|
45
|
-
|
48
|
+
|
46
49
|
def self.down
|
47
50
|
drop_table "roles"
|
48
51
|
end
|
49
52
|
end
|
50
53
|
EOF
|
51
54
|
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
55
|
+
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
52
56
|
errors = @runner.errors
|
53
57
|
errors.should_not be_empty
|
54
58
|
errors[0].to_s.should == "db/migrate/20090818130258_create_roles.rb:9 - isolate seed data"
|
55
59
|
end
|
56
|
-
|
60
|
+
|
57
61
|
it "should not isolate seed data without data insert" do
|
58
62
|
content = <<-EOF
|
59
63
|
class CreateRoles < ActiveRecord::Migration
|
@@ -62,13 +66,14 @@ describe RailsBestPractices::Checks::IsolateSeedDataCheck do
|
|
62
66
|
t.string :name
|
63
67
|
end
|
64
68
|
end
|
65
|
-
|
69
|
+
|
66
70
|
def self.down
|
67
71
|
drop_table "roles"
|
68
72
|
end
|
69
73
|
end
|
70
74
|
EOF
|
71
75
|
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
76
|
+
@runner.check('db/migrate/20090818130258_create_roles.rb', content)
|
72
77
|
errors = @runner.errors
|
73
78
|
errors.should be_empty
|
74
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-10 00:00:00 +08:00
|
13
13
|
default_executable: rails_best_practices
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -127,22 +127,22 @@ signing_key:
|
|
127
127
|
specification_version: 3
|
128
128
|
summary: check rails files according to ihower's presentation 'rails best practices'
|
129
129
|
test_files:
|
130
|
-
- spec/rails_best_practices/checks/use_scope_access_check_spec.rb
|
131
|
-
- spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
|
132
|
-
- spec/rails_best_practices/checks/use_filter_check_spec.rb
|
133
130
|
- spec/rails_best_practices/checks/add_model_virtual_attribute_check_spec.rb
|
134
|
-
- spec/rails_best_practices/checks/
|
135
|
-
- spec/rails_best_practices/checks/use_model_callback_check_spec.rb
|
131
|
+
- spec/rails_best_practices/checks/always_add_db_index_check_spec.rb
|
136
132
|
- spec/rails_best_practices/checks/isolate_seed_data_check_spec.rb
|
137
|
-
- spec/rails_best_practices/checks/
|
138
|
-
- spec/rails_best_practices/checks/use_model_association_check_spec.rb
|
139
|
-
- spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
|
133
|
+
- spec/rails_best_practices/checks/keep_finders_on_their_own_model_check_spec.rb
|
140
134
|
- spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
|
141
|
-
- spec/rails_best_practices/checks/
|
142
|
-
- spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
|
143
|
-
- spec/rails_best_practices/checks/use_observer_check_spec.rb
|
135
|
+
- spec/rails_best_practices/checks/many_to_many_collection_check_spec.rb
|
144
136
|
- spec/rails_best_practices/checks/move_finder_to_named_scope_check_spec.rb
|
137
|
+
- spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
|
145
138
|
- spec/rails_best_practices/checks/needless_deep_nesting_check_spec.rb
|
139
|
+
- spec/rails_best_practices/checks/nested_model_forms_check_spec.rb
|
140
|
+
- spec/rails_best_practices/checks/not_use_default_route_check_spec.rb
|
146
141
|
- spec/rails_best_practices/checks/overuse_route_customizations_check_spec.rb
|
147
|
-
- spec/rails_best_practices/checks/
|
142
|
+
- spec/rails_best_practices/checks/replace_complex_creation_with_factory_method_check_spec.rb
|
143
|
+
- spec/rails_best_practices/checks/use_filter_check_spec.rb
|
144
|
+
- spec/rails_best_practices/checks/use_model_association_check_spec.rb
|
145
|
+
- spec/rails_best_practices/checks/use_model_callback_check_spec.rb
|
146
|
+
- spec/rails_best_practices/checks/use_observer_check_spec.rb
|
147
|
+
- spec/rails_best_practices/checks/use_scope_access_check_spec.rb
|
148
148
|
- spec/spec_helper.rb
|