activerecord-oracle_enhanced-adapter 1.2.4 → 1.3.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.
Files changed (33) hide show
  1. data/.gitignore +0 -1
  2. data/History.txt +20 -0
  3. data/README.rdoc +7 -3
  4. data/Rakefile +1 -2
  5. data/VERSION +1 -1
  6. data/activerecord-oracle_enhanced-adapter.gemspec +96 -0
  7. data/lib/active_record/connection_adapters/oracle_enhanced.rake +11 -8
  8. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +37 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +317 -180
  10. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +282 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +3 -2
  12. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +1 -1
  13. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +3 -3
  14. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +6 -1
  15. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +143 -52
  16. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +2 -1
  17. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +39 -20
  18. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +2 -1
  19. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
  20. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +70 -11
  21. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_structure_dumper_spec.rb +27 -20
  22. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +334 -0
  23. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +28 -22
  24. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +24 -28
  25. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +13 -11
  26. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +1 -1
  27. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +72 -69
  28. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +112 -6
  29. data/spec/active_record/connection_adapters/oracle_enhanced_schema_spec.rb +49 -1
  30. data/spec/spec_helper.rb +97 -19
  31. metadata +33 -22
  32. data/Manifest.txt +0 -32
  33. data/lib/active_record/connection_adapters/oracle_enhanced_reserved_words.rb +0 -126
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
3
3
  unless defined?(NO_COMPOSITE_PRIMARY_KEYS)
4
4
 
5
5
  describe "OracleEnhancedAdapter composite_primary_keys support" do
6
+ include SchemaSpecHelper
6
7
 
7
8
  before(:all) do
8
9
  if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
@@ -31,20 +32,29 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
31
32
 
32
33
  describe "do not use count distinct" do
33
34
  before(:all) do
35
+ schema_define do
36
+ create_table :job_history, :primary_key => [:employee_id, :start_date], :force => true do |t|
37
+ t.integer :employee_id
38
+ t.date :start_date
39
+ end
40
+ end
34
41
  class ::JobHistory < ActiveRecord::Base
35
42
  set_table_name "job_history"
36
43
  set_primary_keys :employee_id, :start_date
37
44
  end
38
45
  end
39
-
46
+
40
47
  after(:all) do
41
- Object.send(:remove_const, 'JobHistory') if defined?(JobHistory)
48
+ Object.send(:remove_const, 'JobHistory') if defined?(JobHistory)
49
+ schema_define do
50
+ drop_table :job_history
51
+ end
42
52
  end
43
-
53
+
44
54
  it "should tell ActiveRecord that count distinct is not supported" do
45
55
  ActiveRecord::Base.connection.supports_count_distinct?.should be_false
46
56
  end
47
-
57
+
48
58
  it "should execute correct SQL COUNT DISTINCT statement on table with composite primary keys" do
49
59
  lambda { JobHistory.count(:distinct => true) }.should_not raise_error
50
60
  end
@@ -52,19 +62,17 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
52
62
 
53
63
  describe "table with LOB" do
54
64
  before(:all) do
55
- ActiveRecord::Schema.define do
56
- suppress_messages do
57
- create_table :cpk_write_lobs_test, :primary_key => [:type_category, :date_value], :force => true do |t|
58
- t.string :type_category, :limit => 15, :null => false
59
- t.date :date_value, :null => false
60
- t.text :results, :null => false
61
- t.timestamps
62
- end
63
- create_table :non_cpk_write_lobs_test, :force => true do |t|
64
- t.date :date_value, :null => false
65
- t.text :results, :null => false
66
- t.timestamps
67
- end
65
+ schema_define do
66
+ create_table :cpk_write_lobs_test, :primary_key => [:type_category, :date_value], :force => true do |t|
67
+ t.string :type_category, :limit => 15, :null => false
68
+ t.date :date_value, :null => false
69
+ t.text :results, :null => false
70
+ t.timestamps
71
+ end
72
+ create_table :non_cpk_write_lobs_test, :force => true do |t|
73
+ t.date :date_value, :null => false
74
+ t.text :results, :null => false
75
+ t.timestamps
68
76
  end
69
77
  end
70
78
  class ::CpkWriteLobsTest < ActiveRecord::Base
@@ -77,11 +85,9 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
77
85
  end
78
86
 
79
87
  after(:all) do
80
- ActiveRecord::Schema.define do
81
- suppress_messages do
82
- drop_table :cpk_write_lobs_test
83
- drop_table :non_cpk_write_lobs_test
84
- end
88
+ schema_define do
89
+ drop_table :cpk_write_lobs_test
90
+ drop_table :non_cpk_write_lobs_test
85
91
  end
86
92
  Object.send(:remove_const, "CpkWriteLobsTest")
87
93
  Object.send(:remove_const, "NonCpkWriteLobsTest")
@@ -6,7 +6,7 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
6
6
  @conn = ActiveRecord::Base.connection
7
7
  @conn.execute <<-SQL
8
8
  CREATE TABLE test_employees (
9
- employee_id NUMBER(6,0),
9
+ employee_id NUMBER(6,0) PRIMARY KEY,
10
10
  first_name VARCHAR2(20),
11
11
  last_name VARCHAR2(25),
12
12
  email VARCHAR2(25),
@@ -192,7 +192,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
192
192
  @conn = ActiveRecord::Base.connection
193
193
  @conn.execute <<-SQL
194
194
  CREATE TABLE test2_employees (
195
- id NUMBER,
195
+ id NUMBER PRIMARY KEY,
196
196
  first_name VARCHAR2(20),
197
197
  last_name VARCHAR2(25),
198
198
  email VARCHAR2(25),
@@ -338,7 +338,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
338
338
  @conn = ActiveRecord::Base.connection
339
339
  @conn.execute <<-SQL
340
340
  CREATE TABLE test3_employees (
341
- id NUMBER,
341
+ id NUMBER PRIMARY KEY,
342
342
  first_name VARCHAR2(20),
343
343
  last_name VARCHAR2(25),
344
344
  email VARCHAR2(25),
@@ -521,7 +521,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
521
521
  @conn = ActiveRecord::Base.connection
522
522
  @conn.execute <<-SQL
523
523
  CREATE TABLE test_employees (
524
- employee_id NUMBER(6,0),
524
+ employee_id NUMBER(6,0) PRIMARY KEY,
525
525
  first_name VARCHAR2(20),
526
526
  last_name VARCHAR2(25),
527
527
  email VARCHAR2(25),
@@ -604,7 +604,7 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
604
604
  @conn = ActiveRecord::Base.connection
605
605
  @conn.execute <<-SQL
606
606
  CREATE TABLE test_employees (
607
- employee_id NUMBER(6,0),
607
+ employee_id NUMBER(6,0) PRIMARY KEY,
608
608
  first_name VARCHAR2(20),
609
609
  last_name VARCHAR2(25),
610
610
  email VARCHAR2(25),
@@ -709,7 +709,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
709
709
  @conn = ActiveRecord::Base.connection
710
710
  @conn.execute <<-SQL
711
711
  CREATE TABLE test_employees (
712
- employee_id NUMBER(6,0),
712
+ employee_id NUMBER(6,0) PRIMARY KEY,
713
713
  first_name VARCHAR2(20),
714
714
  last_name VARCHAR2(25),
715
715
  hire_date DATE,
@@ -750,6 +750,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
750
750
  :last_name => "Last",
751
751
  :hire_date => @today_iso
752
752
  )
753
+ @employee.hire_date.should == @today
753
754
  @employee.reload
754
755
  @employee.hire_date.should == @today
755
756
  end
@@ -761,6 +762,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
761
762
  :last_name => "Last",
762
763
  :hire_date => @today_nls
763
764
  )
765
+ @employee.hire_date.should == @today
764
766
  @employee.reload
765
767
  @employee.hire_date.should == @today
766
768
  end
@@ -771,6 +773,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
771
773
  :last_name => "Last",
772
774
  :hire_date => @now_iso
773
775
  )
776
+ @employee.hire_date.should == @today
774
777
  @employee.reload
775
778
  @employee.hire_date.should == @today
776
779
  end
@@ -783,6 +786,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
783
786
  :last_name => "Last",
784
787
  :hire_date => @now_nls
785
788
  )
789
+ @employee.hire_date.should == @today
786
790
  @employee.reload
787
791
  @employee.hire_date.should == @today
788
792
  end
@@ -793,6 +797,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
793
797
  :last_name => "Last",
794
798
  :last_login_at => @now_iso
795
799
  )
800
+ @employee.last_login_at.should == @now
796
801
  @employee.reload
797
802
  @employee.last_login_at.should == @now
798
803
  end
@@ -805,6 +810,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
805
810
  :last_name => "Last",
806
811
  :last_login_at => @now_nls
807
812
  )
813
+ @employee.last_login_at.should == @now
808
814
  @employee.reload
809
815
  @employee.last_login_at.should == @now
810
816
  end
@@ -815,6 +821,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
815
821
  :last_name => "Last",
816
822
  :last_login_at => @today_iso
817
823
  )
824
+ @employee.last_login_at.should == @today.to_time
818
825
  @employee.reload
819
826
  @employee.last_login_at.should == @today.to_time
820
827
  end
@@ -827,6 +834,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
827
834
  :last_name => "Last",
828
835
  :last_login_at => @today_nls
829
836
  )
837
+ @employee.last_login_at.should == @today.to_time
830
838
  @employee.reload
831
839
  @employee.last_login_at.should == @today.to_time
832
840
  end
@@ -839,7 +847,7 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
839
847
  @conn = ActiveRecord::Base.connection
840
848
  @conn.execute <<-SQL
841
849
  CREATE TABLE test_employees (
842
- employee_id NUMBER(6,0),
850
+ employee_id NUMBER(6,0) PRIMARY KEY,
843
851
  first_name VARCHAR2(20),
844
852
  last_name VARCHAR2(25),
845
853
  comments CLOB
@@ -849,20 +857,23 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
849
857
  CREATE SEQUENCE test_employees_seq MINVALUE 1
850
858
  INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
851
859
  SQL
852
- class ::TestEmployee < ActiveRecord::Base
853
- set_primary_key :employee_id
854
- end
855
860
  end
856
861
 
857
862
  after(:all) do
858
- Object.send(:remove_const, "TestEmployee")
859
863
  @conn.execute "DROP TABLE test_employees"
860
864
  @conn.execute "DROP SEQUENCE test_employees_seq"
861
865
  end
862
866
 
863
867
  before(:each) do
868
+ class ::TestEmployee < ActiveRecord::Base
869
+ set_primary_key :employee_id
870
+ end
864
871
  end
865
-
872
+
873
+ after(:each) do
874
+ Object.send(:remove_const, "TestEmployee")
875
+ end
876
+
866
877
  it "should create record without CLOB data when attribute is serialized" do
867
878
  TestEmployee.serialize :comments
868
879
  @employee = TestEmployee.create!(
@@ -870,21 +881,6 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
870
881
  :last_name => "Last"
871
882
  )
872
883
  @employee.should be_valid
873
- TestEmployee.serialized_attributes.delete('comments')
874
- end
875
-
876
- it "should order by CLOB column" do
877
- @employee = TestEmployee.create!(
878
- :first_name => "First",
879
- :last_name => "Last",
880
- :comments => "comments"
881
- )
882
- TestEmployee.find(:all, :order => "comments ASC").should_not be_empty
883
- TestEmployee.find(:all, :order => " comments ASC ").should_not be_empty
884
- TestEmployee.find(:all, :order => "comments").should_not be_empty
885
- TestEmployee.find(:all, :order => " comments ").should_not be_empty
886
- TestEmployee.find(:all, :order => :comments).should_not be_empty
887
- TestEmployee.find(:all, :order => " first_name DESC, last_name ASC ").should_not be_empty
888
884
  end
889
885
 
890
886
  it "should accept Symbol value for CLOB column" do
@@ -902,7 +898,7 @@ describe "OracleEnhancedAdapter handling of BLOB columns" do
902
898
  @conn = ActiveRecord::Base.connection
903
899
  @conn.execute <<-SQL
904
900
  CREATE TABLE test_employees (
905
- employee_id NUMBER(6,0),
901
+ employee_id NUMBER(6,0) PRIMARY KEY,
906
902
  first_name VARCHAR2(20),
907
903
  last_name VARCHAR2(25),
908
904
  binary_data BLOB
@@ -4,7 +4,6 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
4
4
  include LoggerSpecHelper
5
5
 
6
6
  before(:all) do
7
- @buffer = StringIO.new
8
7
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
9
8
  ActiveRecord::Base.connection.execute <<-SQL
10
9
  CREATE or REPLACE
@@ -31,18 +30,21 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
31
30
  end
32
31
 
33
32
  before(:each) do
34
- @buffer = StringIO.new
35
- log_to @buffer
33
+ set_logger
36
34
  ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
37
35
  @conn = ActiveRecord::Base.connection
38
36
  end
39
37
 
38
+ after(:each) do
39
+ clear_logger
40
+ end
41
+
40
42
  it "should NOT log dbms output when dbms output is disabled" do
41
43
  @conn.disable_dbms_output
42
44
 
43
45
  @conn.select_all("select more_than_five_characters_long('hi there') is_it_long from dual").should == [{'is_it_long'=>1}]
44
-
45
- @buffer.string.should_not match(/^DBMS_OUTPUT/)
46
+
47
+ @logger.output(:debug).should_not match(/^DBMS_OUTPUT/)
46
48
  end
47
49
 
48
50
  it "should log dbms output lines to the rails log" do
@@ -50,9 +52,9 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
50
52
 
51
53
  @conn.select_all("select more_than_five_characters_long('hi there') is_it_long from dual").should == [{'is_it_long'=>1}]
52
54
 
53
- @buffer.string.should match(/^DBMS_OUTPUT: before the if -hi there-$/)
54
- @buffer.string.should match(/^DBMS_OUTPUT: it is longer than 5$/)
55
- @buffer.string.should match(/^DBMS_OUTPUT: about to return: 1$/)
55
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: before the if -hi there-$/)
56
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: it is longer than 5$/)
57
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: about to return: 1$/)
56
58
  end
57
59
 
58
60
  it "should log dbms output lines to the rails log" do
@@ -60,8 +62,8 @@ describe "OracleEnhancedAdapter logging dbms_output from plsql" do
60
62
 
61
63
  @conn.select_all("select more_than_five_characters_long('short') is_it_long from dual").should == [{'is_it_long'=>0}]
62
64
 
63
- @buffer.string.should match(/^DBMS_OUTPUT: before the if -short-$/)
64
- @buffer.string.should match(/^DBMS_OUTPUT: it is 5 or shorter$/)
65
- @buffer.string.should match(/^DBMS_OUTPUT: about to return: 0$/)
65
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: before the if -short-$/)
66
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: it is 5 or shorter$/)
67
+ @logger.output(:debug).should match(/^DBMS_OUTPUT: about to return: 0$/)
66
68
  end
67
69
  end
@@ -9,7 +9,7 @@ if ActiveRecord::Base.instance_methods.include?('changed?')
9
9
  @conn = ActiveRecord::Base.connection
10
10
  @conn.execute <<-SQL
11
11
  CREATE TABLE test_employees (
12
- id NUMBER,
12
+ id NUMBER PRIMARY KEY,
13
13
  first_name VARCHAR2(20),
14
14
  last_name VARCHAR2(25),
15
15
  job_id NUMBER(6,0) NULL,
@@ -1,5 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
+ require 'ruby-plsql'
4
+
3
5
  describe "OracleEnhancedAdapter custom methods for create, update and destroy" do
4
6
  include LoggerSpecHelper
5
7
 
@@ -10,7 +12,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
10
12
  @conn.execute("DROP TABLE test_employees") rescue nil
11
13
  @conn.execute <<-SQL
12
14
  CREATE TABLE test_employees (
13
- employee_id NUMBER(6,0),
15
+ employee_id NUMBER(6,0) PRIMARY KEY,
14
16
  first_name VARCHAR2(20),
15
17
  last_name VARCHAR2(25),
16
18
  hire_date DATE,
@@ -78,9 +80,10 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
78
80
  BEGIN
79
81
  SELECT version INTO v_version FROM test_employees WHERE employee_id = p_employee_id FOR UPDATE;
80
82
  UPDATE test_employees
81
- SET employee_id = p_employee_id, first_name = p_first_name, last_name = p_last_name,
83
+ SET first_name = p_first_name, last_name = p_last_name,
82
84
  hire_date = p_hire_date, salary = p_salary, description = p_description,
83
- version = v_version + 1, update_time = SYSDATE;
85
+ version = v_version + 1, update_time = SYSDATE
86
+ WHERE employee_id = p_employee_id;
84
87
  END update_employee;
85
88
 
86
89
  PROCEDURE delete_employee(
@@ -93,7 +96,16 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
93
96
  SQL
94
97
 
95
98
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
99
+ end
96
100
 
101
+ after(:all) do
102
+ @conn = ActiveRecord::Base.connection
103
+ @conn.execute "DROP TABLE test_employees"
104
+ @conn.execute "DROP SEQUENCE test_employees_s"
105
+ @conn.execute "DROP PACKAGE test_employees_pkg"
106
+ end
107
+
108
+ before(:each) do
97
109
  class ::TestEmployee < ActiveRecord::Base
98
110
  set_primary_key :employee_id
99
111
 
@@ -130,22 +142,21 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
130
142
  )
131
143
  end
132
144
 
145
+ private
146
+
147
+ def raise_make_transaction_rollback
148
+ raise "Make the transaction rollback"
149
+ end
133
150
  end
134
- end
135
-
136
- after(:all) do
137
- Object.send(:remove_const, "TestEmployee")
138
- @conn = ActiveRecord::Base.connection
139
- @conn.execute "DROP TABLE test_employees"
140
- @conn.execute "DROP SEQUENCE test_employees_s"
141
- @conn.execute "DROP PACKAGE test_employees_pkg"
142
- end
143
151
 
144
- before(:each) do
145
152
  @today = Date.new(2008,6,28)
146
153
  @buffer = StringIO.new
147
154
  end
148
155
 
156
+ after(:each) do
157
+ Object.send(:remove_const, "TestEmployee")
158
+ end
159
+
149
160
  it "should create record" do
150
161
  @employee = TestEmployee.create(
151
162
  :first_name => "First",
@@ -162,22 +173,19 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
162
173
  end
163
174
 
164
175
  it "should rollback record when exception is raised in after_create callback" do
176
+ TestEmployee.after_create :raise_make_transaction_rollback
177
+
165
178
  @employee = TestEmployee.new(
166
179
  :first_name => "First",
167
180
  :last_name => "Last",
168
181
  :hire_date => @today
169
182
  )
170
- TestEmployee.class_eval { def after_create() raise "Make the transaction rollback" end }
171
- begin
172
- employees_count = TestEmployee.count
173
- lambda {
174
- @employee.save
175
- }.should raise_error("Make the transaction rollback")
176
- @employee.id.should == nil
177
- TestEmployee.count.should == employees_count
178
- ensure
179
- TestEmployee.class_eval { remove_method :after_create }
180
- end
183
+ employees_count = TestEmployee.count
184
+ lambda {
185
+ @employee.save
186
+ }.should raise_error("Make the transaction rollback")
187
+ @employee.id.should == nil
188
+ TestEmployee.count.should == employees_count
181
189
  end
182
190
 
183
191
  it "should update record" do
@@ -195,25 +203,22 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
195
203
  end
196
204
 
197
205
  it "should rollback record when exception is raised in after_update callback" do
198
- TestEmployee.class_eval { def after_update() raise "Make the transaction rollback" end }
199
- begin
200
- @employee = TestEmployee.create(
201
- :first_name => "First",
202
- :last_name => "Last",
203
- :hire_date => @today,
204
- :description => "description"
205
- )
206
- empl_id = @employee.id
207
- @employee.reload
208
- @employee.first_name = "Second"
209
- lambda {
210
- @employee.save
211
- }.should raise_error("Make the transaction rollback")
212
- @employee.reload
213
- @employee.first_name.should == "First"
214
- ensure
215
- TestEmployee.class_eval { remove_method :after_update }
216
- end
206
+ TestEmployee.after_update :raise_make_transaction_rollback
207
+
208
+ @employee = TestEmployee.create(
209
+ :first_name => "First",
210
+ :last_name => "Last",
211
+ :hire_date => @today,
212
+ :description => "description"
213
+ )
214
+ empl_id = @employee.id
215
+ @employee.reload
216
+ @employee.first_name = "Second"
217
+ lambda {
218
+ @employee.save
219
+ }.should raise_error("Make the transaction rollback")
220
+ @employee.reload
221
+ @employee.first_name.should == "First"
217
222
  end
218
223
 
219
224
  it "should not update record if nothing is changed and partial updates are enabled" do
@@ -269,24 +274,22 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
269
274
  @employee.should be_destroyed
270
275
  end
271
276
 
272
- it "should rollback record when exception is raised in after_desotry callback" do
273
- TestEmployee.class_eval { def after_destroy() raise "Make the transaction rollback" end }
274
- begin
275
- @employee = TestEmployee.create(
276
- :first_name => "First",
277
- :last_name => "Last",
278
- :hire_date => @today
279
- )
280
- @employee.reload
281
- empl_id = @employee.id
282
- lambda {
283
- @employee.destroy
284
- }.should raise_error("Make the transaction rollback")
285
- @employee.id.should == empl_id
286
- TestEmployee.find_by_employee_id(empl_id).should_not be_nil
287
- ensure
288
- TestEmployee.class_eval { remove_method :after_destroy }
289
- end
277
+ it "should rollback record when exception is raised in after_destroy callback" do
278
+ set_logger
279
+ TestEmployee.after_destroy :raise_make_transaction_rollback
280
+
281
+ @employee = TestEmployee.create(
282
+ :first_name => "First",
283
+ :last_name => "Last",
284
+ :hire_date => @today
285
+ )
286
+ @employee.reload
287
+ empl_id = @employee.id
288
+ lambda {
289
+ @employee.destroy
290
+ }.should raise_error("Make the transaction rollback")
291
+ @employee.id.should == empl_id
292
+ TestEmployee.find_by_employee_id(empl_id).should_not be_nil
290
293
  end
291
294
 
292
295
  it "should set timestamps when creating record" do
@@ -315,13 +318,13 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
315
318
  end
316
319
 
317
320
  it "should log create record" do
318
- log_to @buffer
321
+ set_logger
319
322
  @employee = TestEmployee.create(
320
323
  :first_name => "First",
321
324
  :last_name => "Last",
322
325
  :hire_date => @today
323
326
  )
324
- @buffer.string.should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
327
+ @logger.logged(:debug).last.should match(/^TestEmployee Create \(\d+\.\d+(ms)?\) custom create method$/)
325
328
  end
326
329
 
327
330
  it "should log update record" do
@@ -331,9 +334,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
331
334
  :last_name => "Last",
332
335
  :hire_date => @today
333
336
  )
334
- log_to @buffer
337
+ set_logger
335
338
  @employee.save!
336
- @buffer.string.should match(/^TestEmployee Update \(\d+\.\d+(ms)?\) custom update method with employee_id=#{@employee.id}$/)
339
+ @logger.logged(:debug).last.should match(/^TestEmployee Update \(\d+\.\d+(ms)?\) custom update method with employee_id=#{@employee.id}$/)
337
340
  end
338
341
 
339
342
  it "should log delete record" do
@@ -342,9 +345,9 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
342
345
  :last_name => "Last",
343
346
  :hire_date => @today
344
347
  )
345
- log_to @buffer
348
+ set_logger
346
349
  @employee.destroy
347
- @buffer.string.should match(/^TestEmployee Destroy \(\d+\.\d+(ms)?\) custom delete method with employee_id=#{@employee.id}$/)
350
+ @logger.logged(:debug).last.should match(/^TestEmployee Destroy \(\d+\.\d+(ms)?\) custom delete method with employee_id=#{@employee.id}$/)
348
351
  end
349
352
 
350
353
  it "should validate new record before creation" do
@@ -353,7 +356,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
353
356
  :hire_date => @today
354
357
  )
355
358
  @employee.save.should be_false
356
- @employee.errors.on(:first_name).should_not be_nil
359
+ @employee.errors[:first_name].should_not be_blank
357
360
  end
358
361
 
359
362
  it "should validate existing record before update" do
@@ -364,7 +367,7 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
364
367
  )
365
368
  @employee.first_name = nil
366
369
  @employee.save.should be_false
367
- @employee.errors.on(:first_name).should_not be_nil
370
+ @employee.errors[:first_name].should_not be_blank
368
371
  end
369
372
 
370
373
  end