squint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,65 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ title: Post One Title
5
+ body: Post One Body
6
+ request_info: { referer: "http://example.com/one" }
7
+ properties: { referer: "http://example.com/one" }
8
+
9
+ two:
10
+ title: Post Two Title
11
+ body: Post Two Body
12
+ request_info: { referer: "http://example.com/two" }
13
+ properties: { referer: "http://example.com/two" }
14
+
15
+ three:
16
+ title: Post Three Title
17
+ body: Post Three Body
18
+
19
+ with_storext:
20
+ title: With Storext title
21
+ body: With Storext title
22
+ request_info: { referer: "http://example.com/random" }
23
+ properties: { referer: "http://example.com/random" }
24
+ storext_jsonb_attributes: { jsonb_zip_code: '35124' }
25
+ storext_hstore_attributes: { hstore_zip_code: '35124' }
26
+
27
+ with_storext_friends:
28
+ title: With Storext friends title
29
+ body: With Storext friends title
30
+ request_info: { referer: "http://example.com/random" }
31
+ properties: { referer: "http://example.com/random" }
32
+ storext_jsonb_attributes: { jsonb_zip_code: '36081', jsonb_friend_count: 10 }
33
+ storext_hstore_attributes: { hstore_zip_code: '36081', hstore_friend_count: 10 }
34
+
35
+ with_storext_is_awesome_default:
36
+ title: With Storext is awesome title
37
+ body: With Storext is awesome title
38
+ request_info: { referer: "http://example.com/random" }
39
+ properties: { referer: "http://example.com/random" }
40
+ storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_awesome: false }
41
+ storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_awesome: false }
42
+
43
+ with_storext_is_awesome_not_default:
44
+ title: With Storext is aweesome not default title
45
+ body: With Storext is awesome not default body
46
+ request_info: { referer: "http://example.com/random" }
47
+ properties: { referer: "http://example.com/random" }
48
+ storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_awesome: true }
49
+ storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_awesome: true }
50
+
51
+ with_storext_is_present_default:
52
+ title: With Storext is present default title
53
+ body: With Storext is present default body
54
+ request_info: { referer: "http://example.com/random" }
55
+ properties: { referer: "http://example.com/random" }
56
+ storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_present: nil }
57
+ storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_present: nil }
58
+
59
+ with_storext_is_present_not_default:
60
+ title: With Storext is present not default title
61
+ body: With Storext is present not default body
62
+ request_info: { referer: "http://example.com/random" }
63
+ properties: { referer: "http://example.com/random" }
64
+ storext_jsonb_attributes: { jsonb_zip_code: '36085', jsonb_friend_count: 11, jsonb_is_present: "Heck Yeah" }
65
+ storext_hstore_attributes: { hstore_zip_code: '36085', hstore_friend_count: 11, hstore_is_present: "Heck Yeah" }
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ one:
4
+ title: MyString
5
+ body: MyString
6
+ request_info:
7
+ properties:
8
+
9
+ two:
10
+ title: MyString
11
+ body: MyString
12
+ request_info:
13
+ properties:
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ [:request_info, :properties].each do |prop_name|
5
+ test "generates SQL for #{prop_name}" do
6
+ sql_string = Post.where(prop_name => { referer: "http://example.com/one" } ).to_sql
7
+ puts sql_string
8
+ assert_match(/\"posts\".\"#{prop_name}\"-[>]{1,2}\'referer\'/, sql_string)
9
+ end
10
+
11
+ test "finds records for #{prop_name}" do
12
+ reln = Post.where(prop_name => { referer: "http://example.com/one" } )
13
+ puts reln.to_sql
14
+ assert_equal 1,reln.count
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+
3
+ class SquintTest < ActiveSupport::TestCase
4
+ self.use_transactional_fixtures = true
5
+
6
+ # Tests that should pass for both jsonb and hstore properties
7
+ %i[request_info properties].each do |prop_name|
8
+ test "generates SQL for #{prop_name}" do
9
+ sql_string = Post.where(prop_name => { referer: "http://example.com/one" }).to_sql
10
+ assert_match(/\"posts\".\"#{prop_name}\"-[>]{1,2}\'referer\'/, sql_string)
11
+ end
12
+
13
+ test "finds records for #{prop_name} populated" do
14
+ reln = Post.where(prop_name => { referer: "http://example.com/one" })
15
+ assert_equal 1, reln.count
16
+ end
17
+
18
+ test "finds records for #{prop_name} populated with array" do
19
+ reln = Post.where(
20
+ prop_name => { referer: ["http://example.com/one", "http://example.com/two"] }
21
+ )
22
+ assert_equal 2, reln.count, reln.to_sql
23
+ end
24
+ end
25
+
26
+ %i[request_info properties].each do |prop_name|
27
+ test "finds records for #{prop_name} populated with array including nil" do
28
+ reln = Post.where(prop_name => { referer: ["http://example.com/one", nil] })
29
+ assert_equal 2, reln.count, reln.to_sql
30
+ end
31
+
32
+ test "finds records for #{prop_name} with nil" do
33
+ reln = Post.where(prop_name => { referer: nil })
34
+ assert_equal 1, reln.count, reln.to_sql
35
+ end
36
+
37
+ test "finds records for #{prop_name} missing element that doesn't exist with nil" do
38
+ reln = Post.where(prop_name => { not_there: nil })
39
+ assert_equal Post.all.count, reln.count, reln.to_sql
40
+ end
41
+
42
+ test "Doesn't find records for #{prop_name} missing element that doesn't exist populated" do
43
+ reln = Post.where(prop_name => { not_there: "any value will do" })
44
+ assert_equal 0, reln.count, reln.to_sql
45
+ end
46
+ end
47
+
48
+ [[:storext_jsonb_attributes, 'jsonb'],
49
+ [:storext_hstore_attributes, 'hstore']].each do |prop_name, prefix|
50
+ test "detects present #{prop_name}" do
51
+ reln = Post.where(prop_name => { "#{prefix}_zip_code": '35124' })
52
+ # puts reln.to_sql
53
+ assert_equal 1, reln.count, reln.to_sql
54
+ end
55
+
56
+ test "#{prop_name} is composeable in one where" do
57
+ # get the first matching post
58
+ posts = Post.where(prop_name => { "#{prefix}_zip_code": '90210' })
59
+ # compose with previous query with the id of first post
60
+ reln = Post.where(prop_name => { "#{prefix}_zip_code": '90210' }, id: posts.first.id)
61
+ # puts reln.to_sql
62
+ assert_operator posts.count, :>, 1
63
+ assert_equal 1, reln.count, reln.to_sql
64
+ end
65
+
66
+ test "#{prop_name} is composeable in multiple wheres" do
67
+ # get the first matching post
68
+ posts = Post.where(prop_name => { "#{prefix}_zip_code": '90210' })
69
+ # compose with previous query with the id of first post
70
+ reln = Post.where(prop_name => { "#{prefix}_zip_code": '90210' }).where(id: posts.first.id)
71
+ # puts reln.to_sql
72
+ assert posts.count > 1
73
+ assert_equal 1, reln.count, reln.to_sql
74
+ end
75
+ end
76
+
77
+ [[:storext_jsonb_attributes, 'jsonb'],
78
+ [:storext_hstore_attributes, 'hstore']].each do |prop_name, prefix|
79
+ test "detects default #{prop_name}" do
80
+ reln = Post.where(prop_name => { "#{prefix}_zip_code": '90210' })
81
+ # puts reln.to_sql
82
+ assert_equal Post.all.count - 6, reln.count, reln.to_sql
83
+ end
84
+
85
+ test "detects present integer #{prop_name}" do
86
+ reln = Post.where(prop_name => { "#{prefix}_friend_count": 10 })
87
+ # puts reln.to_sql
88
+ assert_equal 1, reln.count, reln.to_sql
89
+ end
90
+
91
+ test "detects default integer #{prop_name}" do
92
+ reln = Post.where(prop_name => { "#{prefix}_friend_count": 0 })
93
+ # puts reln.to_sql
94
+ assert_equal Post.all.count - 5, reln.count, reln.to_sql
95
+ end
96
+
97
+ test "detects default Falseclass #{prop_name}" do
98
+ reln = Post.where(prop_name => { "#{prefix}_is_awesome": false })
99
+ # puts reln.to_sql
100
+ assert_equal Post.all.count - 1, reln.count, reln.to_sql
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,29 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths =
6
+ [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
7
+ require "rails/test_help"
8
+
9
+ require 'minitest/focus'
10
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
11
+ # to be shown.
12
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
13
+
14
+ # Load support files
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
16
+
17
+ # Load fixtures from the engine
18
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
19
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../dummy/test/fixtures", __FILE__)
20
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
21
+ ActiveSupport::TestCase.fixtures :all
22
+ end
23
+
24
+ class ActiveSupport::TestCase
25
+ fixtures :all
26
+ # 'cuz I want to be able to login to the db and see things
27
+ # and there aren't many tests here anyway, so speed isn't a problem
28
+ self.use_transactional_fixtures = false
29
+ end
@@ -0,0 +1,20 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
6
+ require "rails/test_help"
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
11
+
12
+ # Load support files
13
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
14
+
15
+ # Load fixtures from the engine
16
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
17
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
18
+ ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
19
+ ActiveSupport::TestCase.fixtures :all
20
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: squint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David H. Wilkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Use rails semantics to search keys and values inside PostgreSQL jsonb,
42
+ json and hstore columns. Compatible with StoreXT attributes.
43
+ email:
44
+ - dwilkins@proctoru.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - Rakefile
51
+ - lib/squint.rb
52
+ - lib/squint/version.rb
53
+ - test/dummy/Rakefile
54
+ - test/dummy/app/models/post.rb
55
+ - test/dummy/app/models/post.rb~
56
+ - test/dummy/config.ru
57
+ - test/dummy/config/application.rb
58
+ - test/dummy/config/boot.rb
59
+ - test/dummy/config/database.yml
60
+ - test/dummy/config/database.yml~
61
+ - test/dummy/config/environment.rb
62
+ - test/dummy/config/environments/test.rb
63
+ - test/dummy/db/migrate/20170512185941_create_posts.rb
64
+ - test/dummy/db/migrate/20170512185941_create_posts.rb~
65
+ - test/dummy/db/schema.rb
66
+ - test/dummy/log/development.log
67
+ - test/dummy/log/test.log
68
+ - test/dummy/test/fixtures/posts.yml
69
+ - test/dummy/test/fixtures/posts.yml~
70
+ - test/dummy/test/models/post_test.rb
71
+ - test/dummy/test/models/post_test.rb~
72
+ - test/squint_test.rb
73
+ - test/test_helper.rb
74
+ - test/test_helper.rb~
75
+ homepage: https://github.com/ProctorU/squint
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.11
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Search PostgreSQL jsonb and hstore columns
99
+ test_files:
100
+ - test/test_helper.rb
101
+ - test/dummy/Rakefile
102
+ - test/dummy/app/models/post.rb~
103
+ - test/dummy/app/models/post.rb
104
+ - test/dummy/test/models/post_test.rb
105
+ - test/dummy/test/models/post_test.rb~
106
+ - test/dummy/test/fixtures/posts.yml~
107
+ - test/dummy/test/fixtures/posts.yml
108
+ - test/dummy/config/database.yml~
109
+ - test/dummy/config/environments/test.rb
110
+ - test/dummy/config/application.rb
111
+ - test/dummy/config/boot.rb
112
+ - test/dummy/config/environment.rb
113
+ - test/dummy/config/database.yml
114
+ - test/dummy/config.ru
115
+ - test/dummy/log/development.log
116
+ - test/dummy/log/test.log
117
+ - test/dummy/db/schema.rb
118
+ - test/dummy/db/migrate/20170512185941_create_posts.rb~
119
+ - test/dummy/db/migrate/20170512185941_create_posts.rb
120
+ - test/test_helper.rb~
121
+ - test/squint_test.rb