require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Eotb do describe "shoud format objects" do before do @@counter = 0 end it "should format actor in string" do Eotb.hash_format("actor", :actor).should == {"event0[actor]" => "actor"} end it "should format actor in hash" do Eotb.hash_format({:type => "User"}, :actor).should == {"event0[actor][type]" => "User"} end it "should format actor in nested hash" do Eotb.hash_format({:type => { :account => "User"}}, :actor).should == {"event0[actor][type][account]" => "User"} end end describe "should register data" do before(:each) do @response = "200" Eotb.configure("0"*40) @@counter = 100 Net::HTTP.stub(:new) { Net::HTTP } Net::HTTP.stub(:start) { Net::HTTP } Net::HTTP.stub(:request) { "200" } end it "should register two arguments" do Eotb.register_event("actor", "action").should == @response end it "should register three arguments" do Eotb.register_event("actor", "action", {:username => "John"}).should == @response end it "should register symbols" do Eotb.register_event(:actor, :action, {:username => "John"}).should == @response end it "should register objects" do Eotb.register_event(Object.new, :action, {:username => Object.new}).should == @response end it "should register hashes" do Eotb.register_event({:type => "User"}, :action, {:username => {:first_name => "John"}}).should == @response end it "should register nested hashes" do Eotb.register_event({:type => { :account => "User"}}, :action, {:username => {:first_name => "John"}}).should == @response end it "should register JSON messages" do Eotb.register_event('{"actor":{"type":{"account":"User"}},"action":"action","subject":{"username":{"first_name":"John"}}}').should == @response end it "should register arrays" do Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).should == @response end end describe "should register data in one package" do before(:each) do @response = "200" Eotb.configure("0"*40) @@counter = 96 Net::HTTP.stub(:new) { Net::HTTP } Net::HTTP.stub(:start) { Net::HTTP } Net::HTTP.stub(:request) { "200" } end it "when registering 5 events" do 4.times {Eotb.register_event("actor", "action", {:username => "John"})} Eotb.register_event("actor", "action", {:username => "John"}).should == @response end end end