Skip to content

Commit

Permalink
Settingsクラスの作成
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibakeny committed May 7, 2021
1 parent caea0de commit 3cd9642
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "https://rubygems.org"
gemspec

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "rspec", "~> 3.0"
1 change: 1 addition & 0 deletions lib/sp_rails_saml.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "sp_rails_saml/version"
require 'sp_rails_saml/settings'

module SpRailsSaml
class Error < StandardError; end
Expand Down
21 changes: 21 additions & 0 deletions lib/sp_rails_saml/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 :idp_sso_service_url
attr_accessor :assertion_consumer_service_url
attr_accessor :idp_cert
attr_accessor :idp_entity_id

def setup(options = {})
options.each do |key, value|
instance_variable_set("@#{key}", value)
end
yield(self) if block_given?
end
end
end
end
37 changes: 0 additions & 37 deletions spec/setting_spec.rb

This file was deleted.

34 changes: 34 additions & 0 deletions spec/sp_rails_saml/settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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(:idp_sso_service_url) { 'idp_sso_service_url' }
let(:assertion_consumer_service_url) { 'assertion_consumer_service_url' }
let(:idp_cert) { 'idp_cert' }
let(:idp_entity_id) { 'idp_entity_id' }

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.idp_sso_service_url = idp_sso_service_url
config.assertion_consumer_service_url = assertion_consumer_service_url
config.idp_cert = idp_cert
config.idp_entity_id = idp_entity_id
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.idp_sso_service_url).to eq idp_sso_service_url
expect(SpRailsSaml::Settings.assertion_consumer_service_url).to eq assertion_consumer_service_url
expect(SpRailsSaml::Settings.idp_cert).to eq idp_cert
expect(SpRailsSaml::Settings.idp_entity_id).to eq idp_entity_id
end
end
end

0 comments on commit 3cd9642

Please sign in to comment.