railscheck 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,10 +1,19 @@
1
- == 0.1.3 2008-03-15
1
+ == 0.1.5 2008-yet to be releases
2
+ * Adding javascript parse validation.
3
+ * Adding preliminary ruby code parse validation.
4
+
5
+ == 0.1.4 2008-04-26
6
+ * Fix: sqlite3 compatibility.
7
+ * Fix: changed check for plugin lib/init files to warnings.
8
+ * Added test that has_many, has_one, belongs_to and has_and_belongs_to_many associations uses the correct pluralization for names.
9
+
10
+ == 0.1.3 2008-04-15
2
11
  * Fixed typing mistake.
3
12
 
4
- == 0.1.2 2008-03-15
5
- * Included w3c_validators dependency in gem spec.
13
+ == 0.1.2 2008-04-15
14
+ * Included missing w3c_validators dependency in gem spec.
6
15
 
7
- == 0.1.1 2008-03-15
16
+ == 0.1.1 2008-04-15
8
17
  * First proper beta
9
18
 
10
19
  == 0.1.0 2008-03-15
@@ -14,4 +23,4 @@
14
23
  * Internal release converted into a ruby gem (no longer a rails plugin)
15
24
 
16
25
  == 0.0.0 2008-03-03
17
- * Initial proof of concept prerelease as a rails plugin (as demoed at copenhagen.rb)
26
+ * Initial proof of concept prerelease as a rails plugin (as demo'ed at copenhagen.rb)
data/Manifest.txt CHANGED
@@ -11,11 +11,13 @@ config/requirements.rb
11
11
  lib/railscheck.rb
12
12
  lib/railscheck/testcase.rb
13
13
  lib/railscheck/version.rb
14
+ lib/test/tc_associations.rb
14
15
  lib/test/tc_config.rb
15
16
  lib/test/tc_database_models.rb
16
17
  lib/test/tc_html_and_css.rb
17
18
  lib/test/tc_project.rb
18
19
  lib/test/tc_views.rb
20
+ lib/test/test_helper.rb
19
21
  log/debug.log
20
22
  script/console
21
23
  script/destroy
data/README.txt CHANGED
@@ -126,10 +126,13 @@ information. See also my blog postings at "http://techblog.41concepts.com/" abou
126
126
 
127
127
  * ----> Submit your code additions and get your name added here!! <----
128
128
 
129
- INSPIRATION AND ATTRIBUTIONS:
129
+ INSPIRATION, ATTRIBUTIONS AND SPECIAL CREDITS:
130
130
  * Fail Early Task written by Mike Naberezny for Advanced Rail Recipes.
131
131
  * DZone Snippet Rails task to find code typos in rhtml templates by "dseverin"
132
132
 
133
+ + Aaron Patterson for the Johnson javascript gem, Ryan Davis for the ruby parser,
134
+ Alex Dunae for the W3C wrapper gem.
135
+
133
136
  LICENSE INFORMATION:
134
137
  This software is FREE for both public and commercial use - with the possible exception of commercial
135
138
  software development tool makers that require a license (see License.txt file for details).
data/TODO.txt CHANGED
@@ -5,8 +5,6 @@ See below for a list of some future checks that are considered:
5
5
 
6
6
  SHORT/MID TERM:
7
7
 
8
- * Verify javascript
9
- * Syntax check where possible of *.rb
10
8
  * Syntax check *.rjs
11
9
  * Verify other markup than erb.
12
10
  * Additional verification of migration files
@@ -19,7 +17,7 @@ SHORT/MID TERM:
19
17
  * Check (some) model validations against data in database (looking for illegal data in database).
20
18
 
21
19
  LONGER TERM:
22
- * Code analysis checks of ruby and javascriprt code looking for, static detectablable, ruby code
20
+ * Code analysis checks of ruby and javascript code looking for, static detectable, ruby code
23
21
  that may have "simple" errors like accessing a variable before it is declared etc. This
24
22
  may in turn open up for many more features.
25
23
 
data/config/hoe.rb CHANGED
@@ -2,7 +2,7 @@ require 'railscheck/version'
2
2
 
3
3
  AUTHOR = 'Morten M. Christensen / 41concepts' # can also be an array of Authors
4
4
  EMAIL = "mmc@41concepts.com"
5
- DESCRIPTION = "Static verifier for rails 2.0+ projects"
5
+ DESCRIPTION = "Static verifier for Ruby On Rails projects"
6
6
  GEM_NAME = 'railscheck' # what ppl will type to install your gem
7
7
  RUBYFORGE_PROJECT = 'railscheck' # The unix name for your project
8
8
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
@@ -8,7 +8,30 @@ module Railscheck
8
8
  def default_test
9
9
  # Do nothing
10
10
  end
11
+
12
+ protected
13
+ # Helper: Retrive array of all model classes in current rails project
14
+ def lookup_active_record_models_classes
15
+ # Cache loaded model classes so we don't need to reload.
16
+ if !defined? @@model_classes
17
+ @@model_classes = []
18
+ Dir["#{RAILS_ROOT}/app/models/*rb"].each do |fname|
19
+ class_names = load(fname, false)
20
+ class_names.each do |class_name|
21
+ c = Object.const_get(class_name)
22
+ # Note: "c.kind_of?(ActiveRecord::Base)" not working here so do alt. check instead.
23
+ if (c.respond_to? 'abstract_class') && !c.abstract_class? &&
24
+ (c.respond_to? 'descends_from_active_record?')
25
+ @@model_classes << c
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ @@model_classes
32
+ end
11
33
 
34
+ # Helper: Handle warnings
12
35
  def warn(msg)
13
36
  puts "Warning: "+msg
14
37
  end
@@ -2,7 +2,7 @@ module Railscheck #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/railscheck.rb CHANGED
@@ -42,7 +42,8 @@ BANNER
42
42
  "Exclude test files satisfying specified the regular expresssion string (without //)"
43
43
  ) { |OPTIONS[:exclude_test_files]| }
44
44
 
45
- opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
45
+ opts.on("-h", "-?", "--help", "Show this help message.") { puts opts; exit }
46
+
46
47
  opts.parse!(ARGV)
47
48
 
48
49
  if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
@@ -0,0 +1,21 @@
1
+ require 'test/test_helper'
2
+
3
+ module Railscheck
4
+ module Test
5
+ class Associations < Railscheck::TestCase
6
+ # Test that associations uses the correct pluralization.
7
+ def test_associations_pluralization
8
+ lookup_active_record_models_classes.each do |clazz|
9
+ clazz.reflect_on_all_associations.each do |a|
10
+ #puts "Checking associations #{a.macro} #{a.name} for #{clazz}"
11
+ if a.macro==:has_many || a.macro==:has_and_belongs_to_many
12
+ assert plural?(a.name), "#{a.macro} association #{a.name} in model class #{clazz} should be be a plural name (as known by rails pluralizer)"
13
+ elsif a.macro==:has_one || a.macro==:belongs_to
14
+ assert singular?(a.name), "#{a.macro} association #{a.name} in model class #{clazz} should be be a singular name (as known by rails pluralizer)"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
- require 'railscheck/testcase'
1
+ require 'test/test_helper'
2
2
 
3
3
  module Railscheck
4
4
  module Test
@@ -1,4 +1,4 @@
1
- require 'railscheck/testcase'
1
+ require 'test/test_helper'
2
2
 
3
3
  module Railscheck
4
4
  module Test
@@ -7,9 +7,9 @@ module Railscheck
7
7
  def test_database_connection_working
8
8
  assert File.file?("#{RAILS_ROOT}/config/database.yml"), "Database configuration file database.yml must be present"
9
9
 
10
- assert_nothing_raised("Could not open database connection") do
10
+ assert_nothing_raised("Could not open database connection / no migration schema_info table in database") do
11
11
  ActiveRecord::Base.establish_connection
12
- ActiveRecord::Base.connection.select_all('SHOW TABLES')
12
+ ActiveRecord::Base.connection.select_all('select * from schema_info')
13
13
  end
14
14
  end
15
15
 
@@ -25,16 +25,8 @@ module Railscheck
25
25
 
26
26
  # Check that correctly named database tables exist for each rails model
27
27
  def test_database_tables_and_models_consistency
28
- Dir["#{RAILS_ROOT}/app/models/*rb"].each do |fname|
29
- class_names = load(fname, false)
30
- class_names.each do |class_name|
31
- c = Object.const_get(class_name)
32
- # Note: "c.kind_of?(ActiveRecord::Base)" not working here so do alt. check instead.
33
- if (c.respond_to? 'abstract_class') && !c.abstract_class? &&
34
- (c.respond_to? 'descends_from_active_record?') #&& c.descends_from_active_record?
35
- assert c.table_exists?, "Error - Could not find database table #{c.table_name} corresponding to rails model #{c.name}"
36
- end
37
- end
28
+ lookup_active_record_models_classes.each do |clazz|
29
+ assert clazz.table_exists?, "Error - Could not find database table #{clazz.table_name} corresponding to rails model #{clazz.name}"
38
30
  end
39
31
  end
40
32
 
@@ -1,4 +1,4 @@
1
- require 'railscheck/testcase'
1
+ require 'test/test_helper'
2
2
  require 'w3c_validators'
3
3
 
4
4
  module Railscheck
@@ -1,4 +1,4 @@
1
- require 'railscheck/testcase'
1
+ require 'test/test_helper'
2
2
 
3
3
  module Railscheck
4
4
  module Test
@@ -97,8 +97,8 @@ module Railscheck
97
97
  lib_dir = File.join(plugindir, "lib")
98
98
  init_file = File.join(plugindir, "init.rb")
99
99
 
100
- assert File.directory?(lib_dir), "Error no lib sub-directory in plugin at \"#{plugindir}\""
101
- assert File.file?(init_file), "Error no init file in plugin at \"#{plugindir}\""
100
+ warn "No lib sub-directory in plugin at \"#{plugindir}\"" if !File.directory?(lib_dir)
101
+ warn "No init file in plugin at \"#{plugindir}\"" if !File.file?(init_file)
102
102
  end
103
103
  end
104
104
  end
data/lib/test/tc_views.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'railscheck/testcase'
1
+ require 'test/test_helper'
2
2
 
3
3
  module Railscheck
4
4
  module Test
@@ -0,0 +1,19 @@
1
+ require 'test/test_helper'
2
+ require 'railscheck/testcase'
3
+
4
+ # Read and return filename content as string.
5
+ def get_file_as_string(filename)
6
+ File.open(filename, "r") { |f|
7
+ return f.read
8
+ }
9
+ end
10
+
11
+ # Helper: Checks if a string/symbol is pluralized.
12
+ def plural?(str)
13
+ str.to_s.pluralize==str.to_s
14
+ end
15
+
16
+ # Helper: Checks if a string/symbol is singularized.
17
+ def singular?(str)
18
+ str.to_s.singularize==str.to_s
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railscheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten M. Christensen / 41concepts
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-15 00:00:00 +02:00
12
+ date: 2008-04-27 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -21,7 +21,7 @@ dependencies:
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.9.2
23
23
  version:
24
- description: Static verifier for rails 2.0+ projects
24
+ description: Static verifier for Ruby On Rails projects
25
25
  email:
26
26
  - mmc@41concepts.com
27
27
  executables:
@@ -49,11 +49,13 @@ files:
49
49
  - lib/railscheck.rb
50
50
  - lib/railscheck/testcase.rb
51
51
  - lib/railscheck/version.rb
52
+ - lib/test/tc_associations.rb
52
53
  - lib/test/tc_config.rb
53
54
  - lib/test/tc_database_models.rb
54
55
  - lib/test/tc_html_and_css.rb
55
56
  - lib/test/tc_project.rb
56
57
  - lib/test/tc_views.rb
58
+ - lib/test/test_helper.rb
57
59
  - log/debug.log
58
60
  - script/console
59
61
  - script/destroy
@@ -92,7 +94,7 @@ rubyforge_project: railscheck
92
94
  rubygems_version: 1.1.1
93
95
  signing_key:
94
96
  specification_version: 2
95
- summary: Static verifier for rails 2.0+ projects
97
+ summary: Static verifier for Ruby On Rails projects
96
98
  test_files:
97
99
  - test/test_helper.rb
98
100
  - test/test_railscheck.rb