-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model for many-to-many with department and oauth_application.
- Loading branch information
Showing
7 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
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
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,4 @@ | ||
class DepartmentAllowedApplication < ApplicationRecord | ||
belongs_to :department | ||
belongs_to :oauth_application, class_name: 'Doorkeeper::Application' | ||
end |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class DoorkeeperApplication < Doorkeeper::Application | ||
has_many :user_allowed_applications, foreign_key: :oauth_application_id | ||
has_many :department_allowed_applications, foreign_key: :oauth_application_id | ||
end |
10 changes: 10 additions & 0 deletions
10
db/migrate/20240105091805_create_department_allowed_applications.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,10 @@ | ||
class CreateDepartmentAllowedApplications < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :department_allowed_applications do |t| | ||
t.references :department, null: false, foreign_key: true | ||
t.references :oauth_application, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
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
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,8 @@ | ||
--- | ||
thape_it_department_use_oauth_app_test: | ||
department_id: 2 # thape_it_department | ||
oauth_application_id: 1 # oauth_app_test | ||
|
||
thape_operation_group_use_oauth_app_test: | ||
department_id: 7 # thape_operation_group | ||
oauth_application_id: 1 # oauth_app_test |
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,15 @@ | ||
require 'test_helper' | ||
|
||
class DepartmentAllowedApplicationTest < ActiveSupport::TestCase | ||
test 'Thape IT department department_allowed_applications valid' do | ||
it_department = departments(:thape_it_department) | ||
assert it_department.department_allowed_applications.all(&:valid?) | ||
assert_equal it_department.department_allowed_applications.count, 1 | ||
end | ||
|
||
test 'Thape operation_group department_allowed_applications valid' do | ||
oauth_app_test = oauth_applications(:oauth_app_test) | ||
assert oauth_app_test.department_allowed_applications.all(&:valid?) | ||
assert_equal oauth_app_test.department_allowed_applications.count, 2 | ||
end | ||
end |