easy_union_set 0.0.1

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.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/lib/easy_union_set/version.rb +3 -0
  6. data/lib/easy_union_set.rb +31 -0
  7. data/lib/tasks/easy_union_set_tasks.rake +4 -0
  8. data/test/dummy/README.rdoc +28 -0
  9. data/test/dummy/Rakefile +6 -0
  10. data/test/dummy/app/assets/javascripts/application.js +13 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  12. data/test/dummy/app/controllers/application_controller.rb +5 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/models/project.rb +2 -0
  15. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  16. data/test/dummy/bin/bundle +3 -0
  17. data/test/dummy/bin/rails +4 -0
  18. data/test/dummy/bin/rake +4 -0
  19. data/test/dummy/config/application.rb +26 -0
  20. data/test/dummy/config/boot.rb +5 -0
  21. data/test/dummy/config/database.yml +25 -0
  22. data/test/dummy/config/environment.rb +5 -0
  23. data/test/dummy/config/environments/development.rb +37 -0
  24. data/test/dummy/config/environments/production.rb +82 -0
  25. data/test/dummy/config/environments/test.rb +39 -0
  26. data/test/dummy/config/initializers/assets.rb +8 -0
  27. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  29. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  30. data/test/dummy/config/initializers/inflections.rb +16 -0
  31. data/test/dummy/config/initializers/mime_types.rb +4 -0
  32. data/test/dummy/config/initializers/session_store.rb +3 -0
  33. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  34. data/test/dummy/config/locales/en.yml +23 -0
  35. data/test/dummy/config/routes.rb +56 -0
  36. data/test/dummy/config/secrets.yml +22 -0
  37. data/test/dummy/config.ru +4 -0
  38. data/test/dummy/db/development.sqlite3 +0 -0
  39. data/test/dummy/db/migrate/20140804121508_create_projects.rb +11 -0
  40. data/test/dummy/db/schema.rb +24 -0
  41. data/test/dummy/db/test.sqlite3 +0 -0
  42. data/test/dummy/log/development.log +3899 -0
  43. data/test/dummy/log/test.log +35 -0
  44. data/test/dummy/public/404.html +67 -0
  45. data/test/dummy/public/422.html +67 -0
  46. data/test/dummy/public/500.html +66 -0
  47. data/test/dummy/public/favicon.ico +0 -0
  48. data/test/dummy/spec/easy_union_set_spec.rb +60 -0
  49. data/test/dummy/spec/factories/projects.rb +9 -0
  50. data/test/dummy/spec/rails_helper.rb +44 -0
  51. data/test/dummy/spec/spec_helper.rb +80 -0
  52. data/test/easy_union_set_test.rb +7 -0
  53. data/test/test_helper.rb +15 -0
  54. metadata +227 -0
@@ -0,0 +1,35 @@
1
+  (1.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) 
2
+  (0.2ms) select sqlite_version(*)
3
+  (1.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
4
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
5
+ Migrating to CreateProjects (20140804121508)
6
+  (0.1ms) begin transaction
7
+  (0.4ms) CREATE TABLE "projects" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" varchar(255), "category" varchar(255), "created_at" datetime, "updated_at" datetime)
8
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20140804121508"]]
9
+  (0.9ms) commit transaction
10
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
11
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
12
+  (0.1ms) begin transaction
13
+  (0.1ms) rollback transaction
14
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
15
+  (0.1ms) begin transaction
16
+  (0.1ms) rollback transaction
17
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
18
+  (0.1ms) begin transaction
19
+  (0.1ms) rollback transaction
20
+  (0.1ms) begin transaction
21
+  (0.1ms) rollback transaction
22
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
23
+  (0.1ms) begin transaction
24
+  (0.1ms) rollback transaction
25
+  (0.1ms) begin transaction
26
+  (0.1ms) rollback transaction
27
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
28
+  (0.1ms) begin transaction
29
+  (0.1ms) rollback transaction
30
+  (0.1ms) begin transaction
31
+  (0.1ms) rollback transaction
32
+  (0.1ms) begin transaction
33
+  (0.0ms) rollback transaction
34
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
35
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,60 @@
1
+ require 'rails_helper'
2
+
3
+ describe EasyUnionSet do
4
+ it "is included in AR::Relation" do
5
+ expect(ActiveRecord::Relation).to include(EasyUnionSet::GroupMethods)
6
+ end
7
+
8
+ it "allows me to make a union" do
9
+ create_list(:project, 10)
10
+ expect((Project.where("title LIKE '%a%'") | Project.where("title LIKE '%e%'")).to_sql).to include('UNION')
11
+ end
12
+
13
+ it "allows me to make an intersection" do
14
+ create_list(:project, 10)
15
+ expect((Project.where("title LIKE '%a%'") & Project.where("title LIKE '%e%'")).to_sql).to include('INTERSECT')
16
+ end
17
+
18
+ it "allows me to combine multiple intersections and unions" do
19
+ create_list(:project, 20)
20
+ query = ->{ Project.where("title LIKE '%a%'") | Project.where("description LIKE '%e%'") & Project.where("description LIKE '%a%'") }
21
+ expect(&query).to_not raise_error
22
+ expect(query.call.to_sql).to include('UNION', 'INTERSECT')
23
+ end
24
+
25
+ describe "the return value of unions and sets" do
26
+ it "is accurate when using 3 ar:objects where each individual obj matches one of the querries" do
27
+ project1 = create(:project, :title => "George's project")
28
+ project2 = create(:project, :description => "some proj")
29
+ project3 = create(:project, :category => "projectile")
30
+
31
+ expect(Project.where("title LIKE '%proj%'") | Project.where("description LIKE '%proj%'") | Project.where("category LIKE '%proj%'")).to include(project1, project2, project3)
32
+ end
33
+
34
+ it "returns the same object 3 times if it matches 3 of the querries using a union all" do
35
+ project = create(:project, :title => "George's project", :description => "some proj", :category => "projectile")
36
+
37
+ expect(Project.where("title LIKE '%proj%'") | {all: Project.where("description LIKE '%proj%'")} | {all: Project.where("category LIKE '%proj%'")}).to include(project)
38
+ expect((Project.where("title LIKE '%proj%'") | {all: Project.where("description LIKE '%proj%'")} | {all: Project.where("category LIKE '%proj%'")}).count).to eq(3)
39
+ end
40
+
41
+ it "returns 1 object using a set if the object matches all 3 querries" do
42
+ project = create(:project, :title => "George's project", :description => "some proj", :category => "projectile")
43
+
44
+ expect(Project.where("title LIKE '%proj%'") & Project.where("description LIKE '%proj%'") & Project.where("category LIKE '%proj%'")).to include(project)
45
+ end
46
+
47
+ it "does not return anything if one of the queries using a set doesnt match anything" do
48
+ create(:project, :title => "George's project", :description => "some proj", :category => "projectile")
49
+
50
+ expect(Project.where("title LIKE '%proj%'") & Project.where("description LIKE '%proj%'") & Project.where("category LIKE 'blahblah'")).to be_empty
51
+ end
52
+
53
+ end
54
+
55
+ it "still allows me to make ruby unions and intersects by using the to_a method" do
56
+ project = create(:project, :title => "George's project", :description => "some proj", :category => "projectile")
57
+
58
+ expect(Project.where("title LIKE '%proj%'").to_a & Project.where("description LIKE '%proj%'").to_a & Project.where("category LIKE '%proj%'").to_a).to include(project)
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :project do
5
+ title { Faker::Hacker.noun }
6
+ description { Faker::Lorem.sentence }
7
+ category { Faker::Company.bs }
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require 'spec_helper'
4
+ require File.expand_path("../../config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc, in
8
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
9
+ # run as spec files by default. This means that files in spec/support that end
10
+ # in _spec.rb will both be required and run as specs, causing the specs to be
11
+ # run twice. It is recommended that you do not name files matching this glob to
12
+ # end with _spec.rb. You can configure this pattern with with the --pattern
13
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
14
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
15
+
16
+ # Checks for pending migrations before tests are run.
17
+ # If you are not using ActiveRecord, you can remove this line.
18
+ ActiveRecord::Migration.maintain_test_schema!
19
+
20
+ RSpec.configure do |config|
21
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
22
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
23
+
24
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
+ # examples within a transaction, remove the following line or assign false
26
+ # instead of true.
27
+ config.use_transactional_fixtures = true
28
+
29
+ # RSpec Rails can automatically mix in different behaviours to your tests
30
+ # based on their file location, for example enabling you to call `get` and
31
+ # `post` in specs under `spec/controllers`.
32
+ #
33
+ # You can disable this behaviour by removing the line below, and instead
34
+ # explicitly tag your specs with their type, e.g.:
35
+ #
36
+ # RSpec.describe UsersController, :type => :controller do
37
+ # # ...
38
+ # end
39
+ #
40
+ # The different available types are documented in the features, such as in
41
+ # https://relishapp.com/rspec/rspec-rails/docs
42
+ config.include FactoryGirl::Syntax::Methods
43
+ config.infer_spec_type_from_file_location!
44
+ end
@@ -0,0 +1,80 @@
1
+ require File.expand_path("../../config/environment", __FILE__)
2
+
3
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, make a
12
+ # separate helper file that requires this one and then use it only in the specs
13
+ # that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # The settings below are suggested to provide a good initial experience
21
+ # with RSpec, but feel free to customize to your heart's content.
22
+ =begin
23
+ # These two settings work together to allow you to limit a spec run
24
+ # to individual examples or groups you care about by tagging them with
25
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
26
+ # get run.
27
+ config.filter_run :focus
28
+ config.run_all_when_everything_filtered = true
29
+
30
+ # Many RSpec users commonly either run the entire suite or an individual
31
+ # file, and it's useful to allow more verbose output when running an
32
+ # individual spec file.
33
+ if config.files_to_run.one?
34
+ # Use the documentation formatter for detailed output,
35
+ # unless a formatter has already been configured
36
+ # (e.g. via a command-line flag).
37
+ config.default_formatter = 'doc'
38
+ end
39
+
40
+ # Print the 10 slowest examples and example groups at the
41
+ # end of the spec run, to help surface which specs are running
42
+ # particularly slow.
43
+ config.profile_examples = 10
44
+
45
+ # Run specs in random order to surface order dependencies. If you find an
46
+ # order dependency and want to debug it, you can fix the order by providing
47
+ # the seed, which is printed after each run.
48
+ # --seed 1234
49
+ config.order = :random
50
+
51
+ # Seed global randomization in this process using the `--seed` CLI option.
52
+ # Setting this allows you to use `--seed` to deterministically reproduce
53
+ # test failures related to randomization by passing the same `--seed` value
54
+ # as the one that triggered the failure.
55
+ Kernel.srand config.seed
56
+
57
+ # rspec-expectations config goes here. You can use an alternate
58
+ # assertion/expectation library such as wrong or the stdlib/minitest
59
+ # assertions if you prefer.
60
+ config.expect_with :rspec do |expectations|
61
+ # Enable only the newer, non-monkey-patching expect syntax.
62
+ # For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ expectations.syntax = :expect
65
+ end
66
+
67
+ # rspec-mocks config goes here. You can use an alternate test double
68
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
69
+ config.mock_with :rspec do |mocks|
70
+ # Enable only the newer, non-monkey-patching expect syntax.
71
+ # For more details, see:
72
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
+ mocks.syntax = :expect
74
+
75
+ # Prevents you from mocking or stubbing a method that does not exist on
76
+ # a real object. This is generally recommended.
77
+ mocks.verify_partial_doubles = true
78
+ end
79
+ =end
80
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class EasyUnionSetTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, EasyUnionSet
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end