Skip to content

Commit

Permalink
設定値を読み込む機能の実装
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibakeny committed May 10, 2021
1 parent 3cd9642 commit 46a53af
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 20 deletions.
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ source "https://rubygems.org"
gemspec

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "rspec", "~> 3.0"

group :test do
gem "rails", "~> 6.1.0"
gem "generator_spec"
end
128 changes: 128 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,119 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (>= 2.7.1)
actionmailer (6.1.3.2)
actionpack (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activesupport (= 6.1.3.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.3.2)
actionview (= 6.1.3.2)
activesupport (= 6.1.3.2)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.3.2)
actionpack (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
nokogiri (>= 1.8.5)
actionview (6.1.3.2)
activesupport (= 6.1.3.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.3.2)
activesupport (= 6.1.3.2)
globalid (>= 0.3.6)
activemodel (6.1.3.2)
activesupport (= 6.1.3.2)
activerecord (6.1.3.2)
activemodel (= 6.1.3.2)
activesupport (= 6.1.3.2)
activestorage (6.1.3.2)
actionpack (= 6.1.3.2)
activejob (= 6.1.3.2)
activerecord (= 6.1.3.2)
activesupport (= 6.1.3.2)
marcel (~> 1.0.0)
mini_mime (~> 1.0.2)
activesupport (6.1.3.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
builder (3.2.4)
concurrent-ruby (1.1.8)
crass (1.0.6)
diff-lcs (1.4.4)
erubi (1.10.0)
generator_spec (0.9.4)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
loofah (2.9.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.0.3)
minitest (5.14.4)
nio4r (2.5.7)
nokogiri (1.11.3-x86_64-darwin)
racc (~> 1.4)
racc (1.5.2)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.3.2)
actioncable (= 6.1.3.2)
actionmailbox (= 6.1.3.2)
actionmailer (= 6.1.3.2)
actionpack (= 6.1.3.2)
actiontext (= 6.1.3.2)
actionview (= 6.1.3.2)
activejob (= 6.1.3.2)
activemodel (= 6.1.3.2)
activerecord (= 6.1.3.2)
activestorage (= 6.1.3.2)
activesupport (= 6.1.3.2)
bundler (>= 1.15.0)
railties (= 6.1.3.2)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.1.3.2)
actionpack (= 6.1.3.2)
activesupport (= 6.1.3.2)
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rake (12.3.3)
rspec (3.10.0)
rspec-core (~> 3.10.0)
Expand All @@ -21,11 +133,27 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (1.1.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.4.2)

PLATFORMS
ruby

DEPENDENCIES
generator_spec
rails (~> 6.1.0)
rake (~> 12.0)
rspec (~> 3.0)
sp-rails-saml!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SpRailsSaml

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sp_rails_saml`. To experiment with that code, run `bin/console` for an interactive prompt.
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sp-rails-saml`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "sp_rails_saml"
require "sp-rails-saml"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
26 changes: 26 additions & 0 deletions lib/generators/sp-rails-saml/config_generator.rb
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
7 changes: 7 additions & 0 deletions lib/sp-rails-saml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "active_support"
require 'sp-rails-saml/settings'
require 'generators/sp-rails-saml/config_generator'

module SpRailsSaml
class Error < StandardError; end
end
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions lib/sp_rails_saml.rb

This file was deleted.

3 changes: 2 additions & 1 deletion sp-rails-saml.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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"
Expand Down
24 changes: 24 additions & 0 deletions spec/generators/sp_rails_saml/settings_generator_spec.rb
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
9 changes: 0 additions & 9 deletions spec/sp_rails_saml/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,22 @@
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
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "bundler/setup"
require "sp_rails_saml"
require "sp-rails-saml"
require "generator_spec"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down

0 comments on commit 46a53af

Please sign in to comment.