Skip to content

Commit

Permalink
Add generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Aug 29, 2024
1 parent 5ccff1d commit 3d74d83
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "rails/generators"
require "rails/generators/active_record"

module Doorkeeper
# Generates migration with polymorphic resource owner required
# database columns for Doorkeeper Access Token and Access Grant
# models.
#
class RemoveApplicationSecretNotNullConstraint < ::Rails::Generators::Base
include ::Rails::Generators::Migration
source_root File.expand_path("templates", __dir__)
desc "Removes NOT NULL constraint for OAuth2 applications."

def enable_polymorphic_resource_owner
migration_template(
"remove_applications_secret_not_null_constraint.rb.erb",
"db/migrate/remove_applications_secret_not_null_constraint.rb",
migration_version: migration_version,
)
end

def self.next_migration_number(dirname)
ActiveRecord::Generators::Base.next_migration_number(dirname)
end

private

def migration_version
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RemoveApplicationsSecretNotNullConstraint < ActiveRecord::Migration<%= migration_version %>
def change
change_column_null :oauth_applications, :secret, true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require "spec_helper"
require "generators/doorkeeper/remove_applications_secret_not_null_constraint_generator"

RSpec.describe Doorkeeper::RemoveApplicationSecretNotNullConstraint do
include GeneratorSpec::TestCase

tests described_class
destination ::File.expand_path('tmp/dummy', __dir__)

describe "after running the generator" do
before do
prepare_destination
end

it "creates a migration with a version specifier" do
run_generator

assert_migration "db/migrate/remove_applications_secret_not_null_constraint.rb" do |migration|
assert migration.include?("change_column_null :oauth_applications, :secret")
end
end
end
end

0 comments on commit 3d74d83

Please sign in to comment.