active_record_extended 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -8
- data/lib/active_record_extended/query_methods/any_of.rb +1 -1
- data/lib/active_record_extended/query_methods/either.rb +2 -0
- data/lib/active_record_extended/version.rb +1 -1
- data/spec/query_methods/either_spec.rb +15 -0
- data/spec/sql_inspections/any_of_sql_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3676a5b5f744f28f9e545a951e006f03457660046d5908d5f5fdc4200591c6c6
|
4
|
+
data.tar.gz: '0434468d2a6f1988df93a4150b7276e1d0d0538252519cf715e76cd12ba5e8de'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bafb6e58693b523541fe90556bf863a271d93310e76de4929214f4b6e06117da92aa625dad7c932f1a5f58b8647b8b3f521de48b8428d011402b1c329af0fb4
|
7
|
+
data.tar.gz: 234e63478d2f25f2eccdc5fe5c6a96a7a500ae0f5207a8232fdef30638cfb7e773cec4a413cc8073419525c26729796a7766288c955500f402a88e4720728523
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 0.4.0 - May 9th 2018
|
2
|
+
|
3
|
+
- Use Arel's `or` for grouping queries when using `#any_of` or `#none_of`
|
4
|
+
- Added Plural aliases for `.either_join` : `.either_joins` and `.either_order` : `.either_orders`
|
5
|
+
|
1
6
|
# 0.3.0 - May 9th 2018
|
2
7
|
|
3
8
|
- Fixed ActiveRecord QueryMethod constant load error.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.
|
1
|
+
[![Build Status](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended.svg?branch=master)](https://travis-ci.com/GeorgeKaraszi/ActiveRecordExtended) [![Maintainability](https://api.codeclimate.com/v1/badges/98ecffc0239417098cbc/maintainability)](https://codeclimate.com/github/GeorgeKaraszi/active_record_extended/maintainability)
|
2
2
|
|
3
3
|
# Active Record Extended
|
4
4
|
|
@@ -32,14 +32,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
32
32
|
|
33
33
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
34
|
|
35
|
-
## Contributing
|
36
|
-
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/postgres_extended. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
35
|
|
39
36
|
## License
|
40
37
|
|
41
38
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
-
|
43
|
-
## Code of Conduct
|
44
|
-
|
45
|
-
Everyone interacting in the ActiveRecordExtended project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/postgres_extended/blob/master/CODE_OF_CONDUCT.md).
|
@@ -52,7 +52,7 @@ module ActiveRecordExtended
|
|
52
52
|
query_map[:references] << translate_reference(query.references_values) if query.references_values.any?
|
53
53
|
query_map[:binds] += bind_attributes(query)
|
54
54
|
query.arel.constraints.reduce(:and)
|
55
|
-
end.reduce(:
|
55
|
+
end.reduce(:or)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -14,12 +14,14 @@ module ActiveRecordExtended
|
|
14
14
|
condition__query = xor_field_sql(association_options) + "= #{table_name}.#{primary_key}"
|
15
15
|
outer_joins(associations).where(Arel.sql(condition__query))
|
16
16
|
end
|
17
|
+
alias either_joins either_join
|
17
18
|
|
18
19
|
def either_order(direction, **associations_and_columns)
|
19
20
|
reflected_columns = map_columns_to_tables(associations_and_columns)
|
20
21
|
conditional_query = xor_field_sql(reflected_columns) + sort_order_sql(direction)
|
21
22
|
outer_joins(associations_and_columns.keys).order(Arel.sql(conditional_query))
|
22
23
|
end
|
24
|
+
alias either_orders either_order
|
23
25
|
|
24
26
|
private
|
25
27
|
|
@@ -15,6 +15,14 @@ RSpec.describe "Active Record Either Methods" do
|
|
15
15
|
expect(query).to include(one, two)
|
16
16
|
expect(query).to_not include(three)
|
17
17
|
end
|
18
|
+
|
19
|
+
context "Alias .either_joins/2" do
|
20
|
+
it "Should only only return records that belong to profile L or profile R" do
|
21
|
+
query = Person.either_joins(:profile_l, :profile_r)
|
22
|
+
expect(query).to include(one, two)
|
23
|
+
expect(query).to_not include(three)
|
24
|
+
end
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
describe ".either_order/2" do
|
@@ -32,5 +40,12 @@ RSpec.describe "Active Record Either Methods" do
|
|
32
40
|
query = Person.either_order(:desc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
|
33
41
|
expect(query).to match_array([one, two])
|
34
42
|
end
|
43
|
+
|
44
|
+
context "Alias .either_order/2" do
|
45
|
+
it "Should order people based on their likes and dislikes in ascended order" do
|
46
|
+
query = Person.either_orders(:asc, profile_l: :likes, profile_r: :dislikes).where(id: [one.id, two.id])
|
47
|
+
expect(query).to match_array([two, one])
|
48
|
+
end
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
@@ -3,15 +3,15 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe "Any / None of SQL Queries" do
|
6
|
-
let(:equal_query) { "people
|
7
|
-
let(:or_query) {
|
6
|
+
let(:equal_query) { '"people"."personal_id" = 1' }
|
7
|
+
let(:or_query) { 'OR "people"."personal_id" = 2' }
|
8
8
|
let(:equal_or) { equal_query + " " + or_query }
|
9
9
|
let(:join_query) { /INNER JOIN \"tags\" ON \"tags\".\"person_id\" = \"people\".\"id/ }
|
10
10
|
|
11
11
|
describe "where.any_of/1" do
|
12
12
|
it "should group different column arguments into nested or conditions" do
|
13
13
|
query = Person.where.any_of({ personal_id: 1 }, { id: 2 }, { personal_id: 2 }).to_sql
|
14
|
-
expect(query).to match_regex(/WHERE .+ = 1 OR \
|
14
|
+
expect(query).to match_regex(/WHERE \(\(.+ = 1 OR .+ = 2\) OR .+ = 2\)/)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "Should assign where clause predicates for standard queries" do
|
@@ -35,7 +35,7 @@ RSpec.describe "Any / None of SQL Queries" do
|
|
35
35
|
describe "where.none_of/1" do
|
36
36
|
it "Should surround the query in a WHERE NOT clause" do
|
37
37
|
query = Person.where.none_of({ personal_id: 1 }, { id: 2 }, { personal_id: 2 }).to_sql
|
38
|
-
expect(query).to match_regex(/WHERE.+NOT \(.+ = 1 OR \
|
38
|
+
expect(query).to match_regex(/WHERE.+NOT \(\(.+ = 1 OR .+ = 2\) OR .+ = 2\)/)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|