Skip to content

Commit

Permalink
Be Mongoid forward & backwards compatible:
Browse files Browse the repository at this point in the history
- In Mongoid 3, Criteria#and is provided via Origin, and is no longer an
  alias for #where. It is now used for providing $and selection in
  MongoDB queries. I've modified the get_current_users criteria to use
  #where for each chain, which will be both forwards and backwards
  compatible with Mongoid.
- Also fixed 3 broken specs in the rails3_mongoid tests that could not
  cope with Time.now properly if in a timezone ahead of UTC, like I am
  in Berlin
- Fixes #258.
  • Loading branch information
durran committed Apr 13, 2012
1 parent 244f4ec commit fa44534
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/sorcery/model/adapters/mongoid.rb
Expand Up @@ -72,8 +72,8 @@ def find_by_email(email)
def get_current_users def get_current_users
config = sorcery_config config = sorcery_config
where(config.last_activity_at_attribute_name.ne => nil) \ where(config.last_activity_at_attribute_name.ne => nil) \
.and("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \ .where("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \
.and(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc]) .where(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc])
end end
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion spec/rails3_mongoid/config/mongoid.yml
Expand Up @@ -4,4 +4,4 @@ development:


test: test:
host: localhost host: localhost
database: app_root_test database: app_root_test
8 changes: 4 additions & 4 deletions spec/rails3_mongoid/spec/controller_activity_logging_spec.rb
Expand Up @@ -23,7 +23,7 @@
end end


it "should log login time on login" do it "should log login time on login" do
now = Time.now now = Time.now.utc
login_user login_user
@user.last_login_at.should_not be_nil @user.last_login_at.should_not be_nil
@user.last_login_at.to_s.should >= now.to_s @user.last_login_at.to_s.should >= now.to_s
Expand All @@ -32,7 +32,7 @@


it "should log logout time on logout" do it "should log logout time on logout" do
login_user login_user
now = Time.now now = Time.now.utc
logout_user logout_user
User.first.last_logout_at.should_not be_nil User.first.last_logout_at.should_not be_nil
User.first.last_logout_at.to_s.should >= now.to_s User.first.last_logout_at.to_s.should >= now.to_s
Expand All @@ -41,7 +41,7 @@


it "should log last activity time when logged in" do it "should log last activity time when logged in" do
login_user login_user
now = Time.now now = Time.now.utc
get :some_action get :some_action
User.first.last_activity_at.to_s.should >= now.to_s User.first.last_activity_at.to_s.should >= now.to_s
User.first.last_activity_at.to_s.should <= (now+2).to_s User.first.last_activity_at.to_s.should <= (now+2).to_s
Expand Down Expand Up @@ -102,4 +102,4 @@
@user.last_activity_at.should be_nil @user.last_activity_at.should be_nil
end end
end end
end end

0 comments on commit fa44534

Please sign in to comment.