spec/publish_spec.rb in resque-bus-0.3.2 vs spec/publish_spec.rb in resque-bus-0.3.3

- old
+ new

@@ -42,19 +42,40 @@ hash = JSON.parse(val) hash["class"].should == "ResqueBus::Driver" hash["args"].should == [ {"bus_event_type" => event_name, "two"=>"here", "one"=>1}.merge(bus_attrs).merge("bus_id" => 'app-given') ] end + it "should add metadata via callback" do + myval = 0 + ResqueBus.before_publish = lambda { |att| + att["mine"] = 4 + myval += 1 + } + hash = {:one => 1, "two" => "here", "bus_id" => "app-given" } + event_name = "event_name" + + val = ResqueBus.redis.lpop("queue:resquebus_incoming") + val.should == nil + + ResqueBus.publish(event_name, hash) + + + val = ResqueBus.redis.lpop("queue:resquebus_incoming") + hash = JSON.parse(val) + att = hash["args"].first + att["mine"].should == 4 + myval.should == 1 + end it "should set the timezone and locale if available" do defined?(I18n).should be_nil Time.respond_to?(:zone).should be_false stub_const("I18n", Class.new) - I18n.should_receive(:locale).and_return("jp") + I18n.stub(:locale).and_return("jp") - Time.should_receive(:zone).and_return(double('zone', :name => "EST")) + Time.stub(:zone).and_return(double('zone', :name => "EST")) hash = {:one => 1, "two" => "here", "bus_id" => "app-given" } event_name = "event_name" val = ResqueBus.redis.lpop("queue:resquebus_incoming")