rails-erd 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.4.5:
2
+
3
+ * Display more helpful error message when the application models could not be
4
+ loaded successfully by the 'rake erd' task (reported by Greg Weber).
5
+
1
6
  === 0.4.4:
2
7
 
3
8
  * Added the ability to disable HTML markup in node labels (markup=false). This
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.4.5
@@ -19,7 +19,17 @@ namespace :erd do
19
19
  Rake::Task[:environment].invoke
20
20
 
21
21
  say "Loading code in search of Active Record models..."
22
- Rails.application.eager_load!
22
+ begin
23
+ Rails.application.eager_load!
24
+ rescue Exception => err
25
+ if Rake.application.options.trace
26
+ raise
27
+ else
28
+ trace = Rails.backtrace_cleaner.clean(err.backtrace)
29
+ error = (["Loading models failed!\nError occurred while loading application: #{err} (#{err.class})"] + trace).join("\n ")
30
+ raise error
31
+ end
32
+ end
23
33
 
24
34
  raise "Active Record was not loaded." unless defined? ActiveRecord
25
35
  end
data/rails-erd.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-erd}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rolf Timmermans"]
12
- s.date = %q{2011-03-22}
12
+ s.date = %q{2011-04-13}
13
13
  s.description = %q{Automatically generate an entity-relationship diagram (ERD) for your Rails models.}
14
14
  s.email = %q{r.timmermans@voormedia.com}
15
15
  s.extra_rdoc_files = [
@@ -16,7 +16,21 @@ class RakeTaskTest < ActiveSupport::TestCase
16
16
  FileUtils.rm "ERD.dot" rescue nil
17
17
  RailsERD::Diagram.send :remove_const, :Graphviz rescue nil
18
18
  end
19
-
19
+
20
+ define_method :create_app do
21
+ Object::Quux = Module.new
22
+ Object::Quux::Application = Class.new
23
+ Object::Rails = Struct.new(:application).new(Object::Quux::Application.new)
24
+ Rails.class_eval do
25
+ define_method :backtrace_cleaner do
26
+ ActiveSupport::BacktraceCleaner.new.tap do |cleaner|
27
+ cleaner.add_filter { |line| line.sub(File.dirname(__FILE__), "test/unit") }
28
+ cleaner.add_silencer { |line| line !~ /^test\/unit/ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+
20
34
  # Diagram generation =======================================================
21
35
  test "generate task should create output based on domain model" do
22
36
  create_simple_domain
@@ -28,12 +42,10 @@ class RakeTaskTest < ActiveSupport::TestCase
28
42
  Rake::Task["erd:generate"].execute rescue nil
29
43
  assert !File.exists?("ERD.dot")
30
44
  end
31
-
45
+
32
46
  test "generate task should eager load application environment" do
33
47
  eager_loaded, environment_loaded = nil
34
- Object::Quux = Module.new
35
- Object::Quux::Application = Class.new
36
- Object::Rails = Struct.new(:application).new(Object::Quux::Application.new)
48
+ create_app
37
49
  Rails.application.class_eval do
38
50
  define_method :eager_load! do
39
51
  eager_loaded = true
@@ -46,11 +58,9 @@ class RakeTaskTest < ActiveSupport::TestCase
46
58
  Rake::Task["erd:generate"].invoke
47
59
  assert_equal [true, true], [eager_loaded, environment_loaded]
48
60
  end
49
-
61
+
50
62
  test "generate task should complain if active record is not loaded" do
51
- Object::Quux = Module.new
52
- Object::Quux::Application = Class.new
53
- Object::Rails = Struct.new(:application).new(Object::Quux::Application.new)
63
+ create_app
54
64
  Rails.application.class_eval do
55
65
  define_method :eager_load! do end
56
66
  end
@@ -64,7 +74,53 @@ class RakeTaskTest < ActiveSupport::TestCase
64
74
  end
65
75
  assert_equal "Active Record was not loaded.", message
66
76
  end
67
-
77
+
78
+ test "generate task should complain with simplified stack trace if application could not be loaded" do
79
+ create_app
80
+ l1, l2 = nil, nil
81
+ Rails.application.class_eval do
82
+ define_method :eager_load! do
83
+ l1 = __LINE__ + 1
84
+ raise "FooBar"
85
+ end
86
+ end
87
+ Rake::Task.define_task :environment
88
+ message = nil
89
+ begin
90
+ l2 = __LINE__ + 1
91
+ Rake::Task["erd:generate"].invoke
92
+ rescue => e
93
+ message = e.message
94
+ end
95
+ assert_equal <<-MSG.strip, message
96
+ Loading models failed!
97
+ Error occurred while loading application: FooBar (RuntimeError)
98
+ test/unit/rake_task_test.rb:#{l1}:in `block (3 levels) in <class:RakeTaskTest>'
99
+ test/unit/rake_task_test.rb:#{l2}:in `block in <class:RakeTaskTest>'
100
+ MSG
101
+ end
102
+
103
+ test "generate task should reraise if application could not be loaded and trace option is enabled" do
104
+ create_app
105
+ Rails.application.class_eval do
106
+ define_method :eager_load! do
107
+ raise "FooBar"
108
+ end
109
+ end
110
+ Rake::Task.define_task :environment
111
+ message = nil
112
+ begin
113
+ old_stdout, $stdout = $stdout, StringIO.new
114
+ Rake.application.options.trace = true
115
+ Rake::Task["erd:generate"].invoke
116
+ rescue => e
117
+ message = e.message
118
+ ensure
119
+ $stdout = old_stdout
120
+ end
121
+ assert_equal "FooBar", message
122
+ end
123
+
68
124
  # Option processing ========================================================
69
125
  test "options task should ignore unknown command line options" do
70
126
  ENV["unknownoption"] = "value"
@@ -101,7 +157,7 @@ class RakeTaskTest < ActiveSupport::TestCase
101
157
  Rake::Task["erd:options"].execute
102
158
  assert_equal true, RailsERD.options.title
103
159
  end
104
-
160
+
105
161
  test "options task should set known array command line options" do
106
162
  ENV["attributes"] = "content,timestamps"
107
163
  Rake::Task["erd:options"].execute
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails-erd
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.4
5
+ version: 0.4.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rolf Timmermans
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-22 00:00:00 +01:00
13
+ date: 2011-04-13 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency