arel_extensions 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+ require 'date'
3
+
4
+ module ArelExtensions
5
+ module WthAr
6
+
7
+ describe 'the postgresql visitor can do string operations' do
8
+
9
+ before do
10
+ ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
11
+ ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-postgres" : :postgres))
12
+ ActiveRecord::Base.default_timezone = :utc
13
+ begin
14
+ @cnx = ActiveRecord::Base.connection
15
+ rescue => e
16
+ puts "\n#{e.inspect}"
17
+ ActiveRecord::Base.establish_connection(ENV['DB'] || :sqlite)
18
+ @cnx = ActiveRecord::Base.connection
19
+ end
20
+ Arel::Table.engine = ActiveRecord::Base
21
+ @cnx.drop_table(:users) rescue nil
22
+ @cnx.drop_table(:products) rescue nil
23
+ @cnx.create_table :users do |t|
24
+ t.column :age, :integer
25
+ t.column :name, :string
26
+ t.column :comments, :text
27
+ t.column :created_at, :date
28
+ t.column :updated_at, :date
29
+ t.column :score, :decimal
30
+ end
31
+ @cnx.create_table :products do |t|
32
+ t.column :price, :decimal
33
+ end
34
+ class User < ActiveRecord::Base
35
+ end
36
+ d = Date.new(2016, 5,23)
37
+ lucas = User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
38
+ @lucas = User.where(:id => lucas.id)
39
+ sophie = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
40
+ @sophie = User.where(:id => sophie.id)
41
+ User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
42
+ User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
43
+ User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
44
+ @laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
45
+ User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62
46
+ @neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
47
+ @table = Arel::Table.new(:users)
48
+ @name = @table[:name]
49
+ @age = @table[:age]
50
+ end
51
+ after do
52
+ @cnx.drop_table(:users)
53
+ end
54
+
55
+ it "should do string operations" do
56
+ # concat
57
+ d = Date.new(1997, 6, 15)
58
+ assert_equal "SophiePhan", @sophie.select((@name + "Phan").as("res")).first.res
59
+ assert_equal "Sophie2", @sophie.select((@name + 2).as("res")).first.res
60
+ assert_equal "Sophie1997-06-15", @sophie.select((@name + d).as("res")).first.res
61
+ assert_equal "Sophie15", @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
62
+ assert_equal "SophieSophie", @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
63
+ assert_equal "Sophie2016-05-23", @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
64
+ #concat Integer
65
+ assert_equal 1, User.where((@age + 10).eq(33)).count
66
+ assert_equal 6, @lucas.select((@age + "1").as('res')).first.res.to_i
67
+ assert_equal 1, @sophie.where(@age>14).where(@age<16).count
68
+
69
+
70
+
71
+ # Replace
72
+ assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
73
+ assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
74
+
75
+ #
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '6.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '0'
28
+ version: '6.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: minitest
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +149,7 @@ files:
149
149
  - test/with_ar/test_bulk_sqlite.rb
150
150
  - test/with_ar/test_math_sqlite.rb
151
151
  - test/with_ar/test_string_mysql.rb
152
+ - test/with_ar/test_string_postgresql.rb
152
153
  - test/with_ar/test_string_sqlite.rb
153
154
  homepage: https://github.com/Faveod/arel-extensions
154
155
  licenses:
@@ -190,4 +191,5 @@ test_files:
190
191
  - test/with_ar/test_bulk_sqlite.rb
191
192
  - test/with_ar/test_math_sqlite.rb
192
193
  - test/with_ar/test_string_mysql.rb
194
+ - test/with_ar/test_string_postgresql.rb
193
195
  - test/with_ar/test_string_sqlite.rb