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.
Files changed (62) hide show
  1. data/History.txt +6 -0
  2. data/Rakefile +10 -1
  3. data/lib/composite_primary_keys.rb +75 -75
  4. data/lib/composite_primary_keys/base.rb +190 -194
  5. data/lib/composite_primary_keys/composite_arrays.rb +23 -23
  6. data/lib/composite_primary_keys/finder_methods.rb +0 -11
  7. data/lib/composite_primary_keys/reflection.rb +38 -38
  8. data/lib/composite_primary_keys/version.rb +2 -2
  9. data/test/abstract_unit.rb +3 -2
  10. data/test/connections/connection_spec.rb +1 -2
  11. data/test/connections/databases.example.yml +14 -12
  12. data/test/connections/databases.yml +14 -14
  13. data/test/connections/native_ibm_db/connection.rb +0 -3
  14. data/test/connections/native_mysql/connection.rb +3 -9
  15. data/test/connections/native_oracle/connection.rb +4 -10
  16. data/test/connections/native_oracle_enhanced/connection.rb +4 -11
  17. data/test/connections/native_postgresql/connection.rb +1 -3
  18. data/test/connections/native_sqlite/connection.rb +2 -4
  19. data/test/debug.log +589 -589
  20. data/test/fixtures/article.rb +5 -5
  21. data/test/fixtures/articles.yml +5 -5
  22. data/test/fixtures/capitol.rb +3 -0
  23. data/test/fixtures/capitols.yml +16 -0
  24. data/test/fixtures/db_definitions/mysql.sql +5 -0
  25. data/test/fixtures/db_definitions/postgresql.sql +5 -0
  26. data/test/fixtures/product.rb +7 -7
  27. data/test/fixtures/product_tariff.rb +5 -5
  28. data/test/fixtures/product_tariffs.yml +12 -12
  29. data/test/fixtures/products.yml +5 -5
  30. data/test/fixtures/reading.rb +4 -4
  31. data/test/fixtures/readings.yml +9 -9
  32. data/test/fixtures/reference_code.rb +7 -7
  33. data/test/fixtures/reference_codes.yml +29 -29
  34. data/test/fixtures/reference_type.rb +7 -7
  35. data/test/fixtures/reference_types.yml +9 -9
  36. data/test/fixtures/suburb.rb +5 -5
  37. data/test/fixtures/suburbs.yml +8 -8
  38. data/test/fixtures/tariff.rb +6 -6
  39. data/test/fixtures/tariffs.yml +12 -12
  40. data/test/fixtures/user.rb +10 -10
  41. data/test/fixtures/users.yml +5 -5
  42. data/test/hash_tricks.rb +34 -34
  43. data/test/test_associations.rb +180 -180
  44. data/test/test_attribute_methods.rb +0 -2
  45. data/test/test_attributes.rb +0 -5
  46. data/test/test_clone.rb +31 -33
  47. data/test/test_composite_arrays.rb +0 -2
  48. data/test/test_create.rb +0 -4
  49. data/test/test_delete.rb +92 -96
  50. data/test/test_equal.rb +21 -0
  51. data/test/test_exists.rb +0 -2
  52. data/test/test_find.rb +79 -76
  53. data/test/test_ids.rb +81 -83
  54. data/test/test_miscellaneous.rb +36 -38
  55. data/test/test_pagination.rb +35 -37
  56. data/test/test_polymorphic.rb +0 -6
  57. data/test/test_santiago.rb +23 -27
  58. data/test/test_suite.rb +1 -0
  59. data/test/test_tutorial_example.rb +0 -4
  60. data/test/test_update.rb +37 -39
  61. data/test/test_validations.rb +0 -1
  62. metadata +8 -4
@@ -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
+
@@ -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
@@ -0,0 +1,3 @@
1
+ class Capitol < ActiveRecord::Base
2
+ set_primary_keys :country, :city
3
+ end
@@ -0,0 +1,16 @@
1
+ netherlands:
2
+ country: The Netherlands
3
+ city: Amsterdam
4
+
5
+ france:
6
+ country: France
7
+ city: Paris
8
+
9
+ canada:
10
+ country: Canada
11
+ city: Ottawa
12
+
13
+ mexico:
14
+ country: Mexico
15
+ city: Mexico City
16
+
@@ -179,3 +179,8 @@ create table seats (
179
179
  primary key (flight_number, seat)
180
180
  ) type=InnoDB;
181
181
 
182
+ create table capitols (
183
+ country varchar(100) default null,
184
+ city varchar(100) default null,
185
+ primary key (country, city)
186
+ ) type=InnoDB;
@@ -205,3 +205,8 @@ create table seats (
205
205
  primary key (flight_number, seat)
206
206
  );
207
207
 
208
+ create table capitols (
209
+ country text not null,
210
+ city text not null,
211
+ primary key (country, city)
212
+ );
@@ -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) %>
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
 
@@ -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
@@ -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
 
@@ -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
@@ -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
@@ -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