hyper-mesh 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +27 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +396 -0
- data/Rakefile +6 -0
- data/app/controllers/reactive_record/application_controller.rb +4 -0
- data/app/controllers/reactive_record/reactive_record_controller.rb +49 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/codeship.database.yml +18 -0
- data/config/routes.rb +7 -0
- data/docs/action_cable_quickstart.md +151 -0
- data/docs/authorization-policies.md +449 -0
- data/docs/client_side_scoping.md +103 -0
- data/docs/pusher_quickstart.md +0 -0
- data/docs/simple_poller_quickstart.md +121 -0
- data/docs/todo-example.md +116 -0
- data/docs/words-example.md +65 -0
- data/examples/action-cable/.gitignore +21 -0
- data/examples/action-cable/Gemfile +58 -0
- data/examples/action-cable/Gemfile.lock +247 -0
- data/examples/action-cable/README.md +24 -0
- data/examples/action-cable/Rakefile +6 -0
- data/examples/action-cable/app/assets/config/manifest.js +3 -0
- data/examples/action-cable/app/assets/javascripts/application.js +18 -0
- data/examples/action-cable/app/assets/stylesheets/application.css +15 -0
- data/examples/action-cable/app/controllers/application_controller.rb +3 -0
- data/examples/action-cable/app/controllers/test_controller.rb +6 -0
- data/examples/action-cable/app/models/models.rb +2 -0
- data/examples/action-cable/app/models/public/application_record.rb +3 -0
- data/examples/action-cable/app/models/public/word.rb +2 -0
- data/examples/action-cable/app/policies/application_policy.rb +6 -0
- data/examples/action-cable/app/views/components.rb +17 -0
- data/examples/action-cable/app/views/components/app.rb +18 -0
- data/examples/action-cable/app/views/layouts/application.html.erb +14 -0
- data/examples/action-cable/app/views/layouts/mailer.html.erb +13 -0
- data/examples/action-cable/app/views/layouts/mailer.text.erb +1 -0
- data/examples/action-cable/bin/bundle +3 -0
- data/examples/action-cable/bin/rails +9 -0
- data/examples/action-cable/bin/rake +9 -0
- data/examples/action-cable/bin/setup +34 -0
- data/examples/action-cable/bin/spring +15 -0
- data/examples/action-cable/bin/update +29 -0
- data/examples/action-cable/config.ru +5 -0
- data/examples/action-cable/config/application.rb +30 -0
- data/examples/action-cable/config/boot.rb +3 -0
- data/examples/action-cable/config/cable.yml +9 -0
- data/examples/action-cable/config/database.yml +25 -0
- data/examples/action-cable/config/environment.rb +5 -0
- data/examples/action-cable/config/environments/development.rb +45 -0
- data/examples/action-cable/config/environments/production.rb +86 -0
- data/examples/action-cable/config/environments/test.rb +42 -0
- data/examples/action-cable/config/initializers/application_controller_renderer.rb +6 -0
- data/examples/action-cable/config/initializers/assets.rb +11 -0
- data/examples/action-cable/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/action-cable/config/initializers/cookies_serializer.rb +5 -0
- data/examples/action-cable/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/action-cable/config/initializers/inflections.rb +16 -0
- data/examples/action-cable/config/initializers/mime_types.rb +4 -0
- data/examples/action-cable/config/initializers/new_framework_defaults.rb +24 -0
- data/examples/action-cable/config/initializers/session_store.rb +3 -0
- data/examples/action-cable/config/initializers/synchromesh.rb +5 -0
- data/examples/action-cable/config/initializers/wrap_parameters.rb +14 -0
- data/examples/action-cable/config/locales/en.yml +23 -0
- data/examples/action-cable/config/puma.rb +47 -0
- data/examples/action-cable/config/routes.rb +5 -0
- data/examples/action-cable/config/secrets.yml +22 -0
- data/examples/action-cable/config/spring.rb +6 -0
- data/examples/action-cable/db/migrate/20160921223808_create_words.rb +9 -0
- data/examples/action-cable/db/schema.rb +21 -0
- data/examples/action-cable/log/.keep +0 -0
- data/examples/action-cable/public/404.html +67 -0
- data/examples/action-cable/public/422.html +67 -0
- data/examples/action-cable/public/500.html +66 -0
- data/examples/action-cable/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/action-cable/public/apple-touch-icon.png +0 -0
- data/examples/action-cable/public/favicon.ico +0 -0
- data/examples/action-cable/public/robots.txt +5 -0
- data/examples/action-cable/rails_cache_dir2/C91/480/synchromesh_active_connections +0 -0
- data/examples/action-cable/tmp/.keep +0 -0
- data/examples/action-cable/vendor/assets/javascripts/.keep +0 -0
- data/examples/action-cable/vendor/assets/stylesheets/.keep +0 -0
- data/examples/simple-poller/.gitignore +21 -0
- data/examples/simple-poller/Gemfile +64 -0
- data/examples/simple-poller/Gemfile.lock +272 -0
- data/examples/simple-poller/README.md +24 -0
- data/examples/simple-poller/Rakefile +6 -0
- data/examples/simple-poller/app/assets/config/manifest.js +3 -0
- data/examples/simple-poller/app/assets/images/.keep +0 -0
- data/examples/simple-poller/app/assets/javascripts/application.js +20 -0
- data/examples/simple-poller/app/assets/javascripts/channels/.keep +0 -0
- data/examples/simple-poller/app/assets/stylesheets/application.css +15 -0
- data/examples/simple-poller/app/channels/application_cable/channel.rb +4 -0
- data/examples/simple-poller/app/channels/application_cable/connection.rb +4 -0
- data/examples/simple-poller/app/controllers/application_controller.rb +3 -0
- data/examples/simple-poller/app/controllers/concerns/.keep +0 -0
- data/examples/simple-poller/app/controllers/test_controller.rb +6 -0
- data/examples/simple-poller/app/helpers/application_helper.rb +2 -0
- data/examples/simple-poller/app/jobs/application_job.rb +2 -0
- data/examples/simple-poller/app/mailers/application_mailer.rb +4 -0
- data/examples/simple-poller/app/models/concerns/.keep +0 -0
- data/examples/simple-poller/app/models/models.rb +2 -0
- data/examples/simple-poller/app/models/public/.keep +0 -0
- data/examples/simple-poller/app/models/public/application_record.rb +3 -0
- data/examples/simple-poller/app/models/public/word.rb +2 -0
- data/examples/simple-poller/app/policies/application_policy.rb +5 -0
- data/examples/simple-poller/app/views/components.rb +18 -0
- data/examples/simple-poller/app/views/components/.keep +0 -0
- data/examples/simple-poller/app/views/components/app.rb +40 -0
- data/examples/simple-poller/app/views/layouts/application.html.erb +14 -0
- data/examples/simple-poller/app/views/layouts/mailer.html.erb +13 -0
- data/examples/simple-poller/app/views/layouts/mailer.text.erb +1 -0
- data/examples/simple-poller/bin/bundle +3 -0
- data/examples/simple-poller/bin/rails +9 -0
- data/examples/simple-poller/bin/rake +9 -0
- data/examples/simple-poller/bin/setup +34 -0
- data/examples/simple-poller/bin/spring +16 -0
- data/examples/simple-poller/bin/update +29 -0
- data/examples/simple-poller/config.ru +5 -0
- data/examples/simple-poller/config/application.rb +20 -0
- data/examples/simple-poller/config/boot.rb +3 -0
- data/examples/simple-poller/config/cable.yml +9 -0
- data/examples/simple-poller/config/database.yml +25 -0
- data/examples/simple-poller/config/environment.rb +5 -0
- data/examples/simple-poller/config/environments/development.rb +44 -0
- data/examples/simple-poller/config/environments/production.rb +86 -0
- data/examples/simple-poller/config/environments/test.rb +42 -0
- data/examples/simple-poller/config/initializers/application_controller_renderer.rb +6 -0
- data/examples/simple-poller/config/initializers/assets.rb +11 -0
- data/examples/simple-poller/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/simple-poller/config/initializers/cookies_serializer.rb +5 -0
- data/examples/simple-poller/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/simple-poller/config/initializers/inflections.rb +16 -0
- data/examples/simple-poller/config/initializers/mime_types.rb +4 -0
- data/examples/simple-poller/config/initializers/new_framework_defaults.rb +24 -0
- data/examples/simple-poller/config/initializers/session_store.rb +3 -0
- data/examples/simple-poller/config/initializers/synchromesh.rb +15 -0
- data/examples/simple-poller/config/initializers/wrap_parameters.rb +14 -0
- data/examples/simple-poller/config/locales/en.yml +23 -0
- data/examples/simple-poller/config/puma.rb +47 -0
- data/examples/simple-poller/config/routes.rb +5 -0
- data/examples/simple-poller/config/secrets.yml +22 -0
- data/examples/simple-poller/config/spring.rb +6 -0
- data/examples/simple-poller/db/migrate/20161013220135_create_words.rb +9 -0
- data/examples/simple-poller/db/schema.rb +21 -0
- data/examples/simple-poller/db/seeds.rb +7 -0
- data/examples/simple-poller/lib/assets/.keep +0 -0
- data/examples/simple-poller/lib/tasks/.keep +0 -0
- data/examples/simple-poller/log/.keep +0 -0
- data/examples/simple-poller/public/404.html +67 -0
- data/examples/simple-poller/public/422.html +67 -0
- data/examples/simple-poller/public/500.html +66 -0
- data/examples/simple-poller/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/simple-poller/public/apple-touch-icon.png +0 -0
- data/examples/simple-poller/public/favicon.ico +0 -0
- data/examples/simple-poller/public/robots.txt +5 -0
- data/examples/simple-poller/test/controllers/.keep +0 -0
- data/examples/simple-poller/test/fixtures/.keep +0 -0
- data/examples/simple-poller/test/fixtures/files/.keep +0 -0
- data/examples/simple-poller/test/fixtures/words.yml +7 -0
- data/examples/simple-poller/test/helpers/.keep +0 -0
- data/examples/simple-poller/test/integration/.keep +0 -0
- data/examples/simple-poller/test/mailers/.keep +0 -0
- data/examples/simple-poller/test/models/.keep +0 -0
- data/examples/simple-poller/test/models/word_test.rb +7 -0
- data/examples/simple-poller/test/test_helper.rb +10 -0
- data/examples/simple-poller/tmp/.keep +0 -0
- data/examples/simple-poller/vendor/assets/javascripts/.keep +0 -0
- data/examples/simple-poller/vendor/assets/stylesheets/.keep +0 -0
- data/examples/words/.gitignore +21 -0
- data/examples/words/Gemfile +58 -0
- data/examples/words/Gemfile.lock +247 -0
- data/examples/words/README.md +24 -0
- data/examples/words/Rakefile +6 -0
- data/examples/words/app/assets/config/manifest.js +3 -0
- data/examples/words/app/assets/javascripts/application.js +18 -0
- data/examples/words/app/assets/stylesheets/application.css +15 -0
- data/examples/words/app/controllers/application_controller.rb +3 -0
- data/examples/words/app/controllers/test_controller.rb +6 -0
- data/examples/words/app/models/models.rb +2 -0
- data/examples/words/app/models/public/application_record.rb +3 -0
- data/examples/words/app/models/public/word.rb +10 -0
- data/examples/words/app/policies/application_policy.rb +6 -0
- data/examples/words/app/views/components.rb +16 -0
- data/examples/words/app/views/components/app.rb +31 -0
- data/examples/words/app/views/layouts/application.html.erb +14 -0
- data/examples/words/app/views/layouts/mailer.html.erb +13 -0
- data/examples/words/app/views/layouts/mailer.text.erb +1 -0
- data/examples/words/bin/bundle +3 -0
- data/examples/words/bin/rails +9 -0
- data/examples/words/bin/rake +9 -0
- data/examples/words/bin/setup +34 -0
- data/examples/words/bin/spring +15 -0
- data/examples/words/bin/update +29 -0
- data/examples/words/config.ru +5 -0
- data/examples/words/config/application.rb +30 -0
- data/examples/words/config/boot.rb +3 -0
- data/examples/words/config/cable.yml +9 -0
- data/examples/words/config/database.yml +25 -0
- data/examples/words/config/environment.rb +5 -0
- data/examples/words/config/environments/development.rb +45 -0
- data/examples/words/config/environments/production.rb +86 -0
- data/examples/words/config/environments/test.rb +42 -0
- data/examples/words/config/initializers/application_controller_renderer.rb +6 -0
- data/examples/words/config/initializers/assets.rb +11 -0
- data/examples/words/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/words/config/initializers/cookies_serializer.rb +5 -0
- data/examples/words/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/words/config/initializers/inflections.rb +16 -0
- data/examples/words/config/initializers/mime_types.rb +4 -0
- data/examples/words/config/initializers/new_framework_defaults.rb +24 -0
- data/examples/words/config/initializers/session_store.rb +3 -0
- data/examples/words/config/initializers/synchromesh.rb +5 -0
- data/examples/words/config/initializers/wrap_parameters.rb +14 -0
- data/examples/words/config/locales/en.yml +23 -0
- data/examples/words/config/puma.rb +47 -0
- data/examples/words/config/routes.rb +5 -0
- data/examples/words/config/secrets.yml +22 -0
- data/examples/words/config/spring.rb +6 -0
- data/examples/words/db/migrate/20160921223808_create_words.rb +9 -0
- data/examples/words/db/schema.rb +28 -0
- data/examples/words/log/.keep +0 -0
- data/examples/words/public/404.html +67 -0
- data/examples/words/public/422.html +67 -0
- data/examples/words/public/500.html +66 -0
- data/examples/words/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/words/public/apple-touch-icon.png +0 -0
- data/examples/words/public/favicon.ico +0 -0
- data/examples/words/public/robots.txt +5 -0
- data/examples/words/tmp/.keep +0 -0
- data/examples/words/vendor/assets/javascripts/.keep +0 -0
- data/examples/words/vendor/assets/stylesheets/.keep +0 -0
- data/hyper-mesh.gemspec +82 -0
- data/lib/active_record_base.rb +152 -0
- data/lib/enumerable/pluck.rb +6 -0
- data/lib/hyper-mesh.rb +62 -0
- data/lib/hypermesh/version.rb +3 -0
- data/lib/opal/equality_patches.rb +15 -0
- data/lib/opal/parse_patch.rb +14 -0
- data/lib/opal/set_patches.rb +8 -0
- data/lib/reactive_record/active_record/aggregations.rb +69 -0
- data/lib/reactive_record/active_record/associations.rb +111 -0
- data/lib/reactive_record/active_record/base.rb +9 -0
- data/lib/reactive_record/active_record/class_methods.rb +177 -0
- data/lib/reactive_record/active_record/error.rb +26 -0
- data/lib/reactive_record/active_record/instance_methods.rb +129 -0
- data/lib/reactive_record/active_record/public_columns_hash.rb +19 -0
- data/lib/reactive_record/active_record/reactive_record/base.rb +520 -0
- data/lib/reactive_record/active_record/reactive_record/collection.rb +517 -0
- data/lib/reactive_record/active_record/reactive_record/column_types.rb +67 -0
- data/lib/reactive_record/active_record/reactive_record/dummy_value.rb +218 -0
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +532 -0
- data/lib/reactive_record/active_record/reactive_record/reactive_set_relationship_helpers.rb +189 -0
- data/lib/reactive_record/active_record/reactive_record/scoped_collection.rb +62 -0
- data/lib/reactive_record/active_record/reactive_record/unscoped_collection.rb +16 -0
- data/lib/reactive_record/active_record/reactive_record/while_loading.rb +299 -0
- data/lib/reactive_record/engine.rb +13 -0
- data/lib/reactive_record/interval.rb +190 -0
- data/lib/reactive_record/permissions.rb +102 -0
- data/lib/reactive_record/pry.rb +13 -0
- data/lib/reactive_record/reactive_scope.rb +18 -0
- data/lib/reactive_record/scope_description.rb +108 -0
- data/lib/reactive_record/serializers.rb +7 -0
- data/lib/reactive_record/server_data_cache.rb +347 -0
- data/lib/reactive_record/version.rb +3 -0
- data/lib/sources/hyper-mesh/pusher.js +98 -0
- data/lib/synchromesh/action_cable.rb +39 -0
- data/lib/synchromesh/client_drivers.rb +357 -0
- data/lib/synchromesh/configuration.rb +40 -0
- data/lib/synchromesh/connection.rb +144 -0
- data/lib/synchromesh/policy.rb +504 -0
- data/lib/synchromesh/reactive_record/permission_patches.rb +43 -0
- data/lib/synchromesh/synchromesh.rb +155 -0
- data/lib/synchromesh/synchromesh_controller.rb +154 -0
- data/logo.jpg +0 -0
- data/path_release_steps.md +0 -0
- data/reactive_record_test_app/Gemfile +15 -0
- data/reactive_record_test_app/Gemfile.lock +209 -0
- data/reactive_record_test_app/README.rdoc +261 -0
- data/reactive_record_test_app/Rakefile +7 -0
- data/reactive_record_test_app/app/assets/javascripts/application.rb +5 -0
- data/reactive_record_test_app/app/assets/javascripts/components/another_component.rb +24 -0
- data/reactive_record_test_app/app/assets/javascripts/components/empty_component.rb +6 -0
- data/reactive_record_test_app/app/assets/javascripts/components/todo_item_component.js.rb +16 -0
- data/reactive_record_test_app/app/assets/javascripts/components/todos_component.js.rb +42 -0
- data/reactive_record_test_app/app/assets/javascripts/components/todos_main_component.rb +49 -0
- data/reactive_record_test_app/app/assets/javascripts/react_js_test_only.js +21618 -0
- data/reactive_record_test_app/app/assets/javascripts/reactive_record_config.js +2 -0
- data/reactive_record_test_app/app/assets/javascripts/spec/reactive_record_xspec.js.rb +42 -0
- data/reactive_record_test_app/app/assets/stylesheets/application.css +13 -0
- data/reactive_record_test_app/app/controllers/application_controller.rb +8 -0
- data/reactive_record_test_app/app/controllers/home_controller.rb +7 -0
- data/reactive_record_test_app/app/controllers/test_controller.rb +7 -0
- data/reactive_record_test_app/app/helpers/application_helper.rb +2 -0
- data/reactive_record_test_app/app/mailers/.gitkeep +0 -0
- data/reactive_record_test_app/app/models/.gitkeep +0 -0
- data/reactive_record_test_app/app/policies/application_policy.rb +5 -0
- data/reactive_record_test_app/app/views/components.rb +4 -0
- data/reactive_record_test_app/app/views/components/test.rb +18 -0
- data/reactive_record_test_app/app/views/home/index.html.erb +1 -0
- data/reactive_record_test_app/app/views/layouts/application.html.erb +17 -0
- data/reactive_record_test_app/app/views/models.rb +1 -0
- data/reactive_record_test_app/app/views/models/address.rb +13 -0
- data/reactive_record_test_app/app/views/models/comment.rb +19 -0
- data/reactive_record_test_app/app/views/models/todo_item.rb +36 -0
- data/reactive_record_test_app/app/views/models/user.rb +78 -0
- data/reactive_record_test_app/config.ru +33 -0
- data/reactive_record_test_app/config/application.rb +73 -0
- data/reactive_record_test_app/config/boot.rb +10 -0
- data/reactive_record_test_app/config/database.yml +25 -0
- data/reactive_record_test_app/config/environment.rb +5 -0
- data/reactive_record_test_app/config/environments/development.rb +43 -0
- data/reactive_record_test_app/config/environments/production.rb +70 -0
- data/reactive_record_test_app/config/environments/test.rb +41 -0
- data/reactive_record_test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/reactive_record_test_app/config/initializers/inflections.rb +15 -0
- data/reactive_record_test_app/config/initializers/mime_types.rb +5 -0
- data/reactive_record_test_app/config/initializers/secret_token.rb +7 -0
- data/reactive_record_test_app/config/initializers/session_store.rb +8 -0
- data/reactive_record_test_app/config/initializers/wrap_parameters.rb +14 -0
- data/reactive_record_test_app/config/locales/en.yml +5 -0
- data/reactive_record_test_app/config/routes.rb +7 -0
- data/reactive_record_test_app/db/migrate/20150617002932_create_todo_items.rb +11 -0
- data/reactive_record_test_app/db/migrate/20150617134028_create_users.rb +14 -0
- data/reactive_record_test_app/db/migrate/20150729195556_add_address_to_user.rb +20 -0
- data/reactive_record_test_app/db/migrate/20150826142045_create_comments.rb +10 -0
- data/reactive_record_test_app/db/migrate/20150828172008_add_single_comment_to_todo_item.rb +5 -0
- data/reactive_record_test_app/db/migrate/20150908184118_add_address_id_to_user.rb +5 -0
- data/reactive_record_test_app/db/migrate/20150917220236_add_second_address_to_user.rb +10 -0
- data/reactive_record_test_app/db/migrate/20151009000111_add_test_data_attributes_to_user.rb +6 -0
- data/reactive_record_test_app/db/migrate/20160129182544_add_test_enum_to_user.rb +5 -0
- data/reactive_record_test_app/db/schema.rb +63 -0
- data/reactive_record_test_app/db/seeds.rb +60 -0
- data/reactive_record_test_app/public/404.html +26 -0
- data/reactive_record_test_app/public/422.html +26 -0
- data/reactive_record_test_app/public/500.html +25 -0
- data/reactive_record_test_app/public/favicon.ico +0 -0
- data/reactive_record_test_app/script/rails +6 -0
- data/reactive_record_test_app/spec-opal/active-record/aggregations_spec.rb +41 -0
- data/reactive_record_test_app/spec-opal/active-record/associations_spec.rb +75 -0
- data/reactive_record_test_app/spec-opal/active-record/base_spec.rb +126 -0
- data/reactive_record_test_app/spec-opal/active-record/dummy_value_spec.rb +27 -0
- data/reactive_record_test_app/spec-opal/active-record/edge_cases_spec.rb +116 -0
- data/reactive_record_test_app/spec-opal/active-record/enum_spec.rb +43 -0
- data/reactive_record_test_app/spec-opal/active-record/instance_methods_spec.rb +53 -0
- data/reactive_record_test_app/spec-opal/active-record/non_ar_aggregations_spec.rb +74 -0
- data/reactive_record_test_app/spec-opal/active-record/permissions_spec.rb +170 -0
- data/reactive_record_test_app/spec-opal/active-record/prerendering_spec.rb +49 -0
- data/reactive_record_test_app/spec-opal/active-record/reactive_record_load_spec.rb +23 -0
- data/reactive_record_test_app/spec-opal/active-record/rendering_spec.rb +221 -0
- data/reactive_record_test_app/spec-opal/active-record/save_spec.rb +125 -0
- data/reactive_record_test_app/spec-opal/active-record/scope_spec.rb +85 -0
- data/reactive_record_test_app/spec-opal/active-record/update_aggregations_spec.rb +76 -0
- data/reactive_record_test_app/spec-opal/active-record/update_attributes_spec.rb +186 -0
- data/reactive_record_test_app/spec-opal/active-record/virtual_methods_spec.rb +71 -0
- data/reactive_record_test_app/spec-opal/index.html.erb +11 -0
- data/reactive_record_test_app/spec-opal/spec_helper.js.rb +268 -0
- data/reactive_record_test_app/spec-opal/vendor/es5-shim.min.js +6 -0
- data/reactive_record_test_app/spec_dont_run/README.md +26 -0
- data/reactive_record_test_app/spec_dont_run/moved_to_main_spec_dir/zzzmany_to_many_spec_moved_to_main_suite.rb +30 -0
- data/reactive_record_test_app/spec_dont_run/moved_to_main_spec_dir/zzzrevert_record_spec_moved.rb +78 -0
- data/reactive_record_test_app/spec_dont_run/moved_to_main_spec_dir/zzzupdate_associations_spec_moved.rb +142 -0
- data/reactive_record_test_app/spec_dont_run/moved_to_main_spec_dir/zzzupdate_scopes_movedspec.rb +48 -0
- data/remote.md +115 -0
- data/spec/bin/firebug-2.0.13-fx.xpi +0 -0
- data/spec/component_helpers_xspec.rb +49 -0
- data/spec/factories/child_model.rb +5 -0
- data/spec/factories/comment.rb +5 -0
- data/spec/factories/test_models.rb +5 -0
- data/spec/factories/todo.rb +5 -0
- data/spec/factories/user.rb +5 -0
- data/spec/reactive_record/edge_cases_spec.rb +31 -0
- data/spec/reactive_record/factory.rb +62 -0
- data/spec/reactive_record/many_to_many_spec.rb +50 -0
- data/spec/reactive_record/play.rb +64 -0
- data/spec/reactive_record/pry_rescue_xspec.rb +48 -0
- data/spec/reactive_record/revert_spec.rb +112 -0
- data/spec/reactive_record/update_associations_spec.rb +189 -0
- data/spec/reactive_record/update_scopes_spec.rb +53 -0
- data/spec/spec_helper.rb +366 -0
- data/spec/support/component_helpers.rb +351 -0
- data/spec/synchromesh/column_types/column_type_spec.rb +302 -0
- data/spec/synchromesh/connection_spec.rb +144 -0
- data/spec/synchromesh/crud_access_regulation/broadcast_controls_access_spec.rb +105 -0
- data/spec/synchromesh/crud_access_regulation/model_policies_spec.rb +131 -0
- data/spec/synchromesh/examples/dictionary.rb +239 -0
- data/spec/synchromesh/examples/dictionary_with_client_scopes.rb +196 -0
- data/spec/synchromesh/examples/random_examples.rb +100 -0
- data/spec/synchromesh/examples/scoped_todos_spec.rb +167 -0
- data/spec/synchromesh/integration/authorization_spec.rb +111 -0
- data/spec/synchromesh/integration/default_scope_spec.rb +121 -0
- data/spec/synchromesh/integration/has_many_through_spec.rb +173 -0
- data/spec/synchromesh/integration/relationships_spec.rb +263 -0
- data/spec/synchromesh/integration/scope_spec.rb +553 -0
- data/spec/synchromesh/integration/synchromesh_spec.rb +80 -0
- data/spec/synchromesh/integration/test_components.rb +18 -0
- data/spec/synchromesh/integration/transports_spec.rb +308 -0
- data/spec/synchromesh/policies/auto_connect_spec.rb +60 -0
- data/spec/synchromesh/policies/auto_loader_spec.rb +34 -0
- data/spec/synchromesh/policies/policy_methods_spec.rb +85 -0
- data/spec/synchromesh/policies/regulate_all_broadcasts_spec.rb +315 -0
- data/spec/synchromesh/policies/regulate_broadcast_spec.rb +370 -0
- data/spec/synchromesh/policies/regulate_class_connection_spec.rb +50 -0
- data/spec/synchromesh/policies/regulate_instance_connection_spec.rb +66 -0
- data/spec/test_app/Gemfile +61 -0
- data/spec/test_app/Gemfile.lock +253 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/javascripts/application.js +6 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/controllers/application_controller.rb +13 -0
- data/spec/test_app/app/controllers/test_controller.rb +5 -0
- data/spec/test_app/app/models/_react_public_models.rb +2 -0
- data/spec/test_app/app/models/public/address.rb +13 -0
- data/spec/test_app/app/models/public/child_model.rb +3 -0
- data/spec/test_app/app/models/public/comment.rb +25 -0
- data/spec/test_app/app/models/public/test_model.rb +5 -0
- data/spec/test_app/app/models/public/todo.rb +6 -0
- data/spec/test_app/app/models/public/todo_item.rb +36 -0
- data/spec/test_app/app/models/public/user.rb +88 -0
- data/spec/test_app/app/policies/auto_loader_test_classa_policy.rb +3 -0
- data/spec/test_app/app/policies/auto_loader_test_classb_policy.rb +3 -0
- data/spec/test_app/app/policies/auto_loader_test_classc_policy.rb +3 -0
- data/spec/test_app/app/policies/auto_loader_test_classd_policy.rb +3 -0
- data/spec/test_app/app/views/components.rb +14 -0
- data/spec/test_app/app/views/components/show.rb +5 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +4 -0
- data/spec/test_app/bin/rake +4 -0
- data/spec/test_app/bin/setup +29 -0
- data/spec/test_app/config.ru +4 -0
- data/spec/test_app/config/application.rb +42 -0
- data/spec/test_app/config/boot.rb +6 -0
- data/spec/test_app/config/cable.yml +10 -0
- data/spec/test_app/config/database.yml +47 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +41 -0
- data/spec/test_app/config/environments/production.rb +79 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/assets.rb +11 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/session_store.rb +3 -0
- data/spec/test_app/config/initializers/synchromesh.rb +11 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +23 -0
- data/spec/test_app/config/routes.rb +61 -0
- data/spec/test_app/config/secrets.yml +22 -0
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/migrate/20160731182106_create_test_models.rb +75 -0
- data/spec/test_app/db/schema.rb +88 -0
- data/spec/test_app/db/seeds.rb +7 -0
- data/spec/test_app/lib/assets/.keep +0 -0
- data/spec/test_app/log/.keep +0 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/vendor/es5-shim.min.js +6 -0
- data/terminal.md +66 -0
- metadata +1175 -0
@@ -0,0 +1,302 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
require 'rspec-steps'
|
4
|
+
|
5
|
+
describe "column types on client", js: true do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
# TimeXternal - lets us easily get back time values
|
9
|
+
# that will look like client json strings.
|
10
|
+
class Timex
|
11
|
+
|
12
|
+
def initialize(time = nil)
|
13
|
+
if time.is_a? Time
|
14
|
+
@time = time
|
15
|
+
elsif time.is_a? Timex
|
16
|
+
@time = time.time.dup
|
17
|
+
elsif time
|
18
|
+
@time = Time.new(time.localtime)
|
19
|
+
else
|
20
|
+
@time = Time.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(m, *args, &b)
|
25
|
+
val = time.send(m, *args, &b)
|
26
|
+
val = Timex.new(val) if val.is_a? Time
|
27
|
+
val
|
28
|
+
end
|
29
|
+
|
30
|
+
def as_json
|
31
|
+
strftime("%Y-%m-%dT%H:%M:%S%z")
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_reader :time
|
35
|
+
|
36
|
+
def time_only
|
37
|
+
utc_time = Timex.new(self).utc
|
38
|
+
start_time = Time.parse('2000-01-01T00:00:00.000-00:00').utc
|
39
|
+
Timex.new (start_time+(utc_time-utc_time.beginning_of_day.to_i).to_i).localtime
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def at(x)
|
44
|
+
Timex.new(Time.at(x))
|
45
|
+
end
|
46
|
+
def sqlmin
|
47
|
+
Timex.new(Time.parse('2001-01-01T00:00:00.000-00:00').localtime)
|
48
|
+
end
|
49
|
+
def parse(s)
|
50
|
+
Timex.new(Time.parse(s))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
require 'pusher'
|
56
|
+
require 'pusher-fake'
|
57
|
+
Pusher.app_id = "MY_TEST_ID"
|
58
|
+
Pusher.key = "MY_TEST_KEY"
|
59
|
+
Pusher.secret = "MY_TEST_SECRET"
|
60
|
+
require "pusher-fake/support/base"
|
61
|
+
|
62
|
+
HyperMesh.configuration do |config|
|
63
|
+
config.transport = :pusher
|
64
|
+
config.channel_prefix = "synchromesh"
|
65
|
+
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
|
66
|
+
end
|
67
|
+
|
68
|
+
class TypeTest < ActiveRecord::Base
|
69
|
+
def self.build_tables
|
70
|
+
connection.create_table :type_tests, force: true do |t|
|
71
|
+
t.binary :binary
|
72
|
+
t.boolean :boolean
|
73
|
+
t.date :date
|
74
|
+
t.datetime :datetime
|
75
|
+
t.decimal :decimal, precision: 5, scale: 2
|
76
|
+
t.float :float
|
77
|
+
t.integer :integer
|
78
|
+
t.bigint :bigint
|
79
|
+
t.string :string
|
80
|
+
t.text :text
|
81
|
+
t.time :time
|
82
|
+
t.timestamp :timestamp
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class DefaultTest < ActiveRecord::Base
|
88
|
+
def self.build_tables
|
89
|
+
connection.create_table :default_tests, force: true do |t|
|
90
|
+
t.string :string, default: "I'm a string!"
|
91
|
+
t.date :date, default: Date.today
|
92
|
+
t.datetime :datetime, default: Time.now
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
isomorphic do
|
98
|
+
class TypeTest < ActiveRecord::Base
|
99
|
+
end
|
100
|
+
class DefaultTest < ActiveRecord::Base
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
TypeTest.build_tables rescue nil
|
105
|
+
DefaultTest.build_tables rescue nil
|
106
|
+
|
107
|
+
ActiveRecord::Base.instance_variable_set(:@public_columns_hash, nil)
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
before(:each) do
|
112
|
+
stub_const 'ApplicationPolicy', Class.new
|
113
|
+
ApplicationPolicy.class_eval do
|
114
|
+
always_allow_connection
|
115
|
+
regulate_all_broadcasts { |policy| policy.send_all }
|
116
|
+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
117
|
+
end
|
118
|
+
|
119
|
+
size_window(:small, :portrait)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'transfers the columns hash to the client' do
|
123
|
+
expect_evaluate_ruby do
|
124
|
+
TypeTest.columns_hash
|
125
|
+
end.to eq(TypeTest.columns_hash.as_json)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'creates a dummy value of the appropriate type' do
|
129
|
+
t = Time.now
|
130
|
+
TypeTest.create(
|
131
|
+
boolean: true,
|
132
|
+
date: t,
|
133
|
+
datetime: t,
|
134
|
+
decimal: 12.2,
|
135
|
+
float: 13.2,
|
136
|
+
integer: 14,
|
137
|
+
bigint: 15,
|
138
|
+
string: "hello",
|
139
|
+
text: "goodby",
|
140
|
+
time: t,
|
141
|
+
timestamp: t
|
142
|
+
)
|
143
|
+
expect_evaluate_ruby do
|
144
|
+
TypeTest.columns_hash.collect do |attr, _info|
|
145
|
+
TypeTest.find(1).send(attr).class
|
146
|
+
end
|
147
|
+
end.to eq([
|
148
|
+
'Number', 'NilClass', 'Boolean', 'Date', 'Time', 'Number', 'Number', 'Number',
|
149
|
+
'Number', 'String', 'String', 'Time', 'Time'
|
150
|
+
])
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'loads and converts the value' do
|
154
|
+
t = Timex.parse('1/2/2003')
|
155
|
+
r = TypeTest.create(
|
156
|
+
boolean: true,
|
157
|
+
date: t.time,
|
158
|
+
datetime: t.time,
|
159
|
+
decimal: 12.2,
|
160
|
+
float: 13.2,
|
161
|
+
integer: 14,
|
162
|
+
bigint: 15,
|
163
|
+
string: "hello",
|
164
|
+
text: "goodby",
|
165
|
+
time: t.time,
|
166
|
+
timestamp: t.time
|
167
|
+
)
|
168
|
+
r.reload
|
169
|
+
expect_promise do
|
170
|
+
ReactiveRecord.load do
|
171
|
+
TypeTest.columns_hash.collect do |attr, _info|
|
172
|
+
[TypeTest.find(1).send(attr).class, TypeTest.find(1).send(attr)]
|
173
|
+
end.flatten
|
174
|
+
end
|
175
|
+
end.to eq([
|
176
|
+
'Number', 1,
|
177
|
+
'NilClass', nil,
|
178
|
+
'Boolean', true,
|
179
|
+
'Date', t.to_date.as_json,
|
180
|
+
'Time', t.as_json,
|
181
|
+
'Number', 12.2,
|
182
|
+
'Number', 13.2,
|
183
|
+
'Number', 14,
|
184
|
+
'Number', 15,
|
185
|
+
'String', 'hello',
|
186
|
+
'String', 'goodby',
|
187
|
+
'Time', t.time_only.as_json, # date is indeterminate for active record time
|
188
|
+
'Time', t.as_json
|
189
|
+
])
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'while loading the dummy value delegates the correct type with operators etc' do
|
193
|
+
t = Time.parse('1/2/2003')
|
194
|
+
TypeTest.create(
|
195
|
+
boolean: true,
|
196
|
+
date: t,
|
197
|
+
datetime: t,
|
198
|
+
decimal: 12.2,
|
199
|
+
float: 13.2,
|
200
|
+
integer: 14,
|
201
|
+
bigint: 15,
|
202
|
+
string: "hello",
|
203
|
+
text: "goodby",
|
204
|
+
time: t,
|
205
|
+
timestamp: t
|
206
|
+
)
|
207
|
+
expect_evaluate_ruby do
|
208
|
+
t = TypeTest.find(1)
|
209
|
+
[
|
210
|
+
!t.boolean, t.date+1, t.datetime+2.days, t.decimal + 5, t.float + 6, t.integer + 7,
|
211
|
+
t.bigint + 8, t.string.length, t.text.length, t.time+3.days, t.timestamp+4.days
|
212
|
+
]
|
213
|
+
end.to eq([
|
214
|
+
true, "2001-01-02", (Timex.sqlmin+2.days).as_json, 5, 6, 7,
|
215
|
+
8, 0, 0, (Timex.sqlmin+3.days).as_json, (Timex.sqlmin+4.days).as_json
|
216
|
+
])
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'converts a time string to a time on writing' do
|
220
|
+
expect_evaluate_ruby do
|
221
|
+
test = TypeTest.new
|
222
|
+
test.datetime = "1/1/2001"
|
223
|
+
(test.datetime + 1.minute)
|
224
|
+
end.to eq((Timex.parse("1/1/2001") + 1.minute).as_json)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'converts a integer to a time on writing' do
|
228
|
+
expect_evaluate_ruby do
|
229
|
+
test = TypeTest.new
|
230
|
+
test.datetime = 12
|
231
|
+
test.datetime + 60.seconds
|
232
|
+
end.to eq((Timex.at(12)+60.seconds).as_json)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'converts a float to a time on writing' do
|
236
|
+
expect_evaluate_ruby do
|
237
|
+
test = TypeTest.new
|
238
|
+
test.datetime = 12.2
|
239
|
+
test.datetime + 60.9
|
240
|
+
end.to eq((Timex.at(12.2)+60.9).as_json)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'converts a 0, "false" false and nil to a boolean false, everything else is true' do
|
244
|
+
expect_evaluate_ruby do
|
245
|
+
[0, 'false', false, nil, 'hi', 17, [], true].collect do |val|
|
246
|
+
TypeTest.new(boolean: val).boolean
|
247
|
+
end
|
248
|
+
end.to eq([false, false, false, false, true, true, true, true])
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'converts other dates just like time' do
|
252
|
+
expect_evaluate_ruby do
|
253
|
+
[:datetime, :time, :timestamp].collect do |attr|
|
254
|
+
TypeTest.new(attr => 12).send(attr)
|
255
|
+
end.uniq
|
256
|
+
end.to eq([Timex.at(12).as_json])
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'converts floats, decimals, integers and bigints' do
|
260
|
+
expect_evaluate_ruby do
|
261
|
+
[:float, :decimal, :integer, :bigint].collect do |attr|
|
262
|
+
TypeTest.new(attr => 12.5).send(attr) +
|
263
|
+
TypeTest.new(attr => "12.2").send(attr) +
|
264
|
+
TypeTest.new(attr => -12.2).send(attr)
|
265
|
+
end.uniq
|
266
|
+
end.to eq([12.5, 12])
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'converts strings and text' do
|
270
|
+
expect_evaluate_ruby do
|
271
|
+
[:string, :text].collect do |attr|
|
272
|
+
[TypeTest.new(attr => 12).send(attr), TypeTest.new(attr => '12').send(attr)]
|
273
|
+
end.flatten.uniq
|
274
|
+
end.to eq(['12'])
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'uses the default value if specified for the dummy value' do
|
278
|
+
r = DefaultTest.create(string: "no no no")
|
279
|
+
expect_evaluate_ruby do
|
280
|
+
t = DefaultTest.find(1)
|
281
|
+
[t.string, t.date, t.datetime]
|
282
|
+
end.to eq(["I'm a string!", r.date.as_json, Timex.new(r.datetime.localtime).as_json])
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'uses the default value if specified when initializing a new record' do
|
286
|
+
expect_evaluate_ruby do
|
287
|
+
DefaultTest.new.string
|
288
|
+
end.to eq("I'm a string!")
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'uses the default value when initializing a new record & can be saved' do
|
292
|
+
starting_fetch_time = evaluate_ruby("ReactiveRecord::Base.last_fetch_at")
|
293
|
+
expect_promise do
|
294
|
+
record = DefaultTest.new
|
295
|
+
record.string = record.string.reverse
|
296
|
+
record.save
|
297
|
+
end.to be_truthy
|
298
|
+
expect(DefaultTest.find(1).string).to eq("!gnirts a m'I")
|
299
|
+
expect_evaluate_ruby("ReactiveRecord::Base.last_fetch_at").to eq(starting_fetch_time)
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HyperMesh::Connection do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
HyperMesh.configuration do |config|
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
Timecop.return
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'creates the tables' do
|
15
|
+
ActiveRecord::Base.connection.tables.should include('synchromesh_connections')
|
16
|
+
ActiveRecord::Base.connection.tables.should include('synchromesh_queued_messages')
|
17
|
+
described_class.column_names.should =~ ['id', 'channel', 'session', 'created_at', 'expires_at', 'refresh_at']
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'creates the messages queue' do
|
21
|
+
channel = described_class.new
|
22
|
+
channel.messages << HyperMesh::Connection::QueuedMessage.new
|
23
|
+
channel.save
|
24
|
+
channel.reload
|
25
|
+
channel.messages.should eq(HyperMesh::Connection::QueuedMessage.all)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can set the root path' do
|
29
|
+
described_class.root_path = 'foobar'
|
30
|
+
expect(described_class.root_path).to eq('foobar')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'adding new connection' do
|
34
|
+
described_class.open('TestChannel', 0)
|
35
|
+
expect(described_class.active).to eq(['TestChannel'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'new connections expire' do
|
39
|
+
described_class.open('TestChannel', 0)
|
40
|
+
expect(described_class.active).to eq(['TestChannel'])
|
41
|
+
Timecop.travel(Time.now+described_class.transport.expire_new_connection_in)
|
42
|
+
expect(described_class.active).to eq([])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'can send and read data from a channel' do
|
46
|
+
described_class.open('TestChannel', 0)
|
47
|
+
described_class.open('TestChannel', 1)
|
48
|
+
described_class.open('AnotherChannel', 0)
|
49
|
+
described_class.send_to_channel('TestChannel', 'data')
|
50
|
+
expect(described_class.read(0, 'path')).to eq(['data'])
|
51
|
+
expect(described_class.read(0, 'path')).to eq([])
|
52
|
+
expect(described_class.read(1, 'path')).to eq(['data'])
|
53
|
+
expect(described_class.read(1, 'path')).to eq([])
|
54
|
+
expect(described_class.read(0, 'path')).to eq([])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'will update the expiration time after reading' do
|
58
|
+
described_class.open('TestChannel', 0)
|
59
|
+
described_class.send_to_channel('TestChannel', 'data')
|
60
|
+
described_class.read(0, 'path')
|
61
|
+
Timecop.travel(Time.now+described_class.transport.expire_new_connection_in)
|
62
|
+
expect(described_class.active).to eq(['TestChannel'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'will expire a polled connection' do
|
66
|
+
described_class.open('TestChannel', 0)
|
67
|
+
described_class.send_to_channel('TestChannel', 'data')
|
68
|
+
described_class.read(0, 'path')
|
69
|
+
Timecop.travel(Time.now+described_class.transport.expire_polled_connection_in)
|
70
|
+
expect(described_class.active).to eq([])
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'after connecting to the transport' do
|
74
|
+
before(:each) do
|
75
|
+
described_class.open('TestChannel', 0)
|
76
|
+
described_class.open('TestChannel', 1)
|
77
|
+
described_class.send_to_channel('TestChannel', 'data')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "will pass any pending data back" do
|
81
|
+
expect(described_class.connect_to_transport('TestChannel', 0, nil)).to eq(['data'])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "will have the root path set for console access" do
|
85
|
+
described_class.connect_to_transport('TestChannel', 0, "some_path")
|
86
|
+
expect(HyperMesh::Connection.root_path).to eq("some_path")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "the channel will still be active even after initial connection time is expired" do
|
90
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
91
|
+
Timecop.travel(Time.now+described_class.transport.expire_new_connection_in)
|
92
|
+
expect(described_class.active).to eq(['TestChannel'])
|
93
|
+
end
|
94
|
+
|
95
|
+
it "will only effect the session being connected" do
|
96
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
97
|
+
expect(described_class.read(1, 'path')).to eq(['data'])
|
98
|
+
end
|
99
|
+
|
100
|
+
it "will begin refreshing the channel list" do
|
101
|
+
allow(HyperMesh).to receive(:refresh_channels) {['AnotherChannel']}
|
102
|
+
described_class.open('AnotherChannel', 0)
|
103
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
104
|
+
described_class.connect_to_transport('AnotherChannel', 0, nil)
|
105
|
+
expect(described_class.active).to eq(['TestChannel', 'AnotherChannel'])
|
106
|
+
Timecop.travel(Time.now+described_class.transport.refresh_channels_every)
|
107
|
+
expect(described_class.active).to eq(['AnotherChannel'])
|
108
|
+
end
|
109
|
+
|
110
|
+
it "refreshing will not effect channels not connected to the transport" do
|
111
|
+
allow(HyperMesh).to receive(:refresh_channels) {['AnotherChannel']}
|
112
|
+
described_class.open('AnotherChannel', 0)
|
113
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
114
|
+
Timecop.travel(Time.now+described_class.transport.refresh_channels_every-1)
|
115
|
+
described_class.read(1, 'path')
|
116
|
+
described_class.connect_to_transport('AnotherChannel', 0, nil)
|
117
|
+
expect(described_class.active).to eq(['TestChannel', 'AnotherChannel'])
|
118
|
+
Timecop.travel(Time.now+1)
|
119
|
+
described_class.active
|
120
|
+
expect(described_class.active).to eq(['TestChannel', 'AnotherChannel'])
|
121
|
+
end
|
122
|
+
|
123
|
+
it "refreshing will not effect channels added during the refresh" do
|
124
|
+
allow(HyperMesh).to receive(:refresh_channels) do
|
125
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
126
|
+
['AnotherChannel']
|
127
|
+
end
|
128
|
+
described_class.open('AnotherChannel', 0)
|
129
|
+
Timecop.travel(Time.now+described_class.transport.refresh_channels_every)
|
130
|
+
described_class.read(0, 'path')
|
131
|
+
described_class.connect_to_transport('AnotherChannel', 0, nil)
|
132
|
+
expect(described_class.active).to eq(['TestChannel', 'AnotherChannel'])
|
133
|
+
described_class.open('TestChannel', 2)
|
134
|
+
expect(described_class.active).to eq(['TestChannel', 'AnotherChannel'])
|
135
|
+
end
|
136
|
+
|
137
|
+
it "sends messages to the transport as well as open channels" do
|
138
|
+
expect(HyperMesh).to receive(:send).with('TestChannel', 'data2')
|
139
|
+
described_class.connect_to_transport('TestChannel', 0, nil)
|
140
|
+
described_class.send_to_channel('TestChannel', 'data2')
|
141
|
+
expect(described_class.read(1, 'path')).to eq(['data', 'data2'])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
|
4
|
+
describe "regulate access allowed" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
HyperMesh.configuration do |config|
|
8
|
+
config.transport = :none
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "basic tests" do
|
13
|
+
before(:each) do
|
14
|
+
# spec_helper resets the policy system after each test so we have to setup
|
15
|
+
# before each test
|
16
|
+
stub_const 'TestApplication', Class.new
|
17
|
+
stub_const 'C2', Class.new
|
18
|
+
stub_const 'TestApplicationPolicy', Class.new
|
19
|
+
TestApplicationPolicy.class_eval do
|
20
|
+
regulate_class_connection { self }
|
21
|
+
regulate_class_connection(C2) { self }
|
22
|
+
regulate_instance_connections(TestModel) { self if self.is_a? TestModel }
|
23
|
+
regulate_all_broadcasts(C2) { |policy| policy.send_all_but(:created_at) }
|
24
|
+
regulate_broadcast(TestModel) do |policy|
|
25
|
+
policy.send_all.to(TestApplication) unless test_attribute == "bogus"
|
26
|
+
policy.send_all.to(self)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "will allow access if the broadcast policy allows access" do
|
32
|
+
m = FactoryGirl.create(:test_model, test_attribute: "hello")
|
33
|
+
expect { m.check_permission_with_acting_user("user", :view_permitted?, :test_attribute) }.
|
34
|
+
not_to raise_error
|
35
|
+
expect { m.check_permission_with_acting_user("user", :view_permitted?, :created_at) }.
|
36
|
+
not_to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "will disallow access if acting_user is not allowed to connect" do
|
40
|
+
m = FactoryGirl.create(:test_model, test_attribute: "hello")
|
41
|
+
expect { m.check_permission_with_acting_user(nil, :view_permitted?, :test_attribute) }.
|
42
|
+
to raise_error(ReactiveRecord::AccessViolation)
|
43
|
+
expect { m.check_permission_with_acting_user(nil, :view_permitted?, :created_at) }.
|
44
|
+
to raise_error(ReactiveRecord::AccessViolation)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "will disallow access to attributes not broadcast by the model" do
|
48
|
+
m = FactoryGirl.create(:test_model, test_attribute: "bogus")
|
49
|
+
expect { m.check_permission_with_acting_user("user", :view_permitted?, :test_attribute) }.
|
50
|
+
not_to raise_error
|
51
|
+
expect { m.check_permission_with_acting_user("user", :view_permitted?, :created_at) }.
|
52
|
+
to raise_error(ReactiveRecord::AccessViolation)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "will allow access to attributes broadcast over an instance channel" do
|
56
|
+
m = FactoryGirl.create(:test_model, test_attribute: "bogus")
|
57
|
+
expect { m.check_permission_with_acting_user(m, :view_permitted?, :test_attribute) }.
|
58
|
+
not_to raise_error
|
59
|
+
expect { m.check_permission_with_acting_user(m, :view_permitted?, :created_at) }.
|
60
|
+
not_to raise_error
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "will include :id as read attribute as long as any other attribute is readable" do
|
65
|
+
stub_const 'TestApplication', Class.new
|
66
|
+
stub_const 'TestApplicationPolicy', Class.new
|
67
|
+
TestApplicationPolicy.class_eval do
|
68
|
+
always_allow_connection
|
69
|
+
regulate_all_broadcasts { |policy| policy.send_only(:test_attribute) }
|
70
|
+
end
|
71
|
+
m = FactoryGirl.create(:test_model)
|
72
|
+
expect { m.check_permission_with_acting_user(nil, :view_permitted?, :id) }.
|
73
|
+
not_to raise_error
|
74
|
+
end
|
75
|
+
|
76
|
+
it "will not include :id as read attribute if no other attributes are readable" do
|
77
|
+
stub_const 'TestApplication', Class.new
|
78
|
+
stub_const 'TestApplicationPolicy', Class.new
|
79
|
+
TestApplicationPolicy.class_eval do
|
80
|
+
always_allow_connection
|
81
|
+
end
|
82
|
+
m = FactoryGirl.create(:test_model)
|
83
|
+
expect { m.check_permission_with_acting_user(nil, :view_permitted?, :id) }.
|
84
|
+
to raise_error(ReactiveRecord::AccessViolation)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "will ignore auto_connect: false " do
|
88
|
+
stub_const 'TestApplication', Class.new
|
89
|
+
stub_const 'TestApplicationPolicy', Class.new
|
90
|
+
TestApplicationPolicy.class_eval do
|
91
|
+
regulate_class_connection(auto_connect: false) { true }
|
92
|
+
regulate_instance_connections(TestModel, auto_connect: false) { self }
|
93
|
+
regulate_all_broadcasts { |policy| policy.send_only(:test_attribute) }
|
94
|
+
regulate_broadcast(TestModel) { |policy| policy.send_only(:created_at).to(self) }
|
95
|
+
end
|
96
|
+
m = FactoryGirl.create(:test_model)
|
97
|
+
expect { m.check_permission_with_acting_user(m, :view_permitted?, :id) }.
|
98
|
+
not_to raise_error
|
99
|
+
expect { m.check_permission_with_acting_user(m, :view_permitted?, :test_attribute) }.
|
100
|
+
not_to raise_error
|
101
|
+
expect { m.check_permission_with_acting_user(m, :view_permitted?, :created_at) }.
|
102
|
+
not_to raise_error
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|