Sha256: 9b9204f2e6cd15e6abe4e76837c7cdfcc6a5b00cae0efff3cd91dafc25a1efa3
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
require File.expand_path("./helper", File.dirname(__FILE__)) $VERBOSE = false class Ad < Ohm::Model end test "counters aren't overwritten by competing saves" do Ad.counter :hits instance1 = Ad.create instance1.incr :hits instance2 = Ad[instance1.id] instance1.incr :hits instance1.incr :hits instance2.save instance1 = Ad[instance1.id] assert_equal 3, instance1.hits end test "you can increment counters even when attributes is empty" do Ad.counter :hits ad = Ad.create ad = Ad[ad.id] ex = nil begin ad.incr :hits rescue ArgumentError => e ex = e end assert_equal nil, ex end test "an attribute gets saved properly" do Ad.attribute :name Ad.counter :hits ad = Ad.create(name: "foo") ad.incr :hits, 10 assert_equal 10, ad.hits # Now let's just load and save it. ad = Ad[ad.id] ad.save # The attributes should remain the same ad = Ad[ad.id] assert_equal "foo", ad.name assert_equal 10, ad.hits # If we load and save again while we incr behind the scenes, # the latest counter values should be respected. ad = Ad[ad.id] ad.incr :hits, 5 ad.save ad = Ad[ad.id] assert_equal 15, ad.hits end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ohm-1.0.0.rc1 | test/counters.rb |
ohm-1.0.0.alpha2 | test/counters.rb |
ohm-1.0.0.alpha1 | test/counters.rb |