Sha256: d54f64fce7a60c6fac571dc0a06236416ca94f8203b1d90458886aa27422654c

Contents?: true

Size: 796 Bytes

Versions: 18

Compression:

Stored size: 796 Bytes

Contents

require_relative "spec_helper"

describe "Sequel::Plugins::AfterInitialize" do
  before do
    @db = Sequel.mock(:host=>'mysql', :numrows=>1)
    @c = Class.new(Sequel::Model(@db[:test]))
    @c.class_eval do
      columns :id, :name
      plugin :after_initialize
      def after_initialize
        self.name *= 2
        self.id *= 3 if id
      end
    end
  end

  it "should have after_initialize hook be called for new objects" do
    @c.new(:name=>'foo').values.must_equal(:name=>'foofoo')
  end

  it "should have after_initialize hook be called for objects loaded from the database" do
    @c.call(:id=>1, :name=>'foo').values.must_equal(:id=>3, :name=>'foofoo')
  end

  it "should not allow .call to be called without arguments" do
    proc{@c.call}.must_raise ArgumentError
  end
end

Version data entries

18 entries across 17 versions & 2 rubygems

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