File: columns_updated_spec.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require_relative "spec_helper"

describe "Sequel::Plugins::ColumnsUpdated" do
  before do
    @c = Class.new(Sequel::Model(DB[:items].with_autoid(13)))
    @c.columns :id, :x, :y
    @c.plugin :columns_updated
  end
  
  it "should make hash used for updating available in columns_updated until after hooks finish running" do
    res = nil
    @c.send(:define_method, :after_save){res = columns_updated}
    o = @c.new(:x => 1, :y => nil)
    o[:x] = 2
    o.save
    res.must_be_nil
    o.after_save
    res.must_be_nil

    o = @c.load(:id => 23,:x => 1, :y => nil)
    o[:x] = 2
    o.save
    res.must_equal(:x=>2, :y=>nil)
    o.after_save
    res.must_be_nil

    o = @c.load(:id => 23,:x => 2, :y => nil)
    o[:x] = 2
    o[:y] = 22
    o.save(:columns=>:x)
    res.must_equal(:x=>2)
    o.after_save
    res.must_be_nil
  end
end