ibm_db 0.10.0 → 1.0.0

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.
@@ -3,6 +3,7 @@ require 'bigdecimal/util'
3
3
 
4
4
  require 'models/person'
5
5
  require 'models/topic'
6
+ require 'models/developer'
6
7
 
7
8
  require MIGRATIONS_ROOT + "/valid/1_people_have_last_names"
8
9
  require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
@@ -48,8 +49,8 @@ if ActiveRecord::Base.connection.supports_migrations?
48
49
  Person.connection.remove_column('people', column) rescue nil
49
50
  end
50
51
  Person.connection.remove_column("people", "first_name") rescue nil
51
- Person.connection.remove_column("people", "middle_name") rescue nil
52
- Person.connection.add_column("people", "first_name", :string, :limit => 40)
52
+ Person.connection.remove_column("people", "middle_name") rescue nil
53
+ Person.connection.add_column("people", "first_name", :string, :limit => 40)
53
54
  Person.reset_column_information
54
55
  end
55
56
 
@@ -124,7 +125,7 @@ if ActiveRecord::Base.connection.supports_migrations?
124
125
  def test_create_table_with_defaults
125
126
  # MySQL doesn't allow defaults on TEXT or BLOB columns.
126
127
  mysql = current_adapter?(:MysqlAdapter)
127
- ibm_ids_zOS = ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_IDS')||
128
+ ibm_ids_zOS = ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_IDS')||
128
129
  ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_DB2_ZOS')
129
130
 
130
131
  Person.connection.create_table :testings do |t|
@@ -153,39 +154,48 @@ if ActiveRecord::Base.connection.supports_migrations?
153
154
  end
154
155
 
155
156
  if current_adapter?(:IBM_DBAdapter)
156
- def test_no_limits_datatypes_IBM_DB
157
- clasz = Class.new(ActiveRecord::Base)
158
- clasz.table_name = 'test_no_limits_datatypes_IBM_DB'
159
- assert_nothing_raised do
160
- clasz.connection.create_table clasz.table_name do |t|
161
- t.column "test_varchar", :string, :limit => 10
162
- t.column "test_integer", :integer, :limit => 5
163
- t.column "test_boolean", :boolean, :limit => 5
164
- t.column "test_double", :double, :limit => 10
165
- t.column "test_date", :date, :limit => 10
166
- t.column "test_time", :time, :limit => 10
167
- t.column "test_tstamp", :timestamp, :limit => 10
168
- t.column "test_xml", :xml, :limit => 10
169
- t.column "test_clob", :text, :limit => 10000
170
- end
157
+ def test_no_limits_datatypes_IBM_DB
158
+ ibm_ids = ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_IDS')
159
+ clasz = Class.new(ActiveRecord::Base)
160
+ clasz.table_name = 'test_no_limits_datatypes_IBM_DB'
161
+ assert_nothing_raised do
162
+ clasz.connection.create_table clasz.table_name do |t|
163
+ t.column "test_varchar", :string, :limit => 10
164
+ t.column "test_integer", :integer, :limit => 5
165
+ t.column "test_boolean", :boolean, :limit => 5
166
+ t.column "test_double", :double, :limit => 10
167
+ t.column "test_date", :date, :limit => 10
168
+ t.column "test_time", :time, :limit => 10
169
+ t.column "test_tstamp", :timestamp, :limit => 10
170
+ t.column "test_xml", :xml, :limit => 10 unless ibm_ids
171
+ t.column "test_clob", :text, :limit => 10000
171
172
  end
172
- ensure
173
- clasz.connection.drop_table(clasz.table_name) rescue nil
174
173
  end
174
+ ensure
175
+ clasz.connection.drop_table(clasz.table_name) rescue nil
176
+ end
175
177
 
176
- #Sexy migration test for column of type xml
177
- def test_new_xml_migrations
178
- clasz = Class.new(ActiveRecord::Base)
179
- clasz.table_name = 'test_new_xml_migrations'
180
- assert_nothing_raised do
181
- clasz.connection.create_table clasz.table_name do |t|
182
- t.xml :xml_col
183
- end
178
+ #Sexy migration test for column of type xml and char
179
+ def test_short_hand_char_xml_migrations
180
+ ibm_ids = ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_IDS')
181
+ clasz = Class.new(ActiveRecord::Base)
182
+ clasz.table_name = 'test_short_hand_migrations'
183
+ assert_nothing_raised do
184
+ clasz.connection.create_table clasz.table_name do |t|
185
+ t.xml :xml_col unless ibm_ids
186
+ t.char :char_col, :limit=>10
184
187
  end
185
- ensure
186
- clasz.connection.drop_table(clasz.table_name) rescue nil
187
188
  end
189
+ assert_nothing_raised do
190
+ clasz.connection.change_table clasz.table_name do |t|
191
+ t.xml :xml_col1 unless ibm_ids
192
+ t.char :char_col1, :limit=>50
193
+ end
194
+ end
195
+ ensure
196
+ clasz.connection.drop_table(clasz.table_name) rescue nil
188
197
  end
198
+ end
189
199
 
190
200
  def test_create_table_with_limits
191
201
  assert_nothing_raised do
@@ -194,9 +204,10 @@ if ActiveRecord::Base.connection.supports_migrations?
194
204
 
195
205
  t.column :default_int, :integer
196
206
 
197
- t.column :one_int, :integer, :limit => 1
198
- t.column :four_int, :integer, :limit => 4
199
- t.column :eight_int, :integer, :limit => 8
207
+ t.column :one_int, :integer, :limit => 1
208
+ t.column :four_int, :integer, :limit => 4
209
+ t.column :eight_int, :integer, :limit => 8
210
+ t.column :eleven_int, :integer, :limit => 11
200
211
  end
201
212
  end
202
213
 
@@ -208,12 +219,20 @@ if ActiveRecord::Base.connection.supports_migrations?
208
219
  one = columns.detect { |c| c.name == "one_int" }
209
220
  four = columns.detect { |c| c.name == "four_int" }
210
221
  eight = columns.detect { |c| c.name == "eight_int" }
222
+ eleven = columns.detect { |c| c.name == "eleven_int" }
211
223
 
212
224
  if current_adapter?(:PostgreSQLAdapter)
213
225
  assert_equal 'integer', default.sql_type
214
226
  assert_equal 'smallint', one.sql_type
215
227
  assert_equal 'integer', four.sql_type
216
228
  assert_equal 'bigint', eight.sql_type
229
+ assert_equal 'integer', eleven.sql_type
230
+ elsif current_adapter?(:MysqlAdapter)
231
+ assert_match 'int(11)', default.sql_type
232
+ assert_match 'tinyint', one.sql_type
233
+ assert_match 'int', four.sql_type
234
+ assert_match 'bigint', eight.sql_type
235
+ assert_match 'int(11)', eleven.sql_type
217
236
  elsif current_adapter?(:OracleAdapter)
218
237
  assert_equal 'NUMBER(38)', default.sql_type
219
238
  assert_equal 'NUMBER(1)', one.sql_type
@@ -268,6 +287,39 @@ if ActiveRecord::Base.connection.supports_migrations?
268
287
  end
269
288
  end
270
289
 
290
+ def test_create_table_with_timestamps_should_create_datetime_columns
291
+ table_name = :testings
292
+
293
+ Person.connection.create_table table_name do |t|
294
+ t.timestamps
295
+ end
296
+ created_columns = Person.connection.columns(table_name)
297
+
298
+ created_at_column = created_columns.detect {|c| c.name == 'created_at' }
299
+ updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }
300
+
301
+ assert created_at_column.null
302
+ assert updated_at_column.null
303
+ ensure
304
+ Person.connection.drop_table table_name rescue nil
305
+ end
306
+
307
+ def test_create_table_with_timestamps_should_create_datetime_columns_with_options
308
+ table_name = :testings
309
+
310
+ Person.connection.create_table table_name do |t|
311
+ t.timestamps :null => false
312
+ end
313
+ created_columns = Person.connection.columns(table_name)
314
+
315
+ created_at_column = created_columns.detect {|c| c.name == 'created_at' }
316
+ updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }
317
+
318
+ assert !created_at_column.null
319
+ assert !updated_at_column.null
320
+ ensure
321
+ Person.connection.drop_table table_name rescue nil
322
+ end
271
323
 
272
324
  # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
273
325
  # column to a table without a default value.
@@ -440,10 +492,7 @@ if ActiveRecord::Base.connection.supports_migrations?
440
492
 
441
493
  ActiveRecord::Migration.add_column :people, :intelligence_quotient, :tinyint
442
494
  Person.reset_column_information
443
- Person.create :intelligence_quotient => 300
444
- jonnyg = Person.find(:first)
445
- assert_equal 127, jonnyg.intelligence_quotient
446
- jonnyg.destroy
495
+ assert_match /tinyint/, Person.columns_hash['intelligence_quotient'].sql_type
447
496
  ensure
448
497
  ActiveRecord::Migration.remove_column :people, :intelligence_quotient rescue nil
449
498
  end
@@ -525,6 +574,37 @@ if ActiveRecord::Base.connection.supports_migrations?
525
574
  end
526
575
  end
527
576
 
577
+ def test_rename_column_preserves_default_value_not_null
578
+ begin
579
+ default_before = Developer.connection.columns("developers").find { |c| c.name == "salary" }.default
580
+ assert_equal 70000, default_before
581
+ Developer.connection.rename_column "developers", "salary", "anual_salary"
582
+ Developer.reset_column_information
583
+ assert Developer.column_names.include?("anual_salary")
584
+ default_after = Developer.connection.columns("developers").find { |c| c.name == "anual_salary" }.default
585
+ assert_equal 70000, default_after
586
+ ensure
587
+ Developer.connection.rename_column "developers", "anual_salary", "salary"
588
+ Developer.reset_column_information
589
+ end
590
+ end
591
+
592
+ def test_rename_nonexistent_column
593
+ ActiveRecord::Base.connection.create_table(:hats) do |table|
594
+ table.column :hat_name, :string, :default => nil
595
+ end
596
+ exception = if current_adapter?(:PostgreSQLAdapter)
597
+ ActiveRecord::StatementInvalid
598
+ else
599
+ ActiveRecord::ActiveRecordError
600
+ end
601
+ assert_raises(exception) do
602
+ Person.connection.rename_column "hats", "nonexistent", "should_fail"
603
+ end
604
+ ensure
605
+ ActiveRecord::Base.connection.drop_table(:hats)
606
+ end
607
+
528
608
  def test_rename_column_with_sql_reserved_word
529
609
  begin
530
610
  assert_nothing_raised { Person.connection.rename_column "people", "first_name", "group" }
@@ -613,14 +693,14 @@ if ActiveRecord::Base.connection.supports_migrations?
613
693
  Person.connection.add_column "people", "funny", :boolean
614
694
  Person.reset_column_information
615
695
  assert Person.columns_hash["funny"].null, "Column 'funny' must initially allow nulls"
616
- unless current_adapter?(:IBM_DBAdapter) # incompatible types changes
617
- Person.connection.change_column "people", "funny", :boolean, :null => false, :default => true
618
- Person.reset_column_information
619
- assert !Person.columns_hash["funny"].null, "Column 'funny' must *not* allow nulls at this point"
620
- Person.connection.change_column "people", "funny", :boolean, :null => true
621
- Person.reset_column_information
622
- assert Person.columns_hash["funny"].null, "Column 'funny' must allow nulls again at this point"
623
- end
696
+ unless current_adapter?(:IBM_DBAdapter) # incompatible types changes
697
+ Person.connection.change_column "people", "funny", :boolean, :null => false, :default => true
698
+ Person.reset_column_information
699
+ assert !Person.columns_hash["funny"].null, "Column 'funny' must *not* allow nulls at this point"
700
+ Person.connection.change_column "people", "funny", :boolean, :null => true
701
+ Person.reset_column_information
702
+ assert Person.columns_hash["funny"].null, "Column 'funny' must allow nulls again at this point"
703
+ end
624
704
  end
625
705
 
626
706
  def test_rename_table_with_an_index
@@ -705,7 +785,7 @@ if ActiveRecord::Base.connection.supports_migrations?
705
785
  Person.connection.create_table :testings do |t|
706
786
  t.column :select, :string
707
787
  end
708
- unless current_adapter?(:IBM_DBAdapter) # altering a string column to size
788
+ unless current_adapter?(:IBM_DBAdapter) # altering a string column to smaller size
709
789
  assert_nothing_raised { Person.connection.change_column :testings, :select, :string, :limit => 10 }
710
790
  end
711
791
 
@@ -714,6 +794,81 @@ if ActiveRecord::Base.connection.supports_migrations?
714
794
  Person.connection.drop_table :testings rescue nil
715
795
  end
716
796
 
797
+ def test_keeping_default_and_notnull_constaint_on_change
798
+ Person.connection.create_table :testings do |t|
799
+ t.column :title, :string
800
+ end
801
+ person_klass = Class.new(Person)
802
+ person_klass.set_table_name 'testings'
803
+
804
+ person_klass.connection.add_column "testings", "wealth", :integer, :null => false, :default => 99
805
+ person_klass.reset_column_information
806
+ assert_equal 99, person_klass.columns_hash["wealth"].default
807
+ assert_equal false, person_klass.columns_hash["wealth"].null
808
+ assert_nothing_raised {person_klass.connection.execute("insert into testings (title) values ('tester')")}
809
+
810
+ # change column default to see that column doesn't lose its not null definition
811
+ person_klass.connection.change_column_default "testings", "wealth", 100
812
+ person_klass.reset_column_information
813
+ assert_equal 100, person_klass.columns_hash["wealth"].default
814
+ assert_equal false, person_klass.columns_hash["wealth"].null
815
+
816
+ # rename column to see that column doesn't lose its not null and/or default definition
817
+ unless current_adapter?(:IBM_DBAdapter) #rename_column is not implemented in IBM_DBAdapetr
818
+ person_klass.connection.rename_column "testings", "wealth", "money"
819
+ person_klass.reset_column_information
820
+ assert_nil person_klass.columns_hash["wealth"]
821
+ assert_equal 100, person_klass.columns_hash["money"].default
822
+ assert_equal false, person_klass.columns_hash["money"].null
823
+ end
824
+
825
+ # change column
826
+ unless current_adapter?(:IBM_DBAdapter)
827
+ person_klass.connection.change_column "testings", "money", :integer, :null => false, :default => 1000
828
+ person_klass.reset_column_information
829
+ assert_equal 1000, person_klass.columns_hash["money"].default
830
+ assert_equal false, person_klass.columns_hash["money"].null
831
+ else
832
+ person_klass.connection.change_column "testings", "wealth", :decimal, :precision => 15, :scale => 1,:null => false, :default => 1000
833
+ person_klass.reset_column_information
834
+ assert_equal 1000, person_klass.columns_hash["wealth"].default
835
+ assert_equal false, person_klass.columns_hash["wealth"].null
836
+ end
837
+
838
+ # change column, make it nullable and clear default
839
+ unless current_adapter?(:IBM_DBAdapter)
840
+ person_klass.connection.change_column "testings", "money", :integer, :null => true, :default => nil
841
+ person_klass.reset_column_information
842
+ assert_nil person_klass.columns_hash["money"].default
843
+ assert_equal true, person_klass.columns_hash["money"].null
844
+ else
845
+ person_klass.connection.change_column "testings", "wealth", :decimal, :precision => 20, :scale => 2, :null => true, :default => nil
846
+ person_klass.reset_column_information
847
+ assert_nil person_klass.columns_hash["wealth"].default
848
+ assert_equal true, person_klass.columns_hash["wealth"].null
849
+ end
850
+
851
+ # change_column_null, make it not nullable and set null values to a default value
852
+ unless current_adapter?(:IBM_DBAdapter)
853
+ person_klass.connection.execute('UPDATE testings SET money = NULL')
854
+ person_klass.connection.change_column_null "testings", "money", false, 2000
855
+ person_klass.reset_column_information
856
+ assert_nil person_klass.columns_hash["money"].default
857
+ assert_equal false, person_klass.columns_hash["money"].null
858
+ assert_equal [2000], Person.connection.select_values("SELECT money FROM testings").map { |s| s.to_i }.sort
859
+ else
860
+ # Trying to set the value of the column wealth to NULL and
861
+ # in the next statement a not null constraint is being applied which is wrong.
862
+ #person_klass.connection.execute('UPDATE testings SET wealth = NULL')
863
+ person_klass.connection.change_column_null "testings", "wealth", false, 2000
864
+ person_klass.reset_column_information
865
+ assert_equal false, person_klass.columns_hash["wealth"].null
866
+ assert_equal 2000, person_klass.columns_hash["wealth"].default
867
+ end
868
+ ensure
869
+ Person.connection.drop_table :testings rescue nil
870
+ end
871
+
717
872
  def test_change_column_default_to_null
718
873
  Person.connection.change_column_default "people", "first_name", nil
719
874
  Person.reset_column_information
@@ -863,6 +1018,21 @@ if ActiveRecord::Base.connection.supports_migrations?
863
1018
  assert !Reminder.table_exists?
864
1019
  end
865
1020
 
1021
+ def test_migrator_double_up
1022
+ assert_equal(0, ActiveRecord::Migrator.current_version)
1023
+ ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
1024
+ assert_nothing_raised { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1) }
1025
+ assert_equal(1, ActiveRecord::Migrator.current_version)
1026
+ end
1027
+
1028
+ def test_migrator_double_down
1029
+ assert_equal(0, ActiveRecord::Migrator.current_version)
1030
+ ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
1031
+ ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1)
1032
+ assert_nothing_raised { ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1) }
1033
+ assert_equal(0, ActiveRecord::Migrator.current_version)
1034
+ end
1035
+
866
1036
  def test_finds_migrations
867
1037
  migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
868
1038
  [['1', 'people_have_last_names'],
@@ -952,16 +1122,6 @@ if ActiveRecord::Base.connection.supports_migrations?
952
1122
  ActiveRecord::Migrator.rollback(MIGRATIONS_ROOT + "/valid")
953
1123
  assert_equal(0, ActiveRecord::Migrator.current_version)
954
1124
  end
955
-
956
- def test_migrator_run
957
- assert_equal(0, ActiveRecord::Migrator.current_version)
958
- ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 3)
959
- assert_equal(0, ActiveRecord::Migrator.current_version)
960
-
961
- assert_equal(0, ActiveRecord::Migrator.current_version)
962
- ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 3)
963
- assert_equal(0, ActiveRecord::Migrator.current_version)
964
- end
965
1125
 
966
1126
  def test_schema_migrations_table_name
967
1127
  ActiveRecord::Base.table_name_prefix = "prefix_"
@@ -1141,8 +1301,8 @@ if ActiveRecord::Base.connection.supports_migrations?
1141
1301
 
1142
1302
  def test_timestamps_creates_updated_at_and_created_at
1143
1303
  with_new_table do |t|
1144
- t.expects(:column).with(:created_at, :datetime)
1145
- t.expects(:column).with(:updated_at, :datetime)
1304
+ t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
1305
+ t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
1146
1306
  t.timestamps
1147
1307
  end
1148
1308
  end
@@ -1270,10 +1430,10 @@ if ActiveRecord::Base.connection.supports_migrations?
1270
1430
  end
1271
1431
 
1272
1432
  def integer_column
1273
- if current_adapter?(:SQLite3Adapter) || current_adapter?(:SQLiteAdapter) || current_adapter?(:PostgreSQLAdapter)
1274
- "integer"
1275
- else
1433
+ if current_adapter?(:MysqlAdapter)
1276
1434
  'int(11)'
1435
+ else
1436
+ 'integer'
1277
1437
  end
1278
1438
  end
1279
1439
 
@@ -8,120 +8,121 @@ require 'models/post'
8
8
 
9
9
  unless current_adapter?(:IBM_DBAdapter)
10
10
  class QueryCacheTest < ActiveRecord::TestCase
11
- fixtures :tasks, :topics, :categories, :posts, :categories_posts
11
+ fixtures :tasks, :topics, :categories, :posts, :categories_posts
12
12
 
13
- def test_find_queries
14
- assert_queries(2) { Task.find(1); Task.find(1) }
15
- end
16
-
17
- def test_find_queries_with_cache
18
- Task.cache do
19
- assert_queries(1) { Task.find(1); Task.find(1) }
13
+ def test_find_queries
14
+ assert_queries(2) { Task.find(1); Task.find(1) }
20
15
  end
21
- end
22
16
 
23
- def test_count_queries_with_cache
24
- Task.cache do
25
- assert_queries(1) { Task.count; Task.count }
17
+ def test_find_queries_with_cache
18
+ Task.cache do
19
+ assert_queries(1) { Task.find(1); Task.find(1) }
20
+ end
26
21
  end
27
- end
28
22
 
29
- def test_query_cache_dups_results_correctly
30
- Task.cache do
31
- now = Time.now.utc
32
- task = Task.find 1
33
- assert_not_equal now, task.starting
34
- task.starting = now
35
- task.reload
36
- assert_not_equal now, task.starting
23
+ def test_count_queries_with_cache
24
+ Task.cache do
25
+ assert_queries(1) { Task.count; Task.count }
26
+ end
37
27
  end
38
- end
39
28
 
40
- def test_cache_is_flat
41
- Task.cache do
42
- Topic.columns # don't count this query
43
- assert_queries(1) { Topic.find(1); Topic.find(1); }
29
+ def test_query_cache_dups_results_correctly
30
+ Task.cache do
31
+ now = Time.now.utc
32
+ task = Task.find 1
33
+ assert_not_equal now, task.starting
34
+ task.starting = now
35
+ task.reload
36
+ assert_not_equal now, task.starting
37
+ end
44
38
  end
45
39
 
46
- ActiveRecord::Base.cache do
47
- assert_queries(1) { Task.find(1); Task.find(1) }
40
+ def test_cache_is_flat
41
+ Task.cache do
42
+ Topic.columns # don't count this query
43
+ assert_queries(1) { Topic.find(1); Topic.find(1); }
44
+ end
45
+
46
+ ActiveRecord::Base.cache do
47
+ assert_queries(1) { Task.find(1); Task.find(1) }
48
+ end
48
49
  end
49
- end
50
50
 
51
- def test_cache_does_not_wrap_string_results_in_arrays
52
- Task.cache do
53
- assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
51
+ def test_cache_does_not_wrap_string_results_in_arrays
52
+ Task.cache do
53
+ assert_instance_of String, Task.connection.select_value("SELECT count(*) AS count_all FROM tasks")
54
+ end
54
55
  end
55
56
  end
56
- end
57
57
 
58
- uses_mocha 'QueryCacheExpiryTest' do
58
+ uses_mocha 'QueryCacheExpiryTest' do
59
59
 
60
60
  class QueryCacheExpiryTest < ActiveRecord::TestCase
61
- fixtures :tasks
62
-
63
- def test_find
64
- Task.connection.expects(:clear_query_cache).times(1)
65
-
66
- assert !Task.connection.query_cache_enabled
67
- Task.cache do
68
- assert Task.connection.query_cache_enabled
69
- Task.find(1)
70
-
71
- Task.uncached do
72
- assert !Task.connection.query_cache_enabled
61
+ fixtures :tasks, :posts, :categories, :categories_posts
62
+
63
+ def test_find
64
+ Task.connection.expects(:clear_query_cache).times(1)
65
+
66
+ assert !Task.connection.query_cache_enabled
67
+ Task.cache do
68
+ assert Task.connection.query_cache_enabled
73
69
  Task.find(1)
70
+
71
+ Task.uncached do
72
+ assert !Task.connection.query_cache_enabled
73
+ Task.find(1)
74
+ end
75
+
76
+ assert Task.connection.query_cache_enabled
74
77
  end
75
-
76
- assert Task.connection.query_cache_enabled
78
+ assert !Task.connection.query_cache_enabled
77
79
  end
78
- assert !Task.connection.query_cache_enabled
79
- end
80
80
 
81
- def test_update
82
- Task.connection.expects(:clear_query_cache).times(2)
81
+ def test_update
82
+ Task.connection.expects(:clear_query_cache).times(2)
83
83
 
84
- Task.cache do
85
- task = Task.find(1)
86
- task.starting = Time.now.utc
87
- task.save!
84
+ Task.cache do
85
+ task = Task.find(1)
86
+ task.starting = Time.now.utc
87
+ task.save!
88
+ end
88
89
  end
89
- end
90
90
 
91
- def test_destroy
92
- Task.connection.expects(:clear_query_cache).times(2)
91
+ def test_destroy
92
+ Task.connection.expects(:clear_query_cache).times(2)
93
93
 
94
- Task.cache do
95
- Task.find(1).destroy
94
+ Task.cache do
95
+ Task.find(1).destroy
96
+ end
96
97
  end
97
- end
98
98
 
99
- def test_insert
100
- ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
99
+ def test_insert
100
+ ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
101
101
 
102
- Task.cache do
103
- Task.create!
102
+ Task.cache do
103
+ Task.create!
104
+ end
104
105
  end
105
- end
106
106
 
107
- def test_cache_is_expired_by_habtm_update
108
- ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
107
+ def test_cache_is_expired_by_habtm_update
108
+ ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
109
109
  ActiveRecord::Base.cache do
110
110
  c = Category.find(:first)
111
111
  p = Post.find(:first)
112
112
  p.categories << c
113
113
  end
114
- end
114
+ end
115
115
 
116
- def test_cache_is_expired_by_habtm_delete
117
- ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
116
+ def test_cache_is_expired_by_habtm_delete
117
+ ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
118
118
  ActiveRecord::Base.cache do
119
- c = Category.find(:first)
120
- p = Post.find(:first)
119
+ c = Category.find(1)
120
+ p = Post.find(1)
121
+ assert p.categories.any?
121
122
  p.categories.delete_all
122
123
  end
123
124
  end
124
125
  end
125
-
126
+
126
127
  end
127
- end
128
+ end