Skip to content

Commit

Permalink
Merge pull request #259 from durran/mongoid-compatibility
Browse files Browse the repository at this point in the history
Be Mongoid forward & backwards compatible:
  • Loading branch information
NoamB committed Apr 13, 2012
2 parents 244f4ec + fa44534 commit ba30e86
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
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
Expand Down
2 changes: 1 addition & 1 deletion spec/rails3_mongoid/config/mongoid.yml
Expand Up @@ -4,4 +4,4 @@ development:

test:
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

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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -102,4 +102,4 @@
@user.last_activity_at.should be_nil
end
end
end
end

0 comments on commit ba30e86

Please sign in to comment.