Sha256: 2c16197f2606a0ddc37d0588bd493eddd5b83d53d997bb9ce02141e7c0f670ee

Contents?: true

Size: 871 Bytes

Versions: 20

Compression:

Stored size: 871 Bytes

Contents

# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))

if defined?(Ohm::Model::PureRuby)
  class User < Ohm::Model
    attribute :email

    attr_accessor :foo

    def save
      super do |t|
        t.before do
          self.email = email.downcase
        end

        t.after do
          if @foo
            key[:foos].sadd(@foo)
          end
        end
      end
    end

    def delete
      super do |t|
        foos = nil

        t.before do
          foos = key[:foos].smembers
        end

        t.after do
          foos.each { |foo| key[:foos].srem(foo) }
        end
      end
    end
  end

  test do
    u = User.create(:email => "FOO@BAR.COM", :foo => "bar")
    assert_equal "foo@bar.com", u.email
    assert_equal ["bar"], u.key[:foos].smembers

    u.delete
    assert_equal [], User.key[u.id][:foos].smembers
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ohm-1.4.0 test/extensibility.rb
ohm-2.0.0.alpha5 test/extensibility.rb
ohm-2.0.0.alpha4 test/extensibility.rb
ohm-2.0.0.alpha3 test/extensibility.rb
ohm-2.0.0.alpha2 test/extensibility.rb
ohm-2.0.0.alpha1 test/extensibility.rb
ohm-1.3.2 test/extensibility.rb
ohm-1.3.1 test/extensibility.rb
ohm-1.3.0 test/extensibility.rb
ohm-1.2.0 test/extensibility.rb
ohm-1.1.2 test/extensibility.rb
ohm-1.1.1 test/extensibility.rb
ohm-1.1.0 test/extensibility.rb
ohm-1.1.0.rc1 test/extensibility.rb
ohm-1.0.2 test/extensibility.rb
ohm-1.0.1 test/extensibility.rb
ohm-1.0.0 test/extensibility.rb
ohm-1.0.0.rc4 test/extensibility.rb
ohm-1.0.0.rc3 test/extensibility.rb
ohm-1.0.0.rc2 test/extensibility.rb