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

Add support for Nobrainer (RethinkDB) #522

Merged
merged 1 commit into from Feb 13, 2018
Merged

Add support for Nobrainer (RethinkDB) #522

merged 1 commit into from Feb 13, 2018

Conversation

zedtux
Copy link
Contributor

@zedtux zedtux commented Jan 12, 2018

  • Add persistence for NoBrainer
  • Add tests for NoBrainer
  • Show the ORM version when running the tests
  • Add a Dockerfile and a docker-compose.yml file allowing to run from anywhere very easily the test suite with `docker-compose run --rm aasm'
  • Moves the Mongoid database name definition in the gem loader (avoiding code repetition)
  • Update the CHANGELOG.md and the README.md files
  • Add Rails generator for NoBrainer

FYI I had to create new Appraisals for NoBrainer as there is a conflict with Mongoid.

This contribution is in the name of Pharmony!

@zedtux
Copy link
Contributor Author

zedtux commented Jan 12, 2018

The builds for the Rubies are passing now! Ready for merge 😎

@anilmaurya
Copy link
Member

@zedtux Thank you for your efforts 👍

I will review and merge in couple of days .

require 'spec_helper'

if defined?(NoBrainer::Document)
require 'nobrainer'

Choose a reason for hiding this comment

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

the require seems unecessary, as NoBrainer::Document is already defined (so the require is already done)


after do
NoBrainer.purge!
end

Choose a reason for hiding this comment

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

From the describe to here, All this should be global to the rspec test (in rspec_spec? or rspec_spec_nobrainer?), not per test file

Choose a reason for hiding this comment

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

Also, consider doing the purge! in config.before(:each) { }, not after. This is because if the previous test crashes or hangs for whatever reason, the after block won't be run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well then it's conflicting with your previous comment:

Things that are not specific to NoBrainer should probably be in a separate pull request. [...]

I would have to update the spec/unit/persistence/mongoid_persistence_spec.rb, spec/unit/persistence/mongoid_persistence_mutliple_spec.rb, spec/unit/persistence/no_brainer_persistence_spec.rb and spec/unit/persistence/no_brainer_persistence_mutliple_spec.rb files.


rethinkdb_url = "rethinkdb://#{ENV['RETHINKDB_HOST'] || 'localhost'}:"
rethinkdb_url << "#{ENV['RETHINKDB_PORT'] || 28015}/"
rethinkdb_url << "#{ENV['RETHINKDB_DB'] || "nobrainer_#{Process.pid}"}"

Choose a reason for hiding this comment

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

Don't use the Process.pid. Use "aasm_test" instead. This is because are using a new database every time you run the test, resulting in a lot of garbage that won't get cleaned up.

Also if you do this:

NoBrainer.configure do |config|
  config.app_name = :aasm
  config.environment = :test
end

You should be good. NoBrainer will figure out how to use the ENV variables

begin
require 'redis-objects'
puts "redis-objects gem found, running Redis specs \e[32m#{'✔'}\e[0m"

Choose a reason for hiding this comment

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

Things that are not specific to NoBrainer should probably be in a separate pull request. Same for Mongoid, and Sequel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anilmaurya do you want a spearated PR for those changes?

Copy link
Member

Choose a reason for hiding this comment

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

@zedtux It make sense to send separate PR for changes which are not specific to NoBrainer.

Thank you @nviennot for helping in code review. I appreciate your review. 🏅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, then I will split this part.

end

def aasm_update_column(attribute_name, value)
send("#{attribute_name}=", value)

Choose a reason for hiding this comment

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

Use write_attribute(name, value) (which does the send() under the hood), but it's more readable and consistent with the other function.

def aasm_ensure_initial_state
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |state_machine_name|
attribute_name = self.class.aasm(state_machine_name).attribute_name.to_s
if self.class.fields.stringify_keys.keys.include?(attribute_name) && send(attribute_name).blank?

Choose a reason for hiding this comment

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

This is a bit horrendous. I'm looking at the other ORMs implementation, and checking if the attribute exists is not done for others (except Mongoid). It actually would be better to have an error if the attribute is not declared.

I would just do aasm(state_machine_name).entire_initial_state if read_attribute(attribute_name).blank? (like Dynamoid or Redis)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fully agree with you. I have to admit I hardly followed what was done with Mongoid which wasn't a good idea for everything. Thank you! 👍

module ClassMethods
def aasm_create_scope(state_machine_name, scope_name)
scope_options = lambda {
send(

Choose a reason for hiding this comment

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

the send() seems uncessary. Do like CoreDataQuery: lambda { where(...) }

@zedtux
Copy link
Contributor Author

zedtux commented Jan 16, 2018

Code updated and tests passed, thank you @nviennot

@zedtux
Copy link
Contributor Author

zedtux commented Jan 17, 2018

@anilmaurya the code has been updated

@anilmaurya
Copy link
Member

@zedtux Could you resolve conflicts and update this PR ?

* Add persistence for NoBrainer
* Add tests for NoBrainer
* Show the ORM version when running the tests
* Add a Dockerfile and a docker-compose.yml file allowing to run from anywhere very easily the test suite with `docker-compose run --rm aasm\'
* Moves the Mongoid database name definition in the gem loader (avoiding code repetition)
* Update the CHANGELOG.md and the README.md files
* Add Rails generator for NoBrainer
@zedtux
Copy link
Contributor Author

zedtux commented Jan 22, 2018

@anilmaurya it's done but I don't understand why the jruby version is failing. Can you please guide me?

I mean I don't understand why with Ruby it is working fine, but with jruby it is failing stating that the sqlite3 gem is missing.

@anilmaurya
Copy link
Member

anilmaurya commented Jan 24, 2018

@zedtux Thank you for updating.
I will try to spare some time for debugging this issue.

@zedtux
Copy link
Contributor Author

zedtux commented Jan 29, 2018

@anilmaurya if you need anything from me, please feel free to ask.

@anilmaurya
Copy link
Member

@zedtux Can you help in fixing travis build for this PR 😊

Thank you for asking ♡

@anilmaurya
Copy link
Member

Hi @zedtux ,

I am trying to run test suite through docker
It gives me following error:

docker-compose run --rm aasm
Pulling bundle (aasm/aasm:latest)...
ERROR: pull access denied for aasm/aasm, repository does not exist or may require 'docker login'

@zedtux
Copy link
Contributor Author

zedtux commented Feb 3, 2018

You have to run first docker-compose build aasm.
Otherwise Docker tries to download the image from Docker hub, but I will let you manage the upload and the maintenance.

@anilmaurya anilmaurya merged commit 65073e3 into aasm:master Feb 13, 2018
@anilmaurya
Copy link
Member

Thank you @zedtux for your contribution.

@zedtux
Copy link
Contributor Author

zedtux commented Feb 13, 2018

Oh that’s great 👍🏻

@alto
Copy link
Member

alto commented Feb 13, 2018

@zedtux Great OR. Cheers!

@anilmaurya Thanks for taking care of this!

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.

None yet

4 participants