arel-helpers 2.0.2 → 2.1.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
  SHA1:
3
- metadata.gz: 2f4827c570f384201da3e8d5b4cb4ba128647338
4
- data.tar.gz: 41862cd346409a675ce805be9be7b9bf870f1fad
3
+ metadata.gz: 307887bb3095f9de4ea562feb2e36c96dc85f131
4
+ data.tar.gz: 6bc236ff8796f5c9e3aba3aa2dedb2c5fb83fe3b
5
5
  SHA512:
6
- metadata.gz: 74e3d838e06893f725de391c378367693fb1b6215124eeae4ae0f9357347b044fd35d53eafc38673f0fab9c60c05b340c33d543496eec7be259d6230f20b8f80
7
- data.tar.gz: 7aac06ec8e7433ed527cb81ab85aa269affb9bbc760b144565c35f36386d5bfee44264bc7c1e48bb015ca9ff6b36c037c594d06b7b54e84e336caab1f483b1b1
6
+ metadata.gz: 0d7370d6b5fbb42e29b352d4fc07e2dadf0b5d7b1e2e885ac2b85c236556074125eca920a4ab0c7befcb4de7d0a451a66e2f72334210c2804c50df6e3d5186a8
7
+ data.tar.gz: 1805436115bc5c944cd99d5b850a842f5e2f93825e9e0881d51dfdf2010bd3b0b4bfecd5fbb5d4b671d46a31efda36fb615921b7f3f651f288395de21eabb620
data/History.txt CHANGED
@@ -21,3 +21,7 @@
21
21
  == 2.0.2
22
22
 
23
23
  * Fix issue causing CollectionProxy#[] to return Arel::Attribute objects instead of model instances. See https://github.com/camertron/arel-helpers/pull/11
24
+
25
+ == 2.1.0
26
+
27
+ * Adding support for Rails 4.2 (@hasghari, github issue #12)
data/README.md CHANGED
@@ -155,7 +155,7 @@ PostQueryBuilder.new
155
155
 
156
156
  ## Requirements
157
157
 
158
- Requires ActiveRecord >= 3.1.0, <= 4.1.0, tested with Ruby 1.9.3, 2.0.0, and 2.1.0. Depends on SQLite for testing purposes.
158
+ Requires ActiveRecord >= 3.1.0, <= 4.2.0, tested with Ruby 1.9.3, 2.0.0, and 2.1.0. Depends on SQLite for testing purposes.
159
159
 
160
160
  ## Running Tests
161
161
 
@@ -17,8 +17,10 @@ module ArelHelpers
17
17
  # For example, for HABTM associations, two join statements are required.
18
18
  # This method encapsulates that functionality and yields an intermediate object for chaining.
19
19
  # It also allows you to use an outer join instead of the default inner via the join_type arg.
20
- def join_association(table, association, join_type = Arel::InnerJoin, &block)
21
- if ActiveRecord::VERSION::STRING >= '4.1.0'
20
+ def join_association(table, association, join_type = Arel::Nodes::InnerJoin, &block)
21
+ if ActiveRecord::VERSION::STRING >= '4.2.0'
22
+ join_association_4_2(table, association, join_type, &block)
23
+ elsif ActiveRecord::VERSION::STRING >= '4.1.0'
22
24
  join_association_4_1(table, association, join_type, &block)
23
25
  else
24
26
  join_association_3_1(table, association, join_type, &block)
@@ -62,6 +64,23 @@ module ArelHelpers
62
64
  join_type.new(constraint.left, right)
63
65
  end
64
66
  end
67
+
68
+ def join_association_4_2(table, association, join_type)
69
+ associations = association.is_a?(Array) ? association : [association]
70
+ join_dependency = ActiveRecord::Associations::JoinDependency.new(table, associations, [])
71
+
72
+ join_dependency.join_constraints([]).map do |constraint|
73
+ constraint.joins.map do |join|
74
+ right = if block_given?
75
+ yield join.left.name.to_sym, join.right
76
+ else
77
+ join.right
78
+ end
79
+
80
+ join_type.new(join.left, right)
81
+ end
82
+ end
83
+ end
65
84
  end
66
85
  end
67
86
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module ArelHelpers
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -10,7 +10,7 @@ describe ArelHelpers do
10
10
  end
11
11
 
12
12
  it "should work with an outer join" do
13
- Post.joins(ArelHelpers.join_association(Post, :comments, Arel::OuterJoin)).to_sql.should ==
13
+ Post.joins(ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)).to_sql.should ==
14
14
  'SELECT "posts".* FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"'
15
15
  end
16
16
 
@@ -45,6 +45,11 @@ describe ArelHelpers do
45
45
  end).to_sql.should ==
46
46
  'SELECT "posts".* FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" AND "comments"."text" = \'Awesome post!\' INNER JOIN "favorites" (ON "favorites"."post_id" = "posts"."id" OR "favorites"."amount" = \'lots\')'
47
47
  end
48
+
49
+ it 'should be able to handle has_and_belongs_to_many associations' do
50
+ CollabPost.joins(ArelHelpers.join_association(CollabPost, :authors)).to_sql.should ==
51
+ 'SELECT "collab_posts".* FROM "collab_posts" INNER JOIN "authors_collab_posts" ON "authors_collab_posts"."collab_post_id" = "collab_posts"."id" INNER JOIN "authors" ON "authors"."id" = "authors_collab_posts"."author_id"'
52
+ end
48
53
  end
49
54
  end
50
55
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord