Permalink
Browse files

Be Mongoid forward & backwards compatible:

- 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...
1 parent 244f4ec commit fa4453410c8467937bf31d2eb4d35f4c1f9e449a @durran durran committed Apr 13, 2012
@@ -72,8 +72,8 @@ def find_by_email(email)
def get_current_users
config = sorcery_config
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}") \
- .and(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc])
+ .where("this.#{config.last_logout_at_attribute_name} == null || this.#{config.last_activity_at_attribute_name} > this.#{config.last_logout_at_attribute_name}") \
+ .where(config.last_activity_at_attribute_name.gt => config.activity_timeout.seconds.ago.utc).order_by([:_id,:asc])
end
end
end
@@ -4,4 +4,4 @@ development:
test:
host: localhost
- database: app_root_test
+ database: app_root_test
@@ -23,7 +23,7 @@
end
it "should log login time on login" do
- now = Time.now
+ now = Time.now.utc
login_user
@user.last_login_at.should_not be_nil
@user.last_login_at.to_s.should >= now.to_s
@@ -32,7 +32,7 @@
it "should log logout time on logout" do
login_user
- now = Time.now
+ now = Time.now.utc
logout_user
User.first.last_logout_at.should_not be_nil
User.first.last_logout_at.to_s.should >= now.to_s
@@ -41,7 +41,7 @@
it "should log last activity time when logged in" do
login_user
- now = Time.now
+ now = Time.now.utc
get :some_action
User.first.last_activity_at.to_s.should >= now.to_s
User.first.last_activity_at.to_s.should <= (now+2).to_s
@@ -102,4 +102,4 @@
@user.last_activity_at.should be_nil
end
end
-end
+end

0 comments on commit fa44534

Please sign in to comment.