composite_primary_keys 7.0.16 → 8.0.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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +600 -623
  3. data/lib/composite_primary_keys.rb +113 -115
  4. data/lib/composite_primary_keys/associations/association.rb +23 -23
  5. data/lib/composite_primary_keys/associations/association_scope.rb +73 -77
  6. data/lib/composite_primary_keys/associations/collection_association.rb +15 -0
  7. data/lib/composite_primary_keys/associations/has_many_association.rb +69 -56
  8. data/lib/composite_primary_keys/associations/has_many_through_association.rb +30 -28
  9. data/lib/composite_primary_keys/associations/join_dependency.rb +87 -89
  10. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
  11. data/lib/composite_primary_keys/associations/preloader/association.rb +90 -78
  12. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
  13. data/lib/composite_primary_keys/associations/singular_association.rb +15 -0
  14. data/lib/composite_primary_keys/attribute_methods.rb +9 -0
  15. data/lib/composite_primary_keys/attribute_methods/dirty.rb +29 -26
  16. data/lib/composite_primary_keys/attribute_methods/read.rb +19 -34
  17. data/lib/composite_primary_keys/attribute_methods/write.rb +30 -36
  18. data/lib/composite_primary_keys/attribute_set/builder.rb +20 -0
  19. data/lib/composite_primary_keys/base.rb +135 -129
  20. data/lib/composite_primary_keys/composite_arrays.rb +30 -30
  21. data/lib/composite_primary_keys/composite_predicates.rb +50 -50
  22. data/lib/composite_primary_keys/composite_relation.rb +48 -48
  23. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -4
  24. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +46 -60
  25. data/lib/composite_primary_keys/core.rb +69 -47
  26. data/lib/composite_primary_keys/fixtures.rb +22 -22
  27. data/lib/composite_primary_keys/persistence.rb +56 -60
  28. data/lib/composite_primary_keys/relation.rb +68 -56
  29. data/lib/composite_primary_keys/relation/calculations.rb +79 -75
  30. data/lib/composite_primary_keys/relation/finder_methods.rb +175 -196
  31. data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
  32. data/lib/composite_primary_keys/sanitization.rb +52 -52
  33. data/lib/composite_primary_keys/validations/uniqueness.rb +36 -37
  34. data/lib/composite_primary_keys/version.rb +8 -8
  35. data/tasks/databases/oracle.rake +25 -25
  36. data/tasks/databases/sqlserver.rake +27 -40
  37. data/test/abstract_unit.rb +113 -113
  38. data/test/connections/databases.ci.yml +15 -15
  39. data/test/connections/databases.example.yml +18 -18
  40. data/test/connections/native_oracle/connection.rb +11 -11
  41. data/test/connections/native_oracle_enhanced/connection.rb +16 -16
  42. data/test/connections/native_sqlserver/connection.rb +11 -14
  43. data/test/fixtures/comment.rb +7 -7
  44. data/test/fixtures/db_definitions/db2-create-tables.sql +125 -126
  45. data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
  46. data/test/fixtures/db_definitions/mysql.sql +207 -208
  47. data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
  48. data/test/fixtures/db_definitions/oracle.sql +222 -223
  49. data/test/fixtures/db_definitions/postgresql.sql +209 -210
  50. data/test/fixtures/db_definitions/sqlite.sql +196 -197
  51. data/test/fixtures/db_definitions/sqlserver.drop.sql +91 -94
  52. data/test/fixtures/db_definitions/sqlserver.sql +225 -232
  53. data/test/fixtures/dorm.rb +2 -2
  54. data/test/fixtures/employee.rb +5 -5
  55. data/test/fixtures/membership.rb +6 -6
  56. data/test/fixtures/membership_statuses.yml +16 -16
  57. data/test/fixtures/memberships.yml +10 -10
  58. data/test/fixtures/product_tariffs.yml +14 -14
  59. data/test/fixtures/reference_code.rb +7 -7
  60. data/test/fixtures/restaurants_suburb.rb +2 -2
  61. data/test/fixtures/suburb.rb +5 -5
  62. data/test/fixtures/topic.rb +5 -5
  63. data/test/fixtures/topic_source.rb +6 -6
  64. data/test/fixtures/topic_sources.yml +3 -3
  65. data/test/fixtures/topics.yml +8 -8
  66. data/test/fixtures/users.yml +10 -10
  67. data/test/test_associations.rb +295 -275
  68. data/test/test_attribute_methods.rb +63 -63
  69. data/test/test_attributes.rb +60 -60
  70. data/test/test_calculations.rb +37 -42
  71. data/test/test_callbacks.rb +99 -99
  72. data/test/test_create.rb +112 -112
  73. data/test/test_delete.rb +148 -152
  74. data/test/test_delete_all.rb +28 -26
  75. data/test/test_dumpable.rb +15 -15
  76. data/test/test_enum.rb +21 -20
  77. data/test/test_equal.rb +26 -26
  78. data/test/test_find.rb +118 -118
  79. data/test/test_habtm.rb +113 -113
  80. data/test/test_nested_attributes.rb +124 -124
  81. data/test/test_polymorphic.rb +26 -26
  82. data/test/test_predicates.rb +40 -40
  83. data/test/test_santiago.rb +23 -23
  84. data/test/test_suite.rb +33 -34
  85. data/test/test_touch.rb +23 -23
  86. data/test/test_tutorial_example.rb +21 -21
  87. data/test/test_update.rb +71 -71
  88. metadata +9 -13
  89. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -20
  90. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +0 -59
  91. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
  92. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
  93. data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -17
  94. data/lib/composite_primary_keys/locking/optimistic.rb +0 -55
  95. data/test/test_optimistic.rb +0 -18
@@ -1,15 +1,15 @@
1
- mysql:
2
- adapter: mysql2
3
- username: travis
4
- password: ""
5
- database: composite_primary_keys_unittest
6
-
7
- sqlite3:
8
- adapter: sqlite3
9
- database: db/composite_primary_keys_unittest.sqlite
10
-
11
- postgresql:
12
- adapter: postgresql
13
- database: composite_primary_keys_unittest
14
- username: postgres
15
- host: localhost
1
+ mysql:
2
+ adapter: mysql2
3
+ username: travis
4
+ password: ""
5
+ database: composite_primary_keys_unittest
6
+
7
+ sqlite3:
8
+ adapter: sqlite3
9
+ database: db/composite_primary_keys_unittest.sqlite
10
+
11
+ postgresql:
12
+ adapter: postgresql
13
+ database: composite_primary_keys_unittest
14
+ username: postgres
15
+ host: localhost
@@ -1,18 +1,18 @@
1
- # To run tests:
2
- # 1. Copy this file to test/connections/databases.yml.
3
- # 2. Update to match the databases you want to test against.
4
-
5
- mysql:
6
- adapter: mysql2
7
- username: root
8
- database: composite_primary_keys_unittest
9
-
10
- sqlite3:
11
- adapter: sqlite3
12
- database: db/composite_primary_keys_unittest.sqlite
13
-
14
- postgresql:
15
- adapter: postgresql
16
- database: composite_primary_keys_unittest
17
- username: postgres
18
- host: localhost
1
+ # To run tests:
2
+ # 1. Copy this file to test/connections/databases.yml.
3
+ # 2. Update to match the databases you want to test against.
4
+
5
+ mysql:
6
+ adapter: mysql2
7
+ username: root
8
+ database: composite_primary_keys_unittest
9
+
10
+ sqlite3:
11
+ adapter: sqlite3
12
+ database: db/composite_primary_keys_unittest.sqlite
13
+
14
+ postgresql:
15
+ adapter: postgresql
16
+ database: composite_primary_keys_unittest
17
+ username: postgres
18
+ host: localhost
@@ -1,11 +1,11 @@
1
- print "Using native Oracle\n"
2
-
3
- require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
4
-
5
- def connection_string
6
- "#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
7
- end
8
-
9
- # Adapter config setup in locals/database_connections.rb
10
- SPEC = CompositePrimaryKeys::ConnectionSpec['oracle']
11
- ActiveRecord::Base.establish_connection(SPEC)
1
+ print "Using native Oracle\n"
2
+
3
+ require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
4
+
5
+ def connection_string
6
+ "#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
7
+ end
8
+
9
+ # Adapter config setup in locals/database_connections.rb
10
+ SPEC = CompositePrimaryKeys::ConnectionSpec['oracle']
11
+ ActiveRecord::Base.establish_connection(SPEC)
@@ -1,16 +1,16 @@
1
- print "Using native Oracle Enhanced\n"
2
-
3
- require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
4
-
5
- def connection_string
6
- "#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
7
- end
8
-
9
- # Adapter config setup in locals/database_connections.rb
10
- SPEC = CompositePrimaryKeys::ConnectionSpec[:oracle]
11
- ActiveRecord::Base.establish_connection(SPEC)
12
-
13
- # Change default options for Oracle Enhanced adapter
14
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
15
- # Change NLS_DATE_FORMAT to non-default format to verify that all tests should pass
16
- ActiveRecord::Base.connection.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
1
+ print "Using native Oracle Enhanced\n"
2
+
3
+ require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
4
+
5
+ def connection_string
6
+ "#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
7
+ end
8
+
9
+ # Adapter config setup in locals/database_connections.rb
10
+ SPEC = CompositePrimaryKeys::ConnectionSpec[:oracle]
11
+ ActiveRecord::Base.establish_connection(SPEC)
12
+
13
+ # Change default options for Oracle Enhanced adapter
14
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
15
+ # Change NLS_DATE_FORMAT to non-default format to verify that all tests should pass
16
+ ActiveRecord::Base.connection.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
@@ -1,14 +1,11 @@
1
- print "Using native SQL Server\n"
2
-
3
- gem 'activerecord-sqlserver-adapter', '~>4.1.0'
4
- require 'activerecord-sqlserver-adapter'
5
-
6
- require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
7
-
8
- def connection_string
9
- "-S #{SPEC['host']} -U #{SPEC['username']} -P\"#{SPEC['password']}\""
10
- end
11
-
12
- # Adapter config setup in locals/database_connections.rb
13
- SPEC = CompositePrimaryKeys::ConnectionSpec['sqlserver']
14
- ActiveRecord::Base.establish_connection(SPEC)
1
+ print "Using native SQL Server\n"
2
+
3
+ require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
4
+
5
+ def connection_string
6
+ "-S #{SPEC['host']} -U #{SPEC['username']} -P\"#{SPEC['password']}\""
7
+ end
8
+
9
+ # Adapter config setup in locals/database_connections.rb
10
+ SPEC = CompositePrimaryKeys::ConnectionSpec['sqlserver']
11
+ ActiveRecord::Base.establish_connection(SPEC)
@@ -1,7 +1,7 @@
1
- class Comment < ActiveRecord::Base
2
- belongs_to :person, :polymorphic => true
3
- belongs_to :hack
4
-
5
- enum :shown => [ :true, :false ]
6
- end
7
-
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :person, :polymorphic => true
3
+ belongs_to :hack
4
+
5
+ enum :shown => [ :true, :false ]
6
+ end
7
+
@@ -1,126 +1,125 @@
1
- CREATE TABLE topics (
2
- id integer NOT NULL,
3
- name varchar(50) default NULL,
4
- feed_size integer default NULL,
5
- PRIMARY KEY (id)
6
- );
7
-
8
- CREATE TABLE topic_sources (
9
- topic_id integer NOT NULL,
10
- platform varchar(50) NOT NULL,
11
- keywords varchar(50) default NULL,
12
- PRIMARY KEY (topic_id,platform)
13
- );
14
-
15
- CREATE TABLE reference_types (
16
- reference_type_id integer NOT NULL generated by default as identity (start with 100, increment by 1, no cache),
17
- type_label varchar(50) default NULL,
18
- abbreviation varchar(50) default NULL,
19
- description varchar(50) default NULL,
20
- PRIMARY KEY (reference_type_id)
21
- );
22
-
23
- CREATE TABLE reference_codes (
24
- reference_type_id integer,
25
- reference_code integer NOT NULL,
26
- code_label varchar(50) default NULL,
27
- abbreviation varchar(50) default NULL,
28
- description varchar(50) default NULL,
29
- PRIMARY KEY (reference_type_id,reference_code)
30
- );
31
-
32
- CREATE TABLE products (
33
- id integer NOT NULL,
34
- name varchar(50) default NULL,
35
- PRIMARY KEY (id)
36
- );
37
-
38
- CREATE TABLE tariffs (
39
- tariff_id integer NOT NULL,
40
- start_date date NOT NULL,
41
- amount integer default NULL,
42
- PRIMARY KEY (tariff_id,start_date)
43
- );
44
-
45
- CREATE TABLE product_tariffs (
46
- product_id integer NOT NULL,
47
- tariff_id integer NOT NULL,
48
- tariff_start_date date NOT NULL,
49
- PRIMARY KEY (product_id,tariff_id,tariff_start_date)
50
- );
51
-
52
- CREATE TABLE suburbs (
53
- city_id integer NOT NULL,
54
- suburb_id integer NOT NULL,
55
- name varchar(50) NOT NULL,
56
- PRIMARY KEY (city_id,suburb_id)
57
- );
58
-
59
- CREATE TABLE streets (
60
- id integer NOT NULL ,
61
- city_id integer NOT NULL,
62
- suburb_id integer NOT NULL,
63
- name varchar(50) NOT NULL,
64
- PRIMARY KEY (id)
65
- );
66
-
67
- CREATE TABLE users (
68
- id integer NOT NULL ,
69
- name varchar(50) NOT NULL,
70
- PRIMARY KEY (id)
71
- );
72
-
73
- CREATE TABLE articles (
74
- id integer NOT NULL ,
75
- name varchar(50) NOT NULL,
76
- PRIMARY KEY (id)
77
- );
78
-
79
- CREATE TABLE readings (
80
- id integer NOT NULL ,
81
- user_id integer NOT NULL,
82
- article_id integer NOT NULL,
83
- rating integer NOT NULL,
84
- PRIMARY KEY (id)
85
- );
86
-
87
- CREATE TABLE groups (
88
- id integer NOT NULL ,
89
- name varchar(50) NOT NULL,
90
- PRIMARY KEY (id)
91
- );
92
-
93
- CREATE TABLE memberships (
94
- user_id integer NOT NULL,
95
- group_id integer NOT NULL,
96
- PRIMARY KEY (user_id,group_id)
97
- );
98
-
99
- CREATE TABLE membership_statuses (
100
- id integer NOT NULL ,
101
- user_id integer NOT NULL,
102
- group_id integer NOT NULL,
103
- status varchar(50) NOT NULL,
104
- PRIMARY KEY (id)
105
- );
106
-
107
- create table restaurants (
108
- franchise_id integer not null,
109
- store_id integer not null,
110
- name varchar(100),
111
- lock_version integer default 0,
112
- primary key (franchise_id, store_id)
113
- );
114
-
115
- create table restaurants_suburbs (
116
- franchise_id integer not null,
117
- store_id integer not null,
118
- city_id integer not null,
119
- suburb_id integer not null
120
- );
121
-
122
- create table products_restaurants (
123
- product_id integer not null,
124
- franchise_id integer not null,
125
- store_id integer not null
126
- );
1
+ CREATE TABLE topics (
2
+ id integer NOT NULL,
3
+ name varchar(50) default NULL,
4
+ feed_size integer default NULL,
5
+ PRIMARY KEY (id)
6
+ );
7
+
8
+ CREATE TABLE topic_sources (
9
+ topic_id integer NOT NULL,
10
+ platform varchar(50) NOT NULL,
11
+ keywords varchar(50) default NULL,
12
+ PRIMARY KEY (topic_id,platform)
13
+ );
14
+
15
+ CREATE TABLE reference_types (
16
+ reference_type_id integer NOT NULL generated by default as identity (start with 100, increment by 1, no cache),
17
+ type_label varchar(50) default NULL,
18
+ abbreviation varchar(50) default NULL,
19
+ description varchar(50) default NULL,
20
+ PRIMARY KEY (reference_type_id)
21
+ );
22
+
23
+ CREATE TABLE reference_codes (
24
+ reference_type_id integer,
25
+ reference_code integer NOT NULL,
26
+ code_label varchar(50) default NULL,
27
+ abbreviation varchar(50) default NULL,
28
+ description varchar(50) default NULL,
29
+ PRIMARY KEY (reference_type_id,reference_code)
30
+ );
31
+
32
+ CREATE TABLE products (
33
+ id integer NOT NULL,
34
+ name varchar(50) default NULL,
35
+ PRIMARY KEY (id)
36
+ );
37
+
38
+ CREATE TABLE tariffs (
39
+ tariff_id integer NOT NULL,
40
+ start_date date NOT NULL,
41
+ amount integer default NULL,
42
+ PRIMARY KEY (tariff_id,start_date)
43
+ );
44
+
45
+ CREATE TABLE product_tariffs (
46
+ product_id integer NOT NULL,
47
+ tariff_id integer NOT NULL,
48
+ tariff_start_date date NOT NULL,
49
+ PRIMARY KEY (product_id,tariff_id,tariff_start_date)
50
+ );
51
+
52
+ CREATE TABLE suburbs (
53
+ city_id integer NOT NULL,
54
+ suburb_id integer NOT NULL,
55
+ name varchar(50) NOT NULL,
56
+ PRIMARY KEY (city_id,suburb_id)
57
+ );
58
+
59
+ CREATE TABLE streets (
60
+ id integer NOT NULL ,
61
+ city_id integer NOT NULL,
62
+ suburb_id integer NOT NULL,
63
+ name varchar(50) NOT NULL,
64
+ PRIMARY KEY (id)
65
+ );
66
+
67
+ CREATE TABLE users (
68
+ id integer NOT NULL ,
69
+ name varchar(50) NOT NULL,
70
+ PRIMARY KEY (id)
71
+ );
72
+
73
+ CREATE TABLE articles (
74
+ id integer NOT NULL ,
75
+ name varchar(50) NOT NULL,
76
+ PRIMARY KEY (id)
77
+ );
78
+
79
+ CREATE TABLE readings (
80
+ id integer NOT NULL ,
81
+ user_id integer NOT NULL,
82
+ article_id integer NOT NULL,
83
+ rating integer NOT NULL,
84
+ PRIMARY KEY (id)
85
+ );
86
+
87
+ CREATE TABLE groups (
88
+ id integer NOT NULL ,
89
+ name varchar(50) NOT NULL,
90
+ PRIMARY KEY (id)
91
+ );
92
+
93
+ CREATE TABLE memberships (
94
+ user_id integer NOT NULL,
95
+ group_id integer NOT NULL,
96
+ PRIMARY KEY (user_id,group_id)
97
+ );
98
+
99
+ CREATE TABLE membership_statuses (
100
+ id integer NOT NULL ,
101
+ user_id integer NOT NULL,
102
+ group_id integer NOT NULL,
103
+ status varchar(50) NOT NULL,
104
+ PRIMARY KEY (id)
105
+ );
106
+
107
+ create table restaurants (
108
+ franchise_id integer not null,
109
+ store_id integer not null,
110
+ name varchar(100),
111
+ primary key (franchise_id, store_id)
112
+ );
113
+
114
+ create table restaurants_suburbs (
115
+ franchise_id integer not null,
116
+ store_id integer not null,
117
+ city_id integer not null,
118
+ suburb_id integer not null
119
+ );
120
+
121
+ create table products_restaurants (
122
+ product_id integer not null,
123
+ franchise_id integer not null,
124
+ store_id integer not null
125
+ );
@@ -1,19 +1,19 @@
1
- drop table MEMBERSHIPS;
2
- drop table REFERENCE_CODES;
3
- drop table TARIFFS;
4
- drop table ARTICLES;
5
- drop table GROUPS;
6
- drop table MEMBERSHIP_STATUSES;
7
- drop table READINGS;
8
- drop table REFERENCE_TYPES;
9
- drop table STREETS;
10
- drop table PRODUCTS;
11
- drop table USERS;
12
- drop table SUBURBS;
13
- drop table PRODUCT_TARIFFS;
14
- drop table KITCHEN_SINK;
15
- drop table RESTAURANTS;
16
- drop table RESTAURANTS_SUBURBS;
17
- drop table PRODUCTS_RESTAURANTS;
18
- drop table TOPICS;
1
+ drop table MEMBERSHIPS;
2
+ drop table REFERENCE_CODES;
3
+ drop table TARIFFS;
4
+ drop table ARTICLES;
5
+ drop table GROUPS;
6
+ drop table MEMBERSHIP_STATUSES;
7
+ drop table READINGS;
8
+ drop table REFERENCE_TYPES;
9
+ drop table STREETS;
10
+ drop table PRODUCTS;
11
+ drop table USERS;
12
+ drop table SUBURBS;
13
+ drop table PRODUCT_TARIFFS;
14
+ drop table KITCHEN_SINK;
15
+ drop table RESTAURANTS;
16
+ drop table RESTAURANTS_SUBURBS;
17
+ drop table PRODUCTS_RESTAURANTS;
18
+ drop table TOPICS;
19
19
  drop table TOPIC_SOURCES;