Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit 32f13d1

Browse files
committed
Merge pull request #360 from activerecord-hackery/new_rails_dependency_and_ci_env
Support the latest 4-2-stable and 4.1.9+
2 parents 96b6b0e + ddf209a commit 32f13d1

File tree

6 files changed

+60
-21
lines changed

6 files changed

+60
-21
lines changed

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,30 @@ script:
88
rvm:
99
- 1.9.3
1010
- 2.0.0
11-
- 2.1.1
12-
- 2.1.2
11+
- 2.1.5
1312

1413
env:
1514
global:
1615
- SQ_CONFIG_FILE=$TRAVIS_BUILD_DIR/spec/config.travis.yml
1716
matrix:
18-
- RAILS=master AREL=master ADAPTER=sqlite3
17+
- RAILS=4-2-stable AREL=6-0-stable ADAPTER=sqlite3
1918
- RAILS=4-1-stable AREL=5-0-stable ADAPTER=sqlite3
2019
- RAILS=4-0-stable AREL=4-0-stable ADAPTER=sqlite3
2120
- RAILS=3-2-stable AREL=3-0-stable ADAPTER=sqlite3
2221
- RAILS=3-1-stable AREL=2-2-stable ADAPTER=sqlite3
2322
- RAILS=3-0-stable AREL=2-0-stable ADAPTER=sqlite3
24-
- RAILS=master AREL=master ADAPTER=mysql
23+
- RAILS=4-2-stable AREL=6-0-stable ADAPTER=mysql
2524
- RAILS=4-1-stable AREL=5-0-stable ADAPTER=mysql
2625
- RAILS=4-0-stable AREL=4-0-stable ADAPTER=mysql
2726
- RAILS=3-2-stable AREL=3-0-stable ADAPTER=mysql
2827
- RAILS=3-1-stable AREL=2-2-stable ADAPTER=mysql
2928
- RAILS=3-0-stable AREL=2-0-stable ADAPTER=mysql
30-
- RAILS=master AREL=master ADAPTER=mysql2
29+
- RAILS=4-2-stable AREL=6-0-stable ADAPTER=mysql2
3130
- RAILS=4-1-stable AREL=5-0-stable ADAPTER=mysql2
3231
- RAILS=4-0-stable AREL=4-0-stable ADAPTER=mysql2
3332
- RAILS=3-2-stable AREL=3-0-stable ADAPTER=mysql2
3433
- RAILS=3-1-stable AREL=2-2-stable ADAPTER=mysql2
35-
- RAILS=master AREL=master ADAPTER=postgresql
34+
- RAILS=4-2-stable AREL=6-0-stable ADAPTER=postgresql
3635
- RAILS=4-1-stable AREL=5-0-stable ADAPTER=postgresql
3736
- RAILS=4-0-stable AREL=4-0-stable ADAPTER=postgresql
3837
- RAILS=3-2-stable AREL=3-0-stable ADAPTER=postgresql

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
## 1.2.3 (Unreleased)
1+
## 1.2.4 (Unreleased)
2+
3+
4+
## 1.2.3 (2015-2-5)
5+
* Support the latest version of Rails 4.2 and 4.1. By @danielrhodes
26

37
## 1.2.2 (2014-11-25)
48

Gemfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ gemspec
33

44
gem 'rake'
55

6-
rails = ENV['RAILS'] || 'master'
7-
arel = ENV['AREL'] || 'master'
8-
9-
if rails == 'master'
10-
gem 'i18n', github: 'svenfuchs/i18n', branch: 'master'
11-
end
6+
rails = ENV['RAILS'] || '4-2-stable'
7+
arel = ENV['AREL'] || '6-0-stable'
128

139
arel_opts = case arel
1410
when /\// # A path

lib/squeel/adapters/active_record/4.1/relation_extensions.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,15 @@ def build_arel
8080

8181
collapse_wheres(arel, where_visit((where_values - ['']).uniq))
8282

83-
arel.having(*having_visit(having_values.uniq.reject{|h| h.blank?})) unless having_values.empty?
83+
arel.having(*having_visit(having_values.uniq.reject(&:blank?))) unless having_values.empty?
8484

8585
arel.take(connection.sanitize_limit(limit_value)) if limit_value
8686
arel.skip(offset_value.to_i) if offset_value
87-
88-
arel.group(*group_visit(group_values.uniq.reject{|g| g.blank?})) unless group_values.empty?
87+
arel.group(*group_visit(group_values.uniq.reject(&:blank?))) unless group_values.empty?
8988

9089
build_order(arel)
9190

92-
build_select(arel, select_visit(select_values.uniq))
91+
build_select(arel)
9392

9493
arel.distinct(distinct_value)
9594
arel.from(build_from) if from_value
@@ -231,6 +230,14 @@ def build_order(arel)
231230
arel.order(*orders) unless orders.empty?
232231
end
233232

233+
def build_select(arel)
234+
if select_values.any?
235+
arel.project(*select_visit(select_values.uniq))
236+
else
237+
arel.project(@klass.arel_table[Arel.star])
238+
end
239+
end
240+
234241
def where_values_hash_with_squeel(relation_table_name = table_name)
235242
equalities = find_equality_predicates(where_visit(where_values), relation_table_name)
236243
binds = Hash[bind_values.find_all(&:first).map { |column, v| [column.name, v] }]

lib/squeel/adapters/active_record/4.2/relation_extensions.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ def reverse_order!
1717
self
1818
end
1919

20+
def build_arel
21+
arel = Arel::SelectManager.new(table.engine, table)
22+
23+
build_joins(arel, joins_values.flatten) unless joins_values.empty?
24+
25+
collapse_wheres(arel, where_visit((where_values - ['']).uniq))
26+
27+
arel.having(*having_visit(having_values.uniq.reject(&:blank?))) unless having_values.empty?
28+
29+
arel.take(connection.sanitize_limit(limit_value)) if limit_value
30+
arel.skip(offset_value.to_i) if offset_value
31+
arel.group(*group_visit(group_values.uniq.reject(&:blank?))) unless group_values.empty?
32+
33+
build_order(arel)
34+
35+
build_select(arel)
36+
37+
arel.distinct(distinct_value)
38+
arel.from(build_from) if from_value
39+
arel.lock(lock_value) if lock_value
40+
41+
arel
42+
end
43+
2044
def build_join_dependency(manager, joins)
2145
buckets = joins.group_by do |join|
2246
case join
@@ -89,8 +113,7 @@ def where_values_hash_with_squeel(relation_table_name = table_name)
89113
def expand_attrs_from_hash(opts)
90114
opts = ::ActiveRecord::PredicateBuilder.resolve_column_aliases(klass, opts)
91115

92-
bv_len = bind_values.length
93-
tmp_opts, bind_values = create_binds(opts, bv_len)
116+
tmp_opts, bind_values = create_binds(opts)
94117
self.bind_values += bind_values
95118

96119
attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)

spec/squeel/adapters/active_record/relation_extensions_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ module ActiveRecord
134134
})
135135

136136
arel = relation.build_arel
137-
arel.to_sql.should match /#{Q}parents_people_2#{Q}.#{Q}name#{Q} = 'bob'/
137+
138+
if activerecord_version_at_least('4.2.0')
139+
arel.to_sql.should match /#{Q}parents_people_2#{Q}.#{Q}name#{Q} = ?/
140+
else
141+
arel.to_sql.should match /#{Q}parents_people_2#{Q}.#{Q}name#{Q} = 'bob'/
142+
end
138143
end
139144

140145
it 'combines multiple conditions of the same type against the same column with AND' do
@@ -174,7 +179,12 @@ module ActiveRecord
174179
})
175180

176181
arel = relation.build_arel
177-
arel.to_sql.should match /HAVING #{Q}parents_people_2#{Q}.#{Q}name#{Q} = 'joe'/
182+
183+
if activerecord_version_at_least('4.2.0')
184+
arel.to_sql.should match /HAVING #{Q}parents_people_2#{Q}.#{Q}name#{Q} = ?/
185+
else
186+
arel.to_sql.should match /HAVING #{Q}parents_people_2#{Q}.#{Q}name#{Q} = 'joe'/
187+
end
178188
end
179189

180190
it 'maps orders inside a hash to their appropriate association table' do

0 commit comments

Comments
 (0)