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
Conversation
The builds for the Rubies are passing now! Ready for merge 😎 |
@zedtux Thank you for your efforts 👍 I will review and merge in couple of days . |
require 'spec_helper' | ||
|
||
if defined?(NoBrainer::Document) | ||
require 'nobrainer' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
spec/spec_helpers/nobrainer.rb
Outdated
|
||
rethinkdb_url = "rethinkdb://#{ENV['RETHINKDB_HOST'] || 'localhost'}:" | ||
rethinkdb_url << "#{ENV['RETHINKDB_PORT'] || 28015}/" | ||
rethinkdb_url << "#{ENV['RETHINKDB_DB'] || "nobrainer_#{Process.pid}"}" |
There was a problem hiding this comment.
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
spec/spec_helpers/redis.rb
Outdated
begin | ||
require 'redis-objects' | ||
puts "redis-objects gem found, running Redis specs \e[32m#{'✔'}\e[0m" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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(...) }
Code updated and tests passed, thank you @nviennot |
@anilmaurya the code has been updated |
@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
@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. |
@zedtux Thank you for updating. |
@anilmaurya if you need anything from me, please feel free to ask. |
@zedtux Can you help in fixing travis build for this PR 😊 Thank you for asking ♡ |
Hi @zedtux , I am trying to run test suite through docker
|
You have to run first |
Thank you @zedtux for your contribution. |
Oh that’s great 👍🏻 |
@zedtux Great OR. Cheers! @anilmaurya Thanks for taking care of this! |
FYI I had to create new Appraisals for NoBrainer as there is a conflict with Mongoid.
This contribution is in the name of Pharmony!