railroady 1.1.2 → 1.6.0

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/railroady.gemspec CHANGED
@@ -1,27 +1,26 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'railroady/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "railroady"
8
+ spec.name = 'railroady'
8
9
  spec.version = RailRoady::VERSION
9
- spec.authors = ["Preston Lee", "Tobias Crawley", "Peter Hoeg", "Javier Smaldone"]
10
- spec.description = "Ruby on Rails 3/4 model and controller UML class diagram generator. Originally based on the 'railroad' plugin and contributions of many others. (`sudo port install graphviz` before use!)"
11
- spec.email = ["preston.lee@prestonlee.com", "tcrawley@gmail.com", "peter@hoeg.com", "p.hoeg@northwind.sg", "javier@smaldone.com.ar"]
12
- spec.summary = "Ruby on Rails 3/4 model and controller UML class diagram generator."
13
- spec.homepage = "http://github.com/preston/railroady"
14
- spec.license = "GPLv2"
10
+ spec.authors = ['Preston Lee', 'Tobias Crawley', 'Peter Hoeg', 'Javier Smaldone']
11
+ spec.description = "Ruby on Rails model and controller UML class diagram generator. Originally based on the 'railroad' plugin and contributions of many others. (`brew install graphviz` before use!)"
12
+ spec.email = %w[preston.lee@prestonlee.com tcrawley@gmail.com peter@hoeg.com p.hoeg@northwind.sg javier@smaldone.com.ar]
13
+ spec.summary = 'Ruby on Rails model and controller UML class diagram generator.'
14
+ spec.homepage = 'http://github.com/preston/railroady'
15
+ spec.license = 'GPLv2'
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
+ spec.files = `git ls-files`.split("\n")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "minitest"
24
- spec.add_development_dependency "minitest-spec-context"
25
- spec.add_development_dependency "activesupport"
20
+ spec.require_paths = ['lib']
26
21
 
22
+ spec.add_development_dependency 'activesupport'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'rake'
27
26
  end
data/tasks/railroady.rake CHANGED
@@ -26,20 +26,20 @@ module RailRoady
26
26
  def self.sed
27
27
  regex = 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g'
28
28
  case RbConfig::CONFIG['host_os']
29
- when /linux|cygwin|mingw/
29
+ when /linux/
30
30
  return "sed -r '#{regex}'"
31
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
32
+ return "sed -r \"#{regex}\""
31
33
  when /mac|darwin|bsd/
32
34
  return "sed -E '#{regex}'"
33
35
  else
34
- raise NotImplementedError
36
+ fail NotImplementedError
35
37
  end
36
38
  end
37
-
38
39
  end
39
40
  end
40
41
 
41
42
  namespace :diagram do
42
-
43
43
  @MODELS_ALL = RailRoady::RakeHelpers.full_path("models_complete.#{RailRoady::RakeHelpers.format}").freeze
44
44
  @MODELS_BRIEF = RailRoady::RakeHelpers.full_path("models_brief.#{RailRoady::RakeHelpers.format}").freeze
45
45
  @CONTROLLERS_ALL = RailRoady::RakeHelpers.full_path("controllers_complete.#{RailRoady::RakeHelpers.format}").freeze
@@ -49,50 +49,91 @@ namespace :diagram do
49
49
  namespace :setup do
50
50
  desc 'Perform any setup needed for the gem'
51
51
  task :create_new_doc_folder_if_needed do
52
- Dir.mkdir('doc') unless File.exists?('doc')
52
+ Dir.mkdir('doc') unless File.exist?('doc')
53
53
  end
54
54
  end
55
55
 
56
56
  namespace :models do
57
+ desc 'Generates brief and complete class diagrams for all models.'
58
+ task all: ['diagram:setup:create_new_doc_folder_if_needed', 'diagram:models:complete', 'diagram:models:brief']
57
59
 
58
- desc 'Generates an class diagram for all models.'
60
+ desc 'Generates a class diagram for all models.'
59
61
  task :complete do
60
62
  f = @MODELS_ALL
61
63
  puts "Generating #{f}"
62
- sh "railroady -ilamM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
64
+ sh "railroady -lamM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
63
65
  end
64
66
 
65
67
  desc 'Generates an abbreviated class diagram for all models.'
66
68
  task :brief do
67
69
  f = @MODELS_BRIEF
68
70
  puts "Generating #{f}"
69
- sh "railroady -bilamM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
71
+ sh "railroady -blamM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
72
+ end
73
+
74
+ desc 'Generates a class diagram for all models including those in engines'
75
+ task :complete_with_engines do
76
+ f = @MODELS_ALL
77
+ puts "Generating #{f}"
78
+ sh "railroady -ilamzM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
70
79
  end
71
80
 
81
+ desc 'Generates an abbreviated class diagram for all models including those in engines'
82
+ task :brief_with_engines do
83
+ f = @MODELS_BRIEF
84
+ puts "Generating #{f}"
85
+ sh "railroady -bilamzM | #{@SED} | dot -T#{RailRoady::RakeHelpers.format} > #{f}"
86
+ end
72
87
  end
73
88
 
74
89
  namespace :controllers do
90
+ desc 'Generates brief and complete class diagrams for all controllers.'
91
+ task all: ['diagram:setup:create_new_doc_folder_if_needed', 'diagram:controllers:complete', 'diagram:controllers:brief']
75
92
 
76
- desc 'Generates an class diagram for all controllers.'
93
+ desc 'Generates a class diagram for all controllers.'
77
94
  task :complete do
78
95
  f = @CONTROLLERS_ALL
79
96
  puts "Generating #{f}"
80
- sh "railroady -ilC | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
97
+ sh "railroady -lC | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
81
98
  end
82
99
 
83
100
  desc 'Generates an abbreviated class diagram for all controllers.'
84
101
  task :brief do
85
102
  f = @CONTROLLERS_BRIEF
86
103
  puts "Generating #{f}"
87
- sh "railroady -bilC | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
104
+ sh "railroady -blC | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
105
+ end
106
+
107
+ desc 'Generates a class diagram for all controllers including those in engines'
108
+ task :complete_with_engines do
109
+ f = @CONTROLLERS_ALL
110
+ puts "Generating #{f}"
111
+ sh "railroady -ilC --engine-controllers | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
88
112
  end
89
113
 
114
+ desc 'Generates an abbreviated class diagram for all controllers including those in engines.'
115
+ task :brief_with_engines do
116
+ f = @CONTROLLERS_BRIEF
117
+ puts "Generating #{f}"
118
+ sh "railroady -bilC --engine-controllers | #{@SED} | neato -T#{RailRoady::RakeHelpers.format} > #{f}"
119
+ end
90
120
  end
91
121
 
92
122
  desc 'Generates all class diagrams.'
93
- task all: ['diagram:setup:create_new_doc_folder_if_needed',
94
- 'diagram:models:complete',
95
- 'diagram:models:brief',
96
- 'diagram:controllers:complete',
97
- 'diagram:controllers:brief']
123
+ task all: [
124
+ 'diagram:setup:create_new_doc_folder_if_needed',
125
+ 'diagram:models:complete',
126
+ 'diagram:models:brief',
127
+ 'diagram:controllers:complete',
128
+ 'diagram:controllers:brief'
129
+ ]
130
+
131
+ desc 'Generates all class diagrams including those in engines'
132
+ task all_with_engines: [
133
+ 'diagram:setup:create_new_doc_folder_if_needed',
134
+ 'diagram:models:complete_with_engines',
135
+ 'diagram:models:brief_with_engines',
136
+ 'diagram:controllers:complete_with_engines',
137
+ 'diagram:controllers:brief_with_engines'
138
+ ]
98
139
  end
@@ -1,2 +1,2 @@
1
1
  class ApplicationController < ActionController::Base
2
- end
2
+ end
@@ -0,0 +1,12 @@
1
+ module AuthorSettings
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_validation :set_up_author
6
+ end
7
+
8
+ def set_up_author
9
+ self.created_by = 'Admin'
10
+ self.updated_by = 'Admin'
11
+ end
12
+ end
File without changes
File without changes
@@ -2,48 +2,53 @@ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
2
 
3
3
  describe AasmDiagram do
4
4
  describe 'file processing' do
5
-
6
5
  it 'should select all the files under the models dir' do
7
6
  ad = AasmDiagram.new
8
- files = ad.get_files("test/file_fixture/")
7
+ files = ad.get_files('test/file_fixture/')
9
8
  files.size.must_equal 3
10
9
  end
11
10
 
11
+ it 'should include concerns if specified' do
12
+ options = OptionsStruct.new(include_concerns: true)
13
+ ad = AasmDiagram.new(options)
14
+ files = ad.get_files('test/file_fixture/')
15
+ files.size.must_equal 5
16
+ end
17
+
12
18
  it 'should exclude a specific file' do
13
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/models/dummy1.rb'])
19
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/models/dummy1.rb'])
14
20
  ad = AasmDiagram.new(options)
15
- files = ad.get_files("test/file_fixture/")
21
+ files = ad.get_files('test/file_fixture/')
16
22
  files.size.must_equal 2
17
23
  end
18
24
 
19
25
  it 'should exclude a glob pattern of files' do
20
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/models/*/*.rb'])
26
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/models/*/*.rb'])
21
27
  ad = AasmDiagram.new(options)
22
- files = ad.get_files("test/file_fixture/")
28
+ files = ad.get_files('test/file_fixture/')
23
29
  files.size.must_equal 2
24
30
  end
25
31
 
26
32
  it 'should include only specific file' do
27
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
33
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
28
34
  ad = AasmDiagram.new(options)
29
- files = ad.get_files("test/file_fixture/")
35
+ files = ad.get_files('test/file_fixture/')
30
36
  files.size.must_equal 1
31
37
  end
32
38
 
33
39
  it 'should include only specified files' do
34
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'])
40
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'])
35
41
  ad = AasmDiagram.new(options)
36
- files = ad.get_files("test/file_fixture/")
42
+ files = ad.get_files('test/file_fixture/')
37
43
  files.size.must_equal 2
38
44
  end
39
45
 
40
46
  it 'should include only specified files and exclude specified files' do
41
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'],
42
- :exclude => ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
47
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'],
48
+ exclude: ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
43
49
  ad = AasmDiagram.new(options)
44
- files = ad.get_files("test/file_fixture/")
50
+ files = ad.get_files('test/file_fixture/')
45
51
  files.size.must_equal 1
46
52
  end
47
-
48
53
  end
49
54
  end
@@ -4,12 +4,11 @@ describe AppDiagram do
4
4
  describe 'file name processing' do
5
5
  it 'should extract a simple name' do
6
6
  ad = AppDiagram.new
7
- name = ad.instance_eval {extract_class_name('app/models/test_this.rb')}
7
+ name = ad.instance_eval { extract_class_name('app/models/test_this.rb') }
8
8
  name.must_equal 'TestThis'
9
9
  end
10
10
  it 'should constantize a name' do
11
11
  'String'.constantize.must_equal String
12
12
  end
13
-
14
13
  end
15
14
  end
@@ -2,48 +2,55 @@ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
2
 
3
3
  describe ControllersDiagram do
4
4
  describe 'file processing' do
5
-
6
5
  it 'should select all the files under the controllers dir' do
7
6
  cd = ControllersDiagram.new
8
- files = cd.get_files("test/file_fixture/")
7
+ files = cd.get_files('test/file_fixture/')
9
8
  files.size.must_equal 4
10
9
  end
11
10
 
12
11
  it 'should exclude a specific file' do
13
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/controllers/dummy1_controller.rb'])
12
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/controllers/dummy1_controller.rb'])
14
13
  cd = ControllersDiagram.new(options)
15
- files = cd.get_files("test/file_fixture/")
14
+ files = cd.get_files('test/file_fixture/')
16
15
  files.size.must_equal 3
17
16
  end
18
17
 
19
18
  it 'should exclude a glob pattern of files' do
20
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/controllers/sub-dir/*.rb'])
19
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/controllers/sub-dir/*.rb'])
21
20
  cd = ControllersDiagram.new(options)
22
- files = cd.get_files("test/file_fixture/")
21
+ files = cd.get_files('test/file_fixture/')
23
22
  files.size.must_equal 3
24
23
  end
25
24
 
26
25
  it 'should include only specific file' do
27
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb'])
26
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb'])
28
27
  cd = ControllersDiagram.new(options)
29
- files = cd.get_files("test/file_fixture/")
28
+ files = cd.get_files('test/file_fixture/')
30
29
  files.size.must_equal 1
31
30
  end
32
31
 
33
32
  it 'should include only specified files' do
34
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/controllers/{dummy1_*.rb,sub-dir/sub_dummy_controller.rb}'])
33
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/controllers/{dummy1_*.rb,sub-dir/sub_dummy_controller.rb}'])
35
34
  cd = ControllersDiagram.new(options)
36
- files = cd.get_files("test/file_fixture/")
35
+ files = cd.get_files('test/file_fixture/')
37
36
  files.size.must_equal 2
38
37
  end
39
38
 
40
39
  it 'should include only specified files and exclude specified files' do
41
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/controllers/{dummy1_*.rb,sub-dir/sub_dummy_controller.rb}'],
42
- :exclude => ['test/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb'])
40
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/controllers/{dummy1_*.rb,sub-dir/sub_dummy_controller.rb}'],
41
+ exclude: ['test/file_fixture/app/controllers/sub-dir/sub_dummy_controller.rb'])
43
42
  cd = ControllersDiagram.new(options)
44
- files = cd.get_files("test/file_fixture/")
43
+ files = cd.get_files('test/file_fixture/')
45
44
  files.size.must_equal 1
46
45
  end
47
46
 
47
+ it 'should include engine files' do
48
+ options = OptionsStruct.new(engine_controllers: true)
49
+ md = ControllersDiagram.new(options)
50
+ engines = [OpenStruct.new(root: 'test/file_fixture/lib')]
51
+ md.stub(:engines, engines) do
52
+ md.get_files.must_include('test/file_fixture/lib/app/controllers/dummy/dummy_controller.rb')
53
+ end
54
+ end
48
55
  end
49
56
  end
@@ -2,11 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
2
 
3
3
  describe String do
4
4
  describe '#camelize' do
5
- it "should upper-camelcase a lower case and underscored word" do
5
+ it 'should upper-camelcase a lower case and underscored word' do
6
6
  'lower_case_and_underscored_word'.camelize.must_equal 'LowerCaseAndUnderscoredWord'
7
7
  end
8
8
 
9
- it "should lower-camelcase a lower case and underscored word when the :lower parameter is passed" do
9
+ it 'should lower-camelcase a lower case and underscored word when the :lower parameter is passed' do
10
10
  'lower_case_and_underscored_word'.camelize(:lower).must_equal 'lowerCaseAndUnderscoredWord'
11
11
  end
12
12
  end
@@ -5,20 +5,24 @@ module CustomDotMatchers
5
5
  def initialize(expected)
6
6
  @expected = expected
7
7
  end
8
+
8
9
  def matches?(target)
9
10
  @target = target
10
11
  return false unless @target =~ /\[(.*)\]/
11
- @options = $1
12
+ @options = Regexp.last_match(1)
12
13
  @options == @expected
13
14
  end
15
+
14
16
  def failure_message
15
17
  "expected '#{@target.strip}' to have options '[#{@expected}]'"
16
18
  end
19
+
17
20
  def negative_failure_message
18
21
  "expected '#{@target.strip}' to not have options '[#{@expected}]'"
19
22
  end
23
+
20
24
  def description
21
- "have dot options"
25
+ 'have dot options'
22
26
  end
23
27
  end
24
28
  def have_dot_options(expected)
@@ -33,17 +37,17 @@ describe DiagramGraph do
33
37
  @diagram_graph = DiagramGraph.new
34
38
  end
35
39
 
36
- describe ".dot_edge" do
37
- context "has_a/belongs_to" do
38
- it { @diagram_graph.send(:dot_edge, "one-one", "source", "target").must_include "arrowtail=odot, arrowhead=dot, dir=both" }
39
- end
40
+ # describe ".dot_edge" do
41
+ # context "has_a/belongs_to" do
42
+ # it { @diagram_graph.send(:dot_edge, "one-one", "source", "target").must_include "arrowtail=odot, arrowhead=dot, dir=both" }
43
+ # end
40
44
 
41
- context "has_many/belongs_to" do
42
- it { @diagram_graph.send(:dot_edge, "one-many", "source", "target").must_include "arrowtail=odot, arrowhead=crow, dir=both" }
43
- end
45
+ # context "has_many/belongs_to" do
46
+ # it { @diagram_graph.send(:dot_edge, "one-many", "source", "target").must_include "arrowtail=odot, arrowhead=crow, dir=both" }
47
+ # end
44
48
 
45
- context "habtm" do
46
- it { @diagram_graph.send(:dot_edge, "many-many", "source", "target").must_include "arrowtail=crow, arrowhead=crow, dir=both" }
47
- end
48
- end
49
+ # context "habtm" do
50
+ # it { @diagram_graph.send(:dot_edge, "many-many", "source", "target").must_include "arrowtail=crow, arrowhead=crow, dir=both" }
51
+ # end
52
+ # end
49
53
  end
@@ -2,48 +2,161 @@ require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
2
2
 
3
3
  describe ModelsDiagram do
4
4
  describe 'file processing' do
5
-
6
5
  it 'should select all the files under the models dir' do
7
6
  md = ModelsDiagram.new
8
- files = md.get_files("test/file_fixture/")
7
+ files = md.get_files('test/file_fixture/')
9
8
  files.size.must_equal 3
10
9
  end
11
10
 
11
+ it 'should include concerns if specified' do
12
+ options = OptionsStruct.new(include_concerns: true)
13
+ ad = ModelsDiagram.new(options)
14
+ files = ad.get_files('test/file_fixture/')
15
+ files.size.must_equal 5
16
+ end
17
+
12
18
  it 'should exclude a specific file' do
13
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/models/dummy1.rb'])
19
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/models/dummy1.rb'])
14
20
  md = ModelsDiagram.new(options)
15
- files = md.get_files("test/file_fixture/")
21
+ files = md.get_files('test/file_fixture/')
16
22
  files.size.must_equal 2
17
23
  end
18
24
 
19
25
  it 'should exclude a glob pattern of files' do
20
- options = OptionsStruct.new(:exclude => ['test/file_fixture/app/models/*/*.rb'])
26
+ options = OptionsStruct.new(exclude: ['test/file_fixture/app/models/*/*.rb'])
21
27
  md = ModelsDiagram.new(options)
22
- files = md.get_files("test/file_fixture/")
28
+ files = md.get_files('test/file_fixture/')
23
29
  files.size.must_equal 2
24
30
  end
25
31
 
26
32
  it 'should include only specific file' do
27
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
33
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
28
34
  md = ModelsDiagram.new(options)
29
- files = md.get_files("test/file_fixture/")
35
+ files = md.get_files('test/file_fixture/')
30
36
  files.size.must_equal 1
31
37
  end
32
38
 
33
39
  it 'should include only specified files' do
34
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'])
40
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'])
35
41
  md = ModelsDiagram.new(options)
36
- files = md.get_files("test/file_fixture/")
42
+ files = md.get_files('test/file_fixture/')
37
43
  files.size.must_equal 2
38
44
  end
39
45
 
40
46
  it 'should include only specified files and exclude specified files' do
41
- options = OptionsStruct.new(:specify => ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'],
42
- :exclude => ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
47
+ options = OptionsStruct.new(specify: ['test/file_fixture/app/models/{dummy1.rb,sub-dir/sub_dummy.rb}'],
48
+ exclude: ['test/file_fixture/app/models/sub-dir/sub_dummy.rb'])
43
49
  md = ModelsDiagram.new(options)
44
- files = md.get_files("test/file_fixture/")
50
+ files = md.get_files('test/file_fixture/')
45
51
  files.size.must_equal 1
46
52
  end
47
53
 
54
+ it 'should include engine files' do
55
+ options = OptionsStruct.new(engine_models: true)
56
+ md = ModelsDiagram.new(options)
57
+ engines = [OpenStruct.new(root: 'test/file_fixture/lib')]
58
+ md.stub(:engines, engines) do
59
+ md.get_files.must_include('test/file_fixture/lib/app/models/dummy1.rb')
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#extract_class_name' do
65
+ describe 'class can be found' do
66
+ describe 'module without namespace' do
67
+ module AuthorSettings
68
+ end
69
+
70
+ it 'does not take every models subdirectory as a namespace' do
71
+ md = ModelsDiagram.new(OptionsStruct.new)
72
+
73
+ md.extract_class_name('test/file_fixture/app/models/concerns/author_settings.rb').must_equal 'AuthorSettings'
74
+ end
75
+ end
76
+
77
+ describe 'module with parent namespace / class' do
78
+ class User
79
+ module Authentication
80
+ end
81
+ end
82
+
83
+ it 'does not take every models subdirectory as a namespace' do
84
+ md = ModelsDiagram.new(OptionsStruct.new)
85
+
86
+ md.extract_class_name('test/file_fixture/app/models/concerns/user/authentication.rb').must_equal 'User::Authentication'
87
+ end
88
+ end
89
+ end
90
+
91
+ describe 'class cannot be found' do
92
+ it 'returns the full class name' do
93
+ md = ModelsDiagram.new(OptionsStruct.new)
94
+
95
+ md.extract_class_name('test/file_fixture/app/models/concerns/dummy.rb').must_equal 'Concerns::Dummy'
96
+ end
97
+ end
98
+ end
99
+
100
+ describe '#include_inheritance?' do
101
+ after do
102
+ Object.send(:remove_const, :Child)
103
+ end
104
+ describe 'when class inherits from another app class' do
105
+ before do
106
+ class Parent; end;
107
+ class Child < Parent; end;
108
+ end
109
+ it 'returns true' do
110
+ md = ModelsDiagram.new(OptionsStruct.new)
111
+ md.include_inheritance?(Child).must_equal true
112
+ end
113
+ after do
114
+ Object.send(:remove_const, :Parent)
115
+ end
116
+ end
117
+
118
+ describe 'when class inherits from Object' do
119
+ before do
120
+ class Child < Object; end;
121
+ end
122
+ it 'returns false' do
123
+ md = ModelsDiagram.new(OptionsStruct.new)
124
+ md.include_inheritance?(Child).must_equal false
125
+ end
126
+ end
127
+
128
+ describe 'when class inherits from ActiveRecord::Base' do
129
+ before do
130
+ module ActiveRecord
131
+ class Base; end;
132
+ end
133
+ class Child < ActiveRecord::Base; end;
134
+ end
135
+ it 'returns false' do
136
+ md = ModelsDiagram.new(OptionsStruct.new)
137
+ md.include_inheritance?(Child).must_equal false
138
+ end
139
+ after do
140
+ Object.send(:remove_const, :ActiveRecord)
141
+ end
142
+ end
143
+
144
+ describe 'when class inherits from CouchRest::Model::Base' do
145
+ before do
146
+ module CouchRest
147
+ module Model
148
+ class Base; end;
149
+ end
150
+ end
151
+ class Child < CouchRest::Model::Base; end;
152
+ end
153
+ it 'returns false' do
154
+ md = ModelsDiagram.new(OptionsStruct.new)
155
+ md.include_inheritance?(Child).must_equal false
156
+ end
157
+ after do
158
+ Object.send(:remove_const, :CouchRest)
159
+ end
160
+ end
48
161
  end
49
162
  end
data/test/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
- require 'minitest-spec-context'
3
+ require 'minitest/spec'
4
4
  require 'active_support/core_ext/string'
5
- require File.expand_path('../../lib/railroady.rb', __FILE__)
5
+ require File.expand_path('../../lib/railroady.rb', __FILE__)