Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

rails4: OracleEnhancedAdapter dirty object tracking should not mark empty string (stored as NULL) as changed when reassigning it failed #177

Closed
yahonda opened this Issue · 5 comments

2 participants

@yahonda
Collaborator

rails4: OracleEnhancedAdapter dirty object tracking should not mark empty string (stored as NULL) as changed when reassigning it failed

$ rspec ./spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb
==> Running specs with MRI version 1.9.3
==> Running specs with Rails version 4.0-master
F........

Failures:

  1) OracleEnhancedAdapter dirty object tracking should not mark empty string (stored as NULL) as changed when reassigning it
     Failure/Error: @employee.should_not be_changed
       expected changed? to return false, got true
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-expectations-2.10.0/lib/rspec/expectations/fail_with.rb:33:in `fail_with'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-expectations-2.10.0/lib/rspec/expectations/handler.rb:42:in `handle_matcher'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-expectations-2.10.0/lib/rspec/expectations/extensions/kernel.rb:24:in `should_not'
     # ./spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb:44:in `block (2 levels) in <top (required)>'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:87:in `instance_eval'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:87:in `block in run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:195:in `with_around_each_hooks'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example.rb:84:in `run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:353:in `block in run_examples'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:349:in `map'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:349:in `run_examples'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/example_group.rb:335:in `run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `map'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:28:in `block in run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/reporter.rb:34:in `report'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:25:in `run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
     # /home/yahonda/.rvm/gems/ruby-1.9.3-p194@railsmaster/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Finished in 1.33 seconds
9 examples, 1 failure

Failed examples:

rspec ./spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb:38 # OracleEnhancedAdapter dirty object tracking should not mark empty string (stored as NULL) as changed when reassigning it
$

Putting debug p @employees each line and found Just it changes just after @employee.reload executed.

$ git diff
diff --git a/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb b/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb
index 4d3585c..5b0f12a 100644
--- a/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb
+++ b/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb
@@ -37,10 +37,14 @@ if ActiveRecord::Base.method_defined?(:changed?)

     it "should not mark empty string (stored as NULL) as changed when reassigning it" do
       @employee = TestEmployee.create!(:first_name => '')
+      p @employee
       @employee.first_name = ''
+      p @employee
       @employee.should_not be_changed
       @employee.reload
+      p @employee
       @employee.first_name = ''
+      p @employee
       @employee.should_not be_changed
     end

$

You can see the first_name value is set to nil at line 3.

#<TestEmployee id: #<BigDecimal:1579760,'0.1E1',9(36)>, first_name: "", last_name: nil, job_id: nil, salary: nil, comments: nil, hire_date: nil>
#<TestEmployee id: #<BigDecimal:1579760,'0.1E1',9(36)>, first_name: "", last_name: nil, job_id: nil, salary: nil, comments: nil, hire_date: nil>
#<TestEmployee id: #<BigDecimal:17b7f18,'0.1E1',9(36)>, first_name: nil, last_name: nil, job_id: nil, salary: nil, comments: nil, hire_date: nil>
#<TestEmployee id: #<BigDecimal:17b7f18,'0.1E1',9(36)>, first_name: "", last_name: nil, job_id: nil, salary: nil, comments: nil, hire_date: nil>

Other dirty object related tests successfully finished. It only fails with Strings.

@ebeigarts
Collaborator

Maybe the oracle_enhanced_dirty.rb should be included in Model instead of Base.

@yahonda
Collaborator

Thanks for the comment, as always.

Although I do not fully understand it, I just tried as follows but it does not help.

$ git diff
diff --git a/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb b/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
index 9c9df30..fcf0792 100644
--- a/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
+++ b/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb
@@ -32,8 +32,8 @@ module ActiveRecord #:nodoc:
   end
 end

-if ActiveRecord::Base.method_defined?(:changed?)
-  ActiveRecord::Base.class_eval do
+if ActiveRecord::Model.method_defined?(:changed?)
+  ActiveRecord::Model.class_eval do
     include ActiveRecord::ConnectionAdapters::OracleEnhancedDirty::InstanceMethods
   end
-end
\ No newline at end of file
+end
$
@ebeigarts
Collaborator

The method has been renamed to _field_changed? See rails/rails#3544

@yahonda
Collaborator

Thanks as every time! #182 has been opened.

@yahonda
Collaborator

#182 has been merged to the rails4 branch.

@yahonda yahonda closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.