composite_primary_keys 5.0.1 → 5.0.2
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.txt → History.rdoc} +9 -0
- data/{README.txt → README.rdoc} +19 -7
- data/{README_DB2.txt → README_DB2.rdoc} +0 -0
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +8 -2
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/{README_tests.txt → README_tests.rdoc} +0 -0
- data/test/test_composite_arrays.rb +8 -1
- data/test/test_create.rb +23 -1
- metadata +15 -10
@@ -1,3 +1,12 @@
|
|
1
|
+
== 5.0.2 2012-03-16
|
2
|
+
* Use .rdoc extension on RDoc files (Elia Schito)
|
3
|
+
* Update documentation to use self.primary_keys instead of set_primary_keys (Miguel Fonseca)
|
4
|
+
* Added tests for comparing composite ids (Jim Jones)
|
5
|
+
* Updating the README for clarity (Brett Fishman)
|
6
|
+
* Fix method signature mismatch with active_record (Miguel Fonseca)
|
7
|
+
* Fix ref in README (Elia Schito)
|
8
|
+
* Add test for habm create (Charlie Savage)
|
9
|
+
|
1
10
|
== 5.0.1 2012-02-13
|
2
11
|
* Fix deprecation warning that was exactly backwards (Tom Hughes)
|
3
12
|
* Fix primary_keys handling in models that inherit from other models
|
data/{README.txt → README.rdoc}
RENAMED
@@ -2,29 +2,41 @@
|
|
2
2
|
|
3
3
|
== Summary
|
4
4
|
|
5
|
-
ActiveRecords/Rails famously doesn't support composite primary keys.
|
5
|
+
ActiveRecords/Rails famously doesn't support composite primary keys.
|
6
6
|
This RubyGem extends the activerecord gem to provide CPK support.
|
7
7
|
|
8
8
|
== Installation
|
9
9
|
|
10
10
|
gem install composite_primary_keys
|
11
|
-
|
11
|
+
|
12
12
|
== Usage
|
13
|
-
|
13
|
+
|
14
14
|
require 'composite_primary_keys'
|
15
15
|
class ProductVariation
|
16
|
-
|
16
|
+
self.primary_keys = :product_id, :variation_seq
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
pv = ProductVariation.find(345, 12)
|
20
|
-
|
20
|
+
|
21
|
+
== Factories
|
22
|
+
|
23
|
+
class ModelWithCompositeKeys < ActiveRecord::Base
|
24
|
+
set_primary_keys :id, :updated_at
|
25
|
+
end
|
26
|
+
|
27
|
+
FactoryGirl.define do
|
28
|
+
factory :model_with_composite_keys do
|
29
|
+
sequence( :id ) { |n| [n,Time.now] }
|
30
|
+
name "Brett"
|
31
|
+
|
32
|
+
|
21
33
|
It even supports composite foreign keys for associations.
|
22
34
|
|
23
35
|
See http://compositekeys.rubyforge.org for more.
|
24
36
|
|
25
37
|
== Running Tests
|
26
38
|
|
27
|
-
See test/README_tests.
|
39
|
+
See test/README_tests.rdoc
|
28
40
|
|
29
41
|
== Url
|
30
42
|
|
File without changes
|
@@ -1,8 +1,14 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Associations
|
3
3
|
class HasAndBelongsToManyAssociation
|
4
|
-
def insert_record(record, validate = true)
|
5
|
-
|
4
|
+
def insert_record(record, validate = true, raise = false)
|
5
|
+
if record.new_record?
|
6
|
+
if raise
|
7
|
+
record.save!(:validate => validate)
|
8
|
+
else
|
9
|
+
return unless record.save(:validate => validate)
|
10
|
+
end
|
11
|
+
end
|
6
12
|
|
7
13
|
if options[:insert_sql]
|
8
14
|
owner.connection.insert(interpolate(options[:insert_sql], record))
|
File without changes
|
@@ -15,10 +15,17 @@ class CompositeArraysTest < ActiveSupport::TestCase
|
|
15
15
|
assert_equal '1,2,3', keys.to_s
|
16
16
|
assert_equal '1,2,3', "#{keys}"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_to_composite_keys
|
20
20
|
keys = [1,2,3].to_composite_keys
|
21
21
|
assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
|
22
22
|
assert_equal '1,2,3', keys.to_s
|
23
23
|
end
|
24
|
+
|
25
|
+
def test_composite_keys_equality
|
26
|
+
keys_array_1 = [1, Time.now].to_composite_keys
|
27
|
+
keys_array_2 = [1, Time.now].to_composite_keys
|
28
|
+
assert keys_array_1 == keys_array_2
|
29
|
+
assert keys_array_1.eql? keys_array_2
|
30
|
+
end
|
24
31
|
end
|
data/test/test_create.rb
CHANGED
@@ -62,7 +62,7 @@ class TestCreate < ActiveSupport::TestCase
|
|
62
62
|
assert_equal(rc.reference_type_id, rt.reference_type_id)
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
65
|
+
def test_new_habtm
|
66
66
|
restaurant = Restaurant.new(:franchise_id => 22,
|
67
67
|
:store_id => 23,
|
68
68
|
:name => "My Store")
|
@@ -87,4 +87,26 @@ class TestCreate < ActiveSupport::TestCase
|
|
87
87
|
assert_equal(25, suburb.suburb_id)
|
88
88
|
assert_equal("My Suburb", suburb.name)
|
89
89
|
end
|
90
|
+
|
91
|
+
def test_create_habtm
|
92
|
+
restaurant = Restaurant.create(:franchise_id => 22,
|
93
|
+
:store_id => 23,
|
94
|
+
:name => "My Store")
|
95
|
+
|
96
|
+
restaurant.suburbs.create(:city_id => 24,
|
97
|
+
:suburb_id => 25,
|
98
|
+
:name => "My Suburb")
|
99
|
+
|
100
|
+
# Test restaurant
|
101
|
+
assert_equal(22, restaurant.franchise_id)
|
102
|
+
assert_equal(23, restaurant.store_id)
|
103
|
+
assert_equal("My Store", restaurant.name)
|
104
|
+
assert_equal(1, restaurant.suburbs.length)
|
105
|
+
|
106
|
+
# Test suburbs
|
107
|
+
suburb = restaurant.suburbs[0]
|
108
|
+
assert_equal(24, suburb.city_id)
|
109
|
+
assert_equal(25, suburb.suburb_id)
|
110
|
+
assert_equal("My Suburb", suburb.name)
|
111
|
+
end
|
90
112
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-03-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,7 +22,12 @@ dependencies:
|
|
22
22
|
version: 3.2.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.2.0
|
26
31
|
description: Composite key support for ActiveRecord
|
27
32
|
email:
|
28
33
|
executables: []
|
@@ -30,9 +35,9 @@ extensions: []
|
|
30
35
|
extra_rdoc_files: []
|
31
36
|
files:
|
32
37
|
- Rakefile
|
33
|
-
- History.
|
34
|
-
- README.
|
35
|
-
- README_DB2.
|
38
|
+
- History.rdoc
|
39
|
+
- README.rdoc
|
40
|
+
- README_DB2.rdoc
|
36
41
|
- init.rb
|
37
42
|
- install.rb
|
38
43
|
- loader.rb
|
@@ -148,7 +153,7 @@ files:
|
|
148
153
|
- test/fixtures/users.yml
|
149
154
|
- test/plugins/pagination.rb
|
150
155
|
- test/plugins/pagination_helper.rb
|
151
|
-
- test/README_tests.
|
156
|
+
- test/README_tests.rdoc
|
152
157
|
- test/setup.rb
|
153
158
|
- test/test_associations.rb
|
154
159
|
- test/test_attributes.rb
|
@@ -192,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
197
|
version: '0'
|
193
198
|
requirements: []
|
194
199
|
rubyforge_project: compositekeys
|
195
|
-
rubygems_version: 1.8.
|
200
|
+
rubygems_version: 1.8.19
|
196
201
|
signing_key:
|
197
202
|
specification_version: 3
|
198
203
|
summary: Composite key support for ActiveRecord
|
@@ -200,7 +205,7 @@ test_files:
|
|
200
205
|
- test/abstract_unit.rb
|
201
206
|
- test/db_test.rb
|
202
207
|
- test/debug.log
|
203
|
-
- test/README_tests.
|
208
|
+
- test/README_tests.rdoc
|
204
209
|
- test/setup.rb
|
205
210
|
- test/test_associations.rb
|
206
211
|
- test/test_attributes.rb
|