Closed harigopal closed 11 years ago
Thanks for the patches!
Please fix the build on Travis, and let me know when everything works.
@jcoglan I'd like you to take a look at the Travis build results. You'll notice that the failures are for ActiveRecord 2.x, and all of them are caused by the use of the where
method.
I searched for a method that works with AR2.x, and isn't deprecated by AR4, but couldn't find anything.
The only fix I could think of was to check AR version manually, everywhere the where
method is used (five instances in the codebase), and instead use the old count(conditions)
form - which, I think, is a pretty ugly thing to do.
if defined?(ActiveRecord::VERSION && ActiveRecord::VERSION::MAJOR >= 3)
where(:access_token_hash => hash).count.zero?
else
count(:conditions => {:access_token_hash => hash}).zero?
end
This could also be done by capturing the NoMethodError
, though that's probably more dangerous.
Thoughts?
We probably need some wrapper functions that we use like:
Helpers.count(Authorization, :access_token_hash => hash)
Those methods would use respond_to?
rather than version numbers to detect capabilities and dispatch to whatever API is available.
@jcoglan Is that OK?
The build looks good. Can you add an entry to .travis.yml
to make it run the build with ActiveRecord 4.0 on Ruby 1.9.3 with MySQL and check that passes?
There was a duplicate entry in .travis.yml
for 1.9.3 MySQL AR3.2 - I replaced that with the AR4 build.
@jcoglan Hey, is there something wrong with the patches / anything left to do?
I've merged it now. Thanks a lot :)
Hi, because of deprecation warnings being raised by ActiveRecord (AR) 4, I've made a few changes which will probably neccessitate a major version bump. I'm sorry, but I couldn't think of any way to support the 2.x versions of ActiveRecord. :-(
Deprecations warnings removed:
count(conditions)
...many instances of above count method were causing:
I replaced all instance of this count usage with:
find_or_create_by_column(value)
caused:
However, the suggested method works only from AR4 onwards, so I replaced it with:
which works for AR3.0 onwards (where(conditions).find_or_create was only added in AR3.2)
Related changes:
I added AR4 to the Appraisals file, along with the required version of the mysql gem, and protected_attributes gem to allow mass-assignment protection in gem's model code.
RSpec results
AR2.x - Failure. AR3.x - Passes for SQLite and MySQL, and Postgres. AR4 - Passes for MySQL and Postgres. Tests don't start running for SQLite (details below).
I couldn't get AR4 specs to work with SQLite. It complains that an index name is too long:
Running the specs with AR4 (other DB-s) does not generate any more deprecation warnings, but the specs still have very noisy output, with AR complaining about attempts to mass-assign protected attributes (spec appears to test this). I haven't made any alterations there since its possible the specs may need to be updated (now that mass-assignment security is being moved out of the model).
I'd really appreciate it if you could take a look at the changes, and incorporate them if it makes sense. Thanks!
Note: I ran all tests with Ruby 2.0.0-p247.