Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/active_record/connection_adapters/oracle_enhanced/lob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module Lob # :nodoc:

# After setting large objects to empty, select the OCI8::LOB
# and write back the data.
before_create :record_lobs_for_create
after_create :enhanced_write_lobs
before_update :record_changed_lobs
after_update :enhanced_write_lobs
end
Expand All @@ -30,6 +32,13 @@ def enhanced_write_lobs
self.class.connection.write_lobs(self.class.table_name, self.class, attributes, @changed_lob_columns)
end
end

def record_lobs_for_create
@changed_lob_columns = self.class.lob_columns.select do |col|
!attributes[col.name].nil? && !self.class.readonly_attributes.to_a.include?(col.name)
end
end

def record_changed_lobs
@changed_lob_columns = self.class.lob_columns.select do |col|
self.will_save_change_to_attribute?(col.name) && !self.class.readonly_attributes.to_a.include?(col.name)
Expand Down
51 changes: 51 additions & 0 deletions spec/active_record/oracle_enhanced/type/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,55 @@ class ::TestSerializeEmployee < ActiveRecord::Base
)
expect(Test2Employee.where(comments: search_data)).to have_attributes(count: 1)
end

describe "with prepared_statements disabled" do
around(:each) do |example|
old_prepared_statements = @conn.prepared_statements
@conn.instance_variable_set(:@prepared_statements, false)
example.run
@conn.instance_variable_set(:@prepared_statements, old_prepared_statements)
end

it "should create record with CLOB data when prepared_statements is false" do
@employee = TestEmployee.create!(
first_name: "First",
last_name: "Last",
comments: @char_data
)
@employee.reload
expect(@employee.comments).to eq(@char_data)
end

it "should create record with short CLOB data when prepared_statements is false" do
short_data = "Short CLOB content"
@employee = TestEmployee.create!(
first_name: "First",
last_name: "Last",
comments: short_data
)
@employee.reload
expect(@employee.comments).to eq(short_data)
end

it "should create record with empty CLOB when prepared_statements is false" do
@employee = TestEmployee.create!(
first_name: "First",
last_name: "Last",
comments: ""
)
@employee.reload
expect(@employee.comments).to eq("")
end

it "should create record with serialized CLOB data when prepared_statements is false" do
ruby_data = { "test" => ["ruby", :data, 123] }
@employee = Test2Employee.create!(
first_name: "First",
last_name: "Last",
comments: ruby_data
)
@employee.reload
expect(@employee.comments).to eq(ruby_data)
end
end
end