From 90537ed47d09565224ea8db14cd6e31b2b93f46f Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Thu, 7 Dec 2023 14:52:58 +0000 Subject: [PATCH 1/4] fix: Define default Rake task The default Rake task is now set to run RSpec and Standard. --- .rubocop.yml | 10 +++++++ .standard.yml | 5 ++++ .standard_todo.yml | 6 +++++ Gemfile | 2 ++ Rakefile | 7 +++++ bin/rake | 27 +++++++++++++++++++ bin/rubocop | 27 +++++++++++++++++++ cognito_idp_rails.gemspec | 1 + spec/cognito_idp_rails/configuration_spec.rb | 4 +-- .../cognito_idp_rails/sessions_spec.rb | 2 +- spec/routing/mapper_extensions_spec.rb | 8 +++--- 11 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .standard.yml create mode 100644 .standard_todo.yml create mode 100755 bin/rake create mode 100755 bin/rubocop diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..9255d48 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,10 @@ +--- +inherit_gem: + standard: config/base.yml + +AllCops: + NewCops: enable + +require: + - rubocop-rspec + - standard diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..9ad641e --- /dev/null +++ b/.standard.yml @@ -0,0 +1,5 @@ +# For available configuration options, see: +# https://github.com/testdouble/standard +ignore: + - "spec/dummy/**/*" +ruby_version: 2.6 diff --git a/.standard_todo.yml b/.standard_todo.yml new file mode 100644 index 0000000..2b99363 --- /dev/null +++ b/.standard_todo.yml @@ -0,0 +1,6 @@ +# Auto generated files with errors to ignore. +# Remove from this list as you refactor files. +--- +ignore: +- app/controllers/cognito_idp_rails/sessions_controller.rb: + - Lint/NonLocalExitFromIterator diff --git a/Gemfile b/Gemfile index 72f5e35..ad6b028 100644 --- a/Gemfile +++ b/Gemfile @@ -16,3 +16,5 @@ gem "sprockets-rails" gem "rspec-rails", "~> 6.1" gem "standard", "~> 1.32" + +gem "rubocop-rspec", "~> 2.25" diff --git a/Rakefile b/Rakefile index 416b023..29d08f7 100644 --- a/Rakefile +++ b/Rakefile @@ -6,3 +6,10 @@ load "rails/tasks/engine.rake" load "rails/tasks/statistics.rake" require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "standard/rake" + +task default: %i[spec standard] diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4eb7d7b --- /dev/null +++ b/bin/rake @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..369a05b --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/cognito_idp_rails.gemspec b/cognito_idp_rails.gemspec index df9d944..77d7271 100644 --- a/cognito_idp_rails.gemspec +++ b/cognito_idp_rails.gemspec @@ -9,6 +9,7 @@ Gem::Specification.new do |spec| spec.summary = "Simple Rails integration for Amazon Cognito IdP (User Pools)" spec.description = "Simple Rails integration for authentication through Amazon Cognito IdP (User Pools)" spec.license = "MIT" + spec.required_ruby_version = ">= 2.6.0" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage diff --git a/spec/cognito_idp_rails/configuration_spec.rb b/spec/cognito_idp_rails/configuration_spec.rb index 66f3652..375321d 100644 --- a/spec/cognito_idp_rails/configuration_spec.rb +++ b/spec/cognito_idp_rails/configuration_spec.rb @@ -7,7 +7,7 @@ subject(:after_login_route) { configuration.after_login_route } it "defaults to /" do - is_expected.to eq("/") + expect(subject).to eq("/") end context "when specified" do @@ -25,7 +25,7 @@ subject(:after_logout_route) { configuration.after_logout_route } it "defaults to /" do - is_expected.to eq("/") + expect(subject).to eq("/") end context "when specified" do diff --git a/spec/requests/cognito_idp_rails/sessions_spec.rb b/spec/requests/cognito_idp_rails/sessions_spec.rb index 464f6dc..d138ccf 100644 --- a/spec/requests/cognito_idp_rails/sessions_spec.rb +++ b/spec/requests/cognito_idp_rails/sessions_spec.rb @@ -122,7 +122,7 @@ get path expect(client).to have_received(:get_token) - .with(grant_type: :authorization_code, code: code, redirect_uri:) + .with(grant_type: :authorization_code, code: code, redirect_uri: redirect_uri) end context "when a token is received" do diff --git a/spec/routing/mapper_extensions_spec.rb b/spec/routing/mapper_extensions_spec.rb index e054050..83e6aca 100644 --- a/spec/routing/mapper_extensions_spec.rb +++ b/spec/routing/mapper_extensions_spec.rb @@ -1,10 +1,6 @@ require "rails_helper" RSpec.describe CognitoIdpRails::Routing::MapperExtensions, type: :routing do - it "defines cognito_idp method" do - expect(ActionDispatch::Routing::Mapper.new(ActionDispatch::Routing::RouteSet.new)).to respond_to(:cognito_idp) - end - before do Rails.application.routes.draw do cognito_idp @@ -12,6 +8,10 @@ Rails.application.reload_routes! end + it "defines cognito_idp method" do + expect(ActionDispatch::Routing::Mapper.new(ActionDispatch::Routing::RouteSet.new)).to respond_to(:cognito_idp) + end + it "adds login route" do expect(Rails.application.routes.recognize_path("/login")).to match(controller: "cognito_idp_rails/sessions", action: "login") end From d0ac8106508f9f1eeb102f396bc9610b147110b7 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Thu, 7 Dec 2023 12:04:05 +0000 Subject: [PATCH 2/4] doc: Correct installation documentation --- README.md | 2 +- .../templates/cognito_idp_rails_initializer.rb.tt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c561946..3604550 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ If bundler is not being used to manage dependencies, install the gem by executin After adding the gem to your application, run the install generator: - $ rails generate cognito_idp:install + $ rails generate cognito_idp_rails:install This generator will add `cognito_idp` to your routes and install an initializer at `config/initializers/cognito_idp.rb`. diff --git a/lib/generators/cognito_idp_rails/templates/cognito_idp_rails_initializer.rb.tt b/lib/generators/cognito_idp_rails/templates/cognito_idp_rails_initializer.rb.tt index dd44909..4b5bf70 100644 --- a/lib/generators/cognito_idp_rails/templates/cognito_idp_rails_initializer.rb.tt +++ b/lib/generators/cognito_idp_rails/templates/cognito_idp_rails_initializer.rb.tt @@ -4,7 +4,7 @@ CognitoIdpRails.configure do |config| config.domain = ENV["COGNITO_DOMAIN"] config.on_valid_login = lambda do |token, user_info, session| # 1. Find or create a user. - # user = User.where(identifier: user_info.sub).find_or_create do |user| + # user = User.where(identifier: user_info.sub).first_or_create do |user| # user.email = user_info.email # end From 770ce3cd219b1ca9db2c976674fb1f0fa02741f0 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Thu, 7 Dec 2023 15:41:57 +0000 Subject: [PATCH 3/4] chore: Update CHANGELOG --- CHANGELOG.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4fe518..77be31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ -## [Unreleased] +# Changelog -## [0.1.0] - 2023-11-29 +## [0.1.1](https://github.com/appercept/cognito_idp_rails/tree/0.1.1) (2023-12-07) -- Initial release +[Full Changelog](https://github.com/appercept/cognito_idp_rails/compare/v0.1.0...0.1.1) + +**Merged pull requests:** + +- fix: Define default Rake task [\#2](https://github.com/appercept/cognito_idp_rails/pull/2) ([rhatherall](https://github.com/rhatherall)) +- doc: Correct installation documentation [\#1](https://github.com/appercept/cognito_idp_rails/pull/1) ([rhatherall](https://github.com/rhatherall)) + +## [v0.1.0](https://github.com/appercept/cognito_idp_rails/tree/v0.1.0) (2023-12-07) + +[Full Changelog](https://github.com/appercept/cognito_idp_rails/compare/ee7a120d2cdd7c95858f72dfc3beb1ff5cd10449...v0.1.0) + + + +\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* From 7a04ba71d9fe1a0048eb0371101b5348da566a78 Mon Sep 17 00:00:00 2001 From: Richard Hatherall Date: Thu, 7 Dec 2023 15:43:17 +0000 Subject: [PATCH 4/4] chore: Bump version to 0.1.1 --- lib/cognito_idp_rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cognito_idp_rails/version.rb b/lib/cognito_idp_rails/version.rb index 787c9f6..113d398 100644 --- a/lib/cognito_idp_rails/version.rb +++ b/lib/cognito_idp_rails/version.rb @@ -1,3 +1,3 @@ module CognitoIdpRails - VERSION = "0.1.0" + VERSION = "0.1.1" end