Sha256: fddbce88f53bc6639e9027f2eb829fb6eaca90976cc617e465d4a4d24f4a331c

Contents?: true

Size: 1.67 KB

Versions: 17

Compression:

Stored size: 1.67 KB

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
require 'yaml'

describe "serialization_modification_detection plugin" do
  before do
    @c = Class.new(Sequel::Model(:items))
    @c.class_eval do
      columns :id, :h
      plugin :serialization, :yaml, :h
      plugin :serialization_modification_detection
    end
    @o1 = @c.new(:h=>{})
    @o2 = @c.load(:id=>1, :h=>"--- {}\n\n")
    @o3 = @c.new
    @o4 = @c.load(:id=>1, :h=>nil)
    MODEL_DB.reset
  end
  
  it "should not detect columns that haven't been changed" do
    @o1.changed_columns.should == []
    @o1.h.should == {}
    @o1.h[1] = 2
    @o1.h.clear
    @o1.changed_columns.should == []

    @o2.changed_columns.should == []
    @o2.h.should == {}
    @o2.h[1] = 2
    @o2.h.clear
    @o2.changed_columns.should == []
  end
  
  it "should detect columns that have been changed" do
    @o1.changed_columns.should == []
    @o1.h.should == {}
    @o1.h[1] = 2
    @o1.changed_columns.should == [:h]

    @o2.changed_columns.should == []
    @o2.h.should == {}
    @o2.h[1] = 2
    @o2.changed_columns.should == [:h]

    @o3.changed_columns.should == []
    @o3.h.should == nil
    @o3.h = {}
    @o3.changed_columns.should == [:h]

    @o4.changed_columns.should == []
    @o4.h.should == nil
    @o4.h = {}
    @o4.changed_columns.should == [:h]
  end
  
  it "should report correct changed_columns after saving" do
    @o1.h[1] = 2
    @o1.save
    @o1.changed_columns.should == []

    @o2.h[1] = 2
    @o2.save_changes
    @o2.changed_columns.should == []

    @o3.h = {1=>2}
    @o3.save
    @o3.changed_columns.should == []

    @o4.h = {1=>2}
    @o4.save
    @o4.changed_columns.should == []
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
sequel-3.46.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.45.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.44.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.43.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.42.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.41.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.40.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.39.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.38.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.37.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.36.1 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.36.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.35.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.34.1 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.34.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.33.0 spec/extensions/serialization_modification_detection_spec.rb
sequel-3.32.0 spec/extensions/serialization_modification_detection_spec.rb