case_insensitive_arel 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{case_insensitive_arel}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Lamotte"]
12
- s.date = %q{2011-09-16}
12
+ s.date = %q{2011-09-20}
13
13
  s.description = %q{If you're using Oracle or another DBMS that has case-insensitive collation sequences, and you don't want to litter your database access code with case conversions, this gem is for you.}
14
14
  s.email = %q{steve@lexor.ca}
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/case_insensitive_arel.rb",
29
29
  "test/helper.rb",
30
30
  "test/support/fake_record.rb",
31
+ "test/test_as.rb",
31
32
  "test/test_comparisons.rb",
32
33
  "test/test_group_by.rb",
33
34
  "test/test_joins.rb",
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
41
42
  s.test_files = [
42
43
  "test/helper.rb",
43
44
  "test/support/fake_record.rb",
45
+ "test/test_as.rb",
44
46
  "test/test_comparisons.rb",
45
47
  "test/test_group_by.rb",
46
48
  "test/test_joins.rb",
@@ -59,20 +59,29 @@ module Arel #:nodoc:
59
59
  end
60
60
  end
61
61
 
62
- class Table # :nodoc:
62
+ class SelectManager # :nodoc:
63
63
  # We don't want an attribute in the SELECT to be processed by the conversion proc. As such, tag +project+'s' parameters with a special
64
64
  # singleton method to prevent them from being converted.
65
65
  def project_with_case_insensitive(*things)
66
- # If a +thing+ is used elsewhere (e.g. in the WHERE clause), tagging it will cause the WHERE clause to be affected as well. So create a new
67
- # list of things and tag them instead.
68
- new_things = things.map do |thing|
69
- new_thing = thing.clone
70
- def new_thing.do_not_make_case_insensitive?; end
71
- new_thing
66
+ # If a +thing+ is used elsewhere (e.g. in the WHERE clause), tagging it will cause the WHERE clause to be affected as well. So create a new
67
+ # list of things and tag them instead.
68
+ new_things = things.map do |thing|
69
+ case_insensitive_thing thing
72
70
  end
73
71
  project_without_case_insensitive *new_things
74
72
  end
75
73
  alias_method_chain :project, :case_insensitive
74
+
75
+ private
76
+
77
+ # Create a clone of +thing+ with our special tag method.
78
+ # Different objects require the method to be added to different places so it can be seen in +leave_case_sensitive?+ above.
79
+ def case_insensitive_thing(thing)
80
+ new_thing = thing.clone
81
+ target = new_thing.is_a?(Arel::Nodes::As) ? new_thing.left : new_thing
82
+ def target.do_not_make_case_insensitive?; end
83
+ new_thing
84
+ end
76
85
  end
77
86
  end
78
87
 
@@ -0,0 +1,13 @@
1
+ require "helper"
2
+
3
+ class TestAs < Test::Unit::TestCase
4
+ should "work correctly in case-insensitive mode" do
5
+ Arel::CaseInsensitive.case_insensitive = true
6
+ should_be_like @users.project(@users[:name].as("n")).to_sql, "SELECT \"users\".\"name\" AS n FROM \"users\""
7
+ end
8
+
9
+ should "work correctly in case-sensitive mode" do
10
+ Arel::CaseInsensitive.case_insensitive = false
11
+ should_be_like @users.project(@users[:name].as("n")).to_sql, "SELECT \"users\".\"name\" AS n FROM \"users\""
12
+ end
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: case_insensitive_arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steve Lamotte
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-16 00:00:00 -05:00
18
+ date: 2011-09-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -177,6 +177,7 @@ files:
177
177
  - lib/case_insensitive_arel.rb
178
178
  - test/helper.rb
179
179
  - test/support/fake_record.rb
180
+ - test/test_as.rb
180
181
  - test/test_comparisons.rb
181
182
  - test/test_group_by.rb
182
183
  - test/test_joins.rb
@@ -218,6 +219,7 @@ summary: Forces Arel queries to be case-insensitive
218
219
  test_files:
219
220
  - test/helper.rb
220
221
  - test/support/fake_record.rb
222
+ - test/test_as.rb
221
223
  - test/test_comparisons.rb
222
224
  - test/test_group_by.rb
223
225
  - test/test_joins.rb