Sha256: cd63f484bb749ec60841beadd4e923d52f29707da52458175c0abf71c1e35840

Contents?: true

Size: 1004 Bytes

Versions: 35

Compression:

Stored size: 1004 Bytes

Contents

require File.dirname(__FILE__) + '/spec_helper'

module TriggerSpec
	
	class TriggeredObject < RedisObject
		
		int :raw_phone
		bool :mailed_flag
		bool :mail_was_sent_for_realz
		date :srsly_updated
		
		def track_phone_raw(k,v)
			set(:raw_phone, v.gsub(/[^0-9]/,'').to_i)
		end
		
		trigger_on_set :phone, :track_phone_raw
		
		def sent_mail(k,v)
			set(:mail_was_sent_for_realz, true)
		end
		
		def updated_redundant(k,v)
			set(:srsly_updated, Time.now)
		end
		
		trigger_on_set :mailed_flag, :sent_mail
		trigger_on_update :updated_redundant
		
	end
	
	describe Seabright::Triggers do
		before do
			RedisObject.store.flushdb
		end
		
		it "triggers on a call" do
			
			obj = TriggeredObject.create("trig")
			
			obj.phone = "(970) 555-1212"
			obj.raw_phone.should eq(9705551212)
			success = obj.setnx(:mailed_flag,true)
			success.should eq(true)
			obj.mail_was_sent_for_realz.should eq(true)
			success = obj.setnx(:mailed_flag,true)
			success.should eq(false)
			
		end
						
	end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
redis_object-1.3.1 spec/trigger_spec.rb
redis_object-1.3.0 spec/trigger_spec.rb
redis_object-1.2.9b spec/trigger_spec.rb
redis_object-1.2.9 spec/trigger_spec.rb
redis_object-1.2.8 spec/trigger_spec.rb
redis_object-1.2.7 spec/trigger_spec.rb
redis_object-1.2.6 spec/trigger_spec.rb
redis_object-1.2.5 spec/trigger_spec.rb
redis_object-1.2.4 spec/trigger_spec.rb
redis_object-1.2.3 spec/trigger_spec.rb
redis_object-1.2.2 spec/trigger_spec.rb
redis_object-1.2.1 spec/trigger_spec.rb
redis_object-1.2 spec/trigger_spec.rb
redis_object-1.1 spec/trigger_spec.rb
redis_object-0.5.0 spec/trigger_spec.rb