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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea05f761dcce2d09ac0b86e315396e9f6bbc822d53df4bf085bc1b161a28904e
4
- data.tar.gz: 42283db511f3ca78b5d6963c2d1cf642b1bbbf0f8c77416f37d56843e0c8a957
3
+ metadata.gz: 3676a5b5f744f28f9e545a951e006f03457660046d5908d5f5fdc4200591c6c6
4
+ data.tar.gz: '0434468d2a6f1988df93a4150b7276e1d0d0538252519cf715e76cd12ba5e8de'
5
5
  SHA512:
6
- metadata.gz: 050ad5a8796e2886691b63723470d506002c62a53ed0c54b658678c257d9d60e6a50aab580bd189f207c30c28c6c53177a75411b73b03d3255b9f9b7cc4a2fb1
7
- data.tar.gz: bddfdc0cc704d95e98785697a9b1b80e43b193ec97acc40ba12fa0663010b80e9b65437227c16b00f01a52ea3d63ef4d9b04686c4ad66b596d5c05eb8822e0a4
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_record_extended (0.3.0)
4
+ active_record_extended (0.4.0)
5
5
  activerecord (>= 5.1, < 6.0)
6
6
  ar_outer_joins (~> 0.2)
7
7
  pg (~> 0.18)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/GeorgeKaraszi/active_record_extended.svg?branch=master)](https://travis-ci.org/GeorgeKaraszi/active_record_extended) [![Maintainability](https://api.codeclimate.com/v1/badges/98ecffc0239417098cbc/maintainability)](https://codeclimate.com/github/GeorgeKaraszi/active_record_extended/maintainability)
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(:group_or)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordExtended
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -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\".\"personal_id\" = 1" }
7
- let(:or_query) { "OR (\"people\".\"personal_id\" = 2)" }
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 \(.+\) 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 \(.+\) OR \(.+\)\)/)
38
+ expect(query).to match_regex(/WHERE.+NOT \(\(.+ = 1 OR .+ = 2\) OR .+ = 2\)/)
39
39
  end
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Protacio-Karaszi