rails_sql_views4 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +121 -0
- data/lib/active_record/view.rb +80 -0
- data/lib/core_ext/module.rb +13 -0
- data/lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb +63 -0
- data/lib/rails_sql_views4/connection_adapters/abstract/schema_statements.rb +85 -0
- data/lib/rails_sql_views4/connection_adapters/abstract_adapter.rb +41 -0
- data/lib/rails_sql_views4/connection_adapters/mysql2_adapter.rb +66 -0
- data/lib/rails_sql_views4/connection_adapters/mysql_adapter.rb +66 -0
- data/lib/rails_sql_views4/connection_adapters/oci_adapter.rb +33 -0
- data/lib/rails_sql_views4/connection_adapters/oracle_adapter.rb +33 -0
- data/lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb +39 -0
- data/lib/rails_sql_views4/connection_adapters/oracleenhanced_adapter.rb.orig +72 -0
- data/lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb +69 -0
- data/lib/rails_sql_views4/connection_adapters/postgresql_adapter.rb.orig +69 -0
- data/lib/rails_sql_views4/connection_adapters/sqlite3_adapter.rb +68 -0
- data/lib/rails_sql_views4/connection_adapters/sqlite_adapter.rb +68 -0
- data/lib/rails_sql_views4/connection_adapters/sqlserver_adapter.rb +43 -0
- data/lib/rails_sql_views4/loader.rb +18 -0
- data/lib/rails_sql_views4/schema_dumper.rb +114 -0
- data/lib/rails_sql_views4/version.rb +3 -0
- data/lib/rails_sql_views4.rb +28 -0
- data/lib/tasks/rails_sql_views4_tasks.rake +4 -0
- data/test/README.NOT_UP_TO_DATE +63 -0
- data/test/adapter_test.rb +93 -0
- data/test/connection/native_mysql/connection.rb +32 -0
- data/test/connection/native_mysql/schema.sql +34 -0
- data/test/connection/native_postgresql/connection.rb +31 -0
- data/test/connection/native_postgresql/schema.sql +33 -0
- data/test/connection/oracle_enhanced/connection.rb +29 -0
- data/test/connection/oracle_enhanced/procedures.sql +15 -0
- data/test/connection/oracle_enhanced/schema.sql +39 -0
- data/test/connection.example.yml +12 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/item.rb +4 -0
- data/test/dummy/app/models/person.rb +5 -0
- data/test/dummy/app/models/person2.rb +4 -0
- data/test/dummy/app/models/place.rb +2 -0
- data/test/dummy/app/models/v_person.rb +8 -0
- data/test/dummy/app/models/v_profile.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20141228200436_create_people.rb +10 -0
- data/test/dummy/db/migrate/20141228200437_create_people2.rb +11 -0
- data/test/dummy/db/migrate/20141228200438_create_places.rb +12 -0
- data/test/dummy/db/migrate/20141228200439_create_items.rb +8 -0
- data/test/dummy/db/migrate/20141228200440_create_items_people.rb +9 -0
- data/test/dummy/db/schema.rb +53 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +439 -0
- data/test/dummy/log/test.log +29320 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/persons.yml +7 -0
- data/test/dummy/test/models/person_test.rb +7 -0
- data/test/rails_sql_views4_test.rb +11 -0
- data/test/schema.native_mysql.expected.rb +51 -0
- data/test/schema.native_postgresql.expected.rb +51 -0
- data/test/schema.native_postgresql.out.rb +69 -0
- data/test/schema.oracle_enhanced.expected.rb +51 -0
- data/test/schema_dumper_test.rb +134 -0
- data/test/test_helper.rb +41 -0
- data/test/test_helper.rb.old +30 -0
- data/test/view_model_test.rb +68 -0
- data/test/view_operations_test.rb +50 -0
- metadata +225 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
|
+
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define(:version => 0) do
|
13
|
+
|
14
|
+
create_table "items", :force => true do |t|
|
15
|
+
t.integer "person_id"
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table "items_people", :id => false, :force => true do |t|
|
19
|
+
t.integer "person_id"
|
20
|
+
t.integer "item_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "people", :force => true do |t|
|
24
|
+
t.string "first_name"
|
25
|
+
t.string "last_name"
|
26
|
+
t.string "ssn", :limit => 64
|
27
|
+
t.integer "address_id"
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "people2", :force => true do |t|
|
31
|
+
t.string "first_name"
|
32
|
+
t.string "last_name"
|
33
|
+
t.string "ssn", :limit => 64
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "places", :force => true do |t|
|
37
|
+
t.text "address"
|
38
|
+
t.string "city"
|
39
|
+
t.string "cstate"
|
40
|
+
t.string "country", :limit => 2
|
41
|
+
end
|
42
|
+
|
43
|
+
create_view "v_people", "select `people`.`id` AS `id`,`people`.`first_name` AS `f_name`,`people`.`last_name` AS `l_name`,`people`.`ssn` AS `social_security`,`people`.`address_id` AS `address_id` from `people`", :force => true do |v|
|
44
|
+
v.column :id
|
45
|
+
v.column :f_name
|
46
|
+
v.column :l_name
|
47
|
+
v.column :social_security
|
48
|
+
v.column :address_id
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
|
+
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define(:version => 0) do
|
13
|
+
|
14
|
+
create_table "items", :force => true do |t|
|
15
|
+
t.integer "person_id"
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table "items_people", :id => false, :force => true do |t|
|
19
|
+
t.integer "person_id"
|
20
|
+
t.integer "item_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "people", :force => true do |t|
|
24
|
+
t.string "first_name"
|
25
|
+
t.string "last_name"
|
26
|
+
t.string "ssn", :limit => 64
|
27
|
+
t.integer "address_id"
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "people2", :force => true do |t|
|
31
|
+
t.string "first_name"
|
32
|
+
t.string "last_name"
|
33
|
+
t.string "ssn", :limit => 64
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "places", :force => true do |t|
|
37
|
+
t.text "address"
|
38
|
+
t.string "city"
|
39
|
+
t.string "cstate"
|
40
|
+
t.string "country", :limit => 2
|
41
|
+
end
|
42
|
+
|
43
|
+
create_view "v_people", "SELECT people.id, people.first_name AS f_name, people.last_name AS l_name, people.ssn AS social_security, people.address_id FROM people;", :force => true do |v|
|
44
|
+
v.column :id
|
45
|
+
v.column :f_name
|
46
|
+
v.column :l_name
|
47
|
+
v.column :social_security
|
48
|
+
v.column :address_id
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20141228200440) do
|
15
|
+
|
16
|
+
create_table "items", force: true do |t|
|
17
|
+
t.integer "person_id"
|
18
|
+
t.datetime "created_at"
|
19
|
+
t.datetime "updated_at"
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "items_people", force: true do |t|
|
23
|
+
t.integer "person_id"
|
24
|
+
t.integer "item_id"
|
25
|
+
t.datetime "created_at"
|
26
|
+
t.datetime "updated_at"
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "people", force: true do |t|
|
30
|
+
t.string "first_name", limit: 255
|
31
|
+
t.string "last_name", limit: 255
|
32
|
+
t.string "ssn", limit: 255
|
33
|
+
t.integer "address_id"
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "people2", force: true do |t|
|
37
|
+
t.string "first_name", limit: 255
|
38
|
+
t.string "last_name", limit: 255
|
39
|
+
t.string "ssn", limit: 255
|
40
|
+
t.datetime "created_at"
|
41
|
+
t.datetime "updated_at"
|
42
|
+
end
|
43
|
+
|
44
|
+
create_table "places", force: true do |t|
|
45
|
+
t.text "address"
|
46
|
+
t.string "city", limit: 255
|
47
|
+
t.string "cstate", limit: 255
|
48
|
+
t.string "country", limit: 255
|
49
|
+
t.datetime "created_at"
|
50
|
+
t.datetime "updated_at"
|
51
|
+
end
|
52
|
+
|
53
|
+
create_view :v_people , "select id, first_name, last_name, ssn, address_id from people", :force => true do |v|
|
54
|
+
v.column :id
|
55
|
+
v.column :first_name
|
56
|
+
v.column :last_name
|
57
|
+
v.column :ssn
|
58
|
+
v.column :address_id
|
59
|
+
end
|
60
|
+
|
61
|
+
create_view "v_people" , "select id, first_name, last_name, ssn, address_id from people", :force => true do |v|
|
62
|
+
v.column :id
|
63
|
+
v.column :first_name
|
64
|
+
v.column :last_name
|
65
|
+
v.column :ssn
|
66
|
+
v.column :address_id
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
|
+
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define(:version => 0) do
|
13
|
+
|
14
|
+
create_table "items", :force => true do |t|
|
15
|
+
t.integer "person_id", :precision => 38, :scale => 0
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table "items_people", :id => false, :force => true do |t|
|
19
|
+
t.integer "person_id", :precision => 38, :scale => 0
|
20
|
+
t.integer "item_id", :precision => 38, :scale => 0
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "people", :force => true do |t|
|
24
|
+
t.string "first_name"
|
25
|
+
t.string "last_name"
|
26
|
+
t.string "ssn", :limit => 64
|
27
|
+
t.integer "address_id", :precision => 38, :scale => 0
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "people2", :force => true do |t|
|
31
|
+
t.string "first_name"
|
32
|
+
t.string "last_name"
|
33
|
+
t.string "ssn", :limit => 64
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "places", :force => true do |t|
|
37
|
+
t.string "address", :limit => 2000
|
38
|
+
t.string "city"
|
39
|
+
t.string "cstate"
|
40
|
+
t.string "country", :limit => 2
|
41
|
+
end
|
42
|
+
|
43
|
+
create_view "v_people", "select id, first_name, last_name, ssn, address_id from people", :force => true do |v|
|
44
|
+
v.column :id
|
45
|
+
v.column :f_name
|
46
|
+
v.column :l_name
|
47
|
+
v.column :social_security
|
48
|
+
v.column :address_id
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'active_record/schema_dumper'
|
4
|
+
|
5
|
+
class SchemaDumperTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
teardown
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
['V_PEOPLE', 'V_PROFILE'].each do |view|
|
13
|
+
if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
|
14
|
+
ActiveRecord::Base.connection.execute("
|
15
|
+
DECLARE
|
16
|
+
CURSOR C1 is SELECT view_name FROM user_views where view_name = '#{view}';
|
17
|
+
BEGIN
|
18
|
+
FOR I IN C1 LOOP
|
19
|
+
EXECUTE IMMEDIATE 'DROP VIEW '||I.view_name||'';
|
20
|
+
END LOOP;
|
21
|
+
END;
|
22
|
+
");
|
23
|
+
else
|
24
|
+
ActiveRecord::Base.connection.execute("drop view if exists #{view}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_view
|
30
|
+
create_people_view
|
31
|
+
stream = StringIO.new
|
32
|
+
dumper = ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
33
|
+
stream.rewind
|
34
|
+
file_name = File.dirname(__FILE__) + "/schema.#{$connection}.expected.rb"
|
35
|
+
puts "FileName : #{file_name}"
|
36
|
+
assert_equal File.open(File.dirname(__FILE__) + "/schema.#{$connection}.expected.rb", 'r').readlines, stream.readlines
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_dump_and_load
|
40
|
+
create_people_view
|
41
|
+
assert_dump_and_load_succeed
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_union
|
45
|
+
Person.create(:first_name => 'Joe', :last_name => 'User', :ssn => '123456789')
|
46
|
+
Person2.create(:first_name => 'Jane', :last_name => 'Doe', :ssn => '222334444')
|
47
|
+
|
48
|
+
select_stmt = <<-HERE
|
49
|
+
select first_name, last_name, ssn from people
|
50
|
+
UNION
|
51
|
+
select first_name, last_name, ssn from people2
|
52
|
+
HERE
|
53
|
+
|
54
|
+
ActiveRecord::Base.connection.create_view(:v_profile, select_stmt, :force => true) do |v|
|
55
|
+
v.column :first_name
|
56
|
+
v.column :last_name
|
57
|
+
v.column :ssn
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_dump_and_load_succeed
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_view_creation_order
|
64
|
+
ActiveRecord::SchemaDumper.view_creation_order << :v_people
|
65
|
+
create_people_view
|
66
|
+
assert_dump_and_load_succeed
|
67
|
+
ActiveRecord::SchemaDumper.view_creation_order.pop
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_symbol_ignore
|
71
|
+
ActiveRecord::SchemaDumper.ignore_views << :v_people
|
72
|
+
create_people_view
|
73
|
+
assert_dump_and_load_succeed
|
74
|
+
ActiveRecord::SchemaDumper.ignore_views.pop
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_regex_ignore
|
78
|
+
ActiveRecord::SchemaDumper.ignore_views << Regexp.new(/v_people/)
|
79
|
+
create_people_view
|
80
|
+
assert_dump_and_load_succeed
|
81
|
+
ActiveRecord::SchemaDumper.ignore_views.pop
|
82
|
+
end
|
83
|
+
|
84
|
+
# TODO : StandardError expected but nothing was raised.
|
85
|
+
#def test_non_allowed_object_raises_error
|
86
|
+
# create_people_view
|
87
|
+
# ActiveRecord::SchemaDumper.ignore_views << 0
|
88
|
+
# begin
|
89
|
+
# schema_file = File.dirname(__FILE__) + "/schema.#{$connection}.out.rb"
|
90
|
+
# File.open(schema_file, "w") do |file|
|
91
|
+
# assert_raise(StandardError) do
|
92
|
+
# ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
# ensure
|
96
|
+
# ActiveRecord::SchemaDumper.ignore_views.pop
|
97
|
+
# end
|
98
|
+
#end
|
99
|
+
|
100
|
+
# DOTO c'est quio mock
|
101
|
+
#def test_logging_error
|
102
|
+
# ActiveRecord::SchemaDumper.ignore_views << 0
|
103
|
+
# old_logger = ActiveRecord::Base.logger
|
104
|
+
#
|
105
|
+
# begin
|
106
|
+
# mock_logger = flexmock('logger', :error => nil)
|
107
|
+
# mock_logger.should_receive(:error)
|
108
|
+
# ActiveRecord::Base.logger = mock_logger
|
109
|
+
# schema_file = File.dirname(__FILE__) + "/schema.#{$connection}.out.rb"
|
110
|
+
# File.open(schema_file, "w") do |file|
|
111
|
+
# ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
112
|
+
# end
|
113
|
+
# ensure
|
114
|
+
# ActiveRecord::SchemaDumper.ignore_views.pop
|
115
|
+
# ActiveRecord::Base.logger = old_logger
|
116
|
+
# end
|
117
|
+
#end
|
118
|
+
|
119
|
+
def assert_dump_and_load_succeed
|
120
|
+
schema_file = File.dirname(__FILE__) + "/schema.#{$connection}.out.rb"
|
121
|
+
assert_nothing_raised do
|
122
|
+
File.open(schema_file, "w") do |file|
|
123
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
assert_nothing_raised do
|
128
|
+
load(schema_file)
|
129
|
+
end
|
130
|
+
puts "end assert"
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
5
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
6
|
+
|
7
|
+
require "rails/test_help"
|
8
|
+
# require 'flexmock/test_unit' TODO, c'est quoi ca ?
|
9
|
+
|
10
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
11
|
+
$:.unshift(File.dirname(__FILE__))
|
12
|
+
|
13
|
+
#$connection = (ENV['DB'] || 'native_mysql')
|
14
|
+
$connection = (ENV['DB'] || 'native_postgresql')
|
15
|
+
|
16
|
+
|
17
|
+
Rails.backtrace_cleaner.remove_silencers!
|
18
|
+
|
19
|
+
# Load support files
|
20
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
21
|
+
|
22
|
+
# Load fixtures from the engine
|
23
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
24
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
class ActiveSupport::TestCase
|
30
|
+
def create_people_view
|
31
|
+
ActiveRecord::Base.connection.create_view(:v_people,
|
32
|
+
'select id, first_name, last_name, ssn, address_id from people', :force => true) do |v|
|
33
|
+
v.column :id
|
34
|
+
v.column :f_name
|
35
|
+
v.column :l_name
|
36
|
+
v.column :social_security
|
37
|
+
v.column :address_id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
$:.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'pp'
|
7
|
+
require 'flexmock/test_unit'
|
8
|
+
|
9
|
+
require 'active_record'
|
10
|
+
#$connection = (ENV['DB'] || 'native_mysql')
|
11
|
+
$connection = (ENV['DB'] || 'native_postgresql')
|
12
|
+
require "connection/#{$connection}/connection"
|
13
|
+
require 'rails_sql_views'
|
14
|
+
|
15
|
+
require 'models/person'
|
16
|
+
require 'models/person2'
|
17
|
+
require 'models/v_person'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
def create_people_view
|
21
|
+
ActiveRecord::Base.connection.create_view(:v_people,
|
22
|
+
'select id, first_name, last_name, ssn, address_id from people', :force => true) do |v|
|
23
|
+
v.column :id
|
24
|
+
v.column :f_name
|
25
|
+
v.column :l_name
|
26
|
+
v.column :social_security
|
27
|
+
v.column :address_id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|