Sha256: 49d6d89c3f36e435970c3f07a8654a086fceebc21eb45ac1096410c51ed29fff

Contents?: true

Size: 1.22 KB

Versions: 45

Compression:

Stored size: 1.22 KB

Contents

require_relative "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

45 entries across 41 versions & 2 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/spec/extensions/accessed_columns_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/spec/extensions/accessed_columns_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/spec/extensions/accessed_columns_spec.rb
sequel-5.29.0 spec/extensions/accessed_columns_spec.rb
sequel-5.28.0 spec/extensions/accessed_columns_spec.rb
sequel-5.27.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.1.0 vendor/bundle/gems/sequel-5.26.0/spec/extensions/accessed_columns_spec.rb
sequel-5.26.0 spec/extensions/accessed_columns_spec.rb
sequel-5.25.0 spec/extensions/accessed_columns_spec.rb
sequel-5.24.0 spec/extensions/accessed_columns_spec.rb
sequel-5.23.0 spec/extensions/accessed_columns_spec.rb
sequel-5.22.0 spec/extensions/accessed_columns_spec.rb
sequel-5.21.0 spec/extensions/accessed_columns_spec.rb
sequel-5.20.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.0.13 vendor/bundle/gems/sequel-5.18.0/spec/extensions/accessed_columns_spec.rb
sequel-5.19.0 spec/extensions/accessed_columns_spec.rb
tdiary-5.0.12.1 vendor/bundle/gems/sequel-5.18.0/spec/extensions/accessed_columns_spec.rb
sequel-5.18.0 spec/extensions/accessed_columns_spec.rb
sequel-5.17.0 spec/extensions/accessed_columns_spec.rb
sequel-5.16.0 spec/extensions/accessed_columns_spec.rb