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

remove one more Mongoid dependency when rescuing from _invoke #54

Merged

Conversation

alexagranov
Copy link
Collaborator

No description provided.

@alexagranov alexagranov force-pushed the no_mongoid_exception_on_activerecord branch 7 times, most recently from b83b935 to eeec1e1 Compare March 25, 2017 22:59
@dblock
Copy link
Collaborator

dblock commented Mar 25, 2017

Do you think you could try and add a test for this? There should be a way to raise a validation error and get a failure in the AR version.

@alexagranov
Copy link
Collaborator Author

alexagranov commented Mar 25, 2017

Ok. I can add for AR, just realized the specs are using sample_apps/sample_app_activerecord/config/postgresql.yml instead of just in root dir or config/ so I hadn't been running specs locally...

if defined?(::Mongoid)
def invoke(client, data)
_invoke client, data
rescue Mongoid::Errors::Validations => e
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really should refactor this out of here, but I am not sure how or where. I am OK with this change for now, just thinking out loud.

Copy link
Collaborator Author

@alexagranov alexagranov Mar 26, 2017

Choose a reason for hiding this comment

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

ya, maybe the wrapping of invoke needs to be done in DB-specific dirs under ext/?

@alexagranov alexagranov force-pushed the no_mongoid_exception_on_activerecord branch 2 times, most recently from 0a18a45 to 7283748 Compare March 26, 2017 00:48
@alexagranov
Copy link
Collaborator Author

alexagranov commented Mar 26, 2017

Just pushed up a spec. This should handle the StandardError case at least.

Not sure if spec/ext/ is best location but happy to change.

Btw, noticed locally that selenium tests fail as I'm on FF 52 and selenium-webdriver is pinned to 2.x series? Is there a reason not to move up to 3.3.0?

@alexagranov alexagranov force-pushed the no_mongoid_exception_on_activerecord branch 2 times, most recently from dbd08c2 to 4d1c38b Compare March 26, 2017 00:55
@dblock
Copy link
Collaborator

dblock commented Mar 26, 2017

Ok this is great, now add a mongoid spec? You can raise a validation error by creating a dummy model with a validates_presence_of for example and trying to save it.

Any version of Selenium works as long as specs pass green here, but it's a permanent struggle of upgrading versions all around.

@alexagranov
Copy link
Collaborator Author

Sounds good but that may take a little longer - I don't want to put Mongo on this box so would need to rely on Travis or a docker VM.

What do you think of ext/activerecord and ext/mongoid to hold separate versions of slack-ruby-bot/commands/base.rb?

And yep, I hear ya on Selenium, was just wondering if its a Travis limitation perhaps but I just double-checked and Travis can pull down latest FF.

@dblock
Copy link
Collaborator

dblock commented Mar 26, 2017

Re: separate version locations works for me.

Btw you can download mongo and start it temporarily, it's self contained.

@alexagranov
Copy link
Collaborator Author

Oh ya? Shazam. I don't remember that, let me give it a whirl...

@alexagranov alexagranov force-pushed the no_mongoid_exception_on_activerecord branch from 4d1c38b to 0a3fc20 Compare March 27, 2017 23:45
@alexagranov
Copy link
Collaborator Author

alexagranov commented Mar 27, 2017

Ok, Mongoid validation exception handling spec added. Along with splitting the SlackRubyBot::Commands::Base into separate AR and Mongoid versions.

That self-contained binary is handy, I didn't want to mess with homebrew 🍻

require_relative "slack-ruby-bot/#{ext}"
end
require_relative 'slack-ruby-bot/client'
require_relative 'activerecord/slack-ruby-bot/commands/base' if defined?(::ActiveRecord)
Copy link
Collaborator

@dblock dblock Mar 28, 2017

Choose a reason for hiding this comment

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

This should be require_relative "{SlackRubyBotServer::Config.database_adapter}/slack-ruby-but/commands/base" which reads cleaner and is forward compatible for other adapters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes indeed, will do.

@dblock
Copy link
Collaborator

dblock commented Mar 28, 2017

See minor comment above, almost there. Thanks!

end
end

if SlackRubyBotServer::Config.mongoid?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would refactor this into a separate spec, maybe with a directory structure similar to the code, even if it means a bit of duplication, for future adapter-type variations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, coming up.

@alexagranov alexagranov force-pushed the no_mongoid_exception_on_activerecord branch from 0a3fc20 to 656e53c Compare March 28, 2017 23:43
@alexagranov
Copy link
Collaborator Author

OK, updated with suggestions. There was some difficulty with conditionally loading the DB-specific specs from ext/ though:

I wasn't able to use just use describe '...', if: defined?(::Mongoid) or similar as it appears the MockDocument class is loaded prior to the RSpec DSL kicking in - thereby causing a ClassNotFound exception when trying to run AR only specs.

I hope you're ok with adding the exclusion pattern in Rakefile to avoid any specs under ext/ not under the current DB adapter dir.

@@ -5,7 +5,7 @@ require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV['DATABASE_ADAPTER']})})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, I like it.

@dblock dblock merged commit a7a90c4 into slack-ruby:master Mar 29, 2017
@dblock
Copy link
Collaborator

dblock commented Mar 29, 2017

Perfect, merged.

@dblock
Copy link
Collaborator

dblock commented Mar 29, 2017

@alexagranov Want to help with this library? Maybe make a release?

I would be very happy to invite you to contributors and give you rubygems access (what's your rubygems email?).

@alexagranov alexagranov deleted the no_mongoid_exception_on_activerecord branch March 29, 2017 03:10
@alexagranov
Copy link
Collaborator Author

@dblock Sure, I can lend a hand. If all goes well I'll be leveraging this library quite a bit...

I use the same email as my GitHub account for Rubygems: alex@morphogenic.net

@dblock
Copy link
Collaborator

dblock commented Mar 29, 2017

You're in @alexagranov!

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

Successfully merging this pull request may close these issues.

2 participants