-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
設定ファイルから設定値を読み込む機能の実装 #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails/generators' | ||
|
||
module SpRailsSaml | ||
class ConfigGenerator < Rails::Generators::Base | ||
|
||
desc "config/initializersにイニシャライザファイルを作成します" | ||
|
||
def create_initializer_file | ||
create_file "config/initializers/sp-rails-saml.rb", default_initializer | ||
end | ||
|
||
private | ||
|
||
def default_initializer | ||
<<-EOS | ||
SpRailsSaml::Settings.setup do |config| | ||
config.sp_entity_id = '' | ||
config.name_identifier_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' | ||
config.authn_context = 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509' | ||
config.authn_context_comparison = 'exact' | ||
config.assertion_consumer_service_url = '' | ||
end | ||
EOS | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'sp-rails-saml/settings' | ||
require 'generators/sp-rails-saml/config_generator' | ||
|
||
module SpRailsSaml | ||
class Error < StandardError; end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ライブラリ内で発生するエラークラスは e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ありがとうございます! |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module SpRailsSaml | ||
class Settings | ||
class << self | ||
attr_accessor :sp_entity_id | ||
attr_accessor :name_identifier_format | ||
attr_accessor :authn_context | ||
attr_accessor :authn_context_comparison | ||
attr_accessor :assertion_consumer_service_url | ||
|
||
def setup(options = {}) | ||
options.each do |key, value| | ||
instance_variable_set("@#{key}", value) | ||
end | ||
yield(self) if block_given? | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module SpRailsSaml | ||
VERSION = "0.1.0" | ||
end |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
require_relative 'lib/sp/rails/saml/version' | ||
$LOAD_PATH.push File.expand_path('../lib', __FILE__) | ||
require 'sp-rails-saml/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "sp-rails-saml" | ||
spec.version = Sp::Rails::Saml::VERSION | ||
spec.version = SpRailsSaml::VERSION | ||
spec.authors = ["psyashes"] | ||
spec.email = ["[email protected]"] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
RSpec.describe SpRailsSaml::ConfigGenerator, type: :generator do | ||
destination File.expand_path("../../../../tmp", __FILE__) | ||
|
||
before(:all) do | ||
prepare_destination | ||
run_generator | ||
end | ||
|
||
let(:initializer_text) do | ||
<<-EOS | ||
SpRailsSaml::Settings.setup do |config| | ||
config.sp_entity_id = '' | ||
config.name_identifier_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' | ||
config.authn_context = 'urn:oasis:names:tc:SAML:2.0:ac:classes:X509' | ||
config.authn_context_comparison = 'exact' | ||
config.assertion_consumer_service_url = '' | ||
end | ||
EOS | ||
end | ||
|
||
it "should create saml_settings initializer file" do | ||
assert_file "config/initializers/sp-rails-saml.rb", initializer_text | ||
end | ||
end |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RSpec.describe SpRailsSaml do | ||
it "has a version number" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. テストコードはどの粒度 (カバレッジやテスト観点など) で作成するか方針は決まってますか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 別タスクで方針を決めたいと思います! |
||
expect(SpRailsSaml::VERSION).not_to be nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
RSpec.describe SpRailsSaml::Settings do | ||
describe '#setup' do | ||
let(:sp_entity_id) { 'sp_entity_id' } | ||
let(:name_identifier_format) { 'name_identifier_format' } | ||
let(:authn_context) { 'authn_context' } | ||
let(:authn_context_comparison) { 'authn_context_comparison' } | ||
let(:assertion_consumer_service_url) { 'assertion_consumer_service_url' } | ||
|
||
it 'should set settings value' do | ||
SpRailsSaml::Settings.setup do |config| | ||
config.sp_entity_id = sp_entity_id | ||
config.name_identifier_format = name_identifier_format | ||
config.authn_context = authn_context | ||
config.authn_context_comparison = authn_context_comparison | ||
config.assertion_consumer_service_url = assertion_consumer_service_url | ||
end | ||
|
||
expect(SpRailsSaml::Settings.sp_entity_id).to eq sp_entity_id | ||
expect(SpRailsSaml::Settings.name_identifier_format).to eq name_identifier_format | ||
expect(SpRailsSaml::Settings.authn_context).to eq authn_context | ||
expect(SpRailsSaml::Settings.authn_context_comparison).to eq authn_context_comparison | ||
expect(SpRailsSaml::Settings.assertion_consumer_service_url).to eq assertion_consumer_service_url | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字列を括る際にシングルクォート、ダブルクォートが混ざってますが、この辺りはrubocopなどで統一 (一括で統一) できます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとうございます!
別途rubocopでコードを綺麗にする対応を行いたいと思います!