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 Rails 6 Support #124
Add Rails 6 Support #124
Changes from all commits
e0ee1ad
1fcf62e
d70375f
90ba8fc
bd13b83
8cbe82b
add128a
00089f4
d10791d
53eef30
2ab706b
63905dd
f5d4fba
363c230
03de215
f167583
7b95093
3230adb
3845921
dbedde4
610cb85
97c060e
04e7af2
980fce2
97fc483
dc333e3
0c9b243
8d8c98f
7d857f2
c8f333e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pkg | |
Gemfile.lock | ||
gemfiles/*.lock | ||
.idea/ | ||
.ruby-version |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'activerecord', '~> 6.0.0', require: 'active_record' | ||
gem 'activesupport', '~> 6.0.0', require: 'active_support' | ||
|
||
# Development dependencies | ||
group :development do | ||
gem "sqlite3", :platforms => [:ruby] | ||
gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby] | ||
end | ||
|
||
gemspec :path => '../' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,9 @@ def self.included(base) | |
|
||
class UniquenessWithoutDeletedValidator | ||
def self.[](version) | ||
version = version.to_s | ||
name = "V#{version.tr('.', '_')}" | ||
name = "V#{version.to_s.tr('.', '_')}" | ||
unless constants.include? name.to_sym | ||
raise "Unknown validator version #{version.inspect}; expected one of #{constants.sort.join(', ')}" | ||
raise "Unknown validator version #{name.inspect}; expected one of #{constants.sort.join(', ')}" | ||
end | ||
const_get name | ||
end | ||
|
@@ -38,8 +37,11 @@ def validate_each(record, attribute, value) | |
protected | ||
|
||
def build_relation(klass, attribute, value) | ||
return super(klass, klass.arel_table, attribute, value) if ActiveRecord::VERSION::MINOR == 0 | ||
super | ||
if ActiveRecord::VERSION::MINOR == 0 && ActiveRecord::VERSION::MAJOR == 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a bit odd because you would think this class would only be used with Rails 5 (except it isn't because it's subclassed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I wasn't sure what the best way to code this would be since most options seemed to involve just copying and pasting, so I opted for the fewest lines of code: simply making V6 an empty subclass of V5. |
||
return super(klass, klass.arel_table, attribute, value) | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
|
@@ -75,6 +77,9 @@ def validate_each(record, attribute, value) | |
end | ||
end | ||
end | ||
|
||
class V6 < V5 | ||
end | ||
end | ||
|
||
module ClassMethods | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,7 +228,7 @@ def test_double_belongs_to_with_deleted | |
end | ||
|
||
def test_mass_assignment_of_paranoid_column_enabled | ||
if ActiveRecord::VERSION::MAJOR > 4 && ActiveRecord::VERSION::MINOR > 1 | ||
if Gem.loaded_specs['activerecord'].version >= Gem::Version.new('5.2.0') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mvz - there are several places in the code that check the current ActiveRecord version. Since Rails 6 is out now, it might be worthwhile to release a new major version of this gem where old versions of Rails/Ruby are no longer supported. A new gem version that supports only Rails 5.2+ w/ Ruby 2.5+ only would be nice clean slate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's definitely a good idea! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind working on that after we get this PR merged. |
||
skip 'Creation as deleted is not supported with Rails >= 5.2' | ||
end | ||
now = Time.now | ||
|
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'm going to check if this doesn't have any unwanted side effects.
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 tried to explain here why I made that change, if it helps railsagency#2
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.
Ok, I created some explicit tests for this and it looks like everything is fine 👍. I'll merge this in and then create another PR to add those tests.