Sha256: 9923f636ee961858ed624259e870c7544be85af16d0ef797ba347e80837d5ea7

Contents?: true

Size: 726 Bytes

Versions: 34

Compression:

Stored size: 726 Bytes

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "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
end

Version data entries

34 entries across 32 versions & 2 rubygems

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