diff --git a/.github/workflows/dynamic-security.yml b/.github/workflows/dynamic-security.yml new file mode 100644 index 0000000..26a424d --- /dev/null +++ b/.github/workflows/dynamic-security.yml @@ -0,0 +1,19 @@ +name: update-security + +on: + push: + paths: + - SECURITY.md + branches: + - main + workflow_dispatch: + +jobs: + update-security: + permissions: + contents: write + pull-requests: write + pages: write + uses: thoughtbot/templates/.github/workflows/dynamic-security.yaml@main + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..2edd79d --- /dev/null +++ b/.standard.yml @@ -0,0 +1,5 @@ +ignore: + - 'lib/generators/michel/view/templates/view_migration.rb': + - Layout/InitialIndentation + - Layout/TrailingEmptyLines + - Layout/TrailingWhitespace diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 67fe8ce..848a59a 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,132 +1,6 @@ -# Contributor Covenant Code of Conduct +# Code of conduct -## Our Pledge +By participating in this project, you agree to abide by the +[thoughtbot code of conduct][1]. -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, caste, color, religion, or sexual -identity and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall - community - -Examples of unacceptable behavior include: - -* The use of sexualized language or imagery, and sexual attention or advances of - any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email address, - without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official email address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -[INSERT CONTACT METHOD]. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of -actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or permanent -ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within the -community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.1, available at -[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. - -Community Impact Guidelines were inspired by -[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. - -For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at -[https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html -[Mozilla CoC]: https://github.com/mozilla/diversity -[FAQ]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations +[1]: https://thoughtbot.com/open-source-code-of-conduct diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c623aba --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing + +We love contributions from everyone. +By participating in this project, +you agree to abide by the thoughtbot [code of conduct]. + + [code of conduct]: https://thoughtbot.com/open-source-code-of-conduct + +We expect everyone to follow the code of conduct +anywhere in thoughtbot's project codebases, +issue trackers, chatrooms, and mailing lists. + +## Contributing Code + +$(INSTALL_DEPENDENCIES) + +Fork the repo. + +Make sure the tests pass: + + $(TEST_RUNNER) + +Make your change, with new passing tests. Follow the [style guide][style]. + + [style]: https://github.com/thoughtbot/guides/tree/master/style + +Mention how your changes affect the project to other developers and users in the +`NEWS.md` file. + +Push to your fork. Write a [good commit message][commit]. Submit a pull request. + + [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html + +Others will give constructive feedback. +This is a time for discussion and improvements, +and making the necessary changes will be required before we can +merge the contribution. diff --git a/Gemfile b/Gemfile index 5fb87b2..c10df18 100644 --- a/Gemfile +++ b/Gemfile @@ -13,3 +13,5 @@ gem "pg", "~> 1.1" gem "bundler-audit", ">= 0.7.0", require: false gem "database_cleaner" gem "ammeter" +gem "debug" +gem "scenic" diff --git a/Gemfile.lock b/Gemfile.lock index d27381a..90c76c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,9 @@ GEM database_cleaner-core (~> 2.0) database_cleaner-core (2.0.1) date (3.5.1) + debug (1.11.1) + irb (~> 1.10) + reline (>= 0.3.8) diff-lcs (1.6.2) drb (2.2.3) erb (6.0.1) @@ -310,10 +313,12 @@ DEPENDENCIES ammeter bundler-audit (>= 0.7.0) database_cleaner + debug michel! pg (~> 1.1) rails (~> 8.0.2, >= 8.0.2.1) rake (~> 13.0) + scenic standardrb BUNDLED WITH diff --git a/LICENSE b/LICENSE index 55ac165..951cca8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,4 @@ -The MIT License - -Copyright (c) thoughtbot, inc. +Copyright (c) Sally Hall and thoughtbot, inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..532aa3b --- /dev/null +++ b/NEWS.md @@ -0,0 +1,51 @@ +# News + +All notable changes to this project will be documented in this file. + +The format is loosely based on [Keep a Changelog] and this project adheres to +[Semantic Versioning]. + + [Keep a Changelog]: http://keepachangelog.com/ + [Semantic Versioning]: http://semver.org/ + +## [Unreleased] + +### Added + +- This is for new features. + +### Changed + +- This is for changes in existing functionality. + +### Deprecated + +- This is for once-stable features removed in upcoming releases. + +### Removed + +- This is for deprecated features removed in this release. + +### Fixed + +- This is for any bug fixes. + +### Security + +- This is to invite users to upgrade in case of vulnerabilities. + + [Unreleased]: https://github.com/thoughtbot/michel/compare/v0.2.0...HEAD + +## [0.0.2] - 2016-02-01 + +### Added + +- This version to show how each version title is linked (`## [0.0.2]`). + + [0.2.0]: https://github.com/thoughtbot/michel/compare/v0.1.0...v0.2.0 + +## 0.0.1 - 2016-01-01 + +### Added + +- This `NEWS.md` file. diff --git a/README.md b/README.md index e335443..197933e 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,76 @@ # Michel -TODO: Delete this and the text below, and describe your gem +Find available time slots quickly with a materialized view. -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/michel`. To experiment with that code, run `bin/console` for an interactive prompt. +## Usage -## Installation +### Install Michel + In order to run the migrations, you must also install Scenic. Add to your gemfile: -TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org. + ``` + gem "michel" + gem "scenic" + ``` -Install the gem and add to the application's Gemfile by executing: + Run `bundle install`, then `rails generate michel:install` -```bash -bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG -``` +### Configure + Configure the class names in `config/initializers/michel.rb` -If bundler is not being used to manage dependencies, install the gem by executing: + Michel expects three classes to exist in the application: + * Resource Class + * The resource that is occupied by a booking, ex: Physician, Room, Instructor. + * This resource is assumed to be available for only one booking at a time. A resource has many bookings and many availabilities. -```bash -gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG -``` + * Booking Class + * The event that is scheduled for a resource, ex: Appointment. + * The resource is unavailable for the duration of the booking. + * It is required to have the following attributes: + * `start_time` - a DateTime indicating the start time of the booking. + * `duration` - an integer representing the number of minutes the booking lasts. + * a reference to the id of the resource class + * The booking class is also used to block off unavailable times. It is recommended that you have a booking type to distinguish between appointments and other events. + * Availability Class + * The weekly schedule during which a resource is available for a booking + * It is required to have the following attributes: + * `timezone` - a string representing the time zone in which the availability is configured, ex: 'UTC' + * `weekday` - an integer representing the weekday, starting with Monday = 1 + * `start_time` - a string representing the beginning time of the availability in the configured timezone in 24-hour format, ex: '09:00' + * `end_time` - a string representing the end time of the availability in the configured timezone in 24-hour format, ex: '017:00' + * a reference to the id of the resource class + * There should be one availability record for each continuous block of available time during a week. For example, if a resource is available from 9-5, M-Th, with a 1 hour break from 12-1, that is represented by eight availabilities: one for each day from 9-12 and another for each day from 1-5. -## Usage -TODO: Write usage instructions here +### Run the generator + To generate the database view and necessary supporting code, run `rails generate michel:view`. This will: + + 1. Generate a migration to add an index to the booking class table on the resource id and start_time. + 2. Generate a Scenic model for available time slots. + 3. Generate a sql file with the view to back the scenic model. + 4. Insert associations between the existing classes and the generated `AvailableTimeSlot` class. -## Development + Once the generator is finished, run `rails db:migrate` to run the generated migrations. -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +### Start Scheduling. + To find available time slots, search for matching `AvailableTimeSlots`. Each slot has a `start_time` and an `end_time` and belongs to an `availability` and a `resource`. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + To refresh the materialized view, run `AvailableTimeSlot.refresh`. The view should be refreshed when a booking is created, updated, or deleted, or when availability changes. ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/michel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/michel/blob/main/CODE_OF_CONDUCT.md). +See the [CONTRIBUTING] document. +Thank you, [contributors]! + +[CONTRIBUTING]: CONTRIBUTING.md +[contributors]: https://github.com/thoughtbot/michel/graphs/contributors + +## License + +Michel is Copyright (c) thoughtbot, inc. +It is free software, and may be redistributed +under the terms specified in the [LICENSE] file. -## Code of Conduct +[LICENSE]: /LICENSE -Everyone interacting in the Michel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/michel/blob/main/CODE_OF_CONDUCT.md). + + diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..637a458 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,43 @@ +# Releasing + +## 1. Update version file accordingly + +Include an RC (release candidate) number if appropriate, e.g. 2.0.0.rc. + +## 2. Update `NEWS.md` or `CHANGELOG.md` to reflect the changes since last release + +You can copy [GitHub automatically generated release notes] for this step. + +## 3. Commit changes + +There shouldn't be code changes, and thus CI doesn't need to run. Add "[ci skip]" to the commit message. + +## 4. Tag the release: `git tag -s vVERSION` + +We recommend the [_quick guide on how to sign a release_] from git ready. + +## 5. Push changes + +Push the changes with `git push --tags` + +## 6. Build and publish + +```bash +gem build project-name.gemspec +gem push project-name-*.gem +``` + +If the project is hosted on RubyGems, consider using [RubyGems Trusted Publication] to automatically +push the release using a GitHub action. + +## 7. Add a new GitHub release using the recent `NEWS.md` or `CHANGELOG.md` as the content + +Sample URL: https://github.com/thoughtbot/project-name/releases/new?tag=vVERSION + +## 8. Announce the new release + +Make sure to say "thank you" to the contributors who helped shape this version! + +[RubyGems Trusted Publication]: https://github.com/rubygems/release-gem +[_quick guide on how to sign a release_]: https://gitready.com/advanced/2014/11/02/gpg-sign-releases.html +[GitHub automatically generated release notes]: https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#about-automatically-generated-release-notes diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..9b63758 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,2 @@ + + diff --git a/lib/generators/michel/install/install_generator.rb b/lib/generators/michel/install/install_generator.rb new file mode 100644 index 0000000..70ef1f2 --- /dev/null +++ b/lib/generators/michel/install/install_generator.rb @@ -0,0 +1,13 @@ +require "rails/generators/base" +require "scenic" +module Michel + module Generators + class InstallGenerator < Rails::Generators::Base + source_root File.expand_path("../templates", __FILE__) + + def create_initializer + copy_file "michel.rb", "config/initializers/michel.rb" + end + end + end +end diff --git a/lib/generators/michel/install/templates/michel.rb b/lib/generators/michel/install/templates/michel.rb new file mode 100644 index 0000000..b9afe67 --- /dev/null +++ b/lib/generators/michel/install/templates/michel.rb @@ -0,0 +1,5 @@ +Michel.setup do |config| + config.resource_class_name = "Resource" + config.booking_class_name = "Booking" + config.availability_class_name = "Availability" +end diff --git a/lib/generators/michel/view/templates/belongs_to_associations.erb b/lib/generators/michel/view/templates/belongs_to_associations.erb new file mode 100644 index 0000000..801fc9f --- /dev/null +++ b/lib/generators/michel/view/templates/belongs_to_associations.erb @@ -0,0 +1,6 @@ + belongs_to :<%=Michel.availability_class_symbol%> + belongs_to :<%=Michel.resource_class_symbol%> + + def self.refresh + Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false) + end diff --git a/lib/generators/templates/has_many_associations.erb b/lib/generators/michel/view/templates/has_many_associations.erb similarity index 100% rename from lib/generators/templates/has_many_associations.erb rename to lib/generators/michel/view/templates/has_many_associations.erb diff --git a/lib/generators/templates/index_migration.erb b/lib/generators/michel/view/templates/index_migration.erb similarity index 90% rename from lib/generators/templates/index_migration.erb rename to lib/generators/michel/view/templates/index_migration.erb index fe97821..2e19d6b 100644 --- a/lib/generators/templates/index_migration.erb +++ b/lib/generators/michel/view/templates/index_migration.erb @@ -2,7 +2,7 @@ reversible do |direction| direction.up do execute <<-SQL - CREATE EXTENSION btree_gist; + CREATE EXTENSION IF NOT EXISTS btree_gist; CREATE INDEX on <%=Michel.booking_class_table_name%> using gist (<%=Michel.resource_class_foreign_id%>, tsrange(start_time, start_time + interval '1 minute' * duration, '()')); SQL end diff --git a/lib/generators/templates/view.erb b/lib/generators/michel/view/templates/view.erb similarity index 100% rename from lib/generators/templates/view.erb rename to lib/generators/michel/view/templates/view.erb diff --git a/lib/generators/michel/view/templates/view_migration.rb b/lib/generators/michel/view/templates/view_migration.rb new file mode 100644 index 0000000..8fed4ae --- /dev/null +++ b/lib/generators/michel/view/templates/view_migration.rb @@ -0,0 +1,8 @@ + unless defined?(Scenic) + raise "Scenic gem must be included in the Gemfile to run this migration" + end + def down + drop_view :available_time_slots, materialized: true + end + + \ No newline at end of file diff --git a/lib/generators/michel_generator.rb b/lib/generators/michel/view/view_generator.rb similarity index 82% rename from lib/generators/michel_generator.rb rename to lib/generators/michel/view/view_generator.rb index 4253cc6..b4aa92d 100644 --- a/lib/generators/michel_generator.rb +++ b/lib/generators/michel/view/view_generator.rb @@ -2,7 +2,7 @@ require "scenic" module Michel module Generators - class MichelGenerator < Rails::Generators::Base + class ViewGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) include Scenic @@ -21,7 +21,12 @@ def create_scenic_model self.destination_root = Rails.root puts "Creating scenic model available_time_slot" - invoke "scenic:model", ["available_time_slot"], {"materialized" => true, "test_framework" => false} + invoke "scenic:model", ["available_time_slots"], {"materialized" => true, "test_framework" => false} + + Dir.glob(Rails.root.join("db/migrate/*create_available_time_slots.rb")).each do |file| + gsub_file file, /change/, "up" + inject_into_class file, "CreateAvailableTimeSlots", template_content("view_migration.rb") + end end def create_sql_file diff --git a/lib/generators/templates/belongs_to_associations.erb b/lib/generators/templates/belongs_to_associations.erb deleted file mode 100644 index c0f6660..0000000 --- a/lib/generators/templates/belongs_to_associations.erb +++ /dev/null @@ -1,2 +0,0 @@ - belongs_to :<%=Michel.availability_class_symbol%> - belongs_to :<%=Michel.resource_class_symbol%> diff --git a/michel.gemspec b/michel.gemspec index ee8225e..37b4b31 100644 --- a/michel.gemspec +++ b/michel.gemspec @@ -8,26 +8,17 @@ Gem::Specification.new do |spec| spec.authors = ["Sally Hall", "Aji Slater"] spec.email = ["sally@thoughtbot.com", "aji.slater@gmail.com"] - spec.summary = "This is the summary" - spec.description = "Write a longer description or delete this line." + spec.summary = "Generator to help with appointment scheduling" spec.homepage = "https://github.com/thoughtbot/michel/" spec.required_ruby_version = ">= 3.0.0" - spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'" - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = "https://github.com/thoughtbot/michel/" # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here." # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - gemspec = File.basename(__FILE__) - spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| - ls.readlines("\x0", chomp: true).reject do |f| - (f == gemspec) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) - end - end + + spec.files = `git ls-files`.split("\n") spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] diff --git a/spec/example-app/README.md b/spec/example-app/README.md deleted file mode 100644 index 7db80e4..0000000 --- a/spec/example-app/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... diff --git a/spec/generators/michel/install/install_generator_spec.rb b/spec/generators/michel/install/install_generator_spec.rb new file mode 100644 index 0000000..27e3f77 --- /dev/null +++ b/spec/generators/michel/install/install_generator_spec.rb @@ -0,0 +1,18 @@ +require "spec_helper" +require "generators/michel/install/install_generator" + +RSpec.describe Michel::Generators::InstallGenerator, :generator do + it "generates initializer file" do + destination File.expand_path("../../../../../tmp", __FILE__) + prepare_destination + + run_generator + initializer = file("config/initializers/michel.rb") + + # is_expected_to contain - verifies the file's contents + expect(initializer).to contain(/Michel.setup do |config|/) + expect(initializer).to contain(/config.resource_class_name = "Resource"/) + expect(initializer).to contain(/config.booking_class_name = "Booking"/) + expect(initializer).to contain(/config.availability_class_name = "Availability"/) + end +end diff --git a/spec/generators/michel_generator_spec.rb b/spec/generators/michel/view/view_generator_spec.rb similarity index 81% rename from spec/generators/michel_generator_spec.rb rename to spec/generators/michel/view/view_generator_spec.rb index f2c7271..26a52c9 100644 --- a/spec/generators/michel_generator_spec.rb +++ b/spec/generators/michel/view/view_generator_spec.rb @@ -1,14 +1,14 @@ require "spec_helper" -RSpec.describe "Michel materialized view", type: :generator do +require "generators/michel/view/view_generator" + +RSpec.describe Michel::Generators::ViewGenerator, :generator do before(:all) do Michel.setup do |config| config.resource_class_name = "Physician" config.booking_class_name = "Appointment" config.availability_class_name = "PhysicianAvailability" end - - Rails::Generators.invoke("michel") - Scenic.load + Rails::Generators.invoke("michel:view") ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate")).migrate Rails.autoloaders.main.reload @@ -16,7 +16,7 @@ after(:all) do ActiveRecord::MigrationContext.new(Rails.root.join("db/migrate")).rollback(2) - Rails::Generators.invoke("michel", [], behavior: :revoke) + Rails::Generators.invoke("michel:view", [], behavior: :revoke) end it "generates available time slots" do @@ -30,9 +30,9 @@ timezone: "UTC" ) - Scenic.database.refresh_materialized_view("available_time_slots", concurrently: false) - + AvailableTimeSlot.refresh slots = AvailableTimeSlot.all + expect(slots).not_to be_empty expect(slots.first.start_time.hour).to eq(9) end @@ -54,7 +54,7 @@ duration: 30 ) - Scenic.database.refresh_materialized_view("available_time_slots", concurrently: false) + AvailableTimeSlot.refresh # Now the 9:00 slot should not be available slot_times = AvailableTimeSlot.pluck(:start_time)