composite_primary_keys 9.0.9 → 9.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +4 -0
  3. data/lib/composite_primary_keys.rb +3 -3
  4. data/lib/composite_primary_keys/autosave_association.rb +32 -0
  5. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  6. data/lib/composite_primary_keys/locking/optimistic.rb +7 -7
  7. data/lib/composite_primary_keys/version.rb +1 -1
  8. data/scripts/console.rb +48 -48
  9. data/scripts/txt2html +76 -76
  10. data/scripts/txt2js +65 -65
  11. data/tasks/website.rake +18 -18
  12. data/test/README_tests.rdoc +56 -56
  13. data/test/connections/databases.yml +40 -30
  14. data/test/db_test.rb +52 -52
  15. data/test/fixtures/articles.yml +6 -6
  16. data/test/fixtures/capitol.rb +3 -3
  17. data/test/fixtures/capitols.yml +16 -16
  18. data/test/fixtures/comments.yml +15 -15
  19. data/test/fixtures/department.rb +5 -5
  20. data/test/fixtures/departments.yml +15 -15
  21. data/test/fixtures/dorms.yml +4 -4
  22. data/test/fixtures/group.rb +2 -2
  23. data/test/fixtures/groups.yml +6 -6
  24. data/test/fixtures/hack.rb +4 -4
  25. data/test/fixtures/hacks.yml +2 -2
  26. data/test/fixtures/membership_status.rb +2 -2
  27. data/test/fixtures/product.rb +9 -9
  28. data/test/fixtures/product_tariff.rb +5 -5
  29. data/test/fixtures/products.yml +11 -11
  30. data/test/fixtures/reading.rb +4 -4
  31. data/test/fixtures/readings.yml +10 -10
  32. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  33. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  34. data/test/fixtures/reference_codes.yml +28 -28
  35. data/test/fixtures/reference_types.yml +9 -9
  36. data/test/fixtures/restaurant.rb +9 -9
  37. data/test/fixtures/restaurants.yml +14 -14
  38. data/test/fixtures/restaurants_suburbs.yml +10 -10
  39. data/test/fixtures/room.rb +11 -11
  40. data/test/fixtures/room_assignment.rb +13 -13
  41. data/test/fixtures/room_assignments.yml +24 -24
  42. data/test/fixtures/room_attribute.rb +2 -2
  43. data/test/fixtures/room_attribute_assignment.rb +4 -4
  44. data/test/fixtures/room_attribute_assignments.yml +4 -4
  45. data/test/fixtures/room_attributes.yml +2 -2
  46. data/test/fixtures/rooms.yml +12 -12
  47. data/test/fixtures/seat.rb +5 -5
  48. data/test/fixtures/seats.yml +8 -8
  49. data/test/fixtures/street.rb +2 -2
  50. data/test/fixtures/streets.yml +16 -16
  51. data/test/fixtures/student.rb +3 -3
  52. data/test/fixtures/students.yml +15 -15
  53. data/test/fixtures/suburbs.yml +14 -14
  54. data/test/plugins/pagination.rb +405 -405
  55. data/test/plugins/pagination_helper.rb +135 -135
  56. data/test/setup.rb +50 -50
  57. data/test/test_aliases.rb +18 -18
  58. data/test/test_associations.rb +10 -0
  59. data/test/test_composite_arrays.rb +24 -24
  60. data/test/test_dup.rb +37 -37
  61. data/test/test_exists.rb +39 -39
  62. data/test/test_miscellaneous.rb +32 -32
  63. data/test/test_pagination.rb +35 -35
  64. data/test/test_validations.rb +13 -13
  65. metadata +10 -4
  66. data/lib/composite_primary_keys/attribute_set/builder.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ff862b93eb239969238798e2bc089b2312861d32a269d3c2cabc8a0873efb9d
4
- data.tar.gz: 6778a792c0849abc74826beb68c61b296199630974c24f855df1434a7c7b4aca
3
+ metadata.gz: 133a4025b9fe7ee82617de7c3c34373d8f52d38d5e88c03ab742ebd954bf6064
4
+ data.tar.gz: 579e4d9e564e4c9e40f976d0d56b76533296c8f7e5b5ba925d7244141604fb08
5
5
  SHA512:
6
- metadata.gz: 7402eb2befdbaaf5a57b95d84921ca56049d0606fcb058b2ad65332b6523bdc8decf8ee92e0a474f718f6664f49758ce97798456c15f216c5c7b9bccf081647c
7
- data.tar.gz: 36796097d0f1b1104561605179cecf0c8476ec2e4f69be288d04cb6b474804de0c9c1f79f85b72dd43d2fc40b6f9a13ef4823ce0b3256aa32f52504db2d37a48
6
+ metadata.gz: 334933952b9a84db67746c48c074c38d197215fa607640e134bf7aedd564e122a0c809318fab4529e0ad5bd181081baa792395419b25a4b19149066122cdfdfc
7
+ data.tar.gz: 2820381f390429bbdf61b0a04434c0432faa88d2cffdb04c5cd74f9dfc26682893809531b2d4dc14b03620614bec0ce1a69e128624b6a511b5718b19e24c9970
data/History.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 9.0.10 (2018-06-24)
2
+
3
+ * Fix AR 5.0.7 (Jordan Owens)
4
+
1
5
  == 9.0.9 (2018-03-06)
2
6
 
3
7
  * Fix update statements that incorrectly pass NULL values for the primary key components (Sean Linsley)
@@ -38,6 +38,7 @@ require 'active_record/persistence'
38
38
  require 'active_record/relation'
39
39
  require 'active_record/sanitization'
40
40
  require 'active_record/attribute_methods'
41
+ require 'active_record/autosave_association'
41
42
 
42
43
  require 'active_record/associations/association'
43
44
  require 'active_record/associations/association_scope'
@@ -50,7 +51,6 @@ require 'active_record/associations/preloader/belongs_to'
50
51
  require 'active_record/associations/singular_association'
51
52
  require 'active_record/associations/collection_association'
52
53
 
53
- require 'active_record/attribute_set/builder'
54
54
  require 'active_record/attribute_methods/primary_key'
55
55
  require 'active_record/attribute_methods/read'
56
56
  require 'active_record/attribute_methods/write'
@@ -76,8 +76,8 @@ require 'composite_primary_keys/composite_predicates'
76
76
  require 'composite_primary_keys/fixtures'
77
77
  require 'composite_primary_keys/relation'
78
78
  require 'composite_primary_keys/sanitization'
79
- require 'composite_primary_keys/attribute_set/builder'
80
79
  require 'composite_primary_keys/attribute_methods'
80
+ require 'composite_primary_keys/autosave_association'
81
81
  require 'composite_primary_keys/version'
82
82
 
83
83
  require 'composite_primary_keys/associations/association'
@@ -110,4 +110,4 @@ require 'composite_primary_keys/composite_relation'
110
110
 
111
111
  require 'composite_primary_keys/arel/in'
112
112
  require 'composite_primary_keys/arel/to_sql'
113
- require 'composite_primary_keys/arel/sqlserver'
113
+ require 'composite_primary_keys/arel/sqlserver'
@@ -0,0 +1,32 @@
1
+ module ActiveRecord
2
+ module AutosaveAssociation
3
+ private
4
+
5
+ def save_belongs_to_association(reflection)
6
+ association = association_instance_get(reflection.name)
7
+ return unless association && association.loaded? && !association.stale_target?
8
+
9
+ record = association.load_target
10
+ if record && !record.destroyed?
11
+ autosave = reflection.options[:autosave]
12
+
13
+ if autosave && record.marked_for_destruction?
14
+ self[reflection.foreign_key] = nil
15
+ record.destroy
16
+ elsif autosave != false
17
+ saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
18
+
19
+ if association.updated?
20
+ # CPK
21
+ # association_id = record.send(reflection.options[:primary_key] || :id)
22
+ association_id = reflection.options[:primary_key] ? record[reflection.options[:primary_key]] : record.id
23
+ self[reflection.foreign_key] = association_id
24
+ association.loaded!
25
+ end
26
+
27
+ saved if autosave
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,11 +1,11 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- class AbstractAdapter
4
- def quote_column_names(name)
5
- Array(name).map do |col|
6
- quote_column_name(col.to_s)
7
- end.join(CompositePrimaryKeys::ID_SEP)
8
- end
9
- end
10
- end
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class AbstractAdapter
4
+ def quote_column_names(name)
5
+ Array(name).map do |col|
6
+ quote_column_name(col.to_s)
7
+ end.join(CompositePrimaryKeys::ID_SEP)
8
+ end
9
+ end
10
+ end
11
11
  end
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
  private
6
6
 
7
7
  silence_warnings do
8
- def _update_record(attribute_names = @attributes.keys) #:nodoc:
8
+ def _update_record(attribute_names = self.attribute_names) #:nodoc:
9
9
  return super unless locking_enabled?
10
10
  return 0 if attribute_names.empty?
11
11
 
@@ -25,18 +25,18 @@ module ActiveRecord
25
25
  ).where(
26
26
  lock_col => previous_lock_value
27
27
  ).update_all(
28
- Hash[attributes_for_update(attribute_names).map do |name|
29
- [name, _read_attribute(name)]
30
- end]
28
+ attributes_for_update(attribute_names).map do |name|
29
+ [name, _read_attribute(name)]
30
+ end.to_h
31
31
  )
32
32
  else
33
33
  affected_rows = relation.where(
34
34
  self.class.primary_key => id,
35
35
  lock_col => previous_lock_value,
36
36
  ).update_all(
37
- Hash[attributes_for_update(attribute_names).map do |name|
38
- [name, _read_attribute(name)]
39
- end]
37
+ attributes_for_update(attribute_names).map do |name|
38
+ [name, _read_attribute(name)]
39
+ end.to_h
40
40
  )
41
41
  end
42
42
 
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 9
4
4
  MINOR = 0
5
- TINY = 9
5
+ TINY = 10
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
data/scripts/console.rb CHANGED
@@ -1,48 +1,48 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # if run as script, load the file as library while starting irb
5
- #
6
- if __FILE__ == $0
7
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
8
- ENV['ADAPTER'] = ARGV[0]
9
- exec "#{irb} -f -r #{$0} --simple-prompt"
10
- end
11
-
12
- #
13
- # check if the given adapter is supported (default: mysql)
14
- #
15
- adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
16
- adapter = ENV['ADAPTER'] || 'mysql'
17
- unless adapters.include? adapter
18
- puts "Usage: #{__FILE__} <adapter>"
19
- puts ''
20
- puts 'Adapters: '
21
- puts adapters.map{ |adapter| " #{adapter}" }.join("\n")
22
- exit 1
23
- end
24
-
25
- #
26
- # load all necessary libraries
27
- #
28
- require 'rubygems'
29
- require 'local/database_connections'
30
-
31
- $LOAD_PATH.unshift 'lib'
32
-
33
- begin
34
- require 'local/paths'
35
- $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/active_record/lib" if ENV['EDGE_RAILS_DIR']
36
- $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
37
- rescue
38
- end
39
-
40
- require 'active_support'
41
- require 'active_record'
42
-
43
- require "test/connections/native_#{adapter}/connection"
44
- require 'composite_primary_keys'
45
-
46
- PROJECT_ROOT = File.join(File.dirname(__FILE__), '..')
47
- Dir[File.join(PROJECT_ROOT,'test/fixtures/*.rb')].each { |model| require model }
48
-
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # if run as script, load the file as library while starting irb
5
+ #
6
+ if __FILE__ == $0
7
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
8
+ ENV['ADAPTER'] = ARGV[0]
9
+ exec "#{irb} -f -r #{$0} --simple-prompt"
10
+ end
11
+
12
+ #
13
+ # check if the given adapter is supported (default: mysql)
14
+ #
15
+ adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
16
+ adapter = ENV['ADAPTER'] || 'mysql'
17
+ unless adapters.include? adapter
18
+ puts "Usage: #{__FILE__} <adapter>"
19
+ puts ''
20
+ puts 'Adapters: '
21
+ puts adapters.map{ |adapter| " #{adapter}" }.join("\n")
22
+ exit 1
23
+ end
24
+
25
+ #
26
+ # load all necessary libraries
27
+ #
28
+ require 'rubygems'
29
+ require 'local/database_connections'
30
+
31
+ $LOAD_PATH.unshift 'lib'
32
+
33
+ begin
34
+ require 'local/paths'
35
+ $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/active_record/lib" if ENV['EDGE_RAILS_DIR']
36
+ $LOAD_PATH.unshift "#{ENV['EDGE_RAILS_DIR']}/activesupport/lib" if ENV['EDGE_RAILS_DIR']
37
+ rescue
38
+ end
39
+
40
+ require 'active_support'
41
+ require 'active_record'
42
+
43
+ require "test/connections/native_#{adapter}/connection"
44
+ require 'composite_primary_keys'
45
+
46
+ PROJECT_ROOT = File.join(File.dirname(__FILE__), '..')
47
+ Dir[File.join(PROJECT_ROOT,'test/fixtures/*.rb')].each { |model| require model }
48
+
data/scripts/txt2html CHANGED
@@ -1,76 +1,76 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- gem 'RedCloth'
5
- gem 'syntax'
6
-
7
- require 'redcloth'
8
- require 'syntax/convertors/html'
9
- require 'erb'
10
-
11
- version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
12
- require File.expand_path(version_path)
13
-
14
- version = CompositePrimaryKeys::VERSION::STRING
15
- download = 'http://rubygems.org/gems/composite_primary_keys'
16
-
17
- class Fixnum
18
- def ordinal
19
- # teens
20
- return 'th' if (10..19).include?(self % 100)
21
- # others
22
- case self % 10
23
- when 1
24
- return 'st'
25
- when 2
26
- return 'nd'
27
- when 3
28
- return 'rd'
29
- else
30
- return 'th'
31
- end
32
- end
33
- end
34
-
35
- class Time
36
- def pretty
37
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
38
- end
39
- end
40
-
41
- def convert_syntax(syntax, source)
42
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
43
- end
44
-
45
- if ARGV.length >= 1
46
- src, template = ARGV
47
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
48
-
49
- else
50
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
51
- exit!
52
- end
53
-
54
- template = ERB.new(File.open(template).read)
55
-
56
- title = nil
57
- body = nil
58
- File.open(src) do |fsrc|
59
- title_text = fsrc.readline
60
- body_text = fsrc.read
61
- syntax_items = []
62
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
63
- ident = syntax_items.length
64
- element, syntax, source = $1, $2, $3
65
- syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
66
- "syntax-temp-#{ident}"
67
- }
68
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
69
- body = RedCloth.new(body_text).to_html
70
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
71
- end
72
- stat = File.stat(src)
73
- created = stat.ctime
74
- modified = stat.mtime
75
-
76
- $stdout << template.result(binding)
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ gem 'RedCloth'
5
+ gem 'syntax'
6
+
7
+ require 'redcloth'
8
+ require 'syntax/convertors/html'
9
+ require 'erb'
10
+
11
+ version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
12
+ require File.expand_path(version_path)
13
+
14
+ version = CompositePrimaryKeys::VERSION::STRING
15
+ download = 'http://rubygems.org/gems/composite_primary_keys'
16
+
17
+ class Fixnum
18
+ def ordinal
19
+ # teens
20
+ return 'th' if (10..19).include?(self % 100)
21
+ # others
22
+ case self % 10
23
+ when 1
24
+ return 'st'
25
+ when 2
26
+ return 'nd'
27
+ when 3
28
+ return 'rd'
29
+ else
30
+ return 'th'
31
+ end
32
+ end
33
+ end
34
+
35
+ class Time
36
+ def pretty
37
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
38
+ end
39
+ end
40
+
41
+ def convert_syntax(syntax, source)
42
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
43
+ end
44
+
45
+ if ARGV.length >= 1
46
+ src, template = ARGV
47
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
48
+
49
+ else
50
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
51
+ exit!
52
+ end
53
+
54
+ template = ERB.new(File.open(template).read)
55
+
56
+ title = nil
57
+ body = nil
58
+ File.open(src) do |fsrc|
59
+ title_text = fsrc.readline
60
+ body_text = fsrc.read
61
+ syntax_items = []
62
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
63
+ ident = syntax_items.length
64
+ element, syntax, source = $1, $2, $3
65
+ syntax_items << "<#{element} class=\"syntax\">#{convert_syntax(syntax, source)}</#{element}>"
66
+ "syntax-temp-#{ident}"
67
+ }
68
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
69
+ body = RedCloth.new(body_text).to_html
70
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
71
+ end
72
+ stat = File.stat(src)
73
+ created = stat.ctime
74
+ modified = stat.mtime
75
+
76
+ $stdout << template.result(binding)
data/scripts/txt2js CHANGED
@@ -1,65 +1,65 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'redcloth'
5
- require 'syntax/convertors/html'
6
- require 'erb'
7
- require 'active_support'
8
-
9
- version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
10
- require File.expand_path(version_path)
11
-
12
- version = CompositePrimaryKeys::VERSION::STRING
13
- download = 'http://rubygems.org/gems/composite_primary_keys'
14
-
15
- class Fixnum
16
- def ordinal
17
- # teens
18
- return 'th' if (10..19).include?(self % 100)
19
- # others
20
- case self % 10
21
- when 1
22
- return 'st'
23
- when 2
24
- return 'nd'
25
- when 3
26
- return 'rd'
27
- else
28
- return 'th'
29
- end
30
- end
31
- end
32
-
33
- class Time
34
- def pretty
35
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
- end
37
- end
38
-
39
- def convert_syntax(syntax, source)
40
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
- end
42
-
43
- if ARGV.length >= 1
44
- src, template = ARGV
45
- template ||= File.dirname(__FILE__) + '/../website/template.js'
46
- else
47
- puts("Usage: #{File.split($0).last} source.txt [template.js] > output.html")
48
- exit!
49
- end
50
-
51
- template = ERB.new(File.open(template).read)
52
-
53
- title = nil
54
- body = nil
55
- File.open(src) do |fsrc|
56
- title_text = fsrc.readline
57
- body_text = fsrc.read
58
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
59
- body = RedCloth.new(body_text)
60
- end
61
- stat = File.stat(src)
62
- created = stat.ctime
63
- modified = stat.mtime
64
-
65
- $stdout << template.result(binding)
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require 'active_support'
8
+
9
+ version_path = File.join(File.dirname(__FILE__), '..', 'lib', 'composite_primary_keys', 'version.rb')
10
+ require File.expand_path(version_path)
11
+
12
+ version = CompositePrimaryKeys::VERSION::STRING
13
+ download = 'http://rubygems.org/gems/composite_primary_keys'
14
+
15
+ class Fixnum
16
+ def ordinal
17
+ # teens
18
+ return 'th' if (10..19).include?(self % 100)
19
+ # others
20
+ case self % 10
21
+ when 1
22
+ return 'st'
23
+ when 2
24
+ return 'nd'
25
+ when 3
26
+ return 'rd'
27
+ else
28
+ return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.dirname(__FILE__) + '/../website/template.js'
46
+ else
47
+ puts("Usage: #{File.split($0).last} source.txt [template.js] > output.html")
48
+ exit!
49
+ end
50
+
51
+ template = ERB.new(File.open(template).read)
52
+
53
+ title = nil
54
+ body = nil
55
+ File.open(src) do |fsrc|
56
+ title_text = fsrc.readline
57
+ body_text = fsrc.read
58
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
59
+ body = RedCloth.new(body_text)
60
+ end
61
+ stat = File.stat(src)
62
+ created = stat.ctime
63
+ modified = stat.mtime
64
+
65
+ $stdout << template.result(binding)