From 2ef842e0ea322f3d1033939d17fad340ebbc26f1 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Sun, 20 Oct 2024 09:04:49 -0400 Subject: [PATCH] Upgraded to Ruby 3.3.5. --- .github/workflows/rubocop.yml | 2 +- .github/workflows/test.yml | 37 +- .rubocop.yml | 6 + .rubocop_todo.yml | 112 ++++- Gemfile | 15 +- Gemfile.lock | 415 ++++++++++-------- lib/commands/base.rb | 8 +- lib/models/entry.rb | 3 +- spec/commands/cat_spec.rb | 3 + spec/commands/cd_spec.rb | 1 + spec/commands/echo_spec.rb | 7 +- spec/commands/ls_spec.rb | 1 + spec/commands/man_spec.rb | 1 + spec/commands/mkdir_spec.rb | 2 + spec/commands/pwd_spec.rb | 1 + spec/commands/rm_spec.rb | 5 + spec/commands/touch_spec.rb | 1 + spec/commands/uname_spec.rb | 1 + spec/commands/vi_spec.rb | 29 +- spec/commands/whoami_spec.rb | 1 + spec/integration/add_to_slack_spec.rb | 9 +- spec/integration/help_spec.rb | 3 +- spec/integration/index_spec.rb | 6 +- spec/integration/privacy_spec.rb | 3 +- spec/models/directory_entry_spec.rb | 7 +- spec/models/entry_spec.rb | 18 +- spec/models/file_system_spec.rb | 24 + spec/models/team_spec.rb | 25 +- .../endpoints/it_behaves_like_a_cursor_api.rb | 11 +- spec/support/database_cleaner.rb | 8 +- spec/version_spec.rb | 2 +- 31 files changed, 477 insertions(+), 290 deletions(-) diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index 8330afa..a8cf9be 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -11,7 +11,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: "2.7.7" + ruby-version: "3.3.5" bundler-cache: true - name: Run RuboCop run: bundle exec rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5e81b9..5d6f9c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,32 +1,25 @@ -name: test - +name: Tests on: [push, pull_request] - jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Firefox - uses: browser-actions/setup-firefox@latest + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 with: - firefox-version: "54.0" - - name: Download geckodriver - uses: browser-actions/setup-geckodriver@latest + ruby-version: "3.3.5" + - uses: supercharge/mongodb-github-action@1.7.0 with: - geckodriver-version: "0.18.0" - - name: Set up Ruby - uses: ruby/setup-ruby@v1 + mongodb-version: "7.0" + - uses: browser-actions/setup-geckodriver@latest with: - ruby-version: "2.7.7" - bundler-cache: true - - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.7.0 + geckodriver-version: "0.34.0" + - uses: browser-actions/setup-firefox@v1 with: - mongodb-version: "5" - mongodb-db: shellbot_test - - name: Run tests - uses: GabrielBB/xvfb-action@v1 + firefox-version: "129.0.2" + - run: | + bundle install + - uses: GabrielBB/xvfb-action@v1 with: - run: bundle exec rake + run: | + bundle exec rake spec diff --git a/.rubocop.yml b/.rubocop.yml index bf80f9b..6eb3025 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ AllCops: NewCops: enable + TargetRubyVersion: 3.3 Exclude: - vendor/**/* - bin/**/* @@ -11,3 +12,8 @@ Metrics: Enabled: false inherit_from: .rubocop_todo.yml + +require: + - rubocop-capybara + - rubocop-rake + - rubocop-rspec \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 11857d9..4957368 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,20 +1,13 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-11-28 01:32:55 UTC using RuboCop version 1.4.2. +# on 2024-10-20 13:03:27 UTC using RuboCop version 1.67.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. -# Include: **/*.gemfile, **/Gemfile, **/gems.rb -Bundler/OrderedGems: - Exclude: - - 'Gemfile' - # Offense count: 1 +# Configuration parameters: AllowedParentClasses. Lint/MissingSuper: Exclude: - 'lib/commands/base.rb' @@ -31,30 +24,105 @@ Lint/MixedRegexpCaptureTypes: - 'lib/commands/touch.rb' - 'lib/commands/vi.rb' -# Offense count: 2 -# Cop supports --auto-correct. -Lint/NonDeterministicRequireOrder: - Exclude: - - 'app.rb' - - 'spec/spec_helper.rb' - # Offense count: 1 -# Configuration parameters: AllowComments. +# Configuration parameters: AllowComments, AllowNil. Lint/SuppressedException: Exclude: - 'lib/models/vi_program.rb' # Offense count: 2 # Configuration parameters: ForbiddenDelimiters. -# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: Exclude: - 'lib/commands/man.rb' - 'lib/info.rb' -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 2 +RSpec/AnyInstance: + Exclude: + - 'spec/integration/add_to_slack_spec.rb' + +# Offense count: 22 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/commands/cat_spec.rb' + - 'spec/commands/cd_spec.rb' + - 'spec/commands/echo_spec.rb' + - 'spec/commands/ls_spec.rb' + - 'spec/commands/man_spec.rb' + - 'spec/commands/mkdir_spec.rb' + - 'spec/commands/pwd_spec.rb' + - 'spec/commands/rm_spec.rb' + - 'spec/commands/touch_spec.rb' + - 'spec/commands/uname_spec.rb' + - 'spec/commands/vi_spec.rb' + - 'spec/commands/whoami_spec.rb' + - 'spec/models/file_system_spec.rb' + - 'spec/models/team_spec.rb' + - 'spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb' + +# Offense count: 9 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 11 + +# Offense count: 1 +# Configuration parameters: AssignmentOnly. +RSpec/InstanceVariable: + Exclude: + - 'spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb' + +# Offense count: 2 +RSpec/LetSetup: + Exclude: + - 'spec/commands/rm_spec.rb' + +# Offense count: 27 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 21 +RSpec/MultipleExpectations: + Max: 6 + +# Offense count: 1 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 6 + +# Offense count: 3 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 13 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/commands/cat_spec.rb' + - 'spec/commands/cd_spec.rb' + - 'spec/commands/echo_spec.rb' + - 'spec/commands/ls_spec.rb' + - 'spec/commands/man_spec.rb' + - 'spec/commands/mkdir_spec.rb' + - 'spec/commands/pwd_spec.rb' + - 'spec/commands/rm_spec.rb' + - 'spec/commands/touch_spec.rb' + - 'spec/commands/uname_spec.rb' + - 'spec/commands/vi_spec.rb' + - 'spec/commands/whoami_spec.rb' + - 'spec/version_spec.rb' + +# Offense count: 9 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https Layout/LineLength: - Max: 150 + Max: 149 diff --git a/Gemfile b/Gemfile index 70695f1..79d8cb6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,25 +1,26 @@ source 'https://rubygems.org' -ruby '2.7.7' +ruby '3.3.5' -gem 'giphy' gem 'irb' gem 'kaminari-grape' gem 'mongoid' gem 'mongoid-scroll' -gem 'newrelic-slack-ruby-bot' gem 'newrelic_rpm' +gem 'newrelic-slack-ruby-bot' gem 'rack-robotz' gem 'rack-server-pages' -gem 'slack-ruby-bot-server' -gem 'slack-ruby-bot-server-mailchimp' gem 'slack-ruby-bot-server-events' +gem 'slack-ruby-bot-server-mailchimp' gem 'unicorn' group :development, :test do gem 'foreman' gem 'rake' gem 'rubocop' + gem 'rubocop-capybara' + gem 'rubocop-rake' + gem 'rubocop-rspec' end group :development do @@ -28,11 +29,13 @@ end group :test do gem 'capybara' - gem 'database_cleaner' + gem 'database_cleaner-mongoid' gem 'fabrication' gem 'faker' + gem 'faraday-rack' gem 'hyperclient' gem 'rack-test' + gem 'rackup' gem 'rspec' gem 'selenium-webdriver' gem 'vcr' diff --git a/Gemfile.lock b/Gemfile.lock index 6fe91d7..7a421f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,236 +1,263 @@ GEM remote: https://rubygems.org/ specs: - activemodel (6.1.7.6) - activesupport (= 6.1.7.6) - activesupport (6.1.7.6) - concurrent-ruby (~> 1.0, >= 1.0.2) + activemodel (7.2.1.1) + activesupport (= 7.2.1.1) + activesupport (7.2.1.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - ast (2.4.1) - async (1.27.0) - console (~> 1.10) - nio4r (~> 2.3) - timers (~> 4.1) - bson (4.11.1) - builder (3.2.4) - capybara (3.34.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.2) + async (2.17.0) + console (~> 1.26) + fiber-annotation + io-event (~> 1.6, >= 1.6.5) + base64 (0.2.0) + bigdecimal (3.1.8) + bson (5.0.1) + capybara (3.40.0) addressable + matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.5) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (3.0.0) - concurrent-ruby (1.2.2) - console (1.10.1) - fiber-local - crack (0.4.4) - database_cleaner (1.8.5) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + console (1.27.0) + fiber-annotation + fiber-local (~> 1.1) + json + crack (1.0.0) + bigdecimal + rexml + database_cleaner-core (2.0.1) + database_cleaner-mongoid (2.0.1) + database_cleaner-core (~> 2.0.0) + mongoid declarative (0.0.20) - declarative-option (0.1.0) - diff-lcs (1.4.4) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - dry-configurable (0.11.6) - concurrent-ruby (~> 1.0) - dry-core (~> 0.4, >= 0.4.7) - dry-equalizer (~> 0.2) - dry-container (0.7.2) + diff-lcs (1.5.1) + domain_name (0.6.20240107) + drb (2.2.1) + dry-core (1.0.1) concurrent-ruby (~> 1.0) - dry-configurable (~> 0.1, >= 0.1.3) - dry-core (0.4.10) + zeitwerk (~> 2.6) + dry-inflector (1.1.0) + dry-logic (1.5.0) concurrent-ruby (~> 1.0) - dry-equalizer (0.3.0) - dry-inflector (0.2.0) - dry-logic (1.0.8) + dry-core (~> 1.0, < 2) + zeitwerk (~> 2.6) + dry-types (1.7.2) + bigdecimal (~> 3.0) concurrent-ruby (~> 1.0) - dry-core (~> 0.2) - dry-equalizer (~> 0.2) - dry-types (1.4.0) - concurrent-ruby (~> 1.0) - dry-container (~> 0.3) - dry-core (~> 0.4, >= 0.4.4) - dry-equalizer (~> 0.3) - dry-inflector (~> 0.1, >= 0.1.2) - dry-logic (~> 1.0, >= 1.0.2) - fabrication (2.21.1) - faker (2.15.1) - i18n (>= 1.6, < 2) - faraday (0.17.3) - multipart-post (>= 1.2, < 3) - faraday-digestauth (0.4.1) - faraday (>= 0.7) - net-http-digest_auth (~> 1.4) - faraday_hal_middleware (0.1.1) - faraday_middleware (>= 0.9) - faraday_middleware (0.14.0) - faraday (>= 0.7.4, < 1.0) - faraday_middleware-parse_oj (0.3.2) - faraday (~> 0.9) - faraday_middleware (>= 0.9.1, < 1.0) - oj (>= 2.0, < 4.0) - fiber-local (1.0.0) - foreman (0.87.2) - giphy (3.0.0) - faraday (~> 0.9) - faraday_middleware (~> 0.9) - faraday_middleware-parse_oj (~> 0.3) - launchy (~> 2.4) - gli (2.19.2) - grape (1.7.0) - activesupport - builder + dry-core (~> 1.0) + dry-inflector (~> 1.0) + dry-logic (~> 1.4) + zeitwerk (~> 2.6) + fabrication (2.31.0) + faker (3.5.1) + i18n (>= 1.8.11, < 2) + faraday (2.12.0) + faraday-net_http (>= 2.0, < 3.4) + json + logger + faraday-follow_redirects (0.3.0) + faraday (>= 1, < 3) + faraday-mashify (0.1.1) + faraday (~> 2.0) + hashie + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (3.3.0) + net-http + faraday-rack (2.0.0) + faraday (~> 2.0) + faraday_hal_middleware (0.2.0) + faraday (~> 2.0) + fiber-annotation (0.2.0) + fiber-local (1.1.0) + fiber-storage + fiber-storage (1.0.0) + foreman (0.88.1) + gli (2.21.5) + grape (2.2.0) + activesupport (>= 6) dry-types (>= 1.1) - mustermann-grape (~> 1.0.0) - rack (>= 1.3.0) - rack-accept + mustermann-grape (~> 1.1.0) + rack (>= 2) + zeitwerk grape-roar (0.4.1) grape multi_json roar (~> 1.1.0) - grape-swagger (1.3.1) - grape (~> 1.3) - hashdiff (1.0.1) - hashie (4.1.0) + grape-swagger (2.1.1) + grape (>= 1.7, < 3.0) + rack-test (~> 2) + hashdiff (1.1.1) + hashie (5.0.0) http-accept (1.7.0) - http-cookie (1.0.3) + http-cookie (1.0.7) domain_name (~> 0.5) - hyperclient (0.9.3) + hyperclient (2.0.0) addressable - faraday (>= 0.9.0) - faraday-digestauth (>= 0.3.0) - faraday_hal_middleware - faraday_middleware - net-http-digest_auth - i18n (1.14.1) + faraday (>= 2) + faraday-follow_redirects + faraday_hal_middleware (>= 0.2) + i18n (1.14.6) concurrent-ruby (~> 1.0) - io-console (0.5.6) - irb (1.2.7) - reline (>= 0.1.5) - kaminari-core (1.2.1) + io-console (0.7.2) + io-event (1.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) + kaminari-core (1.2.2) kaminari-grape (1.0.1) grape kaminari-core (~> 1.0) - kgio (2.11.3) - launchy (2.5.0) - addressable (~> 2.7) + kgio (2.11.4) + language_server-protocol (3.17.0.3) + logger (1.6.1) mailchimp_api_v3 (0.2.18) rest-client (~> 2) - mime-types (3.3.1) + matrix (0.4.2) + mime-types (3.6.0) + logger mime-types-data (~> 3.2015) - mime-types-data (3.2020.1104) - mini_mime (1.0.2) - mini_portile2 (2.8.5) - minitest (5.19.0) - mongo (2.13.1) - bson (>= 4.8.2, < 5.0.0) - mongoid (7.3.1) - activemodel (>= 5.1, < 6.2) - mongo (>= 2.10.5, < 3.0.0) - mongoid-compatibility (0.5.1) + mime-types-data (3.2024.1001) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + minitest (5.25.1) + mongo (2.21.0) + bson (>= 4.14.1, < 6.0.0) + mongoid (9.0.2) + activemodel (>= 5.1, < 7.3, != 7.0.0) + concurrent-ruby (>= 1.0.5, < 2.0) + mongo (>= 2.18.0, < 3.0.0) + mongoid-compatibility (1.0.0) activesupport mongoid (>= 2.0) - mongoid-scroll (0.3.6) + mongoid-scroll (2.0.0) i18n - mongoid (>= 3.0) - mongoid-compatibility + mongoid (>= 6.0) mongoid-shell (0.4.6) i18n mongoid (>= 3.0.0) mongoid-compatibility multi_json (1.15.0) - multipart-post (2.1.1) - mustermann (1.1.1) + multipart-post (2.4.1) + mustermann (3.0.3) ruby2_keywords (~> 0.0.1) - mustermann-grape (1.0.1) + mustermann-grape (1.1.0) mustermann (>= 1.0.0) - net-http-digest_auth (1.4.1) + net-http (0.4.1) + uri netrc (0.11.0) newrelic-slack-ruby-bot (0.2.2) newrelic_rpm slack-ruby-bot (>= 0.10.5) - newrelic_rpm (6.14.0) - nio4r (2.5.4) - nokogiri (1.15.6) + newrelic_rpm (9.14.0) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) - oj (3.10.16) - parallel (1.20.1) - parser (2.7.2.0) + parallel (1.26.3) + parser (3.3.5.0) ast (~> 2.4.1) - public_suffix (4.0.6) - racc (1.7.3) - rack (2.2.8.1) - rack-accept (0.4.5) - rack (>= 0.4) - rack-cors (1.1.1) + racc + psych (5.1.2) + stringio + public_suffix (6.0.1) + racc (1.8.1) + rack (3.1.8) + rack-cors (2.0.2) rack (>= 2.0.0) rack-rewrite (1.5.1) rack-robotz (0.0.4) rack - rack-server-pages (0.1.0) + rack-server-pages (0.2.0) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rainbow (3.0.0) - raindrops (0.19.1) - rake (13.0.1) - regexp_parser (1.8.2) - reline (0.1.9) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rainbow (3.1.1) + raindrops (0.20.1) + rake (13.2.1) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.10) io-console (~> 0.5) - representable (3.0.4) + representable (3.2.0) declarative (< 0.1.0) - declarative-option (< 0.2.0) + trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.3.6) - strscan - roar (1.1.0) - representable (~> 3.0.0) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.0) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.0) + rexml (3.3.8) + roar (1.1.1) + representable (~> 3.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.0) - rubocop (1.4.2) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.67.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) - rexml - rubocop-ast (>= 1.1.1) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.2.0) - parser (>= 2.7.1.5) - ruby-progressbar (1.10.1) - ruby2_keywords (0.0.2) - rubyzip (2.3.0) - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) - slack-ruby-bot (0.16.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (3.1.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) + securerandom (0.3.1) + selenium-webdriver (4.25.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + slack-ruby-bot (0.16.1) + activesupport hashie slack-ruby-client (>= 0.14.0) - slack-ruby-bot-server (1.2.1) + slack-ruby-bot-server (2.1.1) async foreman grape @@ -241,52 +268,49 @@ GEM rack-rewrite rack-server-pages slack-ruby-client - slack-ruby-bot-server-events (0.2.0) + slack-ruby-bot-server-events (0.3.2) slack-ruby-bot-server (>= 0.12.0) - slack-ruby-bot-server-mailchimp (0.2.0) + slack-ruby-bot-server-mailchimp (0.3.0) mailchimp_api_v3 - slack-ruby-bot-server (>= 0.10.0) - slack-ruby-client (0.14.6) - activesupport - faraday (>= 0.9) - faraday_middleware + slack-ruby-bot-server (>= 2.0.1) + slack-ruby-client (2.4.0) + faraday (>= 2.0) + faraday-mashify + faraday-multipart gli hashie - websocket-driver - strscan (3.1.0) - timers (4.3.2) + stringio (3.1.1) + trailblazer-option (0.1.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.7) - unicode-display_width (1.7.0) - unicorn (5.7.0) + unicode-display_width (2.6.0) + unicorn (6.1.0) kgio (~> 2.6) raindrops (~> 0.7) - vcr (6.0.0) - webmock (3.10.0) - addressable (>= 2.3.6) + uri (0.13.1) + vcr (6.3.1) + base64 + webmock (3.24.0) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.3) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) + webrick (1.8.2) + websocket (1.2.11) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.11) + zeitwerk (2.7.1) PLATFORMS ruby DEPENDENCIES capybara - database_cleaner + database_cleaner-mongoid fabrication faker + faraday-rack foreman - giphy hyperclient irb kaminari-grape @@ -298,11 +322,14 @@ DEPENDENCIES rack-robotz rack-server-pages rack-test + rackup rake rspec rubocop + rubocop-capybara + rubocop-rake + rubocop-rspec selenium-webdriver - slack-ruby-bot-server slack-ruby-bot-server-events slack-ruby-bot-server-mailchimp unicorn @@ -310,7 +337,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.7.7p221 + ruby 3.3.5p100 BUNDLED WITH - 2.3.26 + 2.4.2 diff --git a/lib/commands/base.rb b/lib/commands/base.rb index db33e46..b1b9c59 100644 --- a/lib/commands/base.rb +++ b/lib/commands/base.rb @@ -34,7 +34,8 @@ def call(client, data) if result && redirect_to && !redirect_to.empty? redirect_to = Shellwords.split(redirect_to).first file_entry = fs.current_directory_entry.write(redirect_to, Thread.current[:stdout].join("\n")) - client.chat_postMessage(channel: data.channel, text: "```#{file_entry.size} byte(s) written```", as_user: true) + client.chat_postMessage(channel: data.channel, text: "```#{file_entry.size} byte(s) written```", + as_user: true) client.logger.info "WRITE: #{client.owner}, #{fs}, file=#{file_entry}, user=#{data.user}" end result @@ -58,9 +59,10 @@ def split_redirect(text) nil end - def command(*values, &block) + def command(*values, &) values = values.map { |value| value.is_a?(Regexp) ? value.source : Regexp.escape(value) }.join('|') - match Regexp.new("^sh[[:space:]](?#{values})([[:space:]]+(?.*)|)$", Regexp::IGNORECASE | Regexp::MULTILINE), &block + match(Regexp.new("^sh[[:space:]](?#{values})([[:space:]]+(?.*)|)$", Regexp::IGNORECASE | Regexp::MULTILINE), + &) end def invoke(client, data) diff --git a/lib/models/entry.rb b/lib/models/entry.rb index c4110ab..89aa08d 100644 --- a/lib/models/entry.rb +++ b/lib/models/entry.rb @@ -12,7 +12,8 @@ def to_s validates_presence_of :name validate :validate_name - belongs_to :parent_directory_entry, class_name: 'DirectoryEntry', inverse_of: :directories, index: true, optional: true + belongs_to :parent_directory_entry, class_name: 'DirectoryEntry', inverse_of: :directories, index: true, + optional: true index({ name: 1, parent_directory_entry_id: 1, file_system_id: 1 }, unique: true) def self.combine_path(path, name) diff --git a/spec/commands/cat_spec.rb b/spec/commands/cat_spec.rb index d109aa3..f7a0b3a 100644 --- a/spec/commands/cat_spec.rb +++ b/spec/commands/cat_spec.rb @@ -4,13 +4,16 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'echo' do let!(:fs) { team.fs['channel'] } let!(:file) { Fabricate(:file_entry, data: 'hello world', parent_directory_entry: fs.root_directory_entry) } + it 'pipe into a file' do expect(client).to receive(:say).with(channel: 'channel', text: 'hello world') message_hook.call(client, Hashie::Mash.new(text: "cat #{file.name}", channel: 'channel', team: team)) end + it 'provides syntax' do expect(client).to receive(:say).with(channel: 'channel', text: 'usage: cat ...') message_hook.call(client, Hashie::Mash.new(text: "cat", channel: 'channel', team: team)) diff --git a/spec/commands/cd_spec.rb b/spec/commands/cd_spec.rb index 32a14ff..0597f4a 100644 --- a/spec/commands/cd_spec.rb +++ b/spec/commands/cd_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'cd' do it 'changes directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/test') diff --git a/spec/commands/echo_spec.rb b/spec/commands/echo_spec.rb index 0632883..5c8e669 100644 --- a/spec/commands/echo_spec.rb +++ b/spec/commands/echo_spec.rb @@ -4,19 +4,22 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'echo' do it 'no message' do expect(client).to receive(:say).with(channel: 'channel', text: "\n") message_hook.call(client, Hashie::Mash.new(team: team, text: "echo", channel: 'channel')) end + it 'message' do expect(client).to receive(:say).with(channel: 'channel', text: 'hi') message_hook.call(client, Hashie::Mash.new(team: team, text: "echo hi", channel: 'channel')) end + it 'pipe into a file' do expect do - expect(client).to receive(:chat_postMessage).with(channel: 'channel', text: '```hi```', as_user: true) - expect(client).to receive(:chat_postMessage).with(channel: 'channel', text: '```2 byte(s) written```', as_user: true) + expect(client).to receive(:chat_postMessage).with({ channel: 'channel', text: '```hi```', as_user: true }) + expect(client).to receive(:chat_postMessage).with({ channel: 'channel', text: '```2 byte(s) written```', as_user: true }) message_hook.call(client, Hashie::Mash.new(team: team, text: "echo hi > \"text file.txt\"", channel: 'channel')) end.to change(FileEntry, :count).by(1) root = team.fs['channel'].root_directory_entry diff --git a/spec/commands/ls_spec.rb b/spec/commands/ls_spec.rb index 7a8d83e..5fba0fb 100644 --- a/spec/commands/ls_spec.rb +++ b/spec/commands/ls_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'ls' do it 'returns contents of the current directory' do expect(client).to receive(:say).with(channel: 'channel', text: ".\n..") diff --git a/spec/commands/man_spec.rb b/spec/commands/man_spec.rb index 7c0fb55..f4fbc99 100644 --- a/spec/commands/man_spec.rb +++ b/spec/commands/man_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'man' do it 'shows help' do expect(client).to receive(:say).with(channel: 'channel', text: SlackShellbot::Commands::Man::HELP) diff --git a/spec/commands/mkdir_spec.rb b/spec/commands/mkdir_spec.rb index c7fb38f..39079e0 100644 --- a/spec/commands/mkdir_spec.rb +++ b/spec/commands/mkdir_spec.rb @@ -4,11 +4,13 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'mkdir' do it 'returns current directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/test') message_hook.call(client, Hashie::Mash.new(team: team, text: "mkdir test", channel: 'channel')) end + it 'makes a directory with a space' do expect(client).to receive(:say).with(channel: 'channel', text: '/foo bar') message_hook.call(client, Hashie::Mash.new(team: team, text: "mkdir \"foo bar\"", channel: 'channel')) diff --git a/spec/commands/pwd_spec.rb b/spec/commands/pwd_spec.rb index 0b6b9f0..f01805c 100644 --- a/spec/commands/pwd_spec.rb +++ b/spec/commands/pwd_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'pwd' do it 'returns current directory' do expect(client).to receive(:say).with(channel: 'channel', text: '/') diff --git a/spec/commands/rm_spec.rb b/spec/commands/rm_spec.rb index 0aef949..7bda7ee 100644 --- a/spec/commands/rm_spec.rb +++ b/spec/commands/rm_spec.rb @@ -4,10 +4,13 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'rm' do let!(:fs) { team.fs['channel'] } + context 'a file' do let!(:file) { Fabricate(:file_entry, name: 'test.txt', parent_directory_entry: fs.root_directory_entry) } + it 'returns removed file name' do expect do expect(client).to receive(:say).with(channel: 'channel', text: '/test.txt') @@ -15,8 +18,10 @@ end.to change(FileEntry, :count).by(-1) end end + context 'a file with a >' do let!(:file) { Fabricate(:file_entry, name: '> test.txt', parent_directory_entry: fs.root_directory_entry) } + it 'returns removed file name' do expect do expect(client).to receive(:say).with(channel: 'channel', text: '/> test.txt') diff --git a/spec/commands/touch_spec.rb b/spec/commands/touch_spec.rb index 6828304..4a02e46 100644 --- a/spec/commands/touch_spec.rb +++ b/spec/commands/touch_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'touch' do it 'returns new file name' do expect(client).to receive(:say).with(channel: 'channel', text: '/test.txt') diff --git a/spec/commands/uname_spec.rb b/spec/commands/uname_spec.rb index e2ce4d1..688af5a 100644 --- a/spec/commands/uname_spec.rb +++ b/spec/commands/uname_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'uname' do it 'returns Shell' do expect(client).to receive(:say).with(channel: 'channel', text: 'Shell') diff --git a/spec/commands/vi_spec.rb b/spec/commands/vi_spec.rb index 842ffa2..f65144a 100644 --- a/spec/commands/vi_spec.rb +++ b/spec/commands/vi_spec.rb @@ -5,6 +5,7 @@ let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } let!(:fs) { team.fs['channel'] } + context 'vi' do it 'creates a file' do expect do @@ -13,34 +14,50 @@ end.to change(Program, :count).by(1) expect(fs.reload.program).to be_a ViProgram end + context 'existing file' do - let!(:file) { Fabricate(:file_entry, name: 'name.txt', data: 'hello world', file_system: fs, parent_directory_entry: fs.root_directory_entry) } + let!(:file) { + Fabricate(:file_entry, name: 'name.txt', data: 'hello world', file_system: fs, + parent_directory_entry: fs.root_directory_entry) + } + it 'opens an existing file' do expect do - expect(client).to receive(:say).with(channel: 'channel', text: "hello world\n~|\n\n\n\"/name.txt\" 1 line(s), 11 character(s)") + expect(client).to receive(:say).with(channel: 'channel', + text: "hello world\n~|\n\n\n\"/name.txt\" 1 line(s), 11 character(s)") message_hook.call(client, Hashie::Mash.new(team: team, text: "vi \"#{file.name}\"", channel: 'channel')) end.to change(Program, :count).by(1) expect(fs.reload.program).to be_a ViProgram end end + context 'opened file' do - let!(:file) { Fabricate(:file_entry, name: 'name.txt', data: 'hello world', file_system: fs, parent_directory_entry: fs.root_directory_entry) } + let!(:file) { + Fabricate(:file_entry, name: 'name.txt', data: 'hello world', file_system: fs, + parent_directory_entry: fs.root_directory_entry) + } let!(:vi) { Fabricate(:vi_program, file_system: fs, file_entry: file, filename: file.name) } + it 'appends to the file' do - expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") + expect(client).to receive(:say).with(channel: 'channel', + text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(vi.reload.data).to eq ['hello world', 'another line'].join("\n") expect(file.reload.data).to eq ['hello world'].join("\n") end + it 'saves file' do - expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") + expect(client).to receive(:say).with(channel: 'channel', + text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: 'written /name.txt, 2 line(s), 24 character(s)') message_hook.call(client, Hashie::Mash.new(team: team, text: ":wq", channel: 'channel')) expect(file.reload.data).to eq ['hello world', 'another line'].join("\n") end + it 'quits without saving file' do - expect(client).to receive(:say).with(channel: 'channel', text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") + expect(client).to receive(:say).with(channel: 'channel', + text: "\hello world\nanother line\n~|\n\n\n\"/name.txt\" 2 line(s), 24 character(s)") message_hook.call(client, Hashie::Mash.new(team: team, text: "another line", channel: 'channel')) expect(client).to receive(:say).with(channel: 'channel', text: 'quit without saving /name.txt') message_hook.call(client, Hashie::Mash.new(team: team, text: ":q", channel: 'channel')) diff --git a/spec/commands/whoami_spec.rb b/spec/commands/whoami_spec.rb index c8d9688..8e3cea0 100644 --- a/spec/commands/whoami_spec.rb +++ b/spec/commands/whoami_spec.rb @@ -4,6 +4,7 @@ let(:team) { Fabricate(:team) } let(:client) { SlackShellbot::Web::Client.new(token: 'token', team: team) } let(:message_hook) { SlackShellbot::Commands::Base } + context 'whoami' do it 'returns username' do expect(client).to receive(:say).with(channel: 'channel', text: '<@user>') diff --git a/spec/integration/add_to_slack_spec.rb b/spec/integration/add_to_slack_spec.rb index 2fd074a..9740722 100644 --- a/spec/integration/add_to_slack_spec.rb +++ b/spec/integration/add_to_slack_spec.rb @@ -2,23 +2,26 @@ require 'spec_helper' -describe 'Add to Slack', js: true, type: :feature do +describe 'Add to Slack', :js, type: :feature do before do ENV['SLACK_CLIENT_ID'] = 'client_id' ENV['SLACK_CLIENT_SECRET'] = 'client_secret' end + after do ENV.delete 'SLACK_CLIENT_ID' ENV.delete 'SLACK_CLIENT_SECRET' end + it 'registers a team' do allow_any_instance_of(Team).to receive(:ping!).and_return(ok: true) expect(SlackRubyBotServer::Service.instance).to receive(:start!) - oauth_access = Slack::Messages::Message.new({ 'access_token' => 'token', 'team' => { 'id' => 'team_id', 'name' => 'team_name' } }) + oauth_access = Slack::Messages::Message.new({ 'access_token' => 'token', + 'team' => { 'id' => 'team_id', 'name' => 'team_name' } }) allow_any_instance_of(::Slack::Web::Client).to receive(:oauth_v2_access).with(hash_including(code: 'code')).and_return(oauth_access) expect do visit '/?code=code' - expect(page.find('#messages')).to have_content 'Team successfully registered!' + expect(page.find_by_id('messages')).to have_content 'Team successfully registered!' end.to change(Team, :count).by(1) end end diff --git a/spec/integration/help_spec.rb b/spec/integration/help_spec.rb index 2e60a2e..809a7dd 100644 --- a/spec/integration/help_spec.rb +++ b/spec/integration/help_spec.rb @@ -2,10 +2,11 @@ require 'spec_helper' -describe 'help.html', js: true, type: :feature do +describe 'help.html', :js, type: :feature do before do visit '/help.html' end + it 'renders help' do expect(title).to eq('Shell: Help') end diff --git a/spec/integration/index_spec.rb b/spec/integration/index_spec.rb index 041d636..cfff78b 100644 --- a/spec/integration/index_spec.rb +++ b/spec/integration/index_spec.rb @@ -2,16 +2,18 @@ require 'spec_helper' -describe 'index.html', js: true, type: :feature do +describe 'index.html', :js, type: :feature do before do ENV['SLACK_CLIENT_ID'] = 'slack-client-id' visit '/' end + after do ENV.delete 'SLACK_CLIENT_ID' end + it 'includes a link to add to slack with the client id' do expect(title).to eq('Shell: A Unix Shell in Every Slack Channel') - expect(first('p[id=register] a')['href']).to eq 'https://slack.com/oauth/v2/authorize?scope=chat:write+im:history+mpim:history+channels:history+groups:history&client_id=slack-client-id' + expect(first('p[id=register] a')['href']).to eq 'https://slack.com/oauth/v2/authorize?scope=chat:write,im:history,mpim:history,channels:history,groups:history&client_id=slack-client-id' end end diff --git a/spec/integration/privacy_spec.rb b/spec/integration/privacy_spec.rb index 5dddcbe..93f474b 100644 --- a/spec/integration/privacy_spec.rb +++ b/spec/integration/privacy_spec.rb @@ -2,10 +2,11 @@ require 'spec_helper' -describe 'privacy.html', js: true, type: :feature do +describe 'privacy.html', :js, type: :feature do before do visit '/privacy.html' end + it 'renders privacy policy' do expect(title).to eq('Shell: Privacy Policy') end diff --git a/spec/models/directory_entry_spec.rb b/spec/models/directory_entry_spec.rb index 5ceab7a..86e04f9 100644 --- a/spec/models/directory_entry_spec.rb +++ b/spec/models/directory_entry_spec.rb @@ -2,17 +2,22 @@ describe DirectoryEntry do let!(:dir) { Fabricate(:directory_entry) } - context '#touch' do + + describe '#touch' do let!(:file) { dir.touch('test') } + it 'is a file' do expect(file).to be_a FileEntry end + it 'is attached ot the direcotry entry' do expect(file.parent_directory_entry).to eq dir end + it 'is is included in count' do expect(dir.count).to eq 3 end + it 'rm' do expect do expect(dir.rm('test')).to be_a FileEntry diff --git a/spec/models/entry_spec.rb b/spec/models/entry_spec.rb index 0ee42dc..ffe5a61 100644 --- a/spec/models/entry_spec.rb +++ b/spec/models/entry_spec.rb @@ -2,17 +2,19 @@ describe Entry do let(:fs) { Fabricate(:file_system) } - context '#name' do + + describe '#name' do it '.' do - expect(Entry.new(name: '.', file_system: fs)).to_not be_valid - expect(Entry.new(name: '..', file_system: fs)).to_not be_valid - expect(Entry.new(name: '...', file_system: fs)).to_not be_valid + expect(described_class.new(name: '.', file_system: fs)).not_to be_valid + expect(described_class.new(name: '..', file_system: fs)).not_to be_valid + expect(described_class.new(name: '...', file_system: fs)).not_to be_valid end + it 'alphanumeric' do - expect(Entry.new(name: 'foo', file_system: fs)).to be_valid - expect(Entry.new(name: 'foo bar', file_system: fs)).to be_valid - expect(Entry.new(name: '123', file_system: fs)).to be_valid - expect(Entry.new(name: 'abc123', file_system: fs)).to be_valid + expect(described_class.new(name: 'foo', file_system: fs)).to be_valid + expect(described_class.new(name: 'foo bar', file_system: fs)).to be_valid + expect(described_class.new(name: '123', file_system: fs)).to be_valid + expect(described_class.new(name: 'abc123', file_system: fs)).to be_valid end end end diff --git a/spec/models/file_system_spec.rb b/spec/models/file_system_spec.rb index 722499a..32d100d 100644 --- a/spec/models/file_system_spec.rb +++ b/spec/models/file_system_spec.rb @@ -2,100 +2,124 @@ describe FileSystem do let!(:fs) { Fabricate(:file_system) } + it 'has a root directory' do expect(fs.root_directory_entry).to be_a(RootDirectoryEntry) expect(fs.reload.root_directory_entry).to be_a(RootDirectoryEntry) end + context 'root' do let!(:root) { fs.root_directory_entry } + it 'path' do expect(root.path).to eq '/' end + it 'mkdir' do expect do root.mkdir('foobar') end.to change(DirectoryEntry, :count).by(1) end + it 'mkdir .' do expect do root.mkdir('.') end.to raise_error Mongoid::Errors::Validations, /Invalid file or directory name./ end + it 'cd .' do fs.cd('.') expect(fs.current_directory_entry).to eq fs.root_directory_entry end + it 'cd .,' do fs.cd('..') expect(fs.current_directory_entry).to eq fs.root_directory_entry end + context 'with a directory' do let!(:dir) { root.mkdir('test') } + it 'cd' do fs.cd('test') expect(fs.current_directory_entry.path).to eq '/test' end + it 'rmdir' do expect do root.rmdir('test') end.to change(DirectoryEntry, :count).by(-1) end + it 'enumerator' do expect(dir.map(&:to_s)).to eq ['.', '..'] expect(root.map(&:to_s)).to eq ['.', '..', 'test'] end + it 'path' do expect(dir.path).to eq '/test' end + context 'with a sub directory' do let!(:subdir) { dir.mkdir('foo') } + it 'rmdir' do expect do dir.rmdir('foo') end.to change(DirectoryEntry, :count).by(-1) end + it 'enumerator' do expect(subdir.map(&:to_s)).to eq ['.', '..'] expect(dir.map(&:to_s)).to eq ['.', '..', 'foo'] expect(root.map(&:to_s)).to eq ['.', '..', 'test'] end + it 'path' do expect(dir.path).to eq '/test' expect(subdir.path).to eq '/test/foo' end + context 'inside a subdirectory' do before do fs.cd('test') fs.cd('foo') end + it 'cd .' do fs.cd('.') expect(fs.current_directory_entry).to eq subdir end + it 'cd .,' do fs.cd('..') expect(fs.current_directory_entry).to eq dir end end end + context 'inside a directory' do before do fs.cd('test') end + it 'cd .' do fs.cd('.') expect(fs.current_directory_entry).to eq dir end + it 'cd .,' do fs.cd('..') expect(fs.current_directory_entry).to eq fs.root_directory_entry end end end + context 'enumerator' do it 'count' do expect(root.count).to eq 2 end + it 'enumerator' do expect(root.map(&:to_s)).to eq ['.', '..'] end diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 405288c..2e3a149 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -1,38 +1,45 @@ require 'spec_helper' describe Team do - context '#purge!' do + describe '#purge!' do let!(:active_team) { Fabricate(:team) } let!(:inactive_team) { Fabricate(:team, active: false) } let!(:inactive_team_a_week_ago) { Fabricate(:team, updated_at: 1.week.ago, active: false) } let!(:inactive_team_two_weeks_ago) { Fabricate(:team, updated_at: 2.weeks.ago, active: false) } let!(:inactive_team_a_month_ago) { Fabricate(:team, updated_at: 1.month.ago, active: false) } + it 'destroys teams inactive for two weeks' do expect do - Team.purge! - end.to change(Team, :count).by(-2) - expect(Team.find(active_team.id)).to eq active_team - expect(Team.find(inactive_team.id)).to eq inactive_team - expect(Team.find(inactive_team_a_week_ago.id)).to eq inactive_team_a_week_ago - expect(Team.find(inactive_team_two_weeks_ago.id)).to be nil - expect(Team.find(inactive_team_a_month_ago.id)).to be nil + described_class.purge! + end.to change(described_class, :count).by(-2) + expect(described_class.find(active_team.id)).to eq active_team + expect(described_class.find(inactive_team.id)).to eq inactive_team + expect(described_class.find(inactive_team_a_week_ago.id)).to eq inactive_team_a_week_ago + expect(described_class.find(inactive_team_two_weeks_ago.id)).to be_nil + expect(described_class.find(inactive_team_a_month_ago.id)).to be_nil end end - context '#fs' do + + describe '#fs' do let!(:team) { Fabricate(:team) } + it 'is a map' do expect(team.fs).to be_a FileSystemMap end + it 'creates a file system for a channel' do expect do expect(team.fs['channel']).to be_a FileSystem end.to change(FileSystem, :count).by(1) end + context 'filesystem' do let!(:fs) { team.fs['channel'] } + it 'changes directory to root' do expect(fs.current_directory_entry).to be_a RootDirectoryEntry end + it 'saves directory to root' do expect(fs.current_directory_entry).to eq fs.root_directory_entry end diff --git a/spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb b/spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb index be87512..42b33de 100644 --- a/spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb +++ b/spec/support/api/endpoints/it_behaves_like_a_cursor_api.rb @@ -28,7 +28,9 @@ next_cursor = { size: 3 } loop do response = client.send(model_ps, next_cursor.merge(cursor_params)) - models_ids.concat(response.map { |instance| instance._links.self._url.gsub("http://example.org/api/#{model_ps}/", '') }) + models_ids.concat(response.map { |instance| + instance._links.self._url.gsub("http://example.org/api/#{model_ps}/", '') + }) break unless response._links[:next] next_cursor = Hash[CGI.parse(URI.parse(response._links.next._url).query).map { |a| [a[0], a[1][0]] }] @@ -41,7 +43,9 @@ next_cursor = { size: 3, offset: 3 } loop do response = client.send(model_ps, next_cursor.merge(cursor_params)) - models_ids.concat(response.map { |instance| instance._links.self._url.gsub("http://example.org/api/#{model_ps}/", '') }) + models_ids.concat(response.map { |instance| + instance._links.self._url.gsub("http://example.org/api/#{model_ps}/", '') + }) break unless response._links[:next] next_cursor = Hash[CGI.parse(URI.parse(response._links.next._url).query).map { |a| [a[0], a[1][0]] }] @@ -52,8 +56,9 @@ context 'total count' do it "doesn't return total_count" do response = client.send(model_ps, cursor_params) - expect(response).to_not respond_to(:total_count) + expect(response).not_to respond_to(:total_count) end + it 'returns total_count when total_count query string is specified' do response = client.send(model_ps, cursor_params.merge(total_count: true)) expect(response.total_count).to eq model.all.count diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 348130b..4ccef29 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,16 +1,16 @@ -require 'database_cleaner' +require 'database_cleaner-mongoid' RSpec.configure do |config| config.before :suite do - DatabaseCleaner.strategy = :truncation - DatabaseCleaner.clean_with :truncation + DatabaseCleaner.strategy = :deletion + DatabaseCleaner.clean_with :deletion end config.after :suite do Mongoid.purge! end - config.around :each do |example| + config.around do |example| DatabaseCleaner.cleaning do example.run end diff --git a/spec/version_spec.rb b/spec/version_spec.rb index 53603eb..8946036 100644 --- a/spec/version_spec.rb +++ b/spec/version_spec.rb @@ -2,6 +2,6 @@ describe SlackShellbot do it 'has a version' do - expect(SlackShellbot::VERSION).to_not be nil + expect(SlackShellbot::VERSION).not_to be_nil end end