rare_map 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +3 -19
- data/lib/rare_map.rb +13 -3
- data/lib/rare_map/column.rb +42 -0
- data/lib/rare_map/config_loader.rb +18 -69
- data/lib/rare_map/database_profile.rb +32 -0
- data/lib/rare_map/errors.rb +7 -1
- data/lib/rare_map/model.rb +48 -0
- data/lib/rare_map/model_builder.rb +12 -29
- data/lib/rare_map/model_generator.rb +12 -8
- data/lib/rare_map/options.rb +78 -0
- data/lib/rare_map/rails_locator.rb +14 -6
- data/lib/rare_map/relation.rb +41 -0
- data/lib/rare_map/schema_parser.rb +7 -71
- data/lib/rare_map/schema_reader.rb +7 -0
- data/lib/rare_map/table.rb +89 -0
- data/lib/rare_map/version.rb +7 -3
- data/test/column_test.rb +29 -0
- data/test/config_loader_test.rb +34 -0
- data/test/database_profile_test.rb +25 -0
- data/test/model_builder_test.rb +22 -0
- data/test/model_test.rb +40 -0
- data/test/options_test.rb +54 -0
- data/test/rails_locator_test.rb +12 -0
- data/test/rare_map.yml +16 -0
- data/test/rare_map_simple.yml +14 -0
- data/test/rare_map_test.rb +1 -3
- data/test/relation_test.rb +29 -0
- data/test/schema_parser_test.rb +28 -0
- data/test/table_test.rb +51 -0
- data/test/{helper.rb → test_helper.rb} +7 -1
- metadata +50 -19
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/config_loader'
|
3
|
+
require 'rare_map/schema_parser'
|
4
|
+
require 'rare_map/model_builder'
|
5
|
+
|
6
|
+
class ModelBuilderTest < Test::Unit::TestCase
|
7
|
+
include RareMap::ConfigLoader, RareMap::SchemaParser, RareMap::ModelBuilder
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@db_profiles = load_config File.dirname(__FILE__)
|
11
|
+
@profile = @db_profiles.first
|
12
|
+
f = File.open(File.join(File.dirname(__FILE__), 'schema.rb'))
|
13
|
+
@profile.schema = f.read
|
14
|
+
f.close
|
15
|
+
@profile.tables = parse_schema @profile.schema
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_build_models
|
19
|
+
@models = build_models @db_profiles
|
20
|
+
assert_equal 16, @models.size
|
21
|
+
end
|
22
|
+
end
|
data/test/model_test.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/model'
|
3
|
+
require 'rare_map/table'
|
4
|
+
|
5
|
+
class ModelTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@connection = { :adapter => "oracle_enhanced", :host => "192.168.1.177", :port => 1521, :database => "labora", :username => "csis", :password => "csis1111" }
|
8
|
+
@Table = RareMap::Table.new 'table1'
|
9
|
+
@model = RareMap::Model.new 'main', @connection, @Table
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_constructor
|
13
|
+
assert @model.kind_of? RareMap::Model
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_properties
|
17
|
+
assert_equal 'main', @model.db_name
|
18
|
+
assert_equal @connection, @model.connection
|
19
|
+
assert_equal @Table, @model.table
|
20
|
+
assert_equal 'default', @model.group
|
21
|
+
@model = RareMap::Model.new 'main', @connection, @Table, 'group1'
|
22
|
+
assert_equal 'group1', @model.group
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_group?
|
26
|
+
assert_equal false, @model.group?
|
27
|
+
@model = RareMap::Model.new 'main', @connection, @Table, 'group1'
|
28
|
+
assert @model.group?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_group
|
32
|
+
assert_equal 'default', @model.group
|
33
|
+
@model = RareMap::Model.new 'main', @connection, @Table, 'group1'
|
34
|
+
assert_equal 'group1', @model.group
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_classify
|
38
|
+
assert_equal 'Table1', @model.classify
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/options'
|
3
|
+
|
4
|
+
class OptionsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@options = RareMap::Options.new
|
7
|
+
@opts = { 'group' => 'default',
|
8
|
+
'primary_key' => {},
|
9
|
+
'foreign_key' => { 'suffix' => nil, 'alias' => {} } }
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_constructor
|
13
|
+
assert @options.kind_of? RareMap::Options
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_default_options
|
17
|
+
assert @options.opts['group'] == 'default'
|
18
|
+
assert @options.opts['primary_key'] == {}
|
19
|
+
assert @options.opts['foreign_key'] == { 'suffix' => nil, 'alias' => {} }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_group?
|
23
|
+
assert_equal false, @options.group?
|
24
|
+
@options = RareMap::Options.new @opts.merge(group: 'group1')
|
25
|
+
assert @options.group?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_group
|
29
|
+
assert_equal 'default', @options.group
|
30
|
+
@options = RareMap::Options.new @opts.merge(group: 'group1')
|
31
|
+
assert_equal 'group1', @options.group
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_find_primary_key_by_table
|
35
|
+
assert_equal nil, @options.find_primary_key_by_table('table1')
|
36
|
+
@opts['primary_key']['table1'] = 'pk1'
|
37
|
+
@options = RareMap::Options.new @opts
|
38
|
+
assert_equal 'pk1', @options.find_primary_key_by_table('table1')
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_find_table_by_foreign_key
|
42
|
+
assert_equal nil, @options.find_table_by_foreign_key('fk1')
|
43
|
+
@opts['foreign_key']['alias']['fk1'] = 'table1'
|
44
|
+
@options = RareMap::Options.new @opts
|
45
|
+
assert_equal 'table1', @options.find_table_by_foreign_key('fk1')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_fk_suffix
|
49
|
+
assert_equal nil, @options.fk_suffix
|
50
|
+
@opts['foreign_key']['suffix'] = 'suffix'
|
51
|
+
@options = RareMap::Options.new @opts
|
52
|
+
assert_equal 'suffix', @options.fk_suffix
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/rails_locator'
|
3
|
+
|
4
|
+
class RailsLocatorTest < Test::Unit::TestCase
|
5
|
+
include RareMap::RailsLocator
|
6
|
+
|
7
|
+
def test_locate_rails_root
|
8
|
+
assert_equal nil, locate_rails_root
|
9
|
+
assert_equal File.expand_path('rails_root', File.dirname(__FILE__)), locate_rails_root(File.expand_path('rails_root/app', File.dirname(__FILE__)))
|
10
|
+
assert_equal nil, locate_rails_root(File.expand_path('rails_root/app', File.dirname(__FILE__)), 0)
|
11
|
+
end
|
12
|
+
end
|
data/test/rare_map.yml
ADDED
data/test/rare_map_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class RareMapTest < Test::Unit::TestCase
|
4
|
-
|
5
4
|
def setup
|
6
5
|
@mapper = RareMap::Mapper.new
|
7
6
|
end
|
@@ -9,5 +8,4 @@ class RareMapTest < Test::Unit::TestCase
|
|
9
8
|
def test_constructor
|
10
9
|
assert @mapper.kind_of? RareMap::Mapper
|
11
10
|
end
|
12
|
-
|
13
11
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/relation'
|
3
|
+
|
4
|
+
class RelationTest < Test::Unit::TestCase
|
5
|
+
include RareMap::Errors
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@relation = RareMap::Relation.new :has_one, 'fk1', 'table1'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_constructor
|
12
|
+
assert @relation.kind_of? RareMap::Relation
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_constructor_error
|
16
|
+
assert_raise RelationNotDefinedError do
|
17
|
+
RareMap::Relation.new :has_two, 'fk1', 'table1'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_properties
|
22
|
+
assert_equal :has_one, @relation.type
|
23
|
+
assert_equal 'fk1', @relation.foreign_key
|
24
|
+
assert_equal 'table1', @relation.table
|
25
|
+
assert_equal nil, @relation.through
|
26
|
+
@relation = RareMap::Relation.new :has_one, 'fk1', 'table1', 'table2'
|
27
|
+
assert_equal 'table2', @relation.through
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/schema_parser'
|
3
|
+
|
4
|
+
class SchemaParserTest < Test::Unit::TestCase
|
5
|
+
include RareMap::SchemaParser
|
6
|
+
|
7
|
+
def setup
|
8
|
+
f = File.open(File.join(File.dirname(__FILE__), 'schema.rb'))
|
9
|
+
@schema = f.read
|
10
|
+
f.close
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_parse_schema
|
14
|
+
tables = parse_schema @schema
|
15
|
+
assert_equal 16, tables.size
|
16
|
+
table = tables.first
|
17
|
+
assert_equal 'access_log', table.name
|
18
|
+
assert_equal true, table.id
|
19
|
+
assert_equal 'id', table.primary_key
|
20
|
+
assert_equal 'id', table.fk_suffix
|
21
|
+
assert_equal 5, table.columns.size
|
22
|
+
column = table.columns.first
|
23
|
+
assert_equal 'url', column.name
|
24
|
+
assert_equal 'string', column.type
|
25
|
+
assert_equal false, column.unique
|
26
|
+
assert_equal nil, column.ref_table
|
27
|
+
end
|
28
|
+
end
|
data/test/table_test.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rare_map/table'
|
3
|
+
require 'rare_map/column'
|
4
|
+
require 'active_support/inflector'
|
5
|
+
|
6
|
+
class TableTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@Table = RareMap::Table.new 'table1'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_constructor
|
12
|
+
assert @Table.kind_of? RareMap::Table
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_properties
|
16
|
+
assert_equal 'table1', @Table.name
|
17
|
+
assert_equal true, @Table.id
|
18
|
+
assert_equal 'id', @Table.primary_key
|
19
|
+
assert_equal 'id', @Table.fk_suffix
|
20
|
+
assert_equal [], @Table.columns
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_primary_key
|
24
|
+
assert_equal 'id', @Table.primary_key
|
25
|
+
@Table.primary_key = 'id2'
|
26
|
+
assert_equal 'id2', @Table.primary_key
|
27
|
+
@Table = RareMap::Table.new 'table1', id: false
|
28
|
+
@Table.columns = [RareMap::Column.new('table1id', 'integer', unique: true)]
|
29
|
+
assert_equal 'table1id', @Table.primary_key
|
30
|
+
@Table.columns = [RareMap::Column.new('table1sid', 'integer', unique: true)]
|
31
|
+
assert_equal 'table1sid', @Table.primary_key
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_singularize
|
35
|
+
assert_equal 'table1'.pluralize.singularize, @Table.singularize
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_pluralize
|
39
|
+
assert_equal 'table1'.pluralize, @Table.pluralize
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_match_foreign_key
|
43
|
+
assert_equal 'table1', @Table.match_foreign_key(RareMap::Column.new('table1_id', 'integer'))
|
44
|
+
assert_equal nil, @Table.match_foreign_key(RareMap::Column.new('table2_id', 'integer'))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_match_foreign_key_by_primary_key
|
48
|
+
assert_equal 'table1', @Table.match_foreign_key_by_primary_key('table1_id')
|
49
|
+
assert_equal nil, @Table.match_foreign_key_by_primary_key('table2_id')
|
50
|
+
end
|
51
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
+
require 'json'
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
3
6
|
begin
|
4
7
|
Bundler.setup(:default, :development)
|
5
8
|
rescue Bundler::BundlerError => e
|
@@ -8,11 +11,14 @@ rescue Bundler::BundlerError => e
|
|
8
11
|
exit e.status_code
|
9
12
|
end
|
10
13
|
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
14
|
|
13
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
16
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
17
|
require 'rare_map'
|
16
18
|
|
17
19
|
class Test::Unit::TestCase
|
20
|
+
def run_setup_hooks ; end
|
21
|
+
def run_teardown_hooks ; end
|
18
22
|
end
|
23
|
+
|
24
|
+
MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL = nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rare_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wei-Ming Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -39,47 +39,47 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: simplecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,21 +101,39 @@ executables:
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- lib/rare_map/column.rb
|
104
105
|
- lib/rare_map/config_loader.rb
|
106
|
+
- lib/rare_map/database_profile.rb
|
105
107
|
- lib/rare_map/errors.rb
|
108
|
+
- lib/rare_map/model.rb
|
106
109
|
- lib/rare_map/model_builder.rb
|
107
110
|
- lib/rare_map/model_generator.rb
|
111
|
+
- lib/rare_map/options.rb
|
108
112
|
- lib/rare_map/rails_locator.rb
|
113
|
+
- lib/rare_map/relation.rb
|
109
114
|
- lib/rare_map/schema_parser.rb
|
110
115
|
- lib/rare_map/schema_reader.rb
|
116
|
+
- lib/rare_map/table.rb
|
111
117
|
- lib/rare_map/version.rb
|
112
118
|
- lib/rare_map.rb
|
113
119
|
- LICENSE.txt
|
114
120
|
- Rakefile
|
115
121
|
- README.rdoc
|
116
|
-
- test/
|
122
|
+
- test/column_test.rb
|
123
|
+
- test/config_loader_test.rb
|
124
|
+
- test/database_profile_test.rb
|
125
|
+
- test/model_builder_test.rb
|
126
|
+
- test/model_test.rb
|
127
|
+
- test/options_test.rb
|
128
|
+
- test/rails_locator_test.rb
|
129
|
+
- test/rare_map.yml
|
130
|
+
- test/rare_map_simple.yml
|
117
131
|
- test/rare_map_test.rb
|
132
|
+
- test/relation_test.rb
|
118
133
|
- test/schema.rb
|
134
|
+
- test/schema_parser_test.rb
|
135
|
+
- test/table_test.rb
|
136
|
+
- test/test_helper.rb
|
119
137
|
- bin/raremap
|
120
138
|
homepage: http://github.com/wnameless/rare_map
|
121
139
|
licenses:
|
@@ -140,8 +158,21 @@ rubyforge_project:
|
|
140
158
|
rubygems_version: 2.0.6
|
141
159
|
signing_key:
|
142
160
|
specification_version: 4
|
143
|
-
summary: rare_map-2.
|
161
|
+
summary: rare_map-2.2.0
|
144
162
|
test_files:
|
145
|
-
- test/
|
163
|
+
- test/column_test.rb
|
164
|
+
- test/config_loader_test.rb
|
165
|
+
- test/database_profile_test.rb
|
166
|
+
- test/model_builder_test.rb
|
167
|
+
- test/model_test.rb
|
168
|
+
- test/options_test.rb
|
169
|
+
- test/rails_locator_test.rb
|
170
|
+
- test/rare_map.yml
|
171
|
+
- test/rare_map_simple.yml
|
146
172
|
- test/rare_map_test.rb
|
173
|
+
- test/relation_test.rb
|
147
174
|
- test/schema.rb
|
175
|
+
- test/schema_parser_test.rb
|
176
|
+
- test/table_test.rb
|
177
|
+
- test/test_helper.rb
|
178
|
+
has_rdoc:
|