souls 0.10.9 → 0.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb50933cf5e29db7883851f08b8e88ed44e9b0de3a30d3a8faf56db911f79437
4
- data.tar.gz: a757f56a92f4740bd55825f36fc99fcd6ff868d1bc3f70b951cca84be6ea55a9
3
+ metadata.gz: 41f25d625a2113234605b9dae1fd2cbe7e5ae6116c99b675801d7e5b857e39f3
4
+ data.tar.gz: 4f07c3fae2465999b0c0adcb859680e9e45eb4bbfb49d33cf6f07443fb62d11e
5
5
  SHA512:
6
- metadata.gz: 877562b163d9b8c360942990c37a0ff717b5545b2c3cc7381ac829ece20145daf65ab9c33ac420c5f6b4059ca81f36091b1286be0bf673370ac08d4a70c453b7
7
- data.tar.gz: e5c67fd6a73ce4b8a14ea1b8595ea9796913861b799a3ddceaf3f31b8ae78172e62909c92f7cd73d1fde2d4264cb2ce99a450210b6e7ea9500968331f71a6c28
6
+ metadata.gz: 4fab56a0dfb7c3f20f20651f5c87c53b92128ce56e30125c9bb56b0e1648bf867e88b4f92bd87fdfc30b9fcc7cb1beb4faed21e61df855a83adacf8a57ff1700
7
+ data.tar.gz: 603a9c0c54f42750aae84e7d649e5d334c01bbc30157d61ac1d302f017cd7862834ffffa75d4d025b52d19cbae7ac43a8cef7f4ff7ebafcbcf1f5a2bed5c95ec
@@ -133,7 +133,7 @@ Metrics/AbcSize:
133
133
  Enabled: false
134
134
 
135
135
  Metrics/CyclomaticComplexity:
136
- Max: 30
136
+ Max: 40
137
137
 
138
138
  Metrics/PerceivedComplexity:
139
139
  Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- souls (0.10.8)
4
+ souls (0.11.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/souls CHANGED
@@ -46,7 +46,7 @@ begin
46
46
  when "g", "generate"
47
47
  case ARGV[1]
48
48
  when "test"
49
- Souls::Init.rspec_mutation class_name: "user"
49
+ Souls::Init.rspec_query class_name: "user"
50
50
  when "model"
51
51
  Souls::Init.model class_name: ARGV[2]
52
52
  when "mutation"
@@ -460,7 +460,7 @@ module Souls
460
460
  ]
461
461
  end
462
462
 
463
- def create_query class_name: "souls"
463
+ def create_queries class_name: "souls"
464
464
  file_path = "./app/graphql/queries/#{class_name.pluralize}.rb"
465
465
  File.open(file_path, "w") do |f|
466
466
  f.write <<~EOS
@@ -480,17 +480,18 @@ module Souls
480
480
  file_path
481
481
  end
482
482
 
483
- def create_queries class_name: "souls"
483
+ def create_query class_name: "souls"
484
484
  file_path = "./app/graphql/queries/#{class_name}.rb"
485
485
  File.open(file_path, "w") do |f|
486
486
  f.write <<~EOS
487
487
  module Queries
488
488
  class #{class_name.camelize} < Queries::BaseQuery
489
489
  type Types::#{class_name.camelize}Type, null: false
490
- argument :id, Integer, required: true
490
+ argument :id, String, required: true
491
491
 
492
- def resolve id:
493
- ::#{class_name.camelize}.find(id)
492
+ def resolve **args
493
+ _, #{class_name.singularize.underscore}_id = SoulsApiSchema.from_global_id args[:id]
494
+ ::#{class_name.camelize}.find(#{class_name.singularize.underscore}_id)
494
495
  rescue StandardError => error
495
496
  GraphQL::ExecutionError.new error
496
497
  end
@@ -624,12 +625,12 @@ module Souls
624
625
  end
625
626
 
626
627
  def rspec_mutation_head class_name: "souls"
627
- file_path = "./spec/mutations/#{class_name.pluralize}.rb"
628
+ file_path = "./spec/mutations/#{class_name.singularize}_spec.rb"
628
629
  File.open(file_path, "w") do |f|
629
630
  f.write <<~EOS
630
- RSpec.describe #{class_name.camelize} Mutation do
631
- describe "#{class_name.camelize} を作成する" do
632
- let!(:#{class_name.singularize.downcase}) { FactoryBot.create(:#{class_name.singularize.downcase}) }
631
+ RSpec.describe \"#{class_name.camelize} Mutation テスト\" do
632
+ describe "#{class_name.camelize} データを登録する" do
633
+ let!(:#{class_name.singularize.underscore}) { FactoryBot.create(:#{class_name.singularize.underscore}) }
633
634
 
634
635
  let(:mutation) do
635
636
  %(mutation {
@@ -647,12 +648,10 @@ module Souls
647
648
  f.each_line.with_index do |line, i|
648
649
  if @on
649
650
  if line.include?("end") || line.include?("t.index")
650
- new_line.write " }) {\n user {\n id\n"
651
+ new_line.write " }) {\n #{class_name.singularize.camelize} {\n id\n"
651
652
  break
652
653
  end
653
- field = '["tag1", "tag2", "tag3"]' if line.include?("array: true")
654
654
  type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
655
- field ||= get_test_type type
656
655
  case name
657
656
  when "created_at", "updated_at"
658
657
  next
@@ -761,6 +760,7 @@ end
761
760
  end
762
761
  end
763
762
  end
763
+ [file_path]
764
764
  end
765
765
 
766
766
  def rspec_mutation class_name: "souls"
@@ -771,8 +771,115 @@ end
771
771
  rspec_mutation_end class_name: singularized_class_name
772
772
  end
773
773
 
774
+ def rspec_query_head class_name: "souls"
775
+ file_path = "./spec/queries/#{class_name.singularize}_spec.rb"
776
+ File.open(file_path, "w") do |f|
777
+ f.write <<~EOS
778
+ RSpec.describe \"#{class_name.camelize} Query テスト\" do
779
+ describe "#{class_name.camelize} データを取得する" do
780
+ let!(:#{class_name.singularize.underscore}) { FactoryBot.create(:#{class_name.singularize.underscore}) }
781
+
782
+ let(:query) do
783
+ %(query {
784
+ #{class_name.singularize.underscore}(id: \#{Base64.encode64("#{class_name.camelize}:\#{#{class_name.underscore}.id}")}) {
785
+ id
786
+ EOS
787
+ end
788
+ end
789
+
790
+ def rspec_query_params class_name: "souls"
791
+ file_path = "./spec/queries/#{class_name.pluralize}.rb"
792
+ path = "./db/schema.rb"
793
+ @on = false
794
+ File.open(file_path, "a") do |new_line|
795
+ File.open(path, "r") do |f|
796
+ f.each_line.with_index do |line, i|
797
+ if @on
798
+ if line.include?("end") || line.include?("t.index")
799
+ new_line.write <<-EOS
800
+ }
801
+ }
802
+ )
803
+ end
804
+
805
+ subject(:result) do
806
+ SoulsApiSchema.execute(query).as_json
807
+ end
808
+
809
+ it "return #{class_name.camelize} Data" do
810
+ a1 = result.dig("data", "#{class_name.singularize.underscore}")
811
+ expect(a1).to include(
812
+ "id" => be_a(String),
813
+ EOS
814
+ break
815
+ end
816
+ _, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
817
+ case name
818
+ when "created_at", "updated_at"
819
+ next
820
+ else
821
+ new_line.write " #{name.singularize.camelize(:lower)}\n"
822
+ end
823
+ end
824
+ if table_check(line: line, class_name: class_name)
825
+ @on = true
826
+ end
827
+ end
828
+ end
829
+ end
830
+ end
831
+
832
+ def rspec_query_end class_name: "souls"
833
+ file_path = "./spec/queries/#{class_name.pluralize}.rb"
834
+ path = "./db/schema.rb"
835
+ @on = false
836
+ File.open(file_path, "a") do |new_line|
837
+ File.open(path, "r") do |f|
838
+ f.each_line.with_index do |line, i|
839
+ if @on
840
+ if line.include?("end") || line.include?("t.index")
841
+ new_line.write <<-EOS
842
+ )
843
+ end
844
+ end
845
+ end
846
+ EOS
847
+ break
848
+ end
849
+ type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
850
+ field ||= type_check type
851
+ array_true = line.include?("array: true")
852
+ case name
853
+ when "created_at", "updated_at"
854
+ next
855
+ else
856
+ case type
857
+ when "text"
858
+ if array_true
859
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_all(String),\n"
860
+ end
861
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
862
+ when "string", "bigint", "integer", "float", "boolean"
863
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(#{field}),\n"
864
+ when "date", "datetime"
865
+ new_line.write " \"#{name.singularize.camelize(:lower)}\" => be_a(DateTime),\n"
866
+ end
867
+ end
868
+ end
869
+ if table_check(line: line, class_name: class_name)
870
+ @on = true
871
+ end
872
+ end
873
+ end
874
+ end
875
+ [file_path]
876
+ end
877
+
774
878
  def rspec_query class_name: "souls"
775
- # if needed
879
+ singularized_class_name = class_name.singularize
880
+ rspec_query_head class_name: singularized_class_name
881
+ rspec_query_params class_name: singularized_class_name
882
+ rspec_query_end class_name: singularized_class_name
776
883
  end
777
884
 
778
885
  def get_end_point
@@ -809,6 +916,8 @@ end
809
916
  type_paths = type class_name: singularized_class_name
810
917
  rspec_factory_paths = rspec_factory class_name: singularized_class_name
811
918
  rspec_model_paths = rspec_model class_name: singularized_class_name
919
+ rspec_mutation_paths = rspec_mutation class_name: singularized_class_name
920
+ rspec_query_paths = rspec_query class_name: singularized_class_name
812
921
  query_path = query class_name: singularized_class_name
813
922
  mutation_path = mutation class_name: singularized_class_name
814
923
  [
@@ -816,6 +925,8 @@ end
816
925
  type: type_paths,
817
926
  rspec_factory: rspec_factory_paths,
818
927
  rspec_model: rspec_model_paths,
928
+ rspec_mutation: rspec_mutation_paths,
929
+ rspec_query: rspec_query_paths,
819
930
  query: query_path,
820
931
  mutation: mutation_path,
821
932
  add_query_type: [
@@ -832,7 +943,6 @@ end
832
943
 
833
944
  def migrate_all
834
945
  puts "◆◆◆ Let's Auto Generate CRUD API ◆◆◆\n"
835
- `rake db:migrate`
836
946
  paths = get_tables.map do |class_name|
837
947
  migrate class_name: class_name.singularize
838
948
  end
@@ -860,6 +970,18 @@ end
860
970
  path[:rspec_model].each { |line| puts line }
861
971
  end
862
972
  end
973
+ puts "\n============== RspecMutation =================\n\n"
974
+ paths.each do |class_name|
975
+ class_name.each do |path|
976
+ path[:rspec_mutation].each { |line| puts line }
977
+ end
978
+ end
979
+ puts "\n============== RspecQuery =================\n\n"
980
+ paths.each do |class_name|
981
+ class_name.each do |path|
982
+ path[:rspec_query].each { |line| puts line }
983
+ end
984
+ end
863
985
  puts "\n============== Query ======================\n\n"
864
986
  paths.each do |class_name|
865
987
  class_name.each do |path|
@@ -1,3 +1,3 @@
1
1
  module Souls
2
- VERSION = "0.10.9"
2
+ VERSION = "0.11.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.9
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI