spec/user_spec.rb in rhosync-2.0.9 vs spec/user_spec.rb in rhosync-2.1.0.beta.1
- old
+ new
@@ -1,17 +1,21 @@
require File.join(File.dirname(__FILE__),'spec_helper')
+STATS_RECORD_RESOLUTION = 2 unless defined? STATS_RECORD_RESOLUTION
+STATS_RECORD_SIZE = 8 unless defined? STATS_RECORD_SIZE
+
describe "User" do
it_should_behave_like "SpecBootstrapHelper"
it_should_behave_like "SourceAdapterHelper"
it "should create user with fields" do
@u.id.should == @u_fields[:login]
@u1 = User.load(@u_fields[:login])
@u1.id.should == @u.id
@u1.login.should == @u_fields[:login]
@u1.email.should == @u_fields[:email]
+ Store.get_value('user:count').should == "1"
end
it "should delete seats for user's clients" do
Client.create(@c_fields,{:source_name => @s_fields[:name]})
c_size = @u.clients.members.size
@@ -64,16 +68,56 @@
it "should delete user and user clients" do
@c.put_data(:cd,@data)
cid = @c.id
@u.delete
+ Store.get_value('user:count').should == "0"
User.is_exist?(@u_fields[:login]).should == false
Client.is_exist?(cid).should == false
@c.get_data(:cd).should == {}
end
it "should delete token for user" do
token = @u.create_token
@u.delete
ApiToken.is_exist?(token).should == false
+ end
+
+ describe "User Stats" do
+
+ before(:all) do
+ Store.stub!(:lock).and_yield
+ end
+
+ before(:each) do
+ Rhosync::Stats::Record.reset('users')
+ end
+
+ after(:each) do
+ Rhosync::Stats::Record.reset('users')
+ end
+
+ after(:all) do
+ Store.flash_data('stat:users*')
+ end
+
+ it "should increment user stats on create" do
+ Time.stub!(:now).and_return(10)
+ Rhosync.stats = true
+ User.create({:login => 'testuser2'})
+ Rhosync::Stats::Record.range('users',0,-1).should == ["2:10"]
+ Store.get_value('user:count').should == "2"
+ Rhosync.stats = false
+ end
+
+ it "should decrement user stats on delete" do
+ Time.stub!(:now).and_return(10)
+ Rhosync.stats = true
+ u = User.create({:login => 'testuser1'})
+ Rhosync::Stats::Record.range('users',0,-1).should == ["2:10"]
+ u.delete
+ Rhosync::Stats::Record.range('users',0,-1).should == ["1:10"]
+ Store.get_value('user:count').should == "1"
+ Rhosync.stats = false
+ end
end
end
\ No newline at end of file