postgres_ext 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +13 -22
- data/CHANGELOG.md +45 -0
- data/README.md +13 -0
- data/Rakefile +83 -7
- data/docs/querying.md +76 -6
- data/lib/postgres_ext/active_record/relation/predicate_builder.rb +2 -2
- data/lib/postgres_ext/active_record/relation/query_methods.rb +44 -11
- data/lib/postgres_ext/arel/predications.rb +10 -0
- data/lib/postgres_ext/arel/visitors/to_sql.rb +1 -1
- data/lib/postgres_ext/version.rb +1 -1
- data/postgres_ext.gemspec +4 -2
- data/test/arel/array_test.rb +92 -0
- data/{spec/arel/inet_spec.rb → test/arel/inet_test.rb} +6 -6
- data/{spec/queries/array_queries_spec.rb → test/queries/array_queries_test.rb} +22 -14
- data/test/queries/common_table_expression_test.rb +49 -0
- data/{spec/queries/contains_querie_spec.rb → test/queries/contains_test.rb} +5 -5
- data/test/queries/sanity_test.rb +32 -0
- data/test/queries/window_functions_test.rb +64 -0
- data/test/test_helper.rb +38 -0
- metadata +74 -150
- data/spec/arel/array_spec.rb +0 -77
- data/spec/arel/rank_spec.rb +0 -0
- data/spec/dummy/.gitignore +0 -15
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/person.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -56
- data/spec/dummy/config/boot.rb +0 -6
- data/spec/dummy/config/database.yml.example +0 -14
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -33
- data/spec/dummy/config/environments/production.rb +0 -68
- data/spec/dummy/config/environments/test.rb +0 -33
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/db/migrate/20120501163758_create_people.rb +0 -15
- data/spec/dummy/db/schema.rb +0 -31
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/tasks/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/index.html +0 -241
- data/spec/dummy/public/robots.txt +0 -5
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec/factories/people.rb +0 -7
- data/spec/dummy/test/fixtures/.gitkeep +0 -0
- data/spec/dummy/test/functional/.gitkeep +0 -0
- data/spec/dummy/test/integration/.gitkeep +0 -0
- data/spec/dummy/test/performance/browsing_test.rb +0 -12
- data/spec/dummy/test/test_helper.rb +0 -13
- data/spec/dummy/test/unit/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/dummy/vendor/plugins/.gitkeep +0 -0
- data/spec/queries/common_table_expression_spec.rb +0 -36
- data/spec/queries/sanity_spec.rb +0 -17
- data/spec/queries/window_functions_spec.rb +0 -54
- data/spec/spec_helper.rb +0 -36
data/spec/dummy/script/rails
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
-
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
6
|
-
require 'rails/commands'
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rails/performance_test_help'
|
3
|
-
|
4
|
-
class BrowsingTest < ActionDispatch::PerformanceTest
|
5
|
-
# Refer to the documentation for all available options
|
6
|
-
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
7
|
-
# :output => 'tmp/performance', :formats => [:flat] }
|
8
|
-
|
9
|
-
def test_homepage
|
10
|
-
get '/'
|
11
|
-
end
|
12
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path('../../config/environment', __FILE__)
|
3
|
-
require 'rails/test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
-
#
|
8
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
-
# -- they do not yet inherit this setting
|
10
|
-
fixtures :all
|
11
|
-
|
12
|
-
# Add more helper methods to be used by all tests here...
|
13
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Common Table Expression queries' do
|
4
|
-
describe '.with(common_table_expression_hash)' do
|
5
|
-
it 'generates an expression with the CTE' do
|
6
|
-
query = Person.with(lucky_number_seven: Person.where(lucky_number: 7)).joins('JOIN lucky_number_seven ON lucky_number_seven.id = people.id')
|
7
|
-
query.to_sql.should eq 'WITH lucky_number_seven AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 7) SELECT "people".* FROM "people" JOIN lucky_number_seven ON lucky_number_seven.id = people.id'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'generates an expression with multiple CTEs' do
|
11
|
-
query = Person.with(lucky_number_seven: Person.where(lucky_number: 7), lucky_number_three: Person.where(lucky_number: 3)).joins('JOIN lucky_number_seven ON lucky_number_seven.id = people.id').joins('JOIN lucky_number_three ON lucky_number_three.id = people.id')
|
12
|
-
query.to_sql.should eq 'WITH lucky_number_seven AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 7), lucky_number_three AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 3) SELECT "people".* FROM "people" JOIN lucky_number_seven ON lucky_number_seven.id = people.id JOIN lucky_number_three ON lucky_number_three.id = people.id'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'generates an expression with multiple with calls' do
|
16
|
-
query = Person.with(lucky_number_seven: Person.where(lucky_number: 7)).with(lucky_number_three: Person.where(lucky_number: 3)).joins('JOIN lucky_number_seven ON lucky_number_seven.id = people.id').joins('JOIN lucky_number_three ON lucky_number_three.id = people.id')
|
17
|
-
query.to_sql.should eq 'WITH lucky_number_seven AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 7), lucky_number_three AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 3) SELECT "people".* FROM "people" JOIN lucky_number_seven ON lucky_number_seven.id = people.id JOIN lucky_number_three ON lucky_number_three.id = people.id'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '.from_cte(common_table_expression_hash)' do
|
22
|
-
it 'generates an expression with the CTE as the main table' do
|
23
|
-
query = Person.from_cte('lucky_number_seven', Person.where(lucky_number: 7)).where(id: 5)
|
24
|
-
query.to_sql.should eq 'WITH lucky_number_seven AS (SELECT "people".* FROM "people" WHERE "people"."lucky_number" = 7) SELECT "lucky_number_seven".* FROM "lucky_number_seven" WHERE "lucky_number_seven"."id" = 5'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns instances of the model' do
|
28
|
-
3.times { Person.create! lucky_number: 7 }
|
29
|
-
3.times { Person.create! lucky_number: 3 }
|
30
|
-
people = Person.from_cte('lucky_number_seven', Person.where(lucky_number: 7))
|
31
|
-
|
32
|
-
people.count.should eq 3
|
33
|
-
people.first.lucky_number.should eq 7
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/queries/sanity_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Ensure that we don\'t stomp on Active Record\'s queries' do
|
4
|
-
describe '.where' do
|
5
|
-
it 'generates IN clauses for non array columns' do
|
6
|
-
query = Person.where(:id => [1,2,3]).to_sql
|
7
|
-
|
8
|
-
query.should match /IN \(1, 2, 3\)/
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'generates IN clauses for non array columns' do
|
12
|
-
query = Person.where(:id => []).to_sql
|
13
|
-
|
14
|
-
query.should match /WHERE 1=0/
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Window functions' do
|
4
|
-
describe 'ranked' do
|
5
|
-
it 'uses the order when no order is passed to ranked' do
|
6
|
-
query = Person.order(lucky_number: :desc).ranked
|
7
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY "people"."lucky_number" DESC) FROM "people" ORDER BY "people"."lucky_number" DESC'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'uses the order when no order is passed to ranked, swapped calls' do
|
11
|
-
query = Person.ranked.order(lucky_number: :desc)
|
12
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY "people"."lucky_number" DESC) FROM "people" ORDER BY "people"."lucky_number" DESC'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'uses the rank value when there is an order passed to it' do
|
16
|
-
query = Person.ranked(lucky_number: :desc)
|
17
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY "people"."lucky_number" DESC) FROM "people"'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'uses the rank value when a symbol passed to it' do
|
21
|
-
query = Person.ranked(:lucky_number)
|
22
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY "people"."lucky_number" ASC) FROM "people"'
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'uses the rank value when a string passed to it' do
|
26
|
-
query = Person.ranked('ORDER BY lucky_number DESC')
|
27
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY lucky_number DESC) FROM "people"'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'combines the order and rank' do
|
31
|
-
query = Person.ranked(lucky_number: :desc).order(id: :asc)
|
32
|
-
query.to_sql.should eq 'SELECT "people".*, rank() OVER (ORDER BY "people"."lucky_number" DESC) FROM "people" ORDER BY "people"."id" ASC'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'executes the query with the rank' do
|
36
|
-
Person.create!
|
37
|
-
Person.create!
|
38
|
-
|
39
|
-
ranked_people = Person.ranked(:id)
|
40
|
-
ranked_people[0].rank.should eq 1
|
41
|
-
ranked_people[1].rank.should eq 2
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'does not apply the rank when performing a count' do
|
45
|
-
query = Person.ranked(lucky_number: :desc).count
|
46
|
-
query.should eq 0
|
47
|
-
|
48
|
-
Person.create!
|
49
|
-
|
50
|
-
query = Person.ranked(lucky_number: :desc).count
|
51
|
-
query.should eq 1
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# Configure Rails Envinronment
|
2
|
-
ENV['RAILS_ENV'] = 'test'
|
3
|
-
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
4
|
-
|
5
|
-
require 'rspec/rails'
|
6
|
-
require 'rspec/autorun'
|
7
|
-
require 'bourne'
|
8
|
-
|
9
|
-
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
10
|
-
|
11
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
12
|
-
# in spec/support/ and its subdirectories.
|
13
|
-
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
|
14
|
-
require 'postgres_ext'
|
15
|
-
require 'database_cleaner'
|
16
|
-
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.before(:suite) { ActiveRecord::Base.connection.enable_extension('pg_trgm') }
|
19
|
-
config.before(:suite) do
|
20
|
-
DatabaseCleaner.clean
|
21
|
-
DatabaseCleaner.strategy = :deletion
|
22
|
-
end
|
23
|
-
config.before(:each) do
|
24
|
-
DatabaseCleaner.clean
|
25
|
-
end
|
26
|
-
config.use_transactional_fixtures = false
|
27
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
28
|
-
config.mock_with :mocha
|
29
|
-
config.backtrace_clean_patterns = [
|
30
|
-
#/\/lib\d*\/ruby\//,
|
31
|
-
#/bin\//,
|
32
|
-
#/gems/,
|
33
|
-
#/spec\/spec_helper\.rb/,
|
34
|
-
/lib\/rspec\/(core|expectations|matchers|mocks)/
|
35
|
-
]
|
36
|
-
end
|