From 3863cc6b072bd270d6fabf17ef5c6eac25191998 Mon Sep 17 00:00:00 2001 From: Aaron Reisman Date: Sat, 1 Oct 2022 19:57:59 -0700 Subject: [PATCH] chore: upgrades --- .github/workflows/api.yml | 2 +- api/.ruby-version | 2 +- api/.tool-versions | 2 +- api/Gemfile | 2 +- api/Gemfile.lock | 196 +++++++++--------- api/app/controllers/graphql_controller.rb | 4 +- api/app/graphql/mutations/create_article.rb | 2 +- api/app/graphql/mutations/create_comment.rb | 4 +- api/app/graphql/mutations/delete_article.rb | 4 +- api/app/graphql/mutations/delete_comment.rb | 2 +- api/app/graphql/mutations/favorite_article.rb | 4 +- api/app/graphql/mutations/follow_user.rb | 2 +- api/app/graphql/mutations/sign_in.rb | 2 +- api/app/graphql/mutations/sign_up.rb | 2 +- .../graphql/mutations/unfavorite_article.rb | 4 +- api/app/graphql/mutations/unfollow_user.rb | 2 +- api/app/graphql/mutations/update_article.rb | 4 +- api/app/graphql/mutations/update_user.rb | 4 +- api/app/graphql/types/article_type.rb | 3 +- api/app/graphql/types/comment_type.rb | 2 +- api/app/graphql/types/profile_type.rb | 3 +- api/app/graphql/types/query_type.rb | 6 +- api/app/graphql/types/user_type.rb | 2 +- api/app/models/article.rb | 2 +- api/app/models/user.rb | 2 +- api/app/policies/article_feed_policy.rb | 4 + api/app/policies/article_policy.rb | 4 +- api/db/seeds.rb | 2 +- .../feature-development/graphql/read_query.md | 3 +- .../graphql/mutations/delete_article_spec.rb | 2 +- .../graphql/mutations/delete_comment_spec.rb | 2 +- api/spec/graphql/mutations/sign_in_spec.rb | 2 +- .../mutations/unfavorite_article_spec.rb | 2 +- .../graphql/mutations/update_article_spec.rb | 2 +- .../graphql/queries/article_by_slug_spec.rb | 4 +- .../queries/articles_connection_spec.rb | 4 +- api/spec/graphql/queries/comment_spec.rb | 2 +- .../graphql/queries/feed_connection_spec.rb | 4 +- api/spec/models/article_spec.rb | 4 +- api/spec/models/favorite_spec.rb | 4 +- api/spec/models/relationship_spec.rb | 2 +- api/spec/models/tagging_spec.rb | 2 +- api/spec/models/user_spec.rb | 8 +- api/spec/policies/article_feed_policy_spec.rb | 4 +- api/spec/policies/article_policy_spec.rb | 4 +- api/spec/policies/comment_policy_spec.rb | 2 +- api/spec/support/graphql.rb | 8 +- 47 files changed, 169 insertions(+), 170 deletions(-) diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 71983247..faf80608 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -20,7 +20,7 @@ jobs: run: sudo apt-get install libpq-dev - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1.2 + ruby-version: 3.1.1 working-directory: ./api bundler-cache: true - name: Setup Database diff --git a/api/.ruby-version b/api/.ruby-version index 7bde84d0..2a497469 100644 --- a/api/.ruby-version +++ b/api/.ruby-version @@ -1 +1 @@ -ruby-3.1.2 +ruby-3.1.1 diff --git a/api/.tool-versions b/api/.tool-versions index 7a37bda4..0785c811 100644 --- a/api/.tool-versions +++ b/api/.tool-versions @@ -1,2 +1,2 @@ -ruby 3.1.2 +ruby 3.1.1 postgres 12.9 diff --git a/api/Gemfile b/api/Gemfile index 52b58420..43caeca3 100644 --- a/api/Gemfile +++ b/api/Gemfile @@ -27,5 +27,5 @@ gem 'spring', group: :development gem 'spring-watcher-listen', group: :development gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.1.2' +ruby '3.1.1' source 'https://rubygems.org' diff --git a/api/Gemfile.lock b/api/Gemfile.lock index ac3ce0d7..63149240 100644 --- a/api/Gemfile.lock +++ b/api/Gemfile.lock @@ -1,75 +1,75 @@ GEM remote: https://rubygems.org/ specs: - action_policy (0.6.1) + action_policy (0.6.3) ruby-next-core (>= 0.14.0) action_policy-graphql (0.5.3) action_policy (>= 0.5.0) graphql (>= 1.9.3) ruby-next-core (>= 0.10.0) - actioncable (7.0.3) - actionpack (= 7.0.3) - activesupport (= 7.0.3) + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.3) - actionpack (= 7.0.3) - activejob (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.3) - actionpack (= 7.0.3) - actionview (= 7.0.3) - activejob (= 7.0.3) - activesupport (= 7.0.3) + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.3) - actionview (= 7.0.3) - activesupport (= 7.0.3) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.3) - actionpack (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.3) - activesupport (= 7.0.3) + actionview (7.0.4) + activesupport (= 7.0.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - active_record_doctor (1.9.0) + active_record_doctor (1.10.0) activerecord (>= 4.2.0) - activejob (7.0.3) - activesupport (= 7.0.3) + activejob (7.0.4) + activesupport (= 7.0.4) globalid (>= 0.3.6) - activemodel (7.0.3) - activesupport (= 7.0.3) - activerecord (7.0.3) - activemodel (= 7.0.3) - activesupport (= 7.0.3) - activestorage (7.0.3) - actionpack (= 7.0.3) - activejob (= 7.0.3) - activerecord (= 7.0.3) - activesupport (= 7.0.3) + activemodel (7.0.4) + activesupport (= 7.0.4) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.3) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -78,7 +78,7 @@ GEM backport (1.2.0) bcrypt (3.1.18) benchmark (0.2.0) - bootsnap (1.12.0) + bootsnap (1.13.0) msgpack (~> 1.2) builder (3.2.4) byebug (11.1.3) @@ -96,26 +96,26 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.5.0) - digest (3.1.0) e2mmap (0.1.0) - erubi (1.10.0) + erubi (1.11.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faker (2.21.0) + faker (2.23.0) i18n (>= 1.8.11, < 2) ffi (1.15.5) friendly_id (5.4.2) activerecord (>= 4.0.0) globalid (1.0.0) activesupport (>= 5.0) - graphql (2.0.11) - i18n (1.10.0) + graphql (2.0.14) + i18n (1.12.0) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) - jwt (2.4.1) + json (2.6.2) + jwt (2.5.0) kramdown (2.4.0) rexml kramdown-parser-gfm (1.1.0) @@ -123,7 +123,7 @@ GEM listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.18.0) + loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -132,76 +132,70 @@ GEM method_source (1.0.0) mini_mime (1.1.2) mini_portile2 (2.8.0) - minitest (5.16.1) - msgpack (1.5.2) - net-imap (0.2.3) - digest + minitest (5.16.3) + msgpack (1.6.0) + net-imap (0.3.1) net-protocol - strscan - net-pop (0.1.1) - digest + net-pop (0.1.2) net-protocol - timeout net-protocol (0.1.3) timeout - net-smtp (0.3.1) - digest + net-smtp (0.3.2) net-protocol - timeout nio4r (2.5.8) - nokogiri (1.13.6) + nokogiri (1.13.8) mini_portile2 (~> 2.8.0) racc (~> 1.4) orm_adapter (0.5.0) parallel (1.22.1) - parser (3.1.2.0) + parser (3.1.2.1) ast (~> 2.4.1) - pg (1.4.1) - puma (5.6.4) + pg (1.4.3) + puma (5.6.5) nio4r (~> 2.0) racc (1.6.0) - rack (2.2.3.1) + rack (2.2.4) rack-cors (1.1.1) rack (>= 2.0.0) - rack-test (2.0.0) + rack-test (2.0.2) rack (>= 1.3) - rails (7.0.3) - actioncable (= 7.0.3) - actionmailbox (= 7.0.3) - actionmailer (= 7.0.3) - actionpack (= 7.0.3) - actiontext (= 7.0.3) - actionview (= 7.0.3) - activejob (= 7.0.3) - activemodel (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) bundler (>= 1.15.0) - railties (= 7.0.3) + railties (= 7.0.4) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-erd (1.7.1) + rails-erd (1.7.2) activerecord (>= 4.2) activesupport (>= 4.2) choice (~> 0.2.0) ruby-graphviz (~> 1.2) rails-html-sanitizer (1.4.3) loofah (~> 2.3) - railties (7.0.3) - actionpack (= 7.0.3) - activesupport (= 7.0.3) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) - rb-fsevent (0.11.1) + rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - regexp_parser (2.5.0) + regexp_parser (2.6.0) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -210,7 +204,7 @@ GEM rexml (3.2.5) rspec-core (3.11.0) rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rspec-expectations (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-mocks (3.11.1) @@ -224,25 +218,26 @@ GEM rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) rspec-support (~> 3.10) - rspec-support (3.11.0) - rubocop (1.31.0) + rspec-support (3.11.1) + rubocop (1.36.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.1.2.1) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.18.0, < 2.0) + rubocop-ast (>= 1.20.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.18.0) + rubocop-ast (1.21.0) parser (>= 3.1.1.0) ruby-graphviz (1.2.5) rexml - ruby-next-core (0.15.1) + ruby-next-core (0.15.2) ruby-progressbar (1.11.0) - shoulda-matchers (5.1.0) + shoulda-matchers (5.2.0) activesupport (>= 5.2.0) - solargraph (0.45.0) + solargraph (0.47.2) backport (~> 1.2) benchmark bundler (>= 1.17.2) @@ -257,17 +252,16 @@ GEM thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9, >= 0.9.24) - spring (2.1.1) - spring-watcher-listen (2.0.1) + spring (4.1.0) + spring-watcher-listen (2.1.0) listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) - strscan (3.0.3) + spring (>= 4) thor (1.2.1) - tilt (2.0.10) + tilt (2.0.11) timeout (0.3.0) - tzinfo (2.0.4) + tzinfo (2.0.5) concurrent-ruby (~> 1.0) - unicode-display_width (2.2.0) + unicode-display_width (2.3.0) warden (1.2.9) rack (>= 2.0.9) webrick (1.7.0) @@ -276,7 +270,7 @@ GEM websocket-extensions (0.1.5) yard (0.9.28) webrick (~> 1.7.0) - zeitwerk (2.6.0) + zeitwerk (2.6.1) PLATFORMS ruby @@ -310,7 +304,7 @@ DEPENDENCIES tzinfo-data RUBY VERSION - ruby 3.1.2p20 + ruby 3.1.1p18 BUNDLED WITH 2.3.16 diff --git a/api/app/controllers/graphql_controller.rb b/api/app/controllers/graphql_controller.rb index 266ea5a8..98c21ee9 100644 --- a/api/app/controllers/graphql_controller.rb +++ b/api/app/controllers/graphql_controller.rb @@ -11,7 +11,7 @@ def execute variables = ensure_hash(params[:variables]) query = params[:query] operation_name = params[:operationName] - result = ApiSchema.execute(query, variables: variables, context: context, operation_name: operation_name) + result = ApiSchema.execute(query, variables:, context:, operation_name:) render json: result rescue StandardError => e raise e unless Rails.env.development? @@ -23,7 +23,7 @@ def execute def context { - current_user: current_user + current_user: } end diff --git a/api/app/graphql/mutations/create_article.rb b/api/app/graphql/mutations/create_article.rb index fdf89a19..8acfa542 100644 --- a/api/app/graphql/mutations/create_article.rb +++ b/api/app/graphql/mutations/create_article.rb @@ -21,7 +21,7 @@ def resolve(input:) article = context[:current_user].articles.create!(input) - { article: article } + { article: } end end end diff --git a/api/app/graphql/mutations/create_comment.rb b/api/app/graphql/mutations/create_comment.rb index 76d0ecaf..7ad801ec 100644 --- a/api/app/graphql/mutations/create_comment.rb +++ b/api/app/graphql/mutations/create_comment.rb @@ -18,12 +18,12 @@ def resolve(article_slug:, input:) authorize! Comment, to: :create? article = Article.find_by(slug: article_slug) comment = Comment.create!( - article: article, + article:, author: context[:current_user], body: input[:body] ) - { comment: comment } + { comment: } end end end diff --git a/api/app/graphql/mutations/delete_article.rb b/api/app/graphql/mutations/delete_article.rb index 213010d3..796b1abd 100644 --- a/api/app/graphql/mutations/delete_article.rb +++ b/api/app/graphql/mutations/delete_article.rb @@ -7,12 +7,12 @@ class DeleteArticle < Mutations::BaseMutation field :article, Types::ArticleType, null: false def resolve(slug:) - article = Article.find_by(slug: slug) + article = Article.find_by(slug:) authorize! article, to: :delete? article.destroy! - { article: article } + { article: } end end end diff --git a/api/app/graphql/mutations/delete_comment.rb b/api/app/graphql/mutations/delete_comment.rb index f7b1fbf2..cfe440d9 100644 --- a/api/app/graphql/mutations/delete_comment.rb +++ b/api/app/graphql/mutations/delete_comment.rb @@ -11,7 +11,7 @@ def resolve(id:) authorize! comment, to: :delete? comment.destroy! - { comment: comment } + { comment: } end end end diff --git a/api/app/graphql/mutations/favorite_article.rb b/api/app/graphql/mutations/favorite_article.rb index 75ae5ff3..dd14d33a 100644 --- a/api/app/graphql/mutations/favorite_article.rb +++ b/api/app/graphql/mutations/favorite_article.rb @@ -6,10 +6,10 @@ class FavoriteArticle < Mutations::BaseMutation field :article, Types::ArticleType, null: false def resolve(slug:) - article = Article.find_by(slug: slug) + article = Article.find_by(slug:) authorize! article, to: :favorite? - favorite = Favorite.create!(article: article, user: context[:current_user]) + favorite = Favorite.create!(article:, user: context[:current_user]) { article: favorite.article } end diff --git a/api/app/graphql/mutations/follow_user.rb b/api/app/graphql/mutations/follow_user.rb index 7ed5cea0..a8d4a4eb 100644 --- a/api/app/graphql/mutations/follow_user.rb +++ b/api/app/graphql/mutations/follow_user.rb @@ -6,7 +6,7 @@ class FollowUser < Mutations::BaseMutation field :user, Types::UserType, null: false def resolve(username:) - user = User.find_by(username: username) + user = User.find_by(username:) authorize! user, to: :follow? relationship = Relationship.create!(follower: context[:current_user], followed: user) diff --git a/api/app/graphql/mutations/sign_in.rb b/api/app/graphql/mutations/sign_in.rb index 2df25da8..aac2b4c2 100644 --- a/api/app/graphql/mutations/sign_in.rb +++ b/api/app/graphql/mutations/sign_in.rb @@ -20,7 +20,7 @@ def resolve(input:) user.authenticate!(input[:password]) - { user: user, token: user.generate_jwt } + { user:, token: user.generate_jwt } end end end diff --git a/api/app/graphql/mutations/sign_up.rb b/api/app/graphql/mutations/sign_up.rb index e75aed88..358aebc5 100644 --- a/api/app/graphql/mutations/sign_up.rb +++ b/api/app/graphql/mutations/sign_up.rb @@ -20,7 +20,7 @@ def resolve(input:) user.build_profile user.save! - { user: user } + { user: } end end end diff --git a/api/app/graphql/mutations/unfavorite_article.rb b/api/app/graphql/mutations/unfavorite_article.rb index 2c206075..3fa19627 100644 --- a/api/app/graphql/mutations/unfavorite_article.rb +++ b/api/app/graphql/mutations/unfavorite_article.rb @@ -6,11 +6,11 @@ class UnfavoriteArticle < Mutations::BaseMutation field :article, Types::ArticleType, null: false def resolve(slug:) - article = Article.find_by(slug: slug) + article = Article.find_by(slug:) authorize! article, to: :unfavorite? - favorite = Favorite.find_by(article: article, user: context[:current_user]) + favorite = Favorite.find_by(article:, user: context[:current_user]) favorite.destroy! { article: favorite.article } diff --git a/api/app/graphql/mutations/unfollow_user.rb b/api/app/graphql/mutations/unfollow_user.rb index 68056168..1e5002b1 100644 --- a/api/app/graphql/mutations/unfollow_user.rb +++ b/api/app/graphql/mutations/unfollow_user.rb @@ -6,7 +6,7 @@ class UnfollowUser < Mutations::BaseMutation field :user, Types::UserType, null: false def resolve(username:) - user = User.find_by(username: username) + user = User.find_by(username:) authorize! user, to: :unfollow? diff --git a/api/app/graphql/mutations/update_article.rb b/api/app/graphql/mutations/update_article.rb index 0edfd5c0..b3f2a3e5 100644 --- a/api/app/graphql/mutations/update_article.rb +++ b/api/app/graphql/mutations/update_article.rb @@ -19,13 +19,13 @@ def prepare field :article, Types::ArticleType, null: false def resolve(slug:, input:) - article = Article.find_by(slug: slug) + article = Article.find_by(slug:) authorize! article, to: :update? article.update!(input) - { article: article } + { article: } end end end diff --git a/api/app/graphql/mutations/update_user.rb b/api/app/graphql/mutations/update_user.rb index 449e4c65..fd47e46c 100644 --- a/api/app/graphql/mutations/update_user.rb +++ b/api/app/graphql/mutations/update_user.rb @@ -36,7 +36,7 @@ def nil_if_empty(val) field :user, Types::UserType, null: false def resolve(username:, input:) - user = User.includes(:profile).find_by(username: username) + user = User.includes(:profile).find_by(username:) authorize! user, to: :update? authorize! user.profile, to: :update? @@ -44,7 +44,7 @@ def resolve(username:, input:) user.update!(input) { - user: user + user: } end end diff --git a/api/app/graphql/types/article_type.rb b/api/app/graphql/types/article_type.rb index cb8678e6..73d68f60 100644 --- a/api/app/graphql/types/article_type.rb +++ b/api/app/graphql/types/article_type.rb @@ -26,8 +26,7 @@ def viewer_did_favorite context[:current_user].favorite_articles.include?(object) end - expose_authorization_rules :favorite?, :unfavorite?, :update?, :delete?, :create?, - prefix: 'can_' + expose_authorization_rules :favorite?, :unfavorite?, :create?, :update?, :delete? expose_authorization_rules :create?, with: CommentPolicy, field_name: 'can_create_comment' end diff --git a/api/app/graphql/types/comment_type.rb b/api/app/graphql/types/comment_type.rb index 675c9048..497ae409 100644 --- a/api/app/graphql/types/comment_type.rb +++ b/api/app/graphql/types/comment_type.rb @@ -9,6 +9,6 @@ class CommentType < Types::BaseObject field :author, UserType, null: false field :article, ArticleType, null: false - expose_authorization_rules :delete?, prefix: 'can_' + expose_authorization_rules :delete? end end diff --git a/api/app/graphql/types/profile_type.rb b/api/app/graphql/types/profile_type.rb index 02efca53..1338b4cf 100644 --- a/api/app/graphql/types/profile_type.rb +++ b/api/app/graphql/types/profile_type.rb @@ -6,6 +6,7 @@ class ProfileType < Types::BaseObject field :bio, String, null: false field :image_url, String, null: true field :user, UserType, null: false - expose_authorization_rules :update?, prefix: 'can_' + + expose_authorization_rules :update? end end diff --git a/api/app/graphql/types/query_type.rb b/api/app/graphql/types/query_type.rb index b18226bf..1934911d 100644 --- a/api/app/graphql/types/query_type.rb +++ b/api/app/graphql/types/query_type.rb @@ -27,7 +27,7 @@ def articles_connection(tag_name: nil) end def article_by_slug(slug:) - Article.find_by(slug: slug) + Article.find_by(slug:) end field :popular_tags, [TagType], null: false @@ -63,7 +63,7 @@ def comment(id:) end def user_by_username(username:) - User.find_by(username: username) + User.find_by(username:) end field :viewer, UserType, null: true @@ -71,5 +71,7 @@ def user_by_username(username:) def viewer context[:current_user] end + + expose_authorization_rules :read?, with: ArticleFeedPolicy, field_name: 'can_read_feed' end end diff --git a/api/app/graphql/types/user_type.rb b/api/app/graphql/types/user_type.rb index d632212b..778f96d4 100644 --- a/api/app/graphql/types/user_type.rb +++ b/api/app/graphql/types/user_type.rb @@ -34,7 +34,7 @@ def favorite_articles_connection object.favorite_articles.order(created_at: :desc) end - expose_authorization_rules :unfollow?, :follow?, :update?, prefix: 'can_' + expose_authorization_rules :unfollow?, :follow?, :update? expose_authorization_rules :create?, with: ArticlePolicy, field_name: 'can_create_article' end end diff --git a/api/app/models/article.rb b/api/app/models/article.rb index 2518fca3..89e1772d 100644 --- a/api/app/models/article.rb +++ b/api/app/models/article.rb @@ -25,7 +25,7 @@ def self.tagged_with(tags) joins(:taggings).merge(Tagging.joins(:tag).merge(tags)).distinct end - def is_favorited_by?(user) + def favorited_by?(user) users_who_favorited.include?(user) end end diff --git a/api/app/models/user.rb b/api/app/models/user.rb index c713477f..2eae49c3 100644 --- a/api/app/models/user.rb +++ b/api/app/models/user.rb @@ -39,7 +39,7 @@ def self.from_jwt(token) def generate_jwt JWT.encode( { - id: id, + id:, exp: 24.hours.from_now.to_i }, Rails.application.credentials[:secret_key_base] ) diff --git a/api/app/policies/article_feed_policy.rb b/api/app/policies/article_feed_policy.rb index f44fb8e0..df16bdcb 100644 --- a/api/app/policies/article_feed_policy.rb +++ b/api/app/policies/article_feed_policy.rb @@ -8,4 +8,8 @@ class ArticleFeedPolicy < ApplicationPolicy scope.none end end + + def read? + user.instance_of?(User) + end end diff --git a/api/app/policies/article_policy.rb b/api/app/policies/article_policy.rb index 0183da72..4ab981b5 100644 --- a/api/app/policies/article_policy.rb +++ b/api/app/policies/article_policy.rb @@ -14,11 +14,11 @@ def delete? end def favorite? - user_not_author? && !record.is_favorited_by?(user) + user_not_author? && !record.favorited_by?(user) end def unfavorite? - user_not_author? && record.is_favorited_by?(user) + user_not_author? && record.favorited_by?(user) end private diff --git a/api/db/seeds.rb b/api/db/seeds.rb index 56ad2a61..82d9adf5 100644 --- a/api/db/seeds.rb +++ b/api/db/seeds.rb @@ -41,7 +41,7 @@ article.tags << Tag.offset(rand(Tag.count)).first 5.times do User.offset(rand(User.count)).first.comments.create( - article: article, + article:, body: Faker::Lorem.sentence ) end diff --git a/api/docs/feature-development/graphql/read_query.md b/api/docs/feature-development/graphql/read_query.md index 972185bf..65c82f5e 100644 --- a/api/docs/feature-development/graphql/read_query.md +++ b/api/docs/feature-development/graphql/read_query.md @@ -33,8 +33,7 @@ module Types context[:current_user].favorite_articles.include?(object) end - expose_authorization_rules :favorite?, :unfavorite?, :update?, :delete?, :create?, - prefix: 'can_' + expose_authorization_rules :favorite?, :unfavorite?, :create?, :update?, :delete? expose_authorization_rules :create?, with: CommentPolicy, field_name: 'can_create_comment' end diff --git a/api/spec/graphql/mutations/delete_article_spec.rb b/api/spec/graphql/mutations/delete_article_spec.rb index dc505071..df6d42ef 100644 --- a/api/spec/graphql/mutations/delete_article_spec.rb +++ b/api/spec/graphql/mutations/delete_article_spec.rb @@ -18,7 +18,7 @@ end let(:author) { create(:author) } let(:tags) { create_list(:tag, 3) } - let(:article) { create(:article, author: author) } + let(:article) { create(:article, author:) } let(:variables) do { slug: article.slug diff --git a/api/spec/graphql/mutations/delete_comment_spec.rb b/api/spec/graphql/mutations/delete_comment_spec.rb index 1e5cb203..964ae80e 100644 --- a/api/spec/graphql/mutations/delete_comment_spec.rb +++ b/api/spec/graphql/mutations/delete_comment_spec.rb @@ -17,7 +17,7 @@ let(:comment_author) { create(:author) } let(:article_author) { create(:author) } let(:article) { create(:article, author: article_author) } - let(:comment) { create(:comment, author: comment_author, article: article) } + let(:comment) { create(:comment, author: comment_author, article:) } let(:variables) do { id: comment.id diff --git a/api/spec/graphql/mutations/sign_in_spec.rb b/api/spec/graphql/mutations/sign_in_spec.rb index c323f28b..3e74a1dc 100644 --- a/api/spec/graphql/mutations/sign_in_spec.rb +++ b/api/spec/graphql/mutations/sign_in_spec.rb @@ -35,7 +35,7 @@ { data: { signIn: { - token: token, + token:, user: { email: user.email, username: user.username diff --git a/api/spec/graphql/mutations/unfavorite_article_spec.rb b/api/spec/graphql/mutations/unfavorite_article_spec.rb index 14c556e2..f6706b0e 100644 --- a/api/spec/graphql/mutations/unfavorite_article_spec.rb +++ b/api/spec/graphql/mutations/unfavorite_article_spec.rb @@ -24,7 +24,7 @@ } end - before(:each) { Favorite.create(article: article, user: user) } + before(:each) { Favorite.create(article:, user:) } context 'current_user is not defined' do let(:result) do diff --git a/api/spec/graphql/mutations/update_article_spec.rb b/api/spec/graphql/mutations/update_article_spec.rb index 75240531..e7471f28 100644 --- a/api/spec/graphql/mutations/update_article_spec.rb +++ b/api/spec/graphql/mutations/update_article_spec.rb @@ -22,7 +22,7 @@ end let(:author) { create(:author) } let(:tags) { create_list(:tag, 3) } - let(:article) { create(:article, author: author) } + let(:article) { create(:article, author:) } let(:variables) do { slug: article.slug, diff --git a/api/spec/graphql/queries/article_by_slug_spec.rb b/api/spec/graphql/queries/article_by_slug_spec.rb index 25202219..ef889232 100644 --- a/api/spec/graphql/queries/article_by_slug_spec.rb +++ b/api/spec/graphql/queries/article_by_slug_spec.rb @@ -47,7 +47,7 @@ GRAPHQL end let(:author) { create(:author) } - let(:article) { create(:article, author: author) } + let(:article) { create(:article, author:) } let(:variables) do { slug: article.slug @@ -118,7 +118,7 @@ end context 'current_user is a user who has favorited the article' do - let(:current_user) { create(:favorite, article: article, user: build(:user)).user } + let(:current_user) { create(:favorite, article:, user: build(:user)).user } let(:result) do { data: { diff --git a/api/spec/graphql/queries/articles_connection_spec.rb b/api/spec/graphql/queries/articles_connection_spec.rb index bc4c8f1e..e900df94 100644 --- a/api/spec/graphql/queries/articles_connection_spec.rb +++ b/api/spec/graphql/queries/articles_connection_spec.rb @@ -30,8 +30,8 @@ { first: 2 } end - let!(:tagged_articles) { create_list(:article, 2, author: author, tags: tags) } - let!(:articles) { create_list(:article, 2, author: author) } + let!(:tagged_articles) { create_list(:article, 2, author:, tags:) } + let!(:articles) { create_list(:article, 2, author:) } context 'current_user is not defined' do let(:result) do diff --git a/api/spec/graphql/queries/comment_spec.rb b/api/spec/graphql/queries/comment_spec.rb index 82b5c13f..f1b23224 100644 --- a/api/spec/graphql/queries/comment_spec.rb +++ b/api/spec/graphql/queries/comment_spec.rb @@ -25,7 +25,7 @@ let(:article_author) { create(:author) } let(:comment_author) { create(:author) } let(:article) { create(:article, author: article_author) } - let(:comment) { create(:comment, article: article, author: comment_author) } + let(:comment) { create(:comment, article:, author: comment_author) } let(:variables) do { id: comment.id diff --git a/api/spec/graphql/queries/feed_connection_spec.rb b/api/spec/graphql/queries/feed_connection_spec.rb index 780c60e1..a536752b 100644 --- a/api/spec/graphql/queries/feed_connection_spec.rb +++ b/api/spec/graphql/queries/feed_connection_spec.rb @@ -26,8 +26,8 @@ let(:author) { create(:author) } let(:tags) { create_list(:tag, 1) } - let!(:tagged_articles) { create_list(:article, 2, author: author, tags: tags) } - let!(:articles) { create_list(:article, 2, author: author) } + let!(:tagged_articles) { create_list(:article, 2, author:, tags:) } + let!(:articles) { create_list(:article, 2, author:) } context 'current_user is not defined' do let(:result) do diff --git a/api/spec/models/article_spec.rb b/api/spec/models/article_spec.rb index fcce7319..339cc39c 100644 --- a/api/spec/models/article_spec.rb +++ b/api/spec/models/article_spec.rb @@ -55,7 +55,7 @@ before(:each) do create_list(:article, 3, author: build(:author)) - create_list(:article, 3, author: author) + create_list(:article, 3, author:) end subject { described_class.feed_for(relationship.follower) } @@ -72,7 +72,7 @@ describe '#favorites_count' do let(:user) { create(:user) } let(:article) { create(:article, author: build(:author)) } - let(:favorite) { build(:favorite, user: user, article: article) } + let(:favorite) { build(:favorite, user:, article:) } it 'will increment favorites_count by 1 when user favorites an article' do expect do diff --git a/api/spec/models/favorite_spec.rb b/api/spec/models/favorite_spec.rb index dc85570f..6c13db6c 100644 --- a/api/spec/models/favorite_spec.rb +++ b/api/spec/models/favorite_spec.rb @@ -11,9 +11,9 @@ describe 'validations' do let(:user) { create(:user) } let(:author) { create(:author) } - let(:article) { create(:article, author: author) } + let(:article) { create(:article, author:) } - subject { create(:favorite, user: user, article: article) } + subject { create(:favorite, user:, article:) } it { is_expected.to validate_uniqueness_of(:article_id).scoped_to(:user_id) } end diff --git a/api/spec/models/relationship_spec.rb b/api/spec/models/relationship_spec.rb index 5bda70f1..4e038e83 100644 --- a/api/spec/models/relationship_spec.rb +++ b/api/spec/models/relationship_spec.rb @@ -12,7 +12,7 @@ let(:followed) { create(:followed) } let(:follower) { create(:follower) } - subject { create(:relationship, followed: followed, follower: follower) } + subject { create(:relationship, followed:, follower:) } it { is_expected.to validate_presence_of(:followed) } it { is_expected.to validate_presence_of(:follower) } diff --git a/api/spec/models/tagging_spec.rb b/api/spec/models/tagging_spec.rb index 8753eb7e..c52b4a97 100644 --- a/api/spec/models/tagging_spec.rb +++ b/api/spec/models/tagging_spec.rb @@ -12,7 +12,7 @@ let(:article) { create(:article, author: create(:author)) } let(:tag) { create(:tag) } - subject { create(:tagging, article: article, tag: tag) } + subject { create(:tagging, article:, tag:) } it { is_expected.to validate_uniqueness_of(:tag_id).scoped_to(:article_id) } end diff --git a/api/spec/models/user_spec.rb b/api/spec/models/user_spec.rb index 9940563c..4c0d8395 100644 --- a/api/spec/models/user_spec.rb +++ b/api/spec/models/user_spec.rb @@ -63,13 +63,13 @@ it 'will increase for followed when a relationship is created' do expect do - Relationship.create!(followed: followed, follower: follower) + Relationship.create!(followed:, follower:) end.to change { followed.followers_count }.by(1) end it 'will not increase for follower when a relationship is created' do expect do - Relationship.create!(followed: followed, follower: follower) + Relationship.create!(followed:, follower:) end.to change { follower.followers_count }.by(0) end end @@ -80,13 +80,13 @@ it 'will not increase for followed when a relationship is created' do expect do - Relationship.create!(followed: followed, follower: follower) + Relationship.create!(followed:, follower:) end.to change { followed.following_count }.by(0) end it 'will increase for follower when a relationship is created' do expect do - Relationship.create!(followed: followed, follower: follower) + Relationship.create!(followed:, follower:) end.to change { follower.following_count }.by(1) end end diff --git a/api/spec/policies/article_feed_policy_spec.rb b/api/spec/policies/article_feed_policy_spec.rb index 594d320e..df217b0a 100644 --- a/api/spec/policies/article_feed_policy_spec.rb +++ b/api/spec/policies/article_feed_policy_spec.rb @@ -6,12 +6,12 @@ describe 'relation scope' do let(:author) { create(:author) } let(:user) { create(:user) } - let(:context) { { user: user } } + let(:context) { { user: } } before(:each) do user.following << author create(:article, author: user) - create(:article, author: author) + create(:article, author:) end subject { policy.apply_scope(Article.all, type: :active_record_relation) } diff --git a/api/spec/policies/article_policy_spec.rb b/api/spec/policies/article_policy_spec.rb index 80dbc44a..97310be4 100644 --- a/api/spec/policies/article_policy_spec.rb +++ b/api/spec/policies/article_policy_spec.rb @@ -6,7 +6,7 @@ let(:current_user) { nil } let(:author) { create(:author) } let(:user) { create(:user) } - let(:record) { create(:article, author: author) } + let(:record) { create(:article, author:) } let(:context) { { user: current_user } } describe_rule :create? do @@ -42,7 +42,7 @@ describe_rule :unfavorite? do succeed 'when user is not author and has favorited' do - let(:favorite) { create(:favorite, article: record, user: user) } + let(:favorite) { create(:favorite, article: record, user:) } let(:current_user) { favorite.user } end diff --git a/api/spec/policies/comment_policy_spec.rb b/api/spec/policies/comment_policy_spec.rb index d920c524..e321a379 100644 --- a/api/spec/policies/comment_policy_spec.rb +++ b/api/spec/policies/comment_policy_spec.rb @@ -8,7 +8,7 @@ let(:author) { build_stubbed(:author) } let(:context) { { user: current_user } } let(:current_user) { nil } - let(:record) { build_stubbed :comment, author: author, article: article } + let(:record) { build_stubbed :comment, author:, article: } let(:user) { build_stubbed(:user) } describe_rule :create? do diff --git a/api/spec/support/graphql.rb b/api/spec/support/graphql.rb index 12116de5..34fb014d 100644 --- a/api/spec/support/graphql.rb +++ b/api/spec/support/graphql.rb @@ -4,16 +4,16 @@ let(:current_user) { nil } let(:operation_name) { nil } let(:variables) { nil } - let(:context) { { current_user: current_user } } + let(:context) { { current_user: } } let(:query) { nil } let(:mutation) { nil } let(:result) { {} } subject do ApiSchema.execute(query || mutation, - variables: variables, - context: context, - operation_name: operation_name).to_h.deep_symbolize_keys + variables:, + context:, + operation_name:).to_h.deep_symbolize_keys end end