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,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
|
4
|
+
describe "random examples", js: true do
|
5
|
+
|
6
|
+
it "can pass an array subclass as a param" do
|
7
|
+
mount "Tester" do
|
8
|
+
class SubArray < Array
|
9
|
+
end
|
10
|
+
|
11
|
+
class HelloWorld < React::Component::Base
|
12
|
+
param :array, type: SubArray
|
13
|
+
render do
|
14
|
+
i = 10
|
15
|
+
div {
|
16
|
+
div { "params.array.is_a? #{params.array.class}" }
|
17
|
+
params.array.each {|i| h1 {i.to_s}}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Tester < React::Component::Base
|
23
|
+
def render
|
24
|
+
normal_array = [1, 2]
|
25
|
+
sub_array = SubArray.new
|
26
|
+
sub_array << 1; sub_array << 2
|
27
|
+
DIV do
|
28
|
+
# this works
|
29
|
+
HelloWorld(array: normal_array)
|
30
|
+
# this doesn't
|
31
|
+
DIV { "out here a sub_array is a #{sub_array.class}" }
|
32
|
+
HelloWorld(array: sub_array)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
pause
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can destroy on the fly" do
|
41
|
+
|
42
|
+
5.times do |i|
|
43
|
+
FactoryGirl.create(:test_model, test_attribute: "I am model #{i}")
|
44
|
+
end
|
45
|
+
|
46
|
+
mount "RecordsComp" do
|
47
|
+
class RecordsComp < React::Component::Base
|
48
|
+
# you had state.credits as an expression... not sure that is what you wanted
|
49
|
+
render(:div, class: "state.credits") do
|
50
|
+
h2.title { 'Records' }
|
51
|
+
#RecordFormComp()
|
52
|
+
hr { nil }
|
53
|
+
table.table.table_bordered do
|
54
|
+
thead { tr { th { 'Date' }
|
55
|
+
th { 'Title' }
|
56
|
+
#th { 'Amount' }
|
57
|
+
th { 'Actions' } } }
|
58
|
+
tbody do
|
59
|
+
TestModel.each do |record|
|
60
|
+
RecordComp key: record[:id], record: record
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class RecordComp < React::Component::Base
|
68
|
+
param :key, type: String
|
69
|
+
param :record, type: TestModel # type is optional here
|
70
|
+
|
71
|
+
def handle_delete
|
72
|
+
params.record.destroy do |result|
|
73
|
+
alert 'unable to delete record' unless result
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def render
|
78
|
+
tr do
|
79
|
+
# currently you should access attributes using
|
80
|
+
# dot notation only. Currently the [] operator
|
81
|
+
# accesses record values directly without setting up
|
82
|
+
# any reactive response. This will probably change
|
83
|
+
# with release of Hypermesh
|
84
|
+
td { params.record.created_at }
|
85
|
+
td { params.record.test_attribute }
|
86
|
+
#td { amount_format(params.record[:amount]) }
|
87
|
+
td { a.btn.btn_danger { 'Delete' }.on(:click) { handle_delete } }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def amount_format(amount)
|
92
|
+
'$ ' + amount.to_s.reverse.gsub(/...(?!-)(?=.)/,'\&,').reverse
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
pause
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
|
4
|
+
describe "example scopes", js: true do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
require 'pusher'
|
8
|
+
require 'pusher-fake'
|
9
|
+
Pusher.app_id = "MY_TEST_ID"
|
10
|
+
Pusher.key = "MY_TEST_KEY"
|
11
|
+
Pusher.secret = "MY_TEST_SECRET"
|
12
|
+
require "pusher-fake/support/base"
|
13
|
+
|
14
|
+
HyperMesh.configuration do |config|
|
15
|
+
config.transport = :pusher
|
16
|
+
config.channel_prefix = "synchromesh"
|
17
|
+
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
# spec_helper resets the policy system after each test so we have to setup
|
23
|
+
# before each test
|
24
|
+
stub_const 'TestApplicationPolicy', Class.new
|
25
|
+
TestApplicationPolicy.class_eval do
|
26
|
+
always_allow_connection
|
27
|
+
regulate_all_broadcasts { |policy| policy.send_all }
|
28
|
+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
29
|
+
end
|
30
|
+
isomorphic do
|
31
|
+
Todo.class_eval do
|
32
|
+
scope :with_managers_comments,
|
33
|
+
-> { joins(owner: :manager, comments: :author).where('managers_users.id = authors_comments.id').distinct },
|
34
|
+
joins: ['comments.author', 'owner'],
|
35
|
+
client: -> { comments.detect { |comment| comment.author == owner.manager } }
|
36
|
+
end
|
37
|
+
Comment.class_eval do
|
38
|
+
scope :by_manager,
|
39
|
+
-> { joins(todoz: { owner: :manager }).where('managers_users.id = author_id').distinct},
|
40
|
+
joins: ['todoz.owner.manager', 'author'],
|
41
|
+
client: -> { todoz.owner.manager == author }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
size_window(:small, :portrait)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "runs the server side scopes okay" do
|
48
|
+
expect(Todo.with_managers_comments).to be_empty
|
49
|
+
expect(Comment.by_manager).to be_empty
|
50
|
+
boss = FactoryGirl.create(:user, first_name: :boss)
|
51
|
+
employee = FactoryGirl.create(:user, first_name: :fred, manager: boss)
|
52
|
+
todo = FactoryGirl.create(:todo, owner: employee)
|
53
|
+
comment = FactoryGirl.create(:comment, author: boss, todoz: todo)
|
54
|
+
FactoryGirl.create(:comment, author: employee, todoz: todo)
|
55
|
+
FactoryGirl.create(:comment, author: employee, todoz: FactoryGirl.create(:todo, owner: employee))
|
56
|
+
expect(Todo.with_managers_comments).to match_array [todo]
|
57
|
+
expect(Comment.by_manager).to match_array [comment]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "a complex client side scope" do
|
61
|
+
|
62
|
+
mount "TestComponent3" do
|
63
|
+
class UserTodos < React::Component::Base
|
64
|
+
render(DIV) do
|
65
|
+
div { "todos by user with comments" }
|
66
|
+
User.each do |user|
|
67
|
+
DIV do
|
68
|
+
DIV { "#{user.first_name}'s Todos'" }
|
69
|
+
UL do
|
70
|
+
user.assigned_todos.each do |todo|
|
71
|
+
LI do
|
72
|
+
todo.title.span
|
73
|
+
UL do
|
74
|
+
todo.comments.by_manager.each do |comment|
|
75
|
+
LI { "MANAGER SAYS: #{comment.comment}" }
|
76
|
+
end
|
77
|
+
end unless todo.comments.by_manager.empty?
|
78
|
+
end; end; end; end; end; end; end
|
79
|
+
class ManagerComments < React::Component::Base
|
80
|
+
render(DIV) do
|
81
|
+
puts "managers have made comments: #{!!Todo.with_managers_comments.any?}"
|
82
|
+
if Todo.with_managers_comments.any?
|
83
|
+
DIV { "managers comments" }
|
84
|
+
UL do
|
85
|
+
Todo.with_managers_comments.each do |todo|
|
86
|
+
DIV do
|
87
|
+
"#{todo.owner.first_name} - #{todo.title}".span
|
88
|
+
UL do
|
89
|
+
todo.comments.each do |comment|
|
90
|
+
LI { "BOSS SAYS: #{comment.comment}" } if comment.author == todo.owner.manager
|
91
|
+
end; end; end; end; end
|
92
|
+
else
|
93
|
+
DIV { "no manager comments" }
|
94
|
+
end; end; end
|
95
|
+
class TestComponent3 < React::Component::Base
|
96
|
+
def render
|
97
|
+
puts "RENDERING TESTCOMPONENT3"
|
98
|
+
div do
|
99
|
+
UserTodos {}
|
100
|
+
ManagerComments {}
|
101
|
+
end; end; end; end
|
102
|
+
# evaluate_ruby do
|
103
|
+
# ReactiveRecord::Collection.hypertrace instrument: :all
|
104
|
+
# UserTodos.hypertrace instrument: :all
|
105
|
+
# end
|
106
|
+
starting_fetch_time = evaluate_ruby("ReactiveRecord::Base.last_fetch_at")
|
107
|
+
#pause "about to add the boss"
|
108
|
+
boss = FactoryGirl.create(:user, first_name: :boss)
|
109
|
+
#pause "about to add the employee"
|
110
|
+
employee = FactoryGirl.create(:user, first_name: :joe, manager: boss)
|
111
|
+
#pause "about to add the todo"
|
112
|
+
todo = FactoryGirl.create(:todo, title: "joe's todo", owner: employee)
|
113
|
+
wait_for_ajax
|
114
|
+
evaluate_ruby("ReactiveRecord::Base.last_fetch_at").should eq(starting_fetch_time)
|
115
|
+
#pause "adding a comment from the boss"
|
116
|
+
comment = FactoryGirl.create(:comment, comment: "The Boss Speaks", author: boss, todoz: todo)
|
117
|
+
page.should have_content('The Boss Speaks')
|
118
|
+
#pause "added the boss speaks"
|
119
|
+
fred = FactoryGirl.create(:user, role: :employee, first_name: :fred)
|
120
|
+
#pause "fred added"
|
121
|
+
fred.assigned_todos << FactoryGirl.create(:todo, title: 'fred todo')
|
122
|
+
#pause "added another todo to fred" # HAPPENS AFTER HERE.....
|
123
|
+
evaluate_ruby do
|
124
|
+
# ReactiveRecord::Collection.hypertrace instrument: :all
|
125
|
+
# UserTodos.hypertrace instrument: :all
|
126
|
+
|
127
|
+
mitch = User.new(first_name: :mitch)
|
128
|
+
mitch.assigned_todos << Todo.new(title: 'mitch todo')
|
129
|
+
mitch.save
|
130
|
+
end
|
131
|
+
wait_for_ajax
|
132
|
+
#pause "mitch added"
|
133
|
+
user1 = FactoryGirl.create(:user, role: :employee, first_name: :frank)
|
134
|
+
user2 = FactoryGirl.create(:user, role: :employee, first_name: :bob)
|
135
|
+
mgr = FactoryGirl.create(:user, role: :manager, first_name: :sally)
|
136
|
+
#pause "frank, bob, and sally added"
|
137
|
+
user1.assigned_todos << FactoryGirl.create(:todo, title: 'frank todo 1')
|
138
|
+
user1.assigned_todos << FactoryGirl.create(:todo, title: 'frank todo 2')
|
139
|
+
user2.assigned_todos << FactoryGirl.create(:todo, title: 'bob todo 1')
|
140
|
+
user2.assigned_todos << FactoryGirl.create(:todo, title: 'bob todo 2')
|
141
|
+
user1.commentz << FactoryGirl.create(:comment, comment: "frank made this comment", todoz: user2.assigned_todos.first)
|
142
|
+
user2.commentz << FactoryGirl.create(:comment, comment: "bob made this comment", todoz: user1.assigned_todos.first)
|
143
|
+
# evaluate_ruby do
|
144
|
+
# HyperMesh::IncomingBroadcast.hypertrace do
|
145
|
+
# break_on_exit?(:merge_current_values) { Todo.find(5).comments.last.todo.nil? rescue nil }
|
146
|
+
# end
|
147
|
+
# ReactiveRecord::ScopeDescription.hypertrace do
|
148
|
+
# break_on_enter?(:filter_records) { Todo.find(5).comments.last.todo.nil? rescue nil }
|
149
|
+
# end
|
150
|
+
# ReactiveRecord::Collection.hypertrace do
|
151
|
+
# break_on_enter?(:all) { Todo.find(5).comments.last.todo.nil? rescue nil }
|
152
|
+
# break_on_exit?(:all) { Todo.find(5).comments.last.todo.nil? rescue nil }
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
|
156
|
+
mgr.commentz << FactoryGirl.create(:comment, comment: "Me BOSS", todoz: user1.assigned_todos.last)
|
157
|
+
page.should have_content('MANAGER SAYS: The Boss Speaks')
|
158
|
+
page.should have_content('BOSS SAYS: The Boss Speaks')
|
159
|
+
wait_for_ajax
|
160
|
+
page.should_not have_content('MANAGER SAYS: Me BOSS', wait: 0)
|
161
|
+
page.should_not have_content('BOSS SAYS: Me BOSS', wait: 0)
|
162
|
+
user1.update_attribute(:manager, mgr)
|
163
|
+
page.should have_content('MANAGER SAYS: Me BOSS')
|
164
|
+
page.should have_content('BOSS SAYS: Me BOSS')
|
165
|
+
evaluate_ruby("ReactiveRecord::Base.last_fetch_at").should eq(starting_fetch_time)
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
|
4
|
+
describe "authorization integration", js: true do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
# HyperMesh.configuration do |config|
|
8
|
+
# config.transport = :simple_poller
|
9
|
+
# # slow down the polling so wait_for_ajax works
|
10
|
+
# config.opts = { seconds_between_poll: 2 }
|
11
|
+
# end
|
12
|
+
|
13
|
+
require 'pusher'
|
14
|
+
require 'pusher-fake'
|
15
|
+
Pusher.app_id = "MY_TEST_ID"
|
16
|
+
Pusher.key = "MY_TEST_KEY"
|
17
|
+
Pusher.secret = "MY_TEST_SECRET"
|
18
|
+
require "pusher-fake/support/base"
|
19
|
+
|
20
|
+
HyperMesh.configuration do |config|
|
21
|
+
config.transport = :pusher
|
22
|
+
config.channel_prefix = "synchromesh"
|
23
|
+
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:all) do
|
29
|
+
ApplicationController.acting_user = nil
|
30
|
+
ActiveRecord::Base.class_eval do
|
31
|
+
def create_permitted?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
def update_permitted?
|
35
|
+
true
|
36
|
+
end
|
37
|
+
def destroy_permitted?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
def view_permitted?(attribute)
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
before(:each) do
|
47
|
+
# spec_helper resets the policy system after each test so we have to setup
|
48
|
+
# before each test
|
49
|
+
stub_const "User", Class.new
|
50
|
+
User.class_eval do
|
51
|
+
include ActiveModel::Model
|
52
|
+
attr_accessor :name
|
53
|
+
end
|
54
|
+
ApplicationController.acting_user = nil
|
55
|
+
stub_const 'TestApplicationPolicy', Class.new
|
56
|
+
TestApplicationPolicy.class_eval do
|
57
|
+
regulate_class_connection { self }
|
58
|
+
regulate_instance_connections(TestModel) { TestModel.find_by_test_attribute(name) }
|
59
|
+
regulate_all_broadcasts { |policy| policy.send_all_but(:completed, :test_attribute) }
|
60
|
+
regulate_broadcast(TestModel) { |policy| policy.send_all_but(:created_at).to(self) }
|
61
|
+
end
|
62
|
+
size_window(:small, :portrait)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "will only synchronize the connected channels" do
|
66
|
+
mount "TestComponent2"
|
67
|
+
model1 = FactoryGirl.create(:test_model, test_attribute: "hello")
|
68
|
+
wait_for_ajax
|
69
|
+
model1.attributes_on_client(page).should eq({id: 1})
|
70
|
+
ApplicationController.acting_user = User.new(name: "fred")
|
71
|
+
page.evaluate_ruby('HyperMesh.connect("TestApplication")')
|
72
|
+
wait_for_ajax
|
73
|
+
model1.update_attribute(:test_attribute, 'george')
|
74
|
+
wait_for_ajax
|
75
|
+
model1.attributes_on_client(page).should eq({
|
76
|
+
id: 1,
|
77
|
+
created_at: model1.created_at.localtime.strftime('%Y-%m-%dT%H:%M:%S%z'),
|
78
|
+
updated_at: model1.updated_at.localtime.strftime('%Y-%m-%dT%H:%M:%S%z')
|
79
|
+
})
|
80
|
+
ApplicationController.acting_user = User.new(name: "george")
|
81
|
+
page.evaluate_ruby("HyperMesh.connect(['TestModel', #{model1.id}])")
|
82
|
+
wait_for_ajax
|
83
|
+
model1.update_attribute(:completed, true)
|
84
|
+
wait_for_ajax
|
85
|
+
model1.attributes_on_client(page).should eq({
|
86
|
+
id: 1, test_attribute: "george", completed: true,
|
87
|
+
created_at: model1.created_at.localtime.strftime('%Y-%m-%dT%H:%M:%S%z'),
|
88
|
+
updated_at: model1.updated_at.localtime.strftime('%Y-%m-%dT%H:%M:%S%z')
|
89
|
+
})
|
90
|
+
end
|
91
|
+
|
92
|
+
it "will fail on illegal class connections" do
|
93
|
+
mount "TestComponent2"
|
94
|
+
model1 = FactoryGirl.create(:test_model, test_attribute: "hello")
|
95
|
+
page.evaluate_ruby('HyperMesh.connect("TestApplication")')
|
96
|
+
model1.update_attribute(:test_attribute, 'george')
|
97
|
+
wait_for_ajax
|
98
|
+
model1.attributes_on_client(page).should eq({id: 1})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "will fail on illegal instance connections" do
|
102
|
+
mount "TestComponent2"
|
103
|
+
model1 = FactoryGirl.create(:test_model, test_attribute: "george")
|
104
|
+
ApplicationController.acting_user = User.new(name: "fred")
|
105
|
+
page.evaluate_ruby("HyperMesh.connect(['TestModel', #{model1.id}])")
|
106
|
+
model1.update_attribute(:completed, true)
|
107
|
+
wait_for_ajax
|
108
|
+
model1.attributes_on_client(page).should eq({id: 1})
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'synchromesh/integration/test_components'
|
3
|
+
|
4
|
+
describe "default_scope" do
|
5
|
+
|
6
|
+
context "client tests", js: true do
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
require 'pusher'
|
10
|
+
require 'pusher-fake'
|
11
|
+
Pusher.app_id = "MY_TEST_ID"
|
12
|
+
Pusher.key = "MY_TEST_KEY"
|
13
|
+
Pusher.secret = "MY_TEST_SECRET"
|
14
|
+
require "pusher-fake/support/base"
|
15
|
+
|
16
|
+
HyperMesh.configuration do |config|
|
17
|
+
config.transport = :pusher
|
18
|
+
config.channel_prefix = "synchromesh"
|
19
|
+
config.opts = {app_id: Pusher.app_id, key: Pusher.key, secret: Pusher.secret}.merge(PusherFake.configuration.web_options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
# spec_helper resets the policy system after each test so we have to setup
|
25
|
+
# before each test
|
26
|
+
stub_const 'TestApplication', Class.new
|
27
|
+
stub_const 'TestApplicationPolicy', Class.new
|
28
|
+
TestApplicationPolicy.class_eval do
|
29
|
+
always_allow_connection
|
30
|
+
regulate_all_broadcasts { |policy| policy.send_all }
|
31
|
+
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
|
32
|
+
end
|
33
|
+
size_window(:small, :portrait)
|
34
|
+
end
|
35
|
+
|
36
|
+
after(:each) do
|
37
|
+
TestModel.default_scopes = []
|
38
|
+
end
|
39
|
+
|
40
|
+
it "a default scope can be added server side using either a block or proc" do
|
41
|
+
isomorphic do
|
42
|
+
TestModel.class_eval do
|
43
|
+
default_scope -> { where(completed: true) }
|
44
|
+
default_scope { where(test_attribute: 'foo') }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
mount "TestComponent2" do
|
48
|
+
class TestComponent2 < React::Component::Base
|
49
|
+
render(:div) do
|
50
|
+
"#{TestModel.count} items".br
|
51
|
+
"#{TestModel.unscoped.count} unscoped items"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
page.should have_content("0 items")
|
56
|
+
page.should have_content("0 unscoped items")
|
57
|
+
m1 = FactoryGirl.create(:test_model, completed: false, test_attribute: nil)
|
58
|
+
page.should have_content("0 items")
|
59
|
+
page.should have_content("1 unscoped items")
|
60
|
+
m2 = FactoryGirl.create(:test_model, completed: true, test_attribute: nil)
|
61
|
+
page.should have_content("0 items")
|
62
|
+
page.should have_content("2 unscoped items")
|
63
|
+
m2.update(test_attribute: 'foo')
|
64
|
+
page.should have_content("1 items")
|
65
|
+
page.should have_content("2 unscoped items")
|
66
|
+
m3 = FactoryGirl.create(:test_model)
|
67
|
+
page.should have_content("2 items")
|
68
|
+
page.should have_content("3 unscoped items")
|
69
|
+
m3.update_attribute(:completed, false)
|
70
|
+
page.should have_content("1 items")
|
71
|
+
page.should have_content("3 unscoped items")
|
72
|
+
m2.destroy
|
73
|
+
page.should have_content("0 items")
|
74
|
+
page.should have_content("2 unscoped items")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "a default scope can be added client side" do
|
78
|
+
isomorphic do
|
79
|
+
TestModel.class_eval do
|
80
|
+
default_scope server: -> { where(completed: true) },
|
81
|
+
client: -> { completed }
|
82
|
+
default_scope server: -> { where(test_attribute: 'foo') },
|
83
|
+
client: -> { test_attribute == 'foo' }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
mount "TestComponent2" do
|
87
|
+
class TestComponent2 < React::Component::Base
|
88
|
+
render(:div) do
|
89
|
+
"#{TestModel.count} items".br
|
90
|
+
"#{TestModel.unscoped.count} unscoped items"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
starting_fetch_time = evaluate_ruby("ReactiveRecord::Base.last_fetch_at")
|
95
|
+
page.should have_content("0 items")
|
96
|
+
page.should have_content("0 unscoped items")
|
97
|
+
m1 = FactoryGirl.create(:test_model, completed: false, test_attribute: nil)
|
98
|
+
page.should have_content("0 items")
|
99
|
+
page.should have_content("1 unscoped items")
|
100
|
+
m2 = FactoryGirl.create(:test_model, completed: true, test_attribute: nil)
|
101
|
+
page.should have_content("0 items")
|
102
|
+
page.should have_content("2 unscoped items")
|
103
|
+
m2.update(test_attribute: 'foo')
|
104
|
+
page.should have_content("1 items")
|
105
|
+
page.should have_content("2 unscoped items")
|
106
|
+
m3 = FactoryGirl.create(:test_model)
|
107
|
+
page.should have_content("2 items")
|
108
|
+
page.should have_content("3 unscoped items")
|
109
|
+
m3.update_attribute(:completed, false)
|
110
|
+
page.should have_content("1 items")
|
111
|
+
page.should have_content("3 unscoped items")
|
112
|
+
m2.destroy
|
113
|
+
page.should have_content("0 items")
|
114
|
+
page.should have_content("2 unscoped items")
|
115
|
+
# there should be no client fetches should replace this with a double of
|
116
|
+
# ServerDataCache[] which should not be called
|
117
|
+
wait_for_ajax
|
118
|
+
starting_fetch_time.should eq(evaluate_ruby("ReactiveRecord::Base.last_fetch_at"))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|