Skip to content

Commit

Permalink
drop rails lower than 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timdiggins committed Nov 9, 2024
1 parent 58d8ce5 commit 9f0054d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 55 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
matrix:
# just define specific versions for each rails version
include:
- ruby: 2.6
rails: 5.2
- ruby: 2.6
rails: "6.0"
- ruby: "3.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ user_1.posts.union(user_2.posts).union(Post.published)
user_1.posts.union_all(user_2.posts)
```

ActiveRecordUnion is tested against Rails 5.0, 5.1, and 5.2. It should also work on Rails 4.2. It may or may not work on Rails 4.0/4.1.
ActiveRecordUnion is tested against Rails 6.0, 6.1, 7.0, 7.1, 7.2 and 8.0.

If you are using Postgres, you might alternatively check out [ActiveRecordExtended](https://github.com/georgekaraszi/ActiveRecordExtended) which includes support for unions as well as other goodies.

Expand Down Expand Up @@ -218,7 +218,7 @@ This public domain dedication follows the the CC0 1.0 at https://creativecommons
1. Install MySQL and PostgreSQL.
2. You need to be able to connect to a local MySQL and Postgres database as the default user, so the specs can create a `test_active_record_union` database. To set up the users this test expects, execute `bin/create-db-users` (or set the environment variables referenced in `spec/support/databases.rb`).
3. Run `rake` to test with all supported Rails versions. All needed dependencies will be installed via Bundler (`gem install bundler` if you happen not to have Bundler yet).
4. Run `rake test_rails_4_2` or `rake test_rails_5_2` etc. to test a specific Rails version.
4. Run `rake test_rails_8_0` or `rake test_rails_7_2` etc. to test a specific Rails version.
4. There is also a `bin/console` command to load up a REPL for playing around
5. Commit your changes (`git commit -am 'Add some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
Expand Down
2 changes: 1 addition & 1 deletion active_record_union.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.files.grep(%r{^bin/})
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", ">= 5.2"
spec.add_dependency "activerecord", ">= 6.0"

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
Expand Down
37 changes: 2 additions & 35 deletions lib/active_record_union/active_record/relation/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,8 @@ def set_operation(operation, relation_or_where_arg, *args)
build_union_relation(from, other)
end

if ActiveRecord.gem_version >= Gem::Version.new('5.2.0.beta2')
# Since Rails 5.2, binds are maintained only in the Arel AST.
def build_union_relation(arel_table_alias, _other)
self.klass.unscoped.from(arel_table_alias)
end
elsif ActiveRecord::VERSION::MAJOR >= 5
# In Rails >= 5.0, < 5.2, binds are maintained only in ActiveRecord
# relations and clauses.
def build_union_relation(arel_table_alias, other)
relation = self.klass.unscoped.spawn
relation.from_clause =
UnionFromClause.new(arel_table_alias, nil,
self.bound_attributes + other.bound_attributes)
relation
end

class UnionFromClause < ActiveRecord::Relation::FromClause
def initialize(value, name, bound_attributes)
super(value, name)
@bound_attributes = bound_attributes
end

def binds
@bound_attributes
end
end
else
# In Rails 4.x, binds are maintained in both ActiveRecord relations and
# clauses and also in their Arel ASTs.
def build_union_relation(arel_table_alias, other)
relation = self.klass.unscoped.from(arel_table_alias)
relation.bind_values = self.arel.bind_values + self.bind_values +
other.arel.bind_values + other.bind_values
relation
end
def build_union_relation(arel_table_alias, _other)
self.klass.unscoped.from(arel_table_alias)
end

def verify_relations_for_set_operation!(operation, *relations)
Expand Down
15 changes: 0 additions & 15 deletions rails_5.2.gemfile

This file was deleted.

0 comments on commit 9f0054d

Please sign in to comment.