spec/mixpanel/tracker_spec.rb in mixpanel-4.0.5 vs spec/mixpanel/tracker_spec.rb in mixpanel-4.0.6

- old
+ new

@@ -125,18 +125,22 @@ it "should be the same the queue than env['mixpanel_events']" do @mixpanel.instance_variable_get(:@env)['mixpanel_events'].object_id.should == @mixpanel.queue.object_id end it "should append simple events" do - props = { :time => Time.now, :ip => 'ASDF' } + time = Time.now + props = { :time => time, :ip => 'ASDF' } @mixpanel.append_track "Sign up", props + props[:time] = time.to_i mixpanel_queue_should_include(@mixpanel, "track", "Sign up", props) end it "should append events with properties" do - props = { :referer => 'http://example.com', :time => Time.now, :ip => 'ASDF' } + time = Time.now + props = { :referer => 'http://example.com', :time => time, :ip => 'ASDF' } @mixpanel.append_track "Sign up", props + props[:time] = time.to_i mixpanel_queue_should_include(@mixpanel, "track", "Sign up", props) end it "should give direct access to queue" do @mixpanel.append_track("Sign up", {:referer => 'http://example.com'}) @@ -152,10 +156,15 @@ props = {:user_id => 12345, :gender => 'male'} @mixpanel.append_register props mixpanel_queue_should_include(@mixpanel, 'register', props) end + it "should allow the tracking of charges in JS" do + @mixpanel.append_track_charge 40 + mixpanel_queue_should_include(@mixpanel, 'people.track_charge', 40) + end + it "should allow alias to be called through the JS api" do @mixpanel.append_alias "new_id" mixpanel_queue_should_include(@mixpanel, "alias", "new_id") end @@ -190,8 +199,25 @@ Mixpanel::Tracker.dispose_worker(w) w.closed?.should == true w2 = Mixpanel::Tracker.worker w2.should_not == w + end + end + + describe '#properties_hash' do + it "base64encodes json formatted data" do + properties = { :a => 4, :b => "foo"} + special_properties = ["a"] + hash = @mixpanel.send(:properties_hash, properties, special_properties) + hash.should eq({ :'$a' => 4, :b => "foo"}) + end + + it "converts Time objects into integers" do + time = Time.new + properties = { :a => time, :b => "foo"} + special_properties = [] + hash = @mixpanel.send(:properties_hash, properties, special_properties) + hash.should eq({ :a => time.to_i, :b => "foo"}) end end end