-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
lib/generators/doorkeeper/remove_applications_secret_not_null_constraint_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
lib/generators/doorkeeper/templates/remove_applications_secret_not_null_constraint.rb.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
25 changes: 25 additions & 0 deletions
25
spec/generators/remove_applications_secret_not_null_constraint_generator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |