composite_primary_keys 5.0.6 → 5.0.8
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/History.rdoc +15 -0
- data/Rakefile +1 -1
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +2 -0
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +13 -34
- data/lib/composite_primary_keys/validations/uniqueness.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/mysql.rake +3 -1
- data/tasks/databases/sqlserver.rake +27 -0
- data/test/README_tests.rdoc +4 -4
- data/test/connections/native_sqlserver/connection.rb +11 -0
- data/test/fixtures/db_definitions/mysql.sql +4 -0
- data/test/fixtures/db_definitions/oracle.sql +6 -0
- data/test/fixtures/db_definitions/postgresql.sql +6 -1
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/db_definitions/sqlserver.drop.sql +86 -0
- data/test/fixtures/db_definitions/sqlserver.sql +210 -0
- data/test/fixtures/dorms.yml +4 -1
- data/test/fixtures/employee.rb +1 -0
- data/test/fixtures/employees_groups.yml +15 -0
- data/test/fixtures/groups.yml +5 -1
- data/test/fixtures/room.rb +1 -1
- data/test/fixtures/room_assignment.rb +1 -0
- data/test/fixtures/room_attribute_assignments.yml +1 -1
- data/test/fixtures/room_attributes.yml +1 -1
- data/test/test_associations.rb +5 -4
- data/test/test_delete.rb +8 -0
- data/test/test_find.rb +6 -1
- data/test/test_update.rb +9 -0
- data/test/test_validations.rb +5 -5
- metadata +7 -2
data/History.rdoc
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
== 5.0.8 2012-07-01
|
2
|
+
* Enabled tests for MS SQL Server (Enderson Maia)
|
3
|
+
* Update establish_connection to work with Rails 3.2.6 (Ivan Schneider)
|
4
|
+
* Fix typos in rake tasks names in README_tests.rdoc (Ivan Schneider)
|
5
|
+
* Fix problem with deleting non-CPK in Rails 3.2.5 (Sammy Larbi)
|
6
|
+
* Fixes relationship deletion for HABTM in Rails when it passes :all flag instead of
|
7
|
+
an array of IDs. Also adds new tests and test fixtures (Sammy Larbi)
|
8
|
+
* Change mysql db creation to execute one statement each time, since in some setups
|
9
|
+
it will not run multiple statements (Sammy Larbi)
|
10
|
+
* Fix multiple assignments to same column due to duplicate keys in @changed_attributes.
|
11
|
+
Includes test fixes (Jan Vlnas)
|
12
|
+
|
13
|
+
== 5.0.7 2012-06-03
|
14
|
+
* Fixed bug where validates_uniqueness failed for 3 or more primary keys. (Charlie Savage)
|
15
|
+
|
1
16
|
== 5.0.6 2012-05-20
|
2
17
|
* Fixed bug where setting a belongs_to association to nil would raise an error (Tyler Rick)
|
3
18
|
* Remove special case code for 1 column selects and just choose to use Rails version of the
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ Dir.glob('tasks/**/*.rake').each do |rake_file|
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# Set up test tasks for each supported connection adapter
|
23
|
-
%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db).each do |adapter|
|
23
|
+
%w(mysql sqlite3 oracle oracle_enhanced postgresql ibm_db sqlserver).each do |adapter|
|
24
24
|
namespace adapter do
|
25
25
|
desc "Run tests using the #{adapter} adapter"
|
26
26
|
task "test" do
|
@@ -48,7 +48,7 @@ module ActiveRecord
|
|
48
48
|
#).compile_delete
|
49
49
|
|
50
50
|
predicate1 = cpk_id_predicate(relation, Array(reflection.foreign_key), Array(owner.id))
|
51
|
-
predicate2 = cpk_in_predicate(relation, Array(reflection.association_foreign_key), records.map { |x| x.id })
|
51
|
+
predicate2 = cpk_in_predicate(relation, Array(reflection.association_foreign_key), records.map { |x| x.id }) unless records == :all
|
52
52
|
stmt = relation.where(predicate1.and(predicate2)).compile_delete
|
53
53
|
|
54
54
|
owner.connection.delete stmt.to_sql
|
@@ -8,6 +8,8 @@ module ActiveRecord
|
|
8
8
|
# We will come back in here with an *individual* attribute when Write#write_attribute looks through the individual attributes comprising this composite key:
|
9
9
|
# [attr_name, value].transpose.map {|name,val| write_attribute(name, val)}
|
10
10
|
else
|
11
|
+
attr = attr.to_s
|
12
|
+
|
11
13
|
# The attribute already has an unsaved change.
|
12
14
|
if attribute_changed?(attr)
|
13
15
|
old = @changed_attributes[attr]
|
data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb
CHANGED
@@ -5,41 +5,20 @@ module ActiveRecord
|
|
5
5
|
require "composite_primary_keys/connection_adapters/#{adapter}_adapter.rb"
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
9
|
-
def self.establish_connection(spec =
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
establish_connection(configuration)
|
19
|
-
else
|
20
|
-
raise AdapterNotSpecified, "#{spec} database is not configured"
|
21
|
-
end
|
22
|
-
else
|
23
|
-
spec = spec.symbolize_keys
|
24
|
-
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end
|
25
|
-
|
26
|
-
begin
|
27
|
-
require "active_record/connection_adapters/#{spec[:adapter]}_adapter"
|
28
|
-
rescue LoadError => e
|
29
|
-
raise "Please install the #{spec[:adapter]} adapter: `gem install activerecord-#{spec[:adapter]}-adapter` (#{e})"
|
30
|
-
end
|
31
|
-
|
32
|
-
# CPK
|
33
|
-
load_cpk_adapter(spec[:adapter])
|
34
|
-
|
35
|
-
adapter_method = "#{spec[:adapter]}_connection"
|
36
|
-
unless respond_to?(adapter_method)
|
37
|
-
raise AdapterNotFound, "database configuration specifies nonexistent #{spec[:adapter]} adapter"
|
38
|
-
end
|
39
|
-
|
40
|
-
remove_connection
|
41
|
-
establish_connection(ConnectionSpecification.new(spec, adapter_method))
|
8
|
+
|
9
|
+
def self.establish_connection(spec = ENV["DATABASE_URL"])
|
10
|
+
resolver = ConnectionSpecification::Resolver.new spec, configurations
|
11
|
+
spec = resolver.spec
|
12
|
+
|
13
|
+
# CPK
|
14
|
+
load_cpk_adapter(spec.config[:adapter])
|
15
|
+
|
16
|
+
unless respond_to?(spec.adapter_method)
|
17
|
+
raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
|
42
18
|
end
|
19
|
+
|
20
|
+
remove_connection
|
21
|
+
connection_handler.establish_connection name, spec
|
43
22
|
end
|
44
23
|
|
45
24
|
class << self
|
data/tasks/databases/mysql.rake
CHANGED
@@ -22,7 +22,9 @@ namespace :mysql do
|
|
22
22
|
Rake::Task['mysql:load_connection'].reenable
|
23
23
|
Rake::Task['mysql:load_connection'].invoke
|
24
24
|
#puts %(ActiveRecord::Base.connection.instance_variable_get(:@config)=#{(ActiveRecord::Base.connection.instance_variable_get(:@config)).inspect})
|
25
|
-
|
25
|
+
sql.split(";").each do |statement|
|
26
|
+
ActiveRecord::Base.connection.execute(statement) unless statement.strip.length == 0
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
desc 'Drop the MySQL test database'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
+
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
+
|
4
|
+
namespace :sqlserver do
|
5
|
+
desc 'Build the SQL Server test database'
|
6
|
+
task :build_database => :load_connection do
|
7
|
+
options_str = connection_string
|
8
|
+
|
9
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.sql')
|
10
|
+
sh %( sqsh #{options_str} -i #{schema} )
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Drop the SQL Server test database'
|
14
|
+
task :drop_database => :load_connection do
|
15
|
+
options_str = connection_string
|
16
|
+
|
17
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlserver.drop.sql')
|
18
|
+
sh %( sqsh #{options_str} -i #{schema} )
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Rebuild the SQL Server test database'
|
22
|
+
task :rebuild_database => [:drop_database, :build_database]
|
23
|
+
|
24
|
+
task :load_connection do
|
25
|
+
require File.join(PROJECT_ROOT, "test", "connections", "native_sqlserver", "connection")
|
26
|
+
end
|
27
|
+
end
|
data/test/README_tests.rdoc
CHANGED
@@ -28,12 +28,12 @@ To run the tests for one of the adapters follow these steps (using mysql in the
|
|
28
28
|
|
29
29
|
* rake -T mysql
|
30
30
|
|
31
|
-
rake mysql:
|
32
|
-
rake mysql:
|
33
|
-
rake mysql:
|
31
|
+
rake mysql:build_database # Build the MySQL test databases
|
32
|
+
rake mysql:drop_database # Drop the MySQL test databases
|
33
|
+
rake mysql:rebuild_database # Rebuild the MySQL test databases
|
34
34
|
rake mysql:test # Run tests using the mysql adapter
|
35
35
|
|
36
|
-
* rake mysql:
|
36
|
+
* rake mysql:build_database
|
37
37
|
* rake mysql:test
|
38
38
|
|
39
39
|
== Running tests individually
|
@@ -0,0 +1,11 @@
|
|
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)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
USE [composite_primary_keys_unittest];
|
2
|
+
go
|
3
|
+
|
4
|
+
DROP TABLE reference_types;
|
5
|
+
go
|
6
|
+
|
7
|
+
DROP TABLE reference_codes;
|
8
|
+
go
|
9
|
+
|
10
|
+
DROP TABLE products;
|
11
|
+
go
|
12
|
+
|
13
|
+
DROP TABLE tariffs;
|
14
|
+
go
|
15
|
+
|
16
|
+
DROP TABLE product_tariffs;
|
17
|
+
go
|
18
|
+
|
19
|
+
DROP TABLE suburbs;
|
20
|
+
go
|
21
|
+
|
22
|
+
DROP TABLE streets;
|
23
|
+
go
|
24
|
+
|
25
|
+
DROP TABLE users;
|
26
|
+
go
|
27
|
+
|
28
|
+
DROP TABLE articles;
|
29
|
+
go
|
30
|
+
|
31
|
+
DROP TABLE readings;
|
32
|
+
go
|
33
|
+
|
34
|
+
DROP TABLE groups;
|
35
|
+
go
|
36
|
+
|
37
|
+
DROP TABLE memberships;
|
38
|
+
go
|
39
|
+
|
40
|
+
DROP TABLE membership_statuses;
|
41
|
+
go
|
42
|
+
|
43
|
+
DROP TABLE departments;
|
44
|
+
go
|
45
|
+
|
46
|
+
DROP TABLE employees;
|
47
|
+
go
|
48
|
+
|
49
|
+
DROP TABLE comments;
|
50
|
+
go
|
51
|
+
|
52
|
+
DROP TABLE hacks;
|
53
|
+
go
|
54
|
+
|
55
|
+
DROP TABLE restaurants;
|
56
|
+
go
|
57
|
+
|
58
|
+
DROP TABLE restaurants_suburbs;
|
59
|
+
go
|
60
|
+
|
61
|
+
DROP TABLE dorms;
|
62
|
+
go
|
63
|
+
|
64
|
+
DROP TABLE rooms;
|
65
|
+
go
|
66
|
+
|
67
|
+
DROP TABLE room_attributes;
|
68
|
+
go
|
69
|
+
|
70
|
+
DROP TABLE room_attribute_assignments;
|
71
|
+
go
|
72
|
+
|
73
|
+
DROP TABLE students;
|
74
|
+
go
|
75
|
+
|
76
|
+
DROP TABLE room_assignments;
|
77
|
+
go
|
78
|
+
|
79
|
+
DROP TABLE seats;
|
80
|
+
go
|
81
|
+
|
82
|
+
DROP TABLE capitols;
|
83
|
+
go
|
84
|
+
|
85
|
+
DROP TABLE products_restaurants;
|
86
|
+
go
|
@@ -0,0 +1,210 @@
|
|
1
|
+
USE [composite_primary_keys_unittest];
|
2
|
+
go
|
3
|
+
|
4
|
+
CREATE TABLE reference_types (
|
5
|
+
reference_type_id [int] IDENTITY(1000,1) NOT NULL,
|
6
|
+
type_label [varchar](50) NULL,
|
7
|
+
abbreviation [varchar](50) NULL,
|
8
|
+
description [varchar](50) NULL
|
9
|
+
);
|
10
|
+
go
|
11
|
+
|
12
|
+
CREATE TABLE reference_codes (
|
13
|
+
reference_type_id [int],
|
14
|
+
reference_code [int],
|
15
|
+
code_label [varchar](50) NULL,
|
16
|
+
abbreviation [varchar](50) NULL,
|
17
|
+
description [varchar](50) NULL
|
18
|
+
);
|
19
|
+
go
|
20
|
+
|
21
|
+
CREATE TABLE products (
|
22
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
23
|
+
name [varchar](50) NULL
|
24
|
+
);
|
25
|
+
go
|
26
|
+
|
27
|
+
CREATE TABLE tariffs (
|
28
|
+
[tariff_id] [int],
|
29
|
+
[start_date] [date],
|
30
|
+
[amount] [int] NULL
|
31
|
+
CONSTRAINT [tariffs_pk] PRIMARY KEY
|
32
|
+
( [tariff_id], [start_date] )
|
33
|
+
);
|
34
|
+
go
|
35
|
+
|
36
|
+
CREATE TABLE product_tariffs (
|
37
|
+
[product_id] [int],
|
38
|
+
[tariff_id] [int],
|
39
|
+
[tariff_start_date] [date]
|
40
|
+
CONSTRAINT [product_tariffs_pk] PRIMARY KEY
|
41
|
+
( [product_id], [tariff_id], [tariff_start_date] )
|
42
|
+
);
|
43
|
+
go
|
44
|
+
|
45
|
+
CREATE TABLE suburbs (
|
46
|
+
city_id [int],
|
47
|
+
suburb_id [int],
|
48
|
+
name varchar(50) not null,
|
49
|
+
CONSTRAINT [suburbs_pk] PRIMARY KEY
|
50
|
+
( [city_id], [suburb_id] )
|
51
|
+
);
|
52
|
+
go
|
53
|
+
|
54
|
+
CREATE TABLE streets (
|
55
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
56
|
+
city_id [int] NOT NULL,
|
57
|
+
suburb_id [int] NOT NULL,
|
58
|
+
name [varchar](50) NOT NULL
|
59
|
+
);
|
60
|
+
go
|
61
|
+
|
62
|
+
CREATE TABLE users (
|
63
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
64
|
+
name varchar(50) NOT NULL
|
65
|
+
);
|
66
|
+
go
|
67
|
+
|
68
|
+
CREATE TABLE articles (
|
69
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
70
|
+
name varchar(50) NOT NULL
|
71
|
+
);
|
72
|
+
go
|
73
|
+
|
74
|
+
CREATE TABLE readings (
|
75
|
+
id [int] PRIMARY KEY,
|
76
|
+
user_id [int] NOT NULL,
|
77
|
+
article_id [int] NOT NULL,
|
78
|
+
rating [int] NOT NULL
|
79
|
+
);
|
80
|
+
go
|
81
|
+
|
82
|
+
CREATE TABLE groups (
|
83
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
84
|
+
name [varchar](50) NOT NULL
|
85
|
+
);
|
86
|
+
go
|
87
|
+
|
88
|
+
CREATE TABLE memberships (
|
89
|
+
user_id [int] NOT NULL,
|
90
|
+
group_id [int] NOT NULL
|
91
|
+
CONSTRAINT [memberships_pk] PRIMARY KEY
|
92
|
+
( [user_id], [group_id] )
|
93
|
+
);
|
94
|
+
go
|
95
|
+
|
96
|
+
CREATE TABLE membership_statuses (
|
97
|
+
id [int] IDENTITY(1,1) NOT NULL,
|
98
|
+
user_id [int] not null,
|
99
|
+
group_id [int] not null,
|
100
|
+
status varchar(50) not null
|
101
|
+
);
|
102
|
+
go
|
103
|
+
|
104
|
+
CREATE TABLE departments (
|
105
|
+
department_id [int] NOT NULL,
|
106
|
+
location_id [int] NOT NULL
|
107
|
+
CONSTRAINT [departments_pk] PRIMARY KEY
|
108
|
+
( [department_id], [location_id] )
|
109
|
+
);
|
110
|
+
go
|
111
|
+
|
112
|
+
CREATE TABLE employees (
|
113
|
+
id [int] IDENTITY(1000,1) NOT NULL,
|
114
|
+
department_id [int] NULL,
|
115
|
+
location_id [int] NULL
|
116
|
+
);
|
117
|
+
go
|
118
|
+
|
119
|
+
CREATE TABLE comments (
|
120
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
121
|
+
person_id [int] NULL,
|
122
|
+
person_type varchar(100) NULL,
|
123
|
+
hack_id [int] NULL
|
124
|
+
);
|
125
|
+
go
|
126
|
+
|
127
|
+
CREATE TABLE hacks (
|
128
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
129
|
+
name [varchar](50) NOT NULL
|
130
|
+
);
|
131
|
+
go
|
132
|
+
|
133
|
+
CREATE TABLE restaurants (
|
134
|
+
franchise_id [int] NOT NULL,
|
135
|
+
store_id [int] NOT NULL,
|
136
|
+
name [varchar](100)
|
137
|
+
CONSTRAINT [restaurants_pk] PRIMARY KEY CLUSTERED
|
138
|
+
( [franchise_id], [store_id] )
|
139
|
+
);
|
140
|
+
go
|
141
|
+
|
142
|
+
CREATE TABLE restaurants_suburbs (
|
143
|
+
franchise_id [int] NOT NULL,
|
144
|
+
store_id [int] NOT NULL,
|
145
|
+
city_id [int] NOT NULL,
|
146
|
+
suburb_id [int] NOT NULL
|
147
|
+
);
|
148
|
+
go
|
149
|
+
|
150
|
+
CREATE TABLE dorms (
|
151
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
|
152
|
+
);
|
153
|
+
go
|
154
|
+
|
155
|
+
CREATE TABLE rooms (
|
156
|
+
dorm_id [int] NOT NULL,
|
157
|
+
room_id [int] NOT NULL,
|
158
|
+
CONSTRAINT [rooms_pk] PRIMARY KEY CLUSTERED
|
159
|
+
( [dorm_id], [room_id] )
|
160
|
+
);
|
161
|
+
go
|
162
|
+
|
163
|
+
CREATE TABLE room_attributes (
|
164
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL,
|
165
|
+
name [varchar](50)
|
166
|
+
);
|
167
|
+
go
|
168
|
+
|
169
|
+
CREATE TABLE room_attribute_assignments (
|
170
|
+
dorm_id [int] NOT NULL,
|
171
|
+
room_id [int] NOT NULL,
|
172
|
+
room_attribute_id [int] NOT NULL
|
173
|
+
);
|
174
|
+
go
|
175
|
+
|
176
|
+
CREATE TABLE students (
|
177
|
+
id [int] IDENTITY(1000,1) PRIMARY KEY NOT NULL
|
178
|
+
);
|
179
|
+
go
|
180
|
+
|
181
|
+
CREATE TABLE room_assignments (
|
182
|
+
student_id [int] NOT NULL,
|
183
|
+
dorm_id [int] NOT NULL,
|
184
|
+
room_id [int] NOT NULL
|
185
|
+
);
|
186
|
+
go
|
187
|
+
|
188
|
+
CREATE TABLE seats (
|
189
|
+
flight_number [int] NOT NULL,
|
190
|
+
seat [int] NOT NULL,
|
191
|
+
customer [int]
|
192
|
+
CONSTRAINT [seats_pk] PRIMARY KEY
|
193
|
+
( [flight_number], [seat] )
|
194
|
+
);
|
195
|
+
go
|
196
|
+
|
197
|
+
CREATE TABLE capitols (
|
198
|
+
country varchar(450) NOT NULL,
|
199
|
+
city varchar(450) NOT NULL
|
200
|
+
CONSTRAINT [capitols_pk] PRIMARY KEY
|
201
|
+
( [country], [city] )
|
202
|
+
);
|
203
|
+
go
|
204
|
+
|
205
|
+
CREATE TABLE products_restaurants (
|
206
|
+
product_id [int] NOT NULL,
|
207
|
+
franchise_id [int] NOT NULL,
|
208
|
+
store_id [int] NOT NULL
|
209
|
+
);
|
210
|
+
go
|
data/test/fixtures/dorms.yml
CHANGED
data/test/fixtures/employee.rb
CHANGED
data/test/fixtures/groups.yml
CHANGED
data/test/fixtures/room.rb
CHANGED
@@ -6,6 +6,6 @@ class Room < ActiveRecord::Base
|
|
6
6
|
has_many :room_attributes, :through => :room_attribute_assignments
|
7
7
|
|
8
8
|
def find_custom_room_attributes
|
9
|
-
room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "
|
9
|
+
room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "type"])
|
10
10
|
end
|
11
11
|
end
|
@@ -2,6 +2,7 @@ class RoomAssignment < ActiveRecord::Base
|
|
2
2
|
self.primary_keys = :student_id, :dorm_id, :room_id
|
3
3
|
belongs_to :student
|
4
4
|
belongs_to :room, :foreign_key => [:dorm_id, :room_id], :primary_key => [:dorm_id, :room_id]
|
5
|
+
validates_uniqueness_of :student_id
|
5
6
|
|
6
7
|
before_destroy do |record|
|
7
8
|
puts record
|
data/test/test_associations.rb
CHANGED
@@ -133,7 +133,7 @@ class TestAssociations < ActiveSupport::TestCase
|
|
133
133
|
dorm = Dorm.find(:first)
|
134
134
|
assert_equal(2, dorm.rooms.length)
|
135
135
|
assert_equal(1, dorm.rooms.first.room_attributes.length)
|
136
|
-
assert_equal('
|
136
|
+
assert_equal('type', dorm.rooms.first.room_attributes.first.name)
|
137
137
|
end
|
138
138
|
|
139
139
|
def test_associations_with_conditions
|
@@ -167,13 +167,14 @@ class TestAssociations < ActiveSupport::TestCase
|
|
167
167
|
room_assignment.room = rooms(:branner_room_2)
|
168
168
|
# This was raising an error before:
|
169
169
|
# TypeError: [:dorm_id, :room_id] is not a symbol
|
170
|
-
|
170
|
+
# changes returns HashWithIndifferentAccess
|
171
|
+
assert_equal({"room_id"=>[1, 2]}, room_assignment.changes)
|
171
172
|
|
172
173
|
steve = employees(:steve)
|
173
174
|
steve.department = departments(:engineering)
|
174
175
|
# It was returning this before:
|
175
176
|
# {"[:department_id, :location_id]"=>[nil, [2, 1]]}
|
176
|
-
assert_equal({
|
177
|
+
assert_equal({"department_id"=>[1, 2]}, steve.changes)
|
177
178
|
end
|
178
179
|
|
179
180
|
def test_composite_belongs_to__setting_to_nil
|
@@ -237,7 +238,7 @@ class TestAssociations < ActiveSupport::TestCase
|
|
237
238
|
|
238
239
|
def test_has_many_through_with_conditions_when_through_association_is_composite
|
239
240
|
room = Room.find(:first)
|
240
|
-
assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "
|
241
|
+
assert_equal 0, room.room_attributes.find(:all, :conditions => ["room_attributes.name != ?", "type"]).size
|
241
242
|
end
|
242
243
|
|
243
244
|
def test_has_many_through_on_custom_finder_when_through_association_is_composite_finder_when_through_association_is_not_composite
|
data/test/test_delete.rb
CHANGED
@@ -88,6 +88,14 @@ class TestDelete < ActiveSupport::TestCase
|
|
88
88
|
Employee.find(head_id)
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
def test_destroy_has_and_belongs_to_many_on_non_cpk
|
93
|
+
steve = employees(:steve)
|
94
|
+
records_before = ActiveRecord::Base.connection.execute("select * from employees_groups").count
|
95
|
+
steve.destroy
|
96
|
+
records_after = ActiveRecord::Base.connection.execute("select * from employees_groups").count
|
97
|
+
assert_equal records_after, records_before - steve.groups.count
|
98
|
+
end
|
91
99
|
|
92
100
|
# def test_destroy_has_many_delete_all
|
93
101
|
# # In this case the association is a has_many composite key with
|
data/test/test_find.rb
CHANGED
@@ -54,7 +54,12 @@ class TestFind < ActiveSupport::TestCase
|
|
54
54
|
connection = ActiveRecord::Base.connection
|
55
55
|
ref_type_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_type_id')}"
|
56
56
|
ref_code_quoted = "#{connection.quote_table_name('reference_codes')}.#{connection.quote_column_name('reference_code')}"
|
57
|
-
|
57
|
+
|
58
|
+
if current_adapter?(:SQLServerAdapter)
|
59
|
+
expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = N'999' AND #{ref_code_quoted} = N'999'"
|
60
|
+
else
|
61
|
+
expected = "Couldn't find ReferenceCode with ID=999,999 WHERE #{ref_type_quoted} = 999 AND #{ref_code_quoted} = 999"
|
62
|
+
end
|
58
63
|
|
59
64
|
assert_equal(with_quoted_identifiers(expected),
|
60
65
|
error.message)
|
data/test/test_update.rb
CHANGED
@@ -50,4 +50,13 @@ class TestUpdate < ActiveSupport::TestCase
|
|
50
50
|
assert_equal({:reference_type_id => 2, :reference_code => 3}, obj.ids_hash)
|
51
51
|
assert_equal([2, 3], obj.id)
|
52
52
|
end
|
53
|
+
|
54
|
+
def test_update_attribute
|
55
|
+
obj = ReferenceType.find(1)
|
56
|
+
obj[:abbreviation] = 'a'
|
57
|
+
obj['abbreviation'] = 'b'
|
58
|
+
assert(obj.save)
|
59
|
+
assert(obj.reload)
|
60
|
+
assert_equal('b', obj.abbreviation)
|
61
|
+
end
|
53
62
|
end
|
data/test/test_validations.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.expand_path('../abstract_unit', __FILE__)
|
2
2
|
|
3
3
|
class TestValidations < ActiveSupport::TestCase
|
4
|
-
fixtures :
|
4
|
+
fixtures :students, :dorms, :rooms, :room_assignments
|
5
5
|
|
6
6
|
def test_uniqueness_validation_persisted
|
7
|
-
|
8
|
-
assert(
|
7
|
+
room_assignment = RoomAssignment.find([1, 1, 1])
|
8
|
+
assert(room_assignment.valid?)
|
9
9
|
|
10
|
-
|
11
|
-
assert(!
|
10
|
+
room_assignment = RoomAssignment.new(:student_id => 1, :dorm_id => 1, :room_id => 2)
|
11
|
+
assert(!room_assignment.valid?)
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0.
|
4
|
+
version: 5.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- tasks/databases/oracle.rake
|
79
79
|
- tasks/databases/postgresql.rake
|
80
80
|
- tasks/databases/sqlite3.rake
|
81
|
+
- tasks/databases/sqlserver.rake
|
81
82
|
- tasks/website.rake
|
82
83
|
- test/abstract_unit.rb
|
83
84
|
- test/connections/connection_spec.rb
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- test/connections/native_oracle_enhanced/connection.rb
|
90
91
|
- test/connections/native_postgresql/connection.rb
|
91
92
|
- test/connections/native_sqlite3/connection.rb
|
93
|
+
- test/connections/native_sqlserver/connection.rb
|
92
94
|
- test/db_test.rb
|
93
95
|
- test/debug.log
|
94
96
|
- test/fixtures/article.rb
|
@@ -104,12 +106,15 @@ files:
|
|
104
106
|
- test/fixtures/db_definitions/oracle.sql
|
105
107
|
- test/fixtures/db_definitions/postgresql.sql
|
106
108
|
- test/fixtures/db_definitions/sqlite.sql
|
109
|
+
- test/fixtures/db_definitions/sqlserver.drop.sql
|
110
|
+
- test/fixtures/db_definitions/sqlserver.sql
|
107
111
|
- test/fixtures/department.rb
|
108
112
|
- test/fixtures/departments.yml
|
109
113
|
- test/fixtures/dorm.rb
|
110
114
|
- test/fixtures/dorms.yml
|
111
115
|
- test/fixtures/employee.rb
|
112
116
|
- test/fixtures/employees.yml
|
117
|
+
- test/fixtures/employees_groups.yml
|
113
118
|
- test/fixtures/group.rb
|
114
119
|
- test/fixtures/groups.yml
|
115
120
|
- test/fixtures/hack.rb
|