composite_primary_keys 10.0.3 → 10.0.4

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +6 -0
  3. data/lib/composite_primary_keys.rb +0 -2
  4. data/lib/composite_primary_keys/associations/preloader/association.rb +2 -0
  5. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +1 -1
  6. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  7. data/lib/composite_primary_keys/locking/optimistic.rb +21 -31
  8. data/lib/composite_primary_keys/relation.rb +14 -3
  9. data/lib/composite_primary_keys/version.rb +1 -1
  10. data/scripts/console.rb +48 -48
  11. data/scripts/txt2html +76 -76
  12. data/scripts/txt2js +65 -65
  13. data/tasks/website.rake +18 -18
  14. data/test/README_tests.rdoc +56 -56
  15. data/test/connections/databases.yml +40 -30
  16. data/test/db_test.rb +52 -52
  17. data/test/fixtures/articles.yml +6 -6
  18. data/test/fixtures/capitol.rb +3 -3
  19. data/test/fixtures/capitols.yml +16 -16
  20. data/test/fixtures/comments.yml +15 -15
  21. data/test/fixtures/department.rb +5 -5
  22. data/test/fixtures/departments.yml +15 -15
  23. data/test/fixtures/dorms.yml +4 -4
  24. data/test/fixtures/group.rb +2 -2
  25. data/test/fixtures/groups.yml +6 -6
  26. data/test/fixtures/hack.rb +4 -4
  27. data/test/fixtures/hacks.yml +2 -2
  28. data/test/fixtures/membership_status.rb +2 -2
  29. data/test/fixtures/product.rb +9 -9
  30. data/test/fixtures/product_tariff.rb +5 -5
  31. data/test/fixtures/products.yml +11 -11
  32. data/test/fixtures/reading.rb +4 -4
  33. data/test/fixtures/readings.yml +10 -10
  34. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  35. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  36. data/test/fixtures/reference_codes.yml +28 -28
  37. data/test/fixtures/reference_types.yml +9 -9
  38. data/test/fixtures/restaurant.rb +9 -9
  39. data/test/fixtures/restaurants.yml +14 -14
  40. data/test/fixtures/restaurants_suburbs.yml +10 -10
  41. data/test/fixtures/room.rb +11 -11
  42. data/test/fixtures/room_assignment.rb +13 -13
  43. data/test/fixtures/room_assignments.yml +24 -24
  44. data/test/fixtures/room_attribute.rb +2 -2
  45. data/test/fixtures/room_attribute_assignment.rb +4 -4
  46. data/test/fixtures/room_attribute_assignments.yml +4 -4
  47. data/test/fixtures/room_attributes.yml +2 -2
  48. data/test/fixtures/rooms.yml +12 -12
  49. data/test/fixtures/seat.rb +5 -5
  50. data/test/fixtures/seats.yml +8 -8
  51. data/test/fixtures/street.rb +2 -2
  52. data/test/fixtures/streets.yml +16 -16
  53. data/test/fixtures/student.rb +3 -3
  54. data/test/fixtures/students.yml +15 -15
  55. data/test/fixtures/suburbs.yml +14 -14
  56. data/test/plugins/pagination.rb +405 -405
  57. data/test/plugins/pagination_helper.rb +135 -135
  58. data/test/setup.rb +50 -50
  59. data/test/test_aliases.rb +18 -18
  60. data/test/test_composite_arrays.rb +24 -24
  61. data/test/test_counter_cache.rb +30 -30
  62. data/test/test_dup.rb +37 -37
  63. data/test/test_exists.rb +39 -39
  64. data/test/test_miscellaneous.rb +32 -32
  65. data/test/test_pagination.rb +35 -35
  66. data/test/test_preload.rb +7 -0
  67. data/test/test_validations.rb +13 -13
  68. metadata +5 -6
  69. data/lib/composite_primary_keys/attribute_set/builder.rb +0 -22
@@ -1,135 +1,135 @@
1
- module ActionView
2
- module Helpers
3
- # Provides methods for linking to ActionController::Pagination objects using a simple generator API. You can optionally
4
- # also build your links manually using ActionView::Helpers::AssetHelper#link_to like so:
5
- #
6
- # <%= link_to "Previous page", { :page => paginator.current.previous } if paginator.current.previous %>
7
- # <%= link_to "Next page", { :page => paginator.current.next } if paginator.current.next %>
8
- module PaginationHelper
9
- unless const_defined?(:DEFAULT_OPTIONS)
10
- DEFAULT_OPTIONS = {
11
- :name => :page,
12
- :window_size => 2,
13
- :always_show_anchors => true,
14
- :link_to_current_page => false,
15
- :params => {}
16
- }
17
- end
18
-
19
- # Creates a basic HTML link bar for the given +paginator+. Links will be created
20
- # for the next and/or previous page and for a number of other pages around the current
21
- # pages position. The +html_options+ hash is passed to +link_to+ when the links are created.
22
- #
23
- # ==== Options
24
- # <tt>:name</tt>:: the routing name for this paginator
25
- # (defaults to +page+)
26
- # <tt>:prefix</tt>:: prefix for pagination links
27
- # (i.e. Older Pages: 1 2 3 4)
28
- # <tt>:suffix</tt>:: suffix for pagination links
29
- # (i.e. 1 2 3 4 <- Older Pages)
30
- # <tt>:window_size</tt>:: the number of pages to show around
31
- # the current page (defaults to <tt>2</tt>)
32
- # <tt>:always_show_anchors</tt>:: whether or not the first and last
33
- # pages should always be shown
34
- # (defaults to +true+)
35
- # <tt>:link_to_current_page</tt>:: whether or not the current page
36
- # should be linked to (defaults to
37
- # +false+)
38
- # <tt>:params</tt>:: any additional routing parameters
39
- # for page URLs
40
- #
41
- # ==== Examples
42
- # # We'll assume we have a paginator setup in @person_pages...
43
- #
44
- # pagination_links(@person_pages)
45
- # # => 1 <a href="/?page=2/">2</a> <a href="/?page=3/">3</a> ... <a href="/?page=10/">10</a>
46
- #
47
- # pagination_links(@person_pages, :link_to_current_page => true)
48
- # # => <a href="/?page=1/">1</a> <a href="/?page=2/">2</a> <a href="/?page=3/">3</a> ... <a href="/?page=10/">10</a>
49
- #
50
- # pagination_links(@person_pages, :always_show_anchors => false)
51
- # # => 1 <a href="/?page=2/">2</a> <a href="/?page=3/">3</a>
52
- #
53
- # pagination_links(@person_pages, :window_size => 1)
54
- # # => 1 <a href="/?page=2/">2</a> ... <a href="/?page=10/">10</a>
55
- #
56
- # pagination_links(@person_pages, :params => { :viewer => "flash" })
57
- # # => 1 <a href="/?page=2&amp;viewer=flash/">2</a> <a href="/?page=3&amp;viewer=flash/">3</a> ...
58
- # # <a href="/?page=10&amp;viewer=flash/">10</a>
59
- def pagination_links(paginator, options={}, html_options={})
60
- name = options[:name] || DEFAULT_OPTIONS[:name]
61
- params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
62
-
63
- prefix = options[:prefix] || ''
64
- suffix = options[:suffix] || ''
65
-
66
- pagination_links_each(paginator, options, prefix, suffix) do |n|
67
- params[name] = n
68
- link_to(n.to_s, params, html_options)
69
- end
70
- end
71
-
72
- # Iterate through the pages of a given +paginator+, invoking a
73
- # block for each page number that needs to be rendered as a link.
74
- #
75
- # ==== Options
76
- # <tt>:window_size</tt>:: the number of pages to show around
77
- # the current page (defaults to +2+)
78
- # <tt>:always_show_anchors</tt>:: whether or not the first and last
79
- # pages should always be shown
80
- # (defaults to +true+)
81
- # <tt>:link_to_current_page</tt>:: whether or not the current page
82
- # should be linked to (defaults to
83
- # +false+)
84
- #
85
- # ==== Example
86
- # # Turn paginated links into an Ajax call
87
- # pagination_links_each(paginator, page_options) do |link|
88
- # options = { :url => {:action => 'list'}, :update => 'results' }
89
- # html_options = { :href => url_for(:action => 'list') }
90
- #
91
- # link_to_remote(link.to_s, options, html_options)
92
- # end
93
- def pagination_links_each(paginator, options, prefix = nil, suffix = nil)
94
- options = DEFAULT_OPTIONS.merge(options)
95
- link_to_current_page = options[:link_to_current_page]
96
- always_show_anchors = options[:always_show_anchors]
97
-
98
- current_page = paginator.current_page
99
- window_pages = current_page.window(options[:window_size]).pages
100
- return if window_pages.length <= 1 unless link_to_current_page
101
-
102
- first, last = paginator.first, paginator.last
103
-
104
- html = ''
105
-
106
- html << prefix if prefix
107
-
108
- if always_show_anchors and not (wp_first = window_pages[0]).first?
109
- html << yield(first.number)
110
- html << ' ... ' if wp_first.number - first.number > 1
111
- html << ' '
112
- end
113
-
114
- window_pages.each do |page|
115
- if current_page == page && !link_to_current_page
116
- html << page.number.to_s
117
- else
118
- html << yield(page.number)
119
- end
120
- html << ' '
121
- end
122
-
123
- if always_show_anchors and not (wp_last = window_pages[-1]).last?
124
- html << ' ... ' if last.number - wp_last.number > 1
125
- html << yield(last.number)
126
- end
127
-
128
- html << suffix if suffix
129
-
130
- html
131
- end
132
-
133
- end # PaginationHelper
134
- end # Helpers
135
- end # ActionView
1
+ module ActionView
2
+ module Helpers
3
+ # Provides methods for linking to ActionController::Pagination objects using a simple generator API. You can optionally
4
+ # also build your links manually using ActionView::Helpers::AssetHelper#link_to like so:
5
+ #
6
+ # <%= link_to "Previous page", { :page => paginator.current.previous } if paginator.current.previous %>
7
+ # <%= link_to "Next page", { :page => paginator.current.next } if paginator.current.next %>
8
+ module PaginationHelper
9
+ unless const_defined?(:DEFAULT_OPTIONS)
10
+ DEFAULT_OPTIONS = {
11
+ :name => :page,
12
+ :window_size => 2,
13
+ :always_show_anchors => true,
14
+ :link_to_current_page => false,
15
+ :params => {}
16
+ }
17
+ end
18
+
19
+ # Creates a basic HTML link bar for the given +paginator+. Links will be created
20
+ # for the next and/or previous page and for a number of other pages around the current
21
+ # pages position. The +html_options+ hash is passed to +link_to+ when the links are created.
22
+ #
23
+ # ==== Options
24
+ # <tt>:name</tt>:: the routing name for this paginator
25
+ # (defaults to +page+)
26
+ # <tt>:prefix</tt>:: prefix for pagination links
27
+ # (i.e. Older Pages: 1 2 3 4)
28
+ # <tt>:suffix</tt>:: suffix for pagination links
29
+ # (i.e. 1 2 3 4 <- Older Pages)
30
+ # <tt>:window_size</tt>:: the number of pages to show around
31
+ # the current page (defaults to <tt>2</tt>)
32
+ # <tt>:always_show_anchors</tt>:: whether or not the first and last
33
+ # pages should always be shown
34
+ # (defaults to +true+)
35
+ # <tt>:link_to_current_page</tt>:: whether or not the current page
36
+ # should be linked to (defaults to
37
+ # +false+)
38
+ # <tt>:params</tt>:: any additional routing parameters
39
+ # for page URLs
40
+ #
41
+ # ==== Examples
42
+ # # We'll assume we have a paginator setup in @person_pages...
43
+ #
44
+ # pagination_links(@person_pages)
45
+ # # => 1 <a href="/?page=2/">2</a> <a href="/?page=3/">3</a> ... <a href="/?page=10/">10</a>
46
+ #
47
+ # pagination_links(@person_pages, :link_to_current_page => true)
48
+ # # => <a href="/?page=1/">1</a> <a href="/?page=2/">2</a> <a href="/?page=3/">3</a> ... <a href="/?page=10/">10</a>
49
+ #
50
+ # pagination_links(@person_pages, :always_show_anchors => false)
51
+ # # => 1 <a href="/?page=2/">2</a> <a href="/?page=3/">3</a>
52
+ #
53
+ # pagination_links(@person_pages, :window_size => 1)
54
+ # # => 1 <a href="/?page=2/">2</a> ... <a href="/?page=10/">10</a>
55
+ #
56
+ # pagination_links(@person_pages, :params => { :viewer => "flash" })
57
+ # # => 1 <a href="/?page=2&amp;viewer=flash/">2</a> <a href="/?page=3&amp;viewer=flash/">3</a> ...
58
+ # # <a href="/?page=10&amp;viewer=flash/">10</a>
59
+ def pagination_links(paginator, options={}, html_options={})
60
+ name = options[:name] || DEFAULT_OPTIONS[:name]
61
+ params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
62
+
63
+ prefix = options[:prefix] || ''
64
+ suffix = options[:suffix] || ''
65
+
66
+ pagination_links_each(paginator, options, prefix, suffix) do |n|
67
+ params[name] = n
68
+ link_to(n.to_s, params, html_options)
69
+ end
70
+ end
71
+
72
+ # Iterate through the pages of a given +paginator+, invoking a
73
+ # block for each page number that needs to be rendered as a link.
74
+ #
75
+ # ==== Options
76
+ # <tt>:window_size</tt>:: the number of pages to show around
77
+ # the current page (defaults to +2+)
78
+ # <tt>:always_show_anchors</tt>:: whether or not the first and last
79
+ # pages should always be shown
80
+ # (defaults to +true+)
81
+ # <tt>:link_to_current_page</tt>:: whether or not the current page
82
+ # should be linked to (defaults to
83
+ # +false+)
84
+ #
85
+ # ==== Example
86
+ # # Turn paginated links into an Ajax call
87
+ # pagination_links_each(paginator, page_options) do |link|
88
+ # options = { :url => {:action => 'list'}, :update => 'results' }
89
+ # html_options = { :href => url_for(:action => 'list') }
90
+ #
91
+ # link_to_remote(link.to_s, options, html_options)
92
+ # end
93
+ def pagination_links_each(paginator, options, prefix = nil, suffix = nil)
94
+ options = DEFAULT_OPTIONS.merge(options)
95
+ link_to_current_page = options[:link_to_current_page]
96
+ always_show_anchors = options[:always_show_anchors]
97
+
98
+ current_page = paginator.current_page
99
+ window_pages = current_page.window(options[:window_size]).pages
100
+ return if window_pages.length <= 1 unless link_to_current_page
101
+
102
+ first, last = paginator.first, paginator.last
103
+
104
+ html = ''
105
+
106
+ html << prefix if prefix
107
+
108
+ if always_show_anchors and not (wp_first = window_pages[0]).first?
109
+ html << yield(first.number)
110
+ html << ' ... ' if wp_first.number - first.number > 1
111
+ html << ' '
112
+ end
113
+
114
+ window_pages.each do |page|
115
+ if current_page == page && !link_to_current_page
116
+ html << page.number.to_s
117
+ else
118
+ html << yield(page.number)
119
+ end
120
+ html << ' '
121
+ end
122
+
123
+ if always_show_anchors and not (wp_last = window_pages[-1]).last?
124
+ html << ' ... ' if last.number - wp_last.number > 1
125
+ html << yield(last.number)
126
+ end
127
+
128
+ html << suffix if suffix
129
+
130
+ html
131
+ end
132
+
133
+ end # PaginationHelper
134
+ end # Helpers
135
+ end # ActionView
data/test/setup.rb CHANGED
@@ -1,51 +1,51 @@
1
- # setup_db.rb
2
- require 'dbi'
3
-
4
- # Run "createdb cpk_test" first
5
-
6
- teacher_to_school = %Q{
7
- create table teacher_to_school(
8
- schoolid varchar(8),
9
- teacherid varchar(8),
10
- datebegin date,
11
- teacherrole varchar(20),
12
- primary key (schoolid, teacherid)
13
- );
14
-
15
- }
16
-
17
- globe_teacher = %Q{
18
- create table globe_teacher(
19
- teacherid varchar(8) primary key,
20
- currentschoolid varchar(8),
21
- userid varchar(16)
22
- );
23
-
24
- }
25
-
26
- globe_school = %Q{
27
- create table globe_school(
28
- schoolid varchar(8) primary key,
29
- schoolname varchar(100) not null,
30
- city varchar(35) not null
31
- )
32
-
33
- }
34
-
35
- add_records = [
36
- "insert into globe_teacher values ('ZZGLOBEY', 'ZZGLOBE1',
37
- 'dberger');",
38
- "insert into globe_school values ('ZZCOUCAR', 'NCAR Foothills Lab',
39
- 'Boulder');",
40
- "insert into globe_school values ('ZZGLOBE1', 'The GLOBE Program',
41
- 'Boulder');",
42
- "insert into teacher_to_school values('ZZGLOBE1', 'ZZGLOBEY', '1-JUN-2010', 'GLOBE OFFICE');",
43
- "insert into teacher_to_school values('ZZCOUCAR', 'ZZGLOBEY', '1-AUG-2010', 'GLOBE Teacher');"
44
- ]
45
-
46
- DBI.connect('dbi:Pg:cpk_test', 'postgres') do |dbh|
47
- dbh.execute(teacher_to_school)
48
- dbh.execute(globe_teacher)
49
- dbh.execute(globe_school)
50
- add_records.each{ |sql| dbh.execute(sql) }
1
+ # setup_db.rb
2
+ require 'dbi'
3
+
4
+ # Run "createdb cpk_test" first
5
+
6
+ teacher_to_school = %Q{
7
+ create table teacher_to_school(
8
+ schoolid varchar(8),
9
+ teacherid varchar(8),
10
+ datebegin date,
11
+ teacherrole varchar(20),
12
+ primary key (schoolid, teacherid)
13
+ );
14
+
15
+ }
16
+
17
+ globe_teacher = %Q{
18
+ create table globe_teacher(
19
+ teacherid varchar(8) primary key,
20
+ currentschoolid varchar(8),
21
+ userid varchar(16)
22
+ );
23
+
24
+ }
25
+
26
+ globe_school = %Q{
27
+ create table globe_school(
28
+ schoolid varchar(8) primary key,
29
+ schoolname varchar(100) not null,
30
+ city varchar(35) not null
31
+ )
32
+
33
+ }
34
+
35
+ add_records = [
36
+ "insert into globe_teacher values ('ZZGLOBEY', 'ZZGLOBE1',
37
+ 'dberger');",
38
+ "insert into globe_school values ('ZZCOUCAR', 'NCAR Foothills Lab',
39
+ 'Boulder');",
40
+ "insert into globe_school values ('ZZGLOBE1', 'The GLOBE Program',
41
+ 'Boulder');",
42
+ "insert into teacher_to_school values('ZZGLOBE1', 'ZZGLOBEY', '1-JUN-2010', 'GLOBE OFFICE');",
43
+ "insert into teacher_to_school values('ZZCOUCAR', 'ZZGLOBEY', '1-AUG-2010', 'GLOBE Teacher');"
44
+ ]
45
+
46
+ DBI.connect('dbi:Pg:cpk_test', 'postgres') do |dbh|
47
+ dbh.execute(teacher_to_school)
48
+ dbh.execute(globe_teacher)
49
+ dbh.execute(globe_school)
50
+ add_records.each{ |sql| dbh.execute(sql) }
51
51
  end
data/test/test_aliases.rb CHANGED
@@ -1,18 +1,18 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestAliases < ActiveSupport::TestCase
4
- fixtures :reference_codes
5
-
6
- def test_primary_key_setter_alias_composite_key
7
- reference_code = ReferenceCodeUsingCompositeKeyAlias.find([1, 2])
8
- assert_equal 'MRS', reference_code.code_label
9
- assert_equal 'Mrs', reference_code.abbreviation
10
- end
11
-
12
- def test_primary_key_setter_alias_simple_key
13
- reference_code = ReferenceCodeUsingSimpleKeyAlias.find('MRS')
14
- assert_equal 1, reference_code.reference_type_id
15
- assert_equal 2, reference_code.reference_code
16
- assert_equal 'Mrs', reference_code.abbreviation
17
- end
18
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestAliases < ActiveSupport::TestCase
4
+ fixtures :reference_codes
5
+
6
+ def test_primary_key_setter_alias_composite_key
7
+ reference_code = ReferenceCodeUsingCompositeKeyAlias.find([1, 2])
8
+ assert_equal 'MRS', reference_code.code_label
9
+ assert_equal 'Mrs', reference_code.abbreviation
10
+ end
11
+
12
+ def test_primary_key_setter_alias_simple_key
13
+ reference_code = ReferenceCodeUsingSimpleKeyAlias.find('MRS')
14
+ assert_equal 1, reference_code.reference_type_id
15
+ assert_equal 2, reference_code.reference_code
16
+ assert_equal 'Mrs', reference_code.abbreviation
17
+ end
18
+ end
@@ -1,24 +1,24 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class CompositeArraysTest < ActiveSupport::TestCase
4
-
5
- def test_new_primary_keys
6
- keys = CompositePrimaryKeys::CompositeKeys.new
7
- assert_not_nil keys
8
- assert_equal '', keys.to_s
9
- assert_equal '', "#{keys}"
10
- end
11
-
12
- def test_initialize_primary_keys
13
- keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
14
- assert_not_nil keys
15
- assert_equal '1,2,3', keys.to_s
16
- assert_equal '1,2,3', "#{keys}"
17
- end
18
-
19
- def test_to_composite_keys
20
- keys = [1,2,3].to_composite_keys
21
- assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
22
- assert_equal '1,2,3', keys.to_s
23
- end
24
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class CompositeArraysTest < ActiveSupport::TestCase
4
+
5
+ def test_new_primary_keys
6
+ keys = CompositePrimaryKeys::CompositeKeys.new
7
+ assert_not_nil keys
8
+ assert_equal '', keys.to_s
9
+ assert_equal '', "#{keys}"
10
+ end
11
+
12
+ def test_initialize_primary_keys
13
+ keys = CompositePrimaryKeys::CompositeKeys.new([1,2,3])
14
+ assert_not_nil keys
15
+ assert_equal '1,2,3', keys.to_s
16
+ assert_equal '1,2,3', "#{keys}"
17
+ end
18
+
19
+ def test_to_composite_keys
20
+ keys = [1,2,3].to_composite_keys
21
+ assert_equal CompositePrimaryKeys::CompositeKeys, keys.class
22
+ assert_equal '1,2,3', keys.to_s
23
+ end
24
+ end