composite_primary_keys 3.0.9 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Rakefile +10 -1
- data/lib/composite_primary_keys.rb +75 -75
- data/lib/composite_primary_keys/base.rb +190 -194
- data/lib/composite_primary_keys/composite_arrays.rb +23 -23
- data/lib/composite_primary_keys/finder_methods.rb +0 -11
- data/lib/composite_primary_keys/reflection.rb +38 -38
- data/lib/composite_primary_keys/version.rb +2 -2
- data/test/abstract_unit.rb +3 -2
- data/test/connections/connection_spec.rb +1 -2
- data/test/connections/databases.example.yml +14 -12
- data/test/connections/databases.yml +14 -14
- data/test/connections/native_ibm_db/connection.rb +0 -3
- data/test/connections/native_mysql/connection.rb +3 -9
- data/test/connections/native_oracle/connection.rb +4 -10
- data/test/connections/native_oracle_enhanced/connection.rb +4 -11
- data/test/connections/native_postgresql/connection.rb +1 -3
- data/test/connections/native_sqlite/connection.rb +2 -4
- data/test/debug.log +589 -589
- data/test/fixtures/article.rb +5 -5
- data/test/fixtures/articles.yml +5 -5
- data/test/fixtures/capitol.rb +3 -0
- data/test/fixtures/capitols.yml +16 -0
- data/test/fixtures/db_definitions/mysql.sql +5 -0
- data/test/fixtures/db_definitions/postgresql.sql +5 -0
- data/test/fixtures/product.rb +7 -7
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/product_tariffs.yml +12 -12
- data/test/fixtures/products.yml +5 -5
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +9 -9
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/reference_codes.yml +29 -29
- data/test/fixtures/reference_type.rb +7 -7
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/suburbs.yml +8 -8
- data/test/fixtures/tariff.rb +6 -6
- data/test/fixtures/tariffs.yml +12 -12
- data/test/fixtures/user.rb +10 -10
- data/test/fixtures/users.yml +5 -5
- data/test/hash_tricks.rb +34 -34
- data/test/test_associations.rb +180 -180
- data/test/test_attribute_methods.rb +0 -2
- data/test/test_attributes.rb +0 -5
- data/test/test_clone.rb +31 -33
- data/test/test_composite_arrays.rb +0 -2
- data/test/test_create.rb +0 -4
- data/test/test_delete.rb +92 -96
- data/test/test_equal.rb +21 -0
- data/test/test_exists.rb +0 -2
- data/test/test_find.rb +79 -76
- data/test/test_ids.rb +81 -83
- data/test/test_miscellaneous.rb +36 -38
- data/test/test_pagination.rb +35 -37
- data/test/test_polymorphic.rb +0 -6
- data/test/test_santiago.rb +23 -27
- data/test/test_suite.rb +1 -0
- data/test/test_tutorial_example.rb +0 -4
- data/test/test_update.rb +37 -39
- data/test/test_validations.rb +0 -1
- metadata +8 -4
data/test/fixtures/article.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Article < ActiveRecord::Base
|
2
|
-
has_many :readings
|
3
|
-
has_many :users, :through => :readings
|
4
|
-
end
|
5
|
-
|
1
|
+
class Article < ActiveRecord::Base
|
2
|
+
has_many :readings
|
3
|
+
has_many :users, :through => :readings
|
4
|
+
end
|
5
|
+
|
data/test/fixtures/articles.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
first:
|
2
|
-
id: 1
|
3
|
-
name: Article One
|
4
|
-
second:
|
5
|
-
id: 2
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
name: Article One
|
4
|
+
second:
|
5
|
+
id: 2
|
6
6
|
name: Article Two
|
data/test/fixtures/product.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class Product < ActiveRecord::Base
|
2
|
-
set_primary_keys :id # redundant
|
3
|
-
has_many :product_tariffs, :foreign_key => :product_id, :dependent => :delete_all
|
4
|
-
has_one :product_tariff, :foreign_key => :product_id
|
5
|
-
|
6
|
-
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
7
|
-
end
|
1
|
+
class Product < ActiveRecord::Base
|
2
|
+
set_primary_keys :id # redundant
|
3
|
+
has_many :product_tariffs, :foreign_key => :product_id, :dependent => :delete_all
|
4
|
+
has_one :product_tariff, :foreign_key => :product_id
|
5
|
+
|
6
|
+
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
7
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class ProductTariff < ActiveRecord::Base
|
2
|
-
set_primary_keys :product_id, :tariff_id, :tariff_start_date
|
3
|
-
belongs_to :product, :foreign_key => :product_id
|
4
|
-
belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
|
-
end
|
1
|
+
class ProductTariff < ActiveRecord::Base
|
2
|
+
set_primary_keys :product_id, :tariff_id, :tariff_start_date
|
3
|
+
belongs_to :product, :foreign_key => :product_id
|
4
|
+
belongs_to :tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
first_flat:
|
2
|
-
product_id: 1
|
3
|
-
tariff_id: 1
|
4
|
-
tariff_start_date: <%= Date.today.to_s(:db) %>
|
5
|
-
first_free:
|
6
|
-
product_id: 1
|
7
|
-
tariff_id: 2
|
8
|
-
tariff_start_date: <%= Date.today.to_s(:db) %>
|
9
|
-
second_free:
|
10
|
-
product_id: 2
|
11
|
-
tariff_id: 2
|
12
|
-
tariff_start_date: <%= Date.today.to_s(:db) %>
|
1
|
+
first_flat:
|
2
|
+
product_id: 1
|
3
|
+
tariff_id: 1
|
4
|
+
tariff_start_date: <%= Date.today.to_s(:db) %>
|
5
|
+
first_free:
|
6
|
+
product_id: 1
|
7
|
+
tariff_id: 2
|
8
|
+
tariff_start_date: <%= Date.today.to_s(:db) %>
|
9
|
+
second_free:
|
10
|
+
product_id: 2
|
11
|
+
tariff_id: 2
|
12
|
+
tariff_start_date: <%= Date.today.to_s(:db) %>
|
data/test/fixtures/products.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
first_product:
|
2
|
-
id: 1
|
3
|
-
name: Product One
|
4
|
-
second_product:
|
5
|
-
id: 2
|
1
|
+
first_product:
|
2
|
+
id: 1
|
3
|
+
name: Product One
|
4
|
+
second_product:
|
5
|
+
id: 2
|
6
6
|
name: Product Two
|
data/test/fixtures/reading.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class Reading < ActiveRecord::Base
|
2
|
-
belongs_to :article
|
3
|
-
belongs_to :user
|
4
|
-
end
|
1
|
+
class Reading < ActiveRecord::Base
|
2
|
+
belongs_to :article
|
3
|
+
belongs_to :user
|
4
|
+
end
|
data/test/fixtures/readings.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
santiago_first:
|
2
|
-
id: 1
|
3
|
-
user_id: 1
|
4
|
-
article_id: 1
|
5
|
-
rating: 4
|
6
|
-
santiago_second:
|
7
|
-
id: 2
|
8
|
-
user_id: 1
|
9
|
-
article_id: 2
|
1
|
+
santiago_first:
|
2
|
+
id: 1
|
3
|
+
user_id: 1
|
4
|
+
article_id: 1
|
5
|
+
rating: 4
|
6
|
+
santiago_second:
|
7
|
+
id: 2
|
8
|
+
user_id: 1
|
9
|
+
article_id: 2
|
10
10
|
rating: 5
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class ReferenceCode < ActiveRecord::Base
|
2
|
-
set_primary_keys :reference_type_id, :reference_code
|
3
|
-
|
4
|
-
belongs_to :reference_type, :foreign_key => "reference_type_id"
|
5
|
-
|
6
|
-
validates_presence_of :reference_code, :code_label, :abbreviation
|
7
|
-
end
|
1
|
+
class ReferenceCode < ActiveRecord::Base
|
2
|
+
set_primary_keys :reference_type_id, :reference_code
|
3
|
+
|
4
|
+
belongs_to :reference_type, :foreign_key => "reference_type_id"
|
5
|
+
|
6
|
+
validates_presence_of :reference_code, :code_label, :abbreviation
|
7
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
name_prefix_mr:
|
2
|
-
reference_type_id: 1
|
3
|
-
reference_code: 1
|
4
|
-
code_label: MR
|
5
|
-
abbreviation: Mr
|
6
|
-
|
7
|
-
name_prefix_mrs:
|
8
|
-
reference_type_id: 1
|
9
|
-
reference_code: 2
|
10
|
-
code_label: MRS
|
11
|
-
abbreviation: Mrs
|
12
|
-
|
13
|
-
name_prefix_ms:
|
14
|
-
reference_type_id: 1
|
15
|
-
reference_code: 3
|
16
|
-
code_label: MS
|
17
|
-
abbreviation: Ms
|
18
|
-
|
19
|
-
gender_male:
|
20
|
-
reference_type_id: 2
|
21
|
-
reference_code: 1
|
22
|
-
code_label: MALE
|
23
|
-
abbreviation: Male
|
24
|
-
gender_female:
|
25
|
-
reference_type_id: 2
|
26
|
-
reference_code: 2
|
27
|
-
code_label: FEMALE
|
28
|
-
abbreviation: Female
|
29
|
-
|
1
|
+
name_prefix_mr:
|
2
|
+
reference_type_id: 1
|
3
|
+
reference_code: 1
|
4
|
+
code_label: MR
|
5
|
+
abbreviation: Mr
|
6
|
+
|
7
|
+
name_prefix_mrs:
|
8
|
+
reference_type_id: 1
|
9
|
+
reference_code: 2
|
10
|
+
code_label: MRS
|
11
|
+
abbreviation: Mrs
|
12
|
+
|
13
|
+
name_prefix_ms:
|
14
|
+
reference_type_id: 1
|
15
|
+
reference_code: 3
|
16
|
+
code_label: MS
|
17
|
+
abbreviation: Ms
|
18
|
+
|
19
|
+
gender_male:
|
20
|
+
reference_type_id: 2
|
21
|
+
reference_code: 1
|
22
|
+
code_label: MALE
|
23
|
+
abbreviation: Male
|
24
|
+
gender_female:
|
25
|
+
reference_type_id: 2
|
26
|
+
reference_code: 2
|
27
|
+
code_label: FEMALE
|
28
|
+
abbreviation: Female
|
29
|
+
|
30
30
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class ReferenceType < ActiveRecord::Base
|
2
|
-
set_primary_key :reference_type_id
|
3
|
-
has_many :reference_codes, :foreign_key => "reference_type_id", :dependent => :destroy
|
4
|
-
|
5
|
-
validates_presence_of :type_label, :abbreviation
|
6
|
-
validates_uniqueness_of :type_label
|
7
|
-
end
|
1
|
+
class ReferenceType < ActiveRecord::Base
|
2
|
+
set_primary_key :reference_type_id
|
3
|
+
has_many :reference_codes, :foreign_key => "reference_type_id", :dependent => :destroy
|
4
|
+
|
5
|
+
validates_presence_of :type_label, :abbreviation
|
6
|
+
validates_uniqueness_of :type_label
|
7
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
name_prefix:
|
2
|
-
reference_type_id: 1
|
3
|
-
type_label: NAME_PREFIX
|
4
|
-
abbreviation: Name Prefix
|
5
|
-
|
6
|
-
gender:
|
7
|
-
reference_type_id: 2
|
8
|
-
type_label: GENDER
|
9
|
-
abbreviation: Gender
|
1
|
+
name_prefix:
|
2
|
+
reference_type_id: 1
|
3
|
+
type_label: NAME_PREFIX
|
4
|
+
abbreviation: Name Prefix
|
5
|
+
|
6
|
+
gender:
|
7
|
+
reference_type_id: 2
|
8
|
+
type_label: GENDER
|
9
|
+
abbreviation: Gender
|
data/test/fixtures/suburb.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class Suburb < ActiveRecord::Base
|
2
|
-
set_primary_keys :city_id, :suburb_id
|
3
|
-
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
4
|
-
has_many :first_streets, :foreign_key => [:city_id, :suburb_id],
|
5
|
-
:class_name => 'Street', :conditions => "streets.name = 'First Street'"
|
1
|
+
class Suburb < ActiveRecord::Base
|
2
|
+
set_primary_keys :city_id, :suburb_id
|
3
|
+
has_many :streets, :foreign_key => [:city_id, :suburb_id]
|
4
|
+
has_many :first_streets, :foreign_key => [:city_id, :suburb_id],
|
5
|
+
:class_name => 'Street', :conditions => "streets.name = 'First Street'"
|
6
6
|
end
|
data/test/fixtures/suburbs.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
first:
|
2
|
-
city_id: 1
|
3
|
-
suburb_id: 1
|
4
|
-
name: First Suburb
|
5
|
-
second:
|
6
|
-
city_id: 2
|
7
|
-
suburb_id: 1
|
8
|
-
name: Second Suburb
|
1
|
+
first:
|
2
|
+
city_id: 1
|
3
|
+
suburb_id: 1
|
4
|
+
name: First Suburb
|
5
|
+
second:
|
6
|
+
city_id: 2
|
7
|
+
suburb_id: 1
|
8
|
+
name: Second Suburb
|
9
9
|
|
data/test/fixtures/tariff.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class Tariff < ActiveRecord::Base
|
2
|
-
set_primary_keys [:tariff_id, :start_date]
|
3
|
-
has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
4
|
-
has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
|
-
has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
6
|
-
end
|
1
|
+
class Tariff < ActiveRecord::Base
|
2
|
+
set_primary_keys [:tariff_id, :start_date]
|
3
|
+
has_many :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
4
|
+
has_one :product_tariff, :foreign_key => [:tariff_id, :tariff_start_date]
|
5
|
+
has_many :products, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
6
|
+
end
|
data/test/fixtures/tariffs.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
flat:
|
2
|
-
tariff_id: 1
|
3
|
-
start_date: <%= Date.today.to_s(:db) %>
|
4
|
-
amount: 50
|
5
|
-
free:
|
6
|
-
tariff_id: 2
|
7
|
-
start_date: <%= Date.today.to_s(:db) %>
|
8
|
-
amount: 0
|
9
|
-
flat_future:
|
10
|
-
tariff_id: 1
|
11
|
-
start_date: <%= Date.today.next.to_s(:db) %>
|
12
|
-
amount: 100
|
1
|
+
flat:
|
2
|
+
tariff_id: 1
|
3
|
+
start_date: <%= Date.today.to_s(:db) %>
|
4
|
+
amount: 50
|
5
|
+
free:
|
6
|
+
tariff_id: 2
|
7
|
+
start_date: <%= Date.today.to_s(:db) %>
|
8
|
+
amount: 0
|
9
|
+
flat_future:
|
10
|
+
tariff_id: 1
|
11
|
+
start_date: <%= Date.today.next.to_s(:db) %>
|
12
|
+
amount: 100
|
13
13
|
|
data/test/fixtures/user.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
has_many :readings
|
3
|
-
has_many :articles, :through => :readings
|
4
|
-
has_many :comments, :as => :person
|
5
|
-
has_many :hacks, :through => :comments, :source => :hack
|
6
|
-
|
7
|
-
def find_custom_articles
|
8
|
-
articles.find(:all, :conditions => ["name = ?", "Article One"])
|
9
|
-
end
|
10
|
-
end
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
has_many :readings
|
3
|
+
has_many :articles, :through => :readings
|
4
|
+
has_many :comments, :as => :person
|
5
|
+
has_many :hacks, :through => :comments, :source => :hack
|
6
|
+
|
7
|
+
def find_custom_articles
|
8
|
+
articles.find(:all, :conditions => ["name = ?", "Article One"])
|
9
|
+
end
|
10
|
+
end
|
data/test/fixtures/users.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
santiago:
|
2
|
-
id: 1
|
3
|
-
name: Santiago
|
4
|
-
drnic:
|
5
|
-
id: 2
|
1
|
+
santiago:
|
2
|
+
id: 1
|
3
|
+
name: Santiago
|
4
|
+
drnic:
|
5
|
+
id: 2
|
6
6
|
name: Dr Nic
|
data/test/hash_tricks.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# From:
|
2
|
-
# http://www.bigbold.com/snippets/posts/show/2178
|
3
|
-
# http://blog.caboo.se/articles/2006/06/11/stupid-hash-tricks
|
4
|
-
#
|
5
|
-
# An example utilisation of these methods in a controller is:
|
6
|
-
# def some_action
|
7
|
-
# # some script kiddie also passed in :bee, which we don't want tampered with _here_.
|
8
|
-
# @model = Model.create(params.pass(:foo, :bar))
|
9
|
-
# end
|
10
|
-
class Hash
|
11
|
-
|
12
|
-
# lets through the keys in the argument
|
13
|
-
# >> {:one => 1, :two => 2, :three => 3}.pass(:one)
|
14
|
-
# => {:one=>1}
|
15
|
-
def pass(*keys)
|
16
|
-
keys = keys.first if keys.first.is_a?(Array)
|
17
|
-
tmp = self.clone
|
18
|
-
tmp.delete_if {|k,v| ! keys.include?(k.to_sym) }
|
19
|
-
tmp.delete_if {|k,v| ! keys.include?(k.to_s) }
|
20
|
-
tmp
|
21
|
-
end
|
22
|
-
|
23
|
-
# blocks the keys in the arguments
|
24
|
-
# >> {:one => 1, :two => 2, :three => 3}.block(:one)
|
25
|
-
# => {:two=>2, :three=>3}
|
26
|
-
def block(*keys)
|
27
|
-
keys = keys.first if keys.first.is_a?(Array)
|
28
|
-
tmp = self.clone
|
29
|
-
tmp.delete_if {|k,v| keys.include?(k.to_sym) }
|
30
|
-
tmp.delete_if {|k,v| keys.include?(k.to_s) }
|
31
|
-
tmp
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
1
|
+
# From:
|
2
|
+
# http://www.bigbold.com/snippets/posts/show/2178
|
3
|
+
# http://blog.caboo.se/articles/2006/06/11/stupid-hash-tricks
|
4
|
+
#
|
5
|
+
# An example utilisation of these methods in a controller is:
|
6
|
+
# def some_action
|
7
|
+
# # some script kiddie also passed in :bee, which we don't want tampered with _here_.
|
8
|
+
# @model = Model.create(params.pass(:foo, :bar))
|
9
|
+
# end
|
10
|
+
class Hash
|
11
|
+
|
12
|
+
# lets through the keys in the argument
|
13
|
+
# >> {:one => 1, :two => 2, :three => 3}.pass(:one)
|
14
|
+
# => {:one=>1}
|
15
|
+
def pass(*keys)
|
16
|
+
keys = keys.first if keys.first.is_a?(Array)
|
17
|
+
tmp = self.clone
|
18
|
+
tmp.delete_if {|k,v| ! keys.include?(k.to_sym) }
|
19
|
+
tmp.delete_if {|k,v| ! keys.include?(k.to_s) }
|
20
|
+
tmp
|
21
|
+
end
|
22
|
+
|
23
|
+
# blocks the keys in the arguments
|
24
|
+
# >> {:one => 1, :two => 2, :three => 3}.block(:one)
|
25
|
+
# => {:two=>2, :three=>3}
|
26
|
+
def block(*keys)
|
27
|
+
keys = keys.first if keys.first.is_a?(Array)
|
28
|
+
tmp = self.clone
|
29
|
+
tmp.delete_if {|k,v| keys.include?(k.to_sym) }
|
30
|
+
tmp.delete_if {|k,v| keys.include?(k.to_s) }
|
31
|
+
tmp
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|