composite_primary_keys 8.1.6 → 9.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +5 -5
  2. data/History.rdoc +59 -7
  3. data/README.rdoc +62 -1
  4. data/Rakefile +4 -1
  5. data/lib/composite_primary_keys/arel/in.rb +6 -0
  6. data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
  7. data/lib/composite_primary_keys/arel/to_sql.rb +26 -0
  8. data/lib/composite_primary_keys/associations/association.rb +14 -12
  9. data/lib/composite_primary_keys/associations/association_scope.rb +22 -27
  10. data/lib/composite_primary_keys/associations/collection_association.rb +39 -8
  11. data/lib/composite_primary_keys/associations/has_many_association.rb +17 -40
  12. data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
  13. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
  14. data/lib/composite_primary_keys/associations/join_dependency.rb +73 -56
  15. data/lib/composite_primary_keys/associations/preloader/association.rb +75 -73
  16. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
  17. data/lib/composite_primary_keys/attribute_methods/read.rb +18 -15
  18. data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
  19. data/lib/composite_primary_keys/attribute_methods.rb +6 -4
  20. data/lib/composite_primary_keys/autosave_association.rb +19 -54
  21. data/lib/composite_primary_keys/base.rb +18 -82
  22. data/lib/composite_primary_keys/composite_arrays.rb +9 -1
  23. data/lib/composite_primary_keys/composite_predicates.rb +1 -0
  24. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  25. data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +5 -6
  26. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
  27. data/lib/composite_primary_keys/core.rb +46 -45
  28. data/lib/composite_primary_keys/fixtures.rb +19 -17
  29. data/lib/composite_primary_keys/locking/optimistic.rb +53 -49
  30. data/lib/composite_primary_keys/nested_attributes.rb +60 -53
  31. data/lib/composite_primary_keys/persistence.rb +49 -41
  32. data/lib/composite_primary_keys/relation/batches.rb +35 -32
  33. data/lib/composite_primary_keys/relation/calculations.rb +3 -7
  34. data/lib/composite_primary_keys/relation/finder_methods.rb +122 -55
  35. data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
  36. data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
  37. data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
  38. data/lib/composite_primary_keys/relation.rb +96 -43
  39. data/lib/composite_primary_keys/sanitization.rb +6 -15
  40. data/lib/composite_primary_keys/version.rb +3 -3
  41. data/lib/composite_primary_keys.rb +10 -19
  42. data/scripts/console.rb +48 -48
  43. data/scripts/txt2html +76 -76
  44. data/scripts/txt2js +65 -65
  45. data/tasks/databases/mysql.rake +17 -19
  46. data/tasks/databases/oracle.rake +29 -15
  47. data/tasks/databases/postgresql.rake +20 -29
  48. data/tasks/databases/sqlite.rake +25 -0
  49. data/tasks/databases/sqlserver.rake +32 -16
  50. data/tasks/website.rake +18 -18
  51. data/test/README_tests.rdoc +56 -56
  52. data/test/abstract_unit.rb +24 -18
  53. data/test/connections/connection_spec.rb +11 -2
  54. data/test/connections/databases.ci.yml +5 -4
  55. data/test/connections/databases.example.yml +19 -4
  56. data/test/connections/databases.yml +40 -30
  57. data/test/db_test.rb +52 -52
  58. data/test/fixtures/article.rb +1 -0
  59. data/test/fixtures/articles.yml +6 -6
  60. data/test/fixtures/capitol.rb +3 -3
  61. data/test/fixtures/capitols.yml +16 -16
  62. data/test/fixtures/comments.yml +15 -15
  63. data/test/fixtures/db_definitions/mysql.sql +16 -17
  64. data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
  65. data/test/fixtures/db_definitions/oracle.sql +26 -17
  66. data/test/fixtures/db_definitions/postgresql.sql +2 -3
  67. data/test/fixtures/db_definitions/sqlite.sql +0 -1
  68. data/test/fixtures/db_definitions/sqlserver.sql +20 -35
  69. data/test/fixtures/department.rb +5 -5
  70. data/test/fixtures/departments.yml +15 -15
  71. data/test/fixtures/dorms.yml +4 -4
  72. data/test/fixtures/employee.rb +5 -7
  73. data/test/fixtures/employees.yml +1 -5
  74. data/test/fixtures/group.rb +2 -2
  75. data/test/fixtures/groups.yml +6 -6
  76. data/test/fixtures/hack.rb +4 -4
  77. data/test/fixtures/hacks.yml +2 -2
  78. data/test/fixtures/membership_status.rb +2 -2
  79. data/test/fixtures/product.rb +9 -9
  80. data/test/fixtures/product_tariff.rb +5 -5
  81. data/test/fixtures/products.yml +11 -11
  82. data/test/fixtures/reading.rb +4 -4
  83. data/test/fixtures/readings.yml +10 -10
  84. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  85. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  86. data/test/fixtures/reference_codes.yml +28 -28
  87. data/test/fixtures/reference_type.rb +1 -1
  88. data/test/fixtures/reference_types.yml +9 -9
  89. data/test/fixtures/restaurant.rb +9 -9
  90. data/test/fixtures/restaurants.yml +14 -14
  91. data/test/fixtures/restaurants_suburbs.yml +10 -10
  92. data/test/fixtures/room.rb +11 -11
  93. data/test/fixtures/room_assignment.rb +13 -13
  94. data/test/fixtures/room_assignments.yml +24 -24
  95. data/test/fixtures/room_attribute.rb +2 -2
  96. data/test/fixtures/room_attribute_assignment.rb +4 -4
  97. data/test/fixtures/room_attribute_assignments.yml +4 -4
  98. data/test/fixtures/room_attributes.yml +2 -2
  99. data/test/fixtures/rooms.yml +12 -12
  100. data/test/fixtures/seat.rb +5 -5
  101. data/test/fixtures/seats.yml +8 -8
  102. data/test/fixtures/street.rb +2 -2
  103. data/test/fixtures/streets.yml +16 -16
  104. data/test/fixtures/student.rb +3 -3
  105. data/test/fixtures/students.yml +15 -15
  106. data/test/fixtures/suburbs.yml +14 -14
  107. data/test/fixtures/tariff.rb +1 -1
  108. data/test/fixtures/tariffs.yml +14 -14
  109. data/test/fixtures/user.rb +0 -1
  110. data/test/plugins/pagination.rb +405 -405
  111. data/test/plugins/pagination_helper.rb +135 -135
  112. data/test/setup.rb +50 -50
  113. data/test/test_aliases.rb +18 -18
  114. data/test/test_associations.rb +18 -17
  115. data/test/test_composite_arrays.rb +24 -24
  116. data/test/test_counter_cache.rb +30 -30
  117. data/test/test_create.rb +14 -6
  118. data/test/test_delete.rb +36 -34
  119. data/test/test_dup.rb +37 -37
  120. data/test/test_exists.rb +39 -39
  121. data/test/test_find.rb +16 -4
  122. data/test/test_habtm.rb +27 -3
  123. data/test/test_miscellaneous.rb +32 -32
  124. data/test/test_nested_attributes.rb +6 -6
  125. data/test/test_pagination.rb +35 -35
  126. data/test/test_polymorphic.rb +0 -7
  127. data/test/test_predicates.rb +20 -20
  128. data/test/test_preload.rb +94 -0
  129. data/test/test_suite.rb +1 -1
  130. data/test/test_update.rb +10 -7
  131. data/test/test_validations.rb +13 -13
  132. metadata +30 -39
  133. data/README_DB2.rdoc +0 -33
  134. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
  135. data/lib/composite_primary_keys/associations/singular_association.rb +0 -18
  136. data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
  137. data/lib/composite_primary_keys/attribute_set/builder.rb +0 -20
  138. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -70
  139. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -19
  140. data/lib/composite_primary_keys/dirty.rb +0 -19
  141. data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
  142. data/tasks/databases/oracle_enhanced.rake +0 -27
  143. data/tasks/databases/sqlite3.rake +0 -27
  144. data/test/connections/native_ibm_db/connection.rb +0 -19
  145. data/test/connections/native_mysql/connection.rb +0 -17
  146. data/test/connections/native_oracle/connection.rb +0 -11
  147. data/test/connections/native_oracle_enhanced/connection.rb +0 -16
  148. data/test/connections/native_postgresql/connection.rb +0 -13
  149. data/test/connections/native_sqlite3/connection.rb +0 -9
  150. data/test/connections/native_sqlserver/connection.rb +0 -11
  151. data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
  152. data/test/test_delete_all.rb +0 -35
  153. data/test/test_find_in_batches.rb +0 -30
@@ -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
@@ -71,16 +71,6 @@ class TestAssociations < ActiveSupport::TestCase
71
71
  assert_equal(3, tariffs.inject(0) {|sum, tariff| sum + tariff.product_tariffs.length})
72
72
  end
73
73
 
74
- def test_has_one_association_is_not_cached_to_where_it_returns_the_wrong_one
75
- engineering = departments(:engineering)
76
- engineering_head = engineering.head
77
-
78
- accounting = departments(:accounting)
79
- accounting_head = accounting.head
80
-
81
- refute_equal accounting_head, engineering_head
82
- end
83
-
84
74
  def test_association_with_composite_primary_key_can_be_autosaved
85
75
  room = Room.new(dorm_id: 1000, room_id: 1001)
86
76
  room_assignment = RoomAssignment.new(student_id: 1000)
@@ -91,11 +81,16 @@ class TestAssociations < ActiveSupport::TestCase
91
81
  assert_equal(room_assignment.room_id, 1001)
92
82
  end
93
83
 
94
- def test_association_with_composite_primary_key_can_be_autosaved_on_update
95
- robert = employees(:robert)
96
- robert_salary = robert.create_one_salary(year: "2015", month: "1")
97
- robert.update(name: robert.name.reverse)
98
- assert_equal(robert.id, robert_salary.employee_id)
84
+ def test_has_one_association_is_not_cached_to_where_it_returns_the_wrong_one
85
+ engineering = departments(:engineering)
86
+ engineering_head = engineering.head
87
+ assert_equal(employees(:sarah), engineering_head)
88
+
89
+ accounting = departments(:accounting)
90
+ accounting_head = accounting.head
91
+ assert_equal(employees(:steve), accounting_head)
92
+
93
+ refute_equal accounting_head, engineering_head
99
94
  end
100
95
 
101
96
  def test_has_one_association_primary_key_and_foreign_key_are_present
@@ -274,7 +269,7 @@ class TestAssociations < ActiveSupport::TestCase
274
269
  assert_not_nil(department.head)
275
270
  end
276
271
 
277
- def test_has_many_build__simple_key
272
+ def test_has_many_build_simple_key
278
273
  user = users(:santiago)
279
274
  reading = user.readings.build
280
275
  assert_equal user.id, reading.user_id
@@ -352,7 +347,13 @@ class TestAssociations < ActiveSupport::TestCase
352
347
  def test_foreign_key_present_with_null_association_ids
353
348
  group = Group.new
354
349
  group.memberships.build
355
- associations = group.association_cache[:memberships]
350
+ associations = group.association(:memberships)
356
351
  assert_equal(false, associations.send('foreign_key_present?'))
357
352
  end
353
+
354
+ def test_ids_equals_for_non_CPK_case
355
+ article = Article.new
356
+ article.reading_ids = Reading.pluck(:id)
357
+ assert_equal article.reading_ids, Reading.pluck(:id)
358
+ end
358
359
  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
@@ -1,31 +1,31 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestCalculations < ActiveSupport::TestCase
4
- fixtures :tariffs
5
-
6
- def test_update_counter
7
- tariff = tariffs(:flat)
8
- assert_equal(50, tariff.amount)
9
- Tariff.update_counters(tariff.id, :amount => 1)
10
- tariff.reload
11
- assert_equal(51, tariff.amount)
12
- end
13
-
14
- def test_increment_counter
15
- tariff = tariffs(:flat)
16
- assert_equal(50, tariff.amount)
17
- Tariff.increment_counter(:amount, tariff.id)
18
-
19
- tariff.reload
20
- assert_equal(51, tariff.amount)
21
- end
22
-
23
- def test_decrement_counter
24
- tariff = tariffs(:flat)
25
- assert_equal(50, tariff.amount)
26
- Tariff.decrement_counter(:amount, tariff.id)
27
-
28
- tariff.reload
29
- assert_equal(49, tariff.amount)
30
- end
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestCalculations < ActiveSupport::TestCase
4
+ fixtures :tariffs
5
+
6
+ def test_update_counter
7
+ tariff = tariffs(:flat)
8
+ assert_equal(50, tariff.amount)
9
+ Tariff.update_counters(tariff.id, :amount => 1)
10
+ tariff.reload
11
+ assert_equal(51, tariff.amount)
12
+ end
13
+
14
+ def test_increment_counter
15
+ tariff = tariffs(:flat)
16
+ assert_equal(50, tariff.amount)
17
+ Tariff.increment_counter(:amount, tariff.id)
18
+
19
+ tariff.reload
20
+ assert_equal(51, tariff.amount)
21
+ end
22
+
23
+ def test_decrement_counter
24
+ tariff = tariffs(:flat)
25
+ assert_equal(50, tariff.amount)
26
+ Tariff.decrement_counter(:amount, tariff.id)
27
+
28
+ tariff.reload
29
+ assert_equal(49, tariff.amount)
30
+ end
31
31
  end
data/test/test_create.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require File.expand_path('../abstract_unit', __FILE__)
2
2
 
3
3
  class TestCreate < ActiveSupport::TestCase
4
- fixtures :students, :dorms, :rooms, :room_assignments, :reference_types, :reference_codes, :streets, :suburbs
5
-
4
+ fixtures :articles, :students, :dorms, :rooms, :room_assignments, :reference_types, :reference_codes, :streets, :suburbs
5
+
6
6
  CLASSES = {
7
7
  :single => {
8
8
  :class => ReferenceType,
@@ -101,7 +101,7 @@ class TestCreate < ActiveSupport::TestCase
101
101
  assert_equal(200, restaurant.store_id)
102
102
  assert_equal("My Store", restaurant.name)
103
103
 
104
- assert_equal(1, restaurant.suburbs(true).length)
104
+ assert_equal(1, restaurant.suburbs.reload.length)
105
105
 
106
106
  # Test suburbs
107
107
  suburb = restaurant.suburbs[0]
@@ -116,14 +116,13 @@ class TestCreate < ActiveSupport::TestCase
116
116
  room.save!
117
117
 
118
118
  student1 = students(:kelly)
119
- student2 = students(:jordan)
120
119
 
121
120
  RoomAssignment.delete_all
122
121
 
123
122
  assignment1 = RoomAssignment.new(:student_id => student1.id, :dorm_id => room.dorm_id, :room_id => room.room_id)
124
123
  assignment1.save!
125
124
 
126
- room.room_assignments = [assignment1]
125
+ room.room_assignment_ids = [[assignment1.student_id, assignment1.dorm_id, assignment1.room_id]]
127
126
  room.save!
128
127
 
129
128
  assert_equal(1, room.room_assignments.length)
@@ -146,11 +145,20 @@ class TestCreate < ActiveSupport::TestCase
146
145
  assignment2 = RoomAssignment.new(:student_id => student2.id, :dorm_id => room.dorm_id, :room_id => room.room_id)
147
146
  assignment2.save!
148
147
 
149
- room.room_assignments = [assignment1,assignment2]
148
+ room.room_assignment_ids = [[assignment1.student_id, assignment1.dorm_id, assignment1.room_id],
149
+ [assignment2.student_id, assignment2.dorm_id, assignment2.room_id]]
150
150
  room.save!
151
151
 
152
152
  assert_equal(2, room.room_assignments.length)
153
153
  assert_equal(assignment1, room.room_assignments[0])
154
154
  assert_equal(assignment2, room.room_assignments[1])
155
155
  end
156
+
157
+ def test_create_article_invalid_id
158
+ error = assert_raises(ActiveRecord::RecordInvalid) do
159
+ article = Article.create!(:id => 1)
160
+ end
161
+
162
+ assert_equal('Validation failed: Id has already been taken', error.to_s)
163
+ end
156
164
  end