Sha256: d4854213f56c5f29ac0b0310f1d0bfadae9849ee8347c220921512988348a49a

Contents?: true

Size: 1.27 KB

Versions: 34

Compression:

Stored size: 1.27 KB

Contents

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

describe "accessed_columns plugin" do
  before do
    @db = Sequel.mock(:fetch=>{:name=>'a', :b=>'c'}, :numrows=>1)
    @c = Class.new(Sequel::Model(@db[:test]))
    @c.columns :name, :b
    @c.plugin :accessed_columns
    @o = @c.new
  end

  it "should record columns accessed" do
    @o.accessed_columns.must_equal []
    @o.name
    @o.accessed_columns.must_equal [:name]
    @o.name
    @o.accessed_columns.must_equal [:name]
    @o.b
    @o.accessed_columns.sort_by{|s| s.to_s}.must_equal [:b, :name]
  end

  it "should clear accessed columns when refreshing" do
    @o.name
    @o.refresh
    @o.accessed_columns.must_equal []
  end

  it "should clear accessed columns when saving" do
    @o.name
    @o.save
    @o.accessed_columns.must_equal []
  end

  it "should work when duping and cloning instances" do
    @o.name
    o = @o.dup
    @o.accessed_columns.must_equal [:name]
    @o.b
    @o.accessed_columns.sort_by{|s| s.to_s}.must_equal [:b, :name]
    o.accessed_columns.must_equal [:name]
    o2 = o.clone
    o2.refresh
    o.accessed_columns.must_equal [:name]
    o2.accessed_columns.must_equal []
  end

  it "should not raise exceptions when object is frozen" do
    @o.freeze
    @o.name
  end
end

Version data entries

34 entries across 32 versions & 2 rubygems

Version Path
sequel-4.49.0 spec/extensions/accessed_columns_spec.rb
sequel-4.48.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/sequel-4.44.0/spec/extensions/accessed_columns_spec.rb
tdiary-5.0.5 vendor/bundle/gems/sequel-4.47.0/spec/extensions/accessed_columns_spec.rb
tdiary-5.0.5 vendor/bundle/gems/sequel-4.44.0/spec/extensions/accessed_columns_spec.rb
sequel-4.47.0 spec/extensions/accessed_columns_spec.rb
sequel-4.46.0 spec/extensions/accessed_columns_spec.rb
sequel-4.45.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.0.4 vendor/bundle/gems/sequel-4.44.0/spec/extensions/accessed_columns_spec.rb
sequel-4.44.0 spec/extensions/accessed_columns_spec.rb
sequel-4.43.0 spec/extensions/accessed_columns_spec.rb
sequel-4.42.1 spec/extensions/accessed_columns_spec.rb
sequel-4.42.0 spec/extensions/accessed_columns_spec.rb
sequel-4.41.0 spec/extensions/accessed_columns_spec.rb
sequel-4.40.0 spec/extensions/accessed_columns_spec.rb
sequel-4.39.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.0.2 vendor/bundle/gems/sequel-4.37.0/spec/extensions/accessed_columns_spec.rb
sequel-4.38.0 spec/extensions/accessed_columns_spec.rb
sequel-4.37.0 spec/extensions/accessed_columns_spec.rb
sequel-4.36.0 spec/extensions/accessed_columns_spec.rb