Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoid support? #38

Closed
h-unterp opened this issue Mar 10, 2014 · 26 comments
Closed

Mongoid support? #38

h-unterp opened this issue Mar 10, 2014 · 26 comments
Milestone

Comments

@h-unterp
Copy link

mongoid support?

@gonzalo-bulnes
Copy link
Owner

Hi @hunterpp,

Why not? Let's build it together, tell me what you need, and I'll make sure to back it with the proper testing.

@austinpray
Copy link

^^^^ Take note. This guy right here is a proper repo owner.

@exocode
Copy link

exocode commented Mar 29, 2014

Declaration for a mongoid model is normally this:

class User < ActiveRecord::Base
  # this is an AR model
end

class Item
  include Mongoid::Document
  # this is a Mongoid model
end

So it seems

ActiveRecord::Base.send :include, SimpleTokenAuthentication::ActsAsTokenAuthenticatable

must be changed to:

Mongoid::Document.send :include, SimpleTokenAuthentication::ActsAsTokenAuthenticatable

.

For ActiveSupport::Validations or similar stuff I do

class Item
  include Mongoid::Document
  include ActiveModel::Validations
  # this is a Mongoid model along with ActiveModel::Validations
end

I hope this helps. Looking forward! :-)

@exocode
Copy link

exocode commented Mar 29, 2014

a working example is here:

https://github.com/mediatainment/simple_token_authentication

I am sure a simple check "if ActiveRecord::Base defined" elsif Mongoid::Document defined" method extends the functionality of this gem for a lot of users.

@gonzalo-bulnes
Copy link
Owner

Hi @mediatainment! I'll be a bit AFK these days, but I'll start building Cucumber scenarii as soon as I can. That was exaclty the help I needed; many many thanks @mediatainment, really.

@exocode
Copy link

exocode commented Mar 31, 2014

Thank YOU! for making this gem! :-)

@gonzalo-bulnes gonzalo-bulnes changed the title mongoid support? Mongoid support? Mar 31, 2014
@gonzalo-bulnes gonzalo-bulnes added this to the v1.3.0 milestone Apr 3, 2014
@Angelmmiguel
Copy link

Is this solved? Now, I'm cloning the repo of @mediatainment. Thanks for these gems! :D

@gonzalo-bulnes
Copy link
Owner

Hi @Angelmmiguel,

Nope, it's work in progress, but your feedback about the @mediatainment fork would be welcome, particularly if your setup mixes Mongoid and ActiveRecord!

@Angelmmiguel
Copy link

Hi @gonzalo-bulnes!

I'm new on ruby on rails, but I'll try it ;). Thanks!

@exocode
Copy link

exocode commented May 3, 2014

it works for me like a charm...

@gonzalo-bulnes
Copy link
Owner

Hi @mediatainment, all,

I'm struggling with Gemfile-related issues in the testing environment, which are not directly related to Mongoid but which are preventing me from writing a Mongoid version of the existing Cucumber scenarii. Just for you know that I'm not forgetting about bringing Mongoid support to the gem :P

The main point is that supporting Mongoid supposes to make sure the gem features will keep working with it in the future, and that's why the test suite is made for. That being said, it occurs that I haven't managed to be really free to use an arbitrary version of Rails when I build the dummy test app, and since Rails 4 get's installed by default, the Mongoid setup fails. I'm looking for solutions to that (which may be more related to Cucumber than they are to Mongoid) and in case someone had time to take a look at it, I could make make a detailed description of the issue, which is a bit off-topic here. That's one point.

Another point, more mongoistic than the previous one: does any of you work with both Mongoid and ActiveRecord in the same application? All the forks I've seen replace one by the another. I'm not familiar with Mongoid, but I don't see any reason why they could not live together. In order to prepare such a testing scenario, any feedback on that would be greatly appreciated.

Thanks for keeping an eye on this issue, best regards!

@exocode
Copy link

exocode commented May 11, 2014

I can only speak for me. No, I do not use these ORM-Adapters simultaneously. All my apps are using one DB per usage. Postgres, MySQL or Mondoid.

@gonzalo-bulnes gonzalo-bulnes modified the milestones: v1.4.0, v1.3.0 May 17, 2014
@a14m
Copy link

a14m commented May 18, 2014

@gonzalo-bulnes ... first of all thanks for the gem... secondly is the mongoid support near ?
also put the reference to the off topic issue you have with mongoid and cucumber... which i might work on in my free time.

@gonzalo-bulnes gonzalo-bulnes modified the milestones: v1.6.0, v1.4.0 May 22, 2014
@prem-prakash
Copy link

I am trying to use @mediatainment fork with no success.

lib/simple_token_authentication/acts_as_token_authenticatable.rb:33:in `<top (required)>': uninitialized constant Mongoid (NameError)

@exocode
Copy link

exocode commented Jun 4, 2014

@prem-prakash are you sure you have installed mongoid correctly?

try

require 'mongoid'

@prem-prakash
Copy link

I am using setup described here: http://mongoid.org/en/mongoid/docs/installation.html
It don't use

require 'mongoid'

In my Gemfile I have

gem 'rails', '4.0.3'
gem 'mongoid', github: 'mongoid/mongoid'
gem 'simple_token_authentication', github: 'mediatainment/simple_token_authentication'

Also my models are using mongoid with no problem.

@prem-prakash
Copy link

Adding

require 'mongoid'

to beginning of lib//simple_token_authentication/acts_as_token_authenticatable.rb
make it works

@gonzalo-bulnes
Copy link
Owner

Hi @prem-prakash,

Thanks for the feedback, I wonder what in your setup is different from the @mediatainment (and others) setup.

@prem-prakash
Copy link

Hi @gonzalo-bulnes and @mediatainment
As I can see it is a dependency problem, which can be solved at gemspec file.
I will make a pull request.

@oliviermilla
Copy link

Any update on this?

@a14m
Copy link

a14m commented Sep 18, 2014

@mediatainment Fork works fine for me...

@gonzalo-bulnes
Copy link
Owner

Hi @muichkine,

there are little news in #97, and the @mediatainment fork is a good way to go in the meanwhile : )

Regards!

@oliviermilla
Copy link

The @mediatainment fork doesn't work here. As soon as I call acts_as_token_authentication_handler_for User in my controller, I can't start the server and get the following error:

muichkine@ubuntu:~/src/white$ rails s
=> Booting Puma
=> Rails 4.1.6 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/home/muichkine/src/white/app/models/user.rb:18:in `<class:User>': undefined method `devise' for User:Class (NoMethodError)
from /home/muichkine/src/white/app/models/user.rb:1:in `<top (required)>'

As soon as I remove the call from the controller, my devise codes go back to normal. :)

@gonzalo-bulnes
Copy link
Owner

Hi @mediatainment, (and anyone interested!)

If you have a moment, could you please take a look and give a try to this?

# Gemfile

# ...

gem 'simple_token_authentication',
    git: 'https://github.com/gonzalo-bulnes/simple_token_authentication.git',
    branch: 'spike-add-mongoid-support-using-adapter'

# ...

Thanks, regards!

gonzalo-bulnes added a commit that referenced this issue Oct 24, 2014
Add Mongoid as development dependency
Add, enable MongoidAdapter

Thanks to @mediatainment who contributed the "Mongoid support" part
of this this commit a long time before it became production-ready and
who litterally ensured the support for users in the meantime.
See https://github.com/mediatainment/simple_token_authentication/ \
commit/6b30379ebed0f277487b63f3ec1e29129d598196

Fixes #38
@gonzalo-bulnes gonzalo-bulnes removed needs testing work in progress This could be a draft pull request, have you thought of that? labels Oct 24, 2014
@gonzalo-bulnes
Copy link
Owner

Hello @hunterpp, @austinpray, @mediatainment, @Angelmmiguel, @artmees, @prem-prakash and @muichkine!

I just released v1.6.0 which add support for Mongoid. I want to thank all of you for your comments and observations. Also for your patience which has been a great motivator to perform some deep refactoring (#104). The result is a speedy test suite which, I hope, is also easier for everyone to extend and will be beneficial in other scenarios. Here's 🎁 Mongoid support, looking forward for new ideas ; )

I checked the details with Rails 3.2.19 + Mongoid 3.1.6 and Rails 4.1.6 + Mongoid 4.0.0, both with and without ActiveRecord. Please, don't hesitate to raise any issue I could have missed, I'm sure most of you know more about Mongoid than I do.

Regards!

@austinpray
Copy link

🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants