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

Adding mongoid support #123

Closed
wants to merge 16 commits into from
Closed

Adding mongoid support #123

wants to merge 16 commits into from

Conversation

jeremylynch
Copy link
Contributor

I have reintroduced mongoid support. It is working with the exception of the top_scored method .

I have tested this completely with mongoid 3.1.5 and rails 3.2.15

I could not get the mongoid-dummy app to run for some reason, I might look into this later.

Todo: update generators to work with mongoid projects.

@jeremylynch jeremylynch mentioned this pull request Jan 9, 2014
@@orm = :mongoid
else
@@orm = :active_record
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this if construct. @@orm is by default active_record, and can be overridden in the initializer.

@tute
Copy link
Member

tute commented Jan 10, 2014

When this looks good to both of us I'll merge. I'll do it "silently" (without broadcasting in the README) cause I don't work with (and thus can't reliably maintain) other ORMs for now.
Thank you very much for your work!

Also moved common methods between AR and mongoid to a base class
@jeremylynch
Copy link
Contributor Author

OK @tute check it out, updated to your needs. When you decide to merge this over, I think it would be best to broadcast it in the readme. There are Mongoid developers like myself who can keep the code updated, and if it was broadcast in the readme more mongoid developers would use it leading to further development (and bug feedback etc). Let me know if you decide to go through with this and i'll update the readme for directions on how to use the gem with mongoid.
Thanks,

@tute
Copy link
Member

tute commented Jan 15, 2014

Looking way better! @potomak and @huacnlee will probably be interested in this PR/discussion.

Aside, would be nice to add back mongoid testing, in the form of the following block to .travis.yml, and take into account ORM specifics in test_helper.rb https://github.com/tute/merit/blob/3ee9e5830322d54db502bbf31af53c58e30b2c54/test/test_helper.rb (don't remember if anything else, probably the dummy app is old):

 env:
    - ORM=activerecord
    - ORM=mongoid

@@ -45,13 +45,17 @@ class Engine < Rails::Engine
config.app_generators.orm Merit.orm

initializer 'merit.controller' do |app|
require 'merit/models/base/base/sash'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why base/base/? Should be merit/base/.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, ill fix this

@jeremylynch
Copy link
Contributor Author

Check it out now @tute I have addressed everything you mentioned with the exception of fixing up the dummy app. Let me know your thoughts, thanks

require "merit/models/#{Merit.orm}/merit/activity_log"
require "merit/models/#{Merit.orm}/merit/badges_sash"
require "merit/models/#{Merit.orm}/merit/sash"
require "merit/models/#{Merit.orm}/merit/score"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tute
Copy link
Member

tute commented Jan 19, 2014

Looking great, we are very close! Dummy app should be fixed, I can do it after merge I guess.

Can you please rebase on top of current master, so it's mergeable again?

Left a few comments, as always, thank you very much for your work!


belongs_to :action, class_name: 'Merit::Action'
belongs_to :related_change, polymorphic: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny comments (ok to ignore): stray newline.

@jeremylynch
Copy link
Contributor Author

Take a look @tute, let me know what you think and we can look at rebasing if you think that it's ready

require "merit/models/#{Merit.orm}/merit/activity_log"
require "merit/models/#{Merit.orm}/merit/badges_sash"
require "merit/models/#{Merit.orm}/merit/sash"
require "merit/models/#{Merit.orm}/merit/score"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

include Mongoid::Timestamps
include Base::Sash

belongs_to :user, class_name: 'User'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Sash belongs to a "meritable model", which happens to be User many times, but it's not always the case. We should be able to attach sashes to any model in the app, this won't pass the "dummy app" tests, where comments also hold reputation.

@tute
Copy link
Member

tute commented Jan 28, 2014

Looking really good! Should we pair to wrap it up? Specially the test app. We should decide how to attach sashes to arbitrary models in Mongoid first.

@jeremylynch
Copy link
Contributor Author

Sorry @tute. Yes lets wrap this up. We could always make a one sided relationship, so @user.sash => sash and @comment.sash => sash while @sash.user => undefined
To do this we would just need to remove the belongs_to :user from the sash modal

@tute
Copy link
Member

tute commented Feb 4, 2014

It seems AR doesn't have the Sash.belongs_to (https://github.com/tute/merit/blob/master/lib/merit/models/active_record/merit/sash.rb), so it should be fine. If we remove it, and rebase history on top of master, I can take care of the testing through the dummy app. Thank you!

@jeremylynch
Copy link
Contributor Author

Ok, have a look @tute, I've rebased on master, I think it should be ready to pull

@tute
Copy link
Member

tute commented Feb 4, 2014

Thanks @mrjlynch. Though you may have rebased with master on your repository, you need to fetch from tute/merit. It seems that you rebased with a commit from December but there's new changes: https://github.com/tute/merit/commits/master.
Thank you!

@tute
Copy link
Member

tute commented Feb 4, 2014

There's actually duplicate commits, and a merge. I'll do it myself, and fix the tests. Thanks a lot!

tute added a commit that referenced this pull request Feb 4, 2014
@tute
Copy link
Member

tute commented Feb 4, 2014

Merged from the command line, thanks for your help! :)

@tute tute closed this Feb 4, 2014
@jeremylynch
Copy link
Contributor Author

Great, Thanks Tute!

@jeremylynch
Copy link
Contributor Author

Can we also update the readme?

@tute
Copy link
Member

tute commented Feb 4, 2014

Can't make it work @mrjlynch, and got late. If you want to fix tests in current master ($ ORM=mongoid rake, added necessary infrastructure), you are very welcome!

For now, code seems closer to work with mongoid, but won't update the README until it works well. Thanks for the work!

@tagrudev
Copy link

any progress ?

@jeremylynch
Copy link
Contributor Author

@tagrudev I am no longer using this gem with mongoid, everything should work though, the specs just don't pass. Feel free to update them.

@ajpauwels
Copy link

@mrjlynch @tute I can't seem to get Merit to install on a Mongoid setup. rails g merit:install gives module:Merit': uninitialized constant Merit::ActiveRecord (NameError)`

I went into /lib/merit.rb, commented out @config.orm || :active_record and replaced it with @config.orm = :mongoid.

The install went through this time as far as copying over the files, but it gave an error mongoid [not found].

However, I went into the rails console and created a Badge which went through fine, and then added that Badge to my user which also seems to have succeeded:

2.1.2 :007 > @user.add_badge(1)
 => #<Merit::BadgesSash _id: 54244b2b616c651989000000, created_at: 2014-09-25 17:04:43 UTC, updated_at: 2014-09-25 17:04:43 UTC, sash_id: BSON::ObjectId('542447e0616c651960000000'), badge_id: 1> 

I can do @user.badges just fine, it'll return the badge. However, when I try to use @user.rm_badge(1), the function returns => true but when I do @user.badges, the old badge still shows up.

Any suggestions?

UPDATE: So it seems that the badge is removed, but that change isn't reflected immediately in @user. If I remove the badge, set @user = nil, get it again with @user = User.first, and then do @user.badges, the array is empty.

I apologize for my ignorance, but is this expected behavior?

@tute
Copy link
Member

tute commented Sep 25, 2014

You can also do @user.reload and see the change, indeed it is expected.

Though to be 100% sure that it works in mongoid, a Pull Request that reenables CI and gets it green would be needed. See: https://github.com/tute/merit/blob/master/.travis.yml#L14-L16.

@nahankid
Copy link

nahankid commented Mar 1, 2015

I still can't get merit to work with only mongoid. Here are the issues I run into:

  1. When I run rails g merit:install, it gives me `module:Merit': uninitialized constant Merit::ActiveRecord (NameError)
  2. After adding merit.rb in config/initializers, with config.orm:mongoid, i can get past rails g merit:install but it still generates some migrations. It generates mongoid models too. Why AR migrations at all?

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

Successfully merging this pull request may close these issues.

5 participants