composite_primary_keys 12.0.2 → 12.0.7
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.
Potentially problematic release.
This version of composite_primary_keys might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.rdoc +30 -0
- data/README.rdoc +3 -2
- data/lib/composite_primary_keys.rb +57 -56
- data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +1 -3
- data/lib/composite_primary_keys/associations/through_association.rb +2 -1
- data/lib/composite_primary_keys/attribute_methods.rb +1 -1
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -0
- data/lib/composite_primary_keys/base.rb +11 -0
- data/lib/composite_primary_keys/composite_arrays.rb +0 -8
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +24 -4
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +24 -0
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +32 -11
- data/lib/composite_primary_keys/core.rb +1 -1
- data/lib/composite_primary_keys/persistence.rb +2 -2
- data/lib/composite_primary_keys/relation.rb +100 -25
- data/lib/composite_primary_keys/relation/batches.rb +1 -1
- data/lib/composite_primary_keys/relation/finder_methods.rb +1 -1
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/abstract_unit.rb +2 -1
- data/test/connections/databases.ci.yml +5 -2
- data/test/fixtures/article.rb +4 -0
- data/test/fixtures/articles.yml +4 -3
- data/test/fixtures/comment.rb +1 -3
- data/test/fixtures/comments.yml +10 -9
- data/test/fixtures/db_definitions/db2-create-tables.sql +0 -14
- data/test/fixtures/db_definitions/db2-drop-tables.sql +1 -3
- data/test/fixtures/db_definitions/mysql.sql +7 -44
- data/test/fixtures/db_definitions/oracle.drop.sql +3 -9
- data/test/fixtures/db_definitions/oracle.sql +12 -48
- data/test/fixtures/db_definitions/postgresql.sql +7 -44
- data/test/fixtures/db_definitions/sqlite.sql +6 -42
- data/test/fixtures/db_definitions/sqlserver.sql +5 -41
- data/test/fixtures/department.rb +8 -3
- data/test/fixtures/departments.yml +4 -4
- data/test/fixtures/readings.yml +2 -2
- data/test/fixtures/restaurants_suburbs.yml +1 -1
- data/test/fixtures/streets.yml +2 -2
- data/test/fixtures/suburbs.yml +2 -2
- data/test/fixtures/user.rb +3 -2
- data/test/test_associations.rb +30 -23
- data/test/test_create.rb +41 -18
- data/test/test_delete.rb +3 -3
- data/test/test_exists.rb +5 -5
- data/test/test_find.rb +21 -2
- data/test/test_habtm.rb +2 -2
- data/test/test_ids.rb +2 -6
- data/test/test_nested_attributes.rb +0 -57
- data/test/test_polymorphic.rb +29 -13
- data/test/test_preload.rb +4 -3
- data/test/test_serialize.rb +2 -2
- data/test/test_update.rb +19 -1
- metadata +11 -25
- data/test/fixtures/hack.rb +0 -5
- data/test/fixtures/hacks.yml +0 -3
- data/test/fixtures/pk_called_id.rb +0 -5
- data/test/fixtures/pk_called_ids.yml +0 -11
- data/test/fixtures/reference_code_using_composite_key_alias.rb +0 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +0 -8
- data/test/fixtures/seat.rb +0 -5
- data/test/fixtures/seats.yml +0 -9
- data/test/fixtures/topic.rb +0 -6
- data/test/fixtures/topic_source.rb +0 -7
- data/test/test_aliases.rb +0 -18
- data/test/test_enum.rb +0 -21
- data/test/test_suite.rb +0 -35
@@ -1,17 +1,3 @@
|
|
1
|
-
create sequence topics_seq start with 1000;
|
2
|
-
|
3
|
-
create table topics (
|
4
|
-
id number(11) primary key,
|
5
|
-
name varchar(50) default null,
|
6
|
-
feed_size number(11) default null
|
7
|
-
);
|
8
|
-
|
9
|
-
create table topic_sources (
|
10
|
-
topic_id number(11),
|
11
|
-
platform varchar(50),
|
12
|
-
keywords varchar(50) default null
|
13
|
-
);
|
14
|
-
|
15
1
|
create sequence reference_types_seq start with 1000;
|
16
2
|
|
17
3
|
create table reference_types (
|
@@ -52,9 +38,11 @@ create table product_tariffs (
|
|
52
38
|
constraint product_tariffs_pk primary key (product_id, tariff_id, tariff_start_date)
|
53
39
|
);
|
54
40
|
|
41
|
+
create sequence suburbs_city_id_seq start with 1000;
|
42
|
+
|
55
43
|
create table suburbs (
|
56
|
-
city_id number(11),
|
57
|
-
suburb_id number(11),
|
44
|
+
city_id number(11) default suburbs_city_id_seq.nextval not null,
|
45
|
+
suburb_id number(11) not null,
|
58
46
|
name varchar(50) not null,
|
59
47
|
constraint suburbs_pk primary key (city_id, suburb_id)
|
60
48
|
);
|
@@ -113,10 +101,12 @@ create table membership_statuses (
|
|
113
101
|
status varchar(50) not null
|
114
102
|
);
|
115
103
|
|
104
|
+
create sequence departments_seq start with 1000;
|
105
|
+
|
116
106
|
create table departments (
|
117
|
-
|
107
|
+
id number(11) not null,
|
118
108
|
location_id number(11) not null,
|
119
|
-
constraint departments_pk primary key (
|
109
|
+
constraint departments_pk primary key (id, location_id)
|
120
110
|
);
|
121
111
|
|
122
112
|
create sequence employees_seq start with 1000;
|
@@ -132,17 +122,9 @@ create sequence comments_seq start with 1000;
|
|
132
122
|
|
133
123
|
create table comments (
|
134
124
|
id number(11) not null primary key,
|
135
|
-
|
136
|
-
|
137
|
-
person_type varchar(100)
|
138
|
-
hack_id number(11) default null
|
139
|
-
);
|
140
|
-
|
141
|
-
create sequence hacks_seq start with 1000;
|
142
|
-
|
143
|
-
create table hacks (
|
144
|
-
id number(11) not null primary key,
|
145
|
-
name varchar(50) not null
|
125
|
+
article_id number(11) not null,
|
126
|
+
person_id number(11) not null,
|
127
|
+
person_type varchar(100) not null
|
146
128
|
);
|
147
129
|
|
148
130
|
create table restaurants (
|
@@ -200,13 +182,6 @@ create table room_assignments (
|
|
200
182
|
room_id number(11) not null
|
201
183
|
);
|
202
184
|
|
203
|
-
create table seats (
|
204
|
-
flight_number int not null,
|
205
|
-
seat int not null,
|
206
|
-
customer int,
|
207
|
-
primary key (flight_number, seat)
|
208
|
-
);
|
209
|
-
|
210
185
|
create table capitols (
|
211
186
|
country varchar(100) not null,
|
212
187
|
city varchar(100) not null,
|
@@ -222,15 +197,4 @@ create table products_restaurants (
|
|
222
197
|
create table employees_groups (
|
223
198
|
employee_id int not null,
|
224
199
|
group_id int not null
|
225
|
-
);
|
226
|
-
|
227
|
-
create sequence pk_called_ids_seq start with 1000;
|
228
|
-
|
229
|
-
create table pk_called_ids (
|
230
|
-
id int not null,
|
231
|
-
reference_code int not null,
|
232
|
-
code_label varchar(50) default null,
|
233
|
-
abbreviation varchar(50) default null,
|
234
|
-
description varchar(50) default null,
|
235
|
-
constraint pk_called_ids_pk primary key (id, reference_code)
|
236
|
-
);
|
200
|
+
);
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create table topics (
|
2
|
-
id serial not null,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
create table reference_types (
|
16
2
|
reference_type_id serial not null,
|
17
3
|
type_label varchar(50) default null,
|
@@ -109,9 +95,9 @@ create table membership_statuses (
|
|
109
95
|
);
|
110
96
|
|
111
97
|
create table departments (
|
112
|
-
|
113
|
-
location_id
|
114
|
-
primary key (
|
98
|
+
id serial not null,
|
99
|
+
location_id int not null,
|
100
|
+
primary key (id, location_id)
|
115
101
|
);
|
116
102
|
|
117
103
|
create table employees (
|
@@ -124,16 +110,9 @@ create table employees (
|
|
124
110
|
|
125
111
|
create table comments (
|
126
112
|
id serial not null,
|
127
|
-
|
128
|
-
|
129
|
-
person_type varchar(100)
|
130
|
-
hack_id int default null,
|
131
|
-
primary key (id)
|
132
|
-
);
|
133
|
-
|
134
|
-
create table hacks (
|
135
|
-
id serial not null,
|
136
|
-
name varchar(50) not null,
|
113
|
+
article_id int not null references articles (id),
|
114
|
+
person_id int not null,
|
115
|
+
person_type varchar(100) not null,
|
137
116
|
primary key (id)
|
138
117
|
);
|
139
118
|
|
@@ -186,13 +165,6 @@ create table room_assignments (
|
|
186
165
|
room_id int not null
|
187
166
|
);
|
188
167
|
|
189
|
-
create table seats (
|
190
|
-
flight_number int not null,
|
191
|
-
seat int not null,
|
192
|
-
customer int,
|
193
|
-
primary key (flight_number, seat)
|
194
|
-
);
|
195
|
-
|
196
168
|
create table capitols (
|
197
169
|
country text not null,
|
198
170
|
city text not null,
|
@@ -208,13 +180,4 @@ create table products_restaurants (
|
|
208
180
|
create table employees_groups (
|
209
181
|
employee_id int not null,
|
210
182
|
group_id int not null
|
211
|
-
);
|
212
|
-
|
213
|
-
create table pk_called_ids (
|
214
|
-
id serial not null,
|
215
|
-
reference_code int not null,
|
216
|
-
code_label varchar(50) default null,
|
217
|
-
abbreviation varchar(50) default null,
|
218
|
-
description varchar(50) default null,
|
219
|
-
primary key (id, reference_code)
|
220
|
-
);
|
183
|
+
);
|
@@ -1,17 +1,3 @@
|
|
1
|
-
create table topics (
|
2
|
-
id int not null,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
1
|
create table reference_types (
|
16
2
|
reference_type_id integer primary key,
|
17
3
|
type_label varchar(50) default null,
|
@@ -101,9 +87,9 @@ create table membership_statuses (
|
|
101
87
|
);
|
102
88
|
|
103
89
|
create table departments (
|
104
|
-
|
90
|
+
id integer not null,
|
105
91
|
location_id integer not null,
|
106
|
-
primary key (
|
92
|
+
primary key (id, location_id)
|
107
93
|
);
|
108
94
|
|
109
95
|
create table employees (
|
@@ -115,15 +101,9 @@ create table employees (
|
|
115
101
|
|
116
102
|
create table comments (
|
117
103
|
id integer not null primary key autoincrement,
|
118
|
-
|
119
|
-
|
120
|
-
person_type varchar(100) null
|
121
|
-
hack_id int null
|
122
|
-
);
|
123
|
-
|
124
|
-
create table hacks (
|
125
|
-
id integer not null primary key autoincrement,
|
126
|
-
name varchar(50) not null
|
104
|
+
article_id int not null,
|
105
|
+
person_id int not null,
|
106
|
+
person_type varchar(100) not null
|
127
107
|
);
|
128
108
|
|
129
109
|
create table restaurants (
|
@@ -172,13 +152,6 @@ create table room_assignments (
|
|
172
152
|
room_id integer not null
|
173
153
|
);
|
174
154
|
|
175
|
-
create table seats (
|
176
|
-
flight_number integer not_null,
|
177
|
-
seat integer not_null,
|
178
|
-
customer integer,
|
179
|
-
primary key (flight_number, seat)
|
180
|
-
);
|
181
|
-
|
182
155
|
create table capitols (
|
183
156
|
country text not null,
|
184
157
|
city text not null,
|
@@ -194,13 +167,4 @@ create table products_restaurants (
|
|
194
167
|
create table employees_groups (
|
195
168
|
employee_id integer not null,
|
196
169
|
group_id integer not null
|
197
|
-
);
|
198
|
-
|
199
|
-
create table pk_called_ids (
|
200
|
-
id integer not null,
|
201
|
-
reference_code int not null,
|
202
|
-
code_label varchar(50) default null,
|
203
|
-
abbreviation varchar(50) default null,
|
204
|
-
description varchar(50) default null,
|
205
|
-
primary key (id, reference_code)
|
206
|
-
);
|
170
|
+
);
|
@@ -1,17 +1,5 @@
|
|
1
1
|
USE [composite_primary_keys_unittest];
|
2
2
|
|
3
|
-
CREATE TABLE topics (
|
4
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
5
|
-
name [varchar](50) default NULL,
|
6
|
-
feed_size [int] default NULL
|
7
|
-
);
|
8
|
-
|
9
|
-
CREATE TABLE topic_sources (
|
10
|
-
topic_id [int] NOT NULL,
|
11
|
-
platform [varchar](50) NOT NULL,
|
12
|
-
keywords [varchar](50) default NULL,
|
13
|
-
);
|
14
|
-
|
15
3
|
CREATE TABLE reference_types (
|
16
4
|
reference_type_id [int] IDENTITY(1000,1) NOT NULL,
|
17
5
|
type_label [varchar](50) NULL,
|
@@ -102,10 +90,10 @@ CREATE TABLE membership_statuses (
|
|
102
90
|
);
|
103
91
|
|
104
92
|
CREATE TABLE departments (
|
105
|
-
|
93
|
+
id [int] IDENTITY(100,1) NOT NULL,
|
106
94
|
location_id [int] NOT NULL
|
107
95
|
CONSTRAINT [departments_pk] PRIMARY KEY
|
108
|
-
( [
|
96
|
+
( [id], [location_id] )
|
109
97
|
);
|
110
98
|
|
111
99
|
CREATE TABLE employees (
|
@@ -117,15 +105,9 @@ CREATE TABLE employees (
|
|
117
105
|
|
118
106
|
CREATE TABLE comments (
|
119
107
|
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
120
|
-
|
121
|
-
|
122
|
-
person_type varchar(100)
|
123
|
-
hack_id [int] NULL
|
124
|
-
);
|
125
|
-
|
126
|
-
CREATE TABLE hacks (
|
127
|
-
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
128
|
-
name [varchar](50) NOT NULL
|
108
|
+
article_id [int] NOT NULL,
|
109
|
+
person_id [int] NOT NULL,
|
110
|
+
person_type varchar(100) NULL
|
129
111
|
);
|
130
112
|
|
131
113
|
CREATE TABLE restaurants (
|
@@ -176,14 +158,6 @@ CREATE TABLE room_assignments (
|
|
176
158
|
room_id [int] NOT NULL
|
177
159
|
);
|
178
160
|
|
179
|
-
CREATE TABLE seats (
|
180
|
-
flight_number [int] NOT NULL,
|
181
|
-
seat [int] NOT NULL,
|
182
|
-
customer [int]
|
183
|
-
CONSTRAINT [seats_pk] PRIMARY KEY
|
184
|
-
( [flight_number], [seat] )
|
185
|
-
);
|
186
|
-
|
187
161
|
CREATE TABLE capitols (
|
188
162
|
country varchar(450) NOT NULL,
|
189
163
|
city varchar(450) NOT NULL
|
@@ -200,14 +174,4 @@ CREATE TABLE products_restaurants (
|
|
200
174
|
CREATE TABLE employees_groups (
|
201
175
|
employee_id [int] not null,
|
202
176
|
group_id [int] not null
|
203
|
-
);
|
204
|
-
|
205
|
-
CREATE TABLE pk_called_ids (
|
206
|
-
id [int] IDENTITY(1000,1) NOT NULL,
|
207
|
-
reference_code [int] not null,
|
208
|
-
code_label [varchar](50) default null,
|
209
|
-
abbreviation [varchar](50) default null,
|
210
|
-
description [varchar](50) default null
|
211
|
-
CONSTRAINT [pk_called_ids_pk] PRIMARY KEY
|
212
|
-
( [id], [reference_code] )
|
213
177
|
);
|
data/test/fixtures/department.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
class Department < ActiveRecord::Base
|
2
|
-
self.primary_keys = :
|
2
|
+
self.primary_keys = :id, :location_id
|
3
|
+
|
3
4
|
has_many :employees,
|
4
5
|
# We intentionally redefine primary key for test purposes. #455
|
5
|
-
:primary_key => [:
|
6
|
+
:primary_key => [:id, :location_id],
|
6
7
|
:foreign_key => [:department_id, :location_id]
|
8
|
+
|
9
|
+
has_many :comments, :through => :employees
|
10
|
+
|
7
11
|
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
8
12
|
# We intentionally redefine primary key for test purposes. #455
|
9
|
-
:primary_key => [:
|
13
|
+
:primary_key => [:id, :location_id],
|
10
14
|
:foreign_key => [:department_id, :location_id]
|
15
|
+
|
11
16
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
accounting:
|
2
|
-
|
2
|
+
id: 1
|
3
3
|
location_id: 1
|
4
4
|
|
5
5
|
engineering:
|
6
|
-
|
6
|
+
id: 2
|
7
7
|
location_id: 1
|
8
8
|
|
9
9
|
human_resources:
|
10
|
-
|
10
|
+
id: 3
|
11
11
|
location_id: 2
|
12
12
|
|
13
13
|
offsite_accounting:
|
14
|
-
|
14
|
+
id: 1
|
15
15
|
location_id: 2
|
data/test/fixtures/readings.yml
CHANGED
data/test/fixtures/streets.yml
CHANGED
data/test/fixtures/suburbs.yml
CHANGED
data/test/fixtures/user.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
2
|
has_many :readings
|
3
3
|
has_many :articles, :through => :readings
|
4
|
+
|
4
5
|
has_many :comments, :as => :person
|
5
|
-
|
6
|
-
|
6
|
+
has_one :first_comment, :as => :person, :class_name => "Comment"
|
7
|
+
|
7
8
|
def find_custom_articles
|
8
9
|
articles.where("name = ?", "Article One")
|
9
10
|
end
|
data/test/test_associations.rb
CHANGED
@@ -96,18 +96,23 @@ class TestAssociations < ActiveSupport::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_has_one_association_primary_key_and_foreign_key_are_present
|
99
|
-
department = departments(:
|
99
|
+
# department = departments(:engineering)
|
100
|
+
# assert_equal(2, department.employees.count)
|
101
|
+
# assert_equal('Sarah', department.employees[0].name)
|
102
|
+
# assert_equal('Robert', department.employees[1].name)
|
103
|
+
# assert_equal('Sarah', department.head.name)
|
100
104
|
|
105
|
+
department = departments(:human_resources)
|
101
106
|
assert_equal(1, department.employees.count)
|
102
107
|
assert_equal('Mindy', department.employees[0].name)
|
108
|
+
assert_equal('Mindy', department.head.name)
|
103
109
|
|
104
110
|
head = department.create_head(name: 'Rick')
|
105
|
-
assert_equal(department
|
106
|
-
assert_equal(department.
|
111
|
+
assert_equal(department, head.department)
|
112
|
+
assert_equal('Rick', department.head.name)
|
107
113
|
|
108
114
|
department.reload
|
109
115
|
assert_equal(1, department.employees.count)
|
110
|
-
assert_equal('Rick', department.employees[0].name)
|
111
116
|
end
|
112
117
|
|
113
118
|
def test_has_one_autosave
|
@@ -139,9 +144,10 @@ class TestAssociations < ActiveSupport::TestCase
|
|
139
144
|
|
140
145
|
department.reload
|
141
146
|
assert_equal(3, department.employees.count)
|
142
|
-
|
143
|
-
assert_equal('Jill',
|
144
|
-
assert_equal('Rick',
|
147
|
+
employees = department.employees.sort_by(&:name)
|
148
|
+
assert_equal('Jill', employees[0].name)
|
149
|
+
assert_equal('Rick', employees[1].name)
|
150
|
+
assert_equal('Steve', employees[2].name)
|
145
151
|
end
|
146
152
|
|
147
153
|
def test_find_includes_product_tariffs_product
|
@@ -174,6 +180,13 @@ class TestAssociations < ActiveSupport::TestCase
|
|
174
180
|
assert_equal(3, tarrifs_length)
|
175
181
|
end
|
176
182
|
|
183
|
+
def test_has_many_through_2
|
184
|
+
assert_equal(3, Article.count)
|
185
|
+
user = users(:santiago)
|
186
|
+
article_names = user.articles.map(&:name).sort
|
187
|
+
assert_equal(['Article One', 'Article Two'], article_names)
|
188
|
+
end
|
189
|
+
|
177
190
|
def test_new_style_includes_with_conditions
|
178
191
|
product_tariff = ProductTariff.includes(:tariff).where('tariffs.amount < 5').references(:tariffs).first
|
179
192
|
assert_equal(0, product_tariff.tariff.amount)
|
@@ -203,16 +216,8 @@ class TestAssociations < ActiveSupport::TestCase
|
|
203
216
|
end
|
204
217
|
|
205
218
|
def test_associations_with_conditions
|
206
|
-
suburb = Suburb.find([2,
|
207
|
-
assert_equal 2, suburb.streets.size
|
208
|
-
|
209
|
-
suburb = Suburb.find([2, 1])
|
210
|
-
assert_equal 1, suburb.first_streets.size
|
211
|
-
|
212
|
-
suburb = Suburb.includes(:streets).find([2, 1])
|
219
|
+
suburb = Suburb.find([2, 2])
|
213
220
|
assert_equal 2, suburb.streets.size
|
214
|
-
|
215
|
-
suburb = Suburb.includes(:first_streets).find([2, 1])
|
216
221
|
assert_equal 1, suburb.first_streets.size
|
217
222
|
end
|
218
223
|
|
@@ -239,7 +244,7 @@ class TestAssociations < ActiveSupport::TestCase
|
|
239
244
|
steve = employees(:steve)
|
240
245
|
steve.department = departments(:engineering)
|
241
246
|
# It was returning this before:
|
242
|
-
# {"[:
|
247
|
+
# {"[:id, :location_id]"=>[nil, [2, 1]]}
|
243
248
|
assert_equal({"department_id"=>[1, 2]}, steve.changes)
|
244
249
|
end
|
245
250
|
|
@@ -263,12 +268,12 @@ class TestAssociations < ActiveSupport::TestCase
|
|
263
268
|
assert_equal user, reading.user
|
264
269
|
end
|
265
270
|
|
266
|
-
def
|
271
|
+
def test_has_many_build_composite_key
|
267
272
|
department = departments(:engineering)
|
268
273
|
employee = department.employees.build
|
269
|
-
assert_equal
|
270
|
-
assert_equal
|
271
|
-
assert_equal
|
274
|
+
assert_equal(department[:id], employee.department_id)
|
275
|
+
assert_equal(department.location_id, employee.location_id)
|
276
|
+
assert_equal(department, employee.department)
|
272
277
|
end
|
273
278
|
|
274
279
|
def test_has_many_with_primary_key
|
@@ -331,9 +336,11 @@ class TestAssociations < ActiveSupport::TestCase
|
|
331
336
|
end
|
332
337
|
|
333
338
|
def test_limitable_reflections
|
334
|
-
memberships = Membership.includes(:statuses).where("membership_statuses.status = ?", 'Active').references(:membership_statuses)
|
335
|
-
assert_equal(
|
339
|
+
memberships = Membership.includes(:statuses).where("membership_statuses.status = ?", 'Active').references(:membership_statuses)
|
340
|
+
assert_equal(2, memberships.length)
|
341
|
+
|
336
342
|
assert_equal([1,1], memberships[0].id)
|
343
|
+
assert_equal([3,2], memberships[1].id)
|
337
344
|
end
|
338
345
|
|
339
346
|
def test_foreign_key_present_with_null_association_ids
|