Skip to content
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

feat: 🎸 Star のインポータを作成した #74

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: インポータを実行する
run: |
bundle exec rails db:construction:execute
bundle exec rails runner "ImportService::Character.new.execute"
bundle exec rails db:importer:execute
- name: RSpec を実行する
run: |
bundle exec rspec
13 changes: 13 additions & 0 deletions app/service/import_service/star.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ImportService
class Star < Base
def rows
on_sheet_stars = ::OnSheet::Star.all

seating_orders = on_sheet_stars.map(&:seating_order)
names = on_sheet_stars.map(&:name)
name_ens = on_sheet_stars.map(&:name_en)

seating_orders.zip(names, name_ens)
end
end
end
4 changes: 2 additions & 2 deletions lib/tasks/db/construction.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace :db do

ActiveRecord::Base.transaction do
class_name_to_csv_filepath_map.each do |class_name_string, csv_filepath|
show_message_and_execute(class_name_string, csv_filepath)
show_message_and_execute_on_construction(class_name_string, csv_filepath)
end
end

Expand All @@ -31,7 +31,7 @@ namespace :db do
end
end

def show_message_and_execute(class_name_string, csv_filepath)
def show_message_and_execute_on_construction(class_name_string, csv_filepath)
puts "[#{Time.zone.now}] #{class_name_string} の実行を開始します。"

klass = class_name_string.constantize
Expand Down
19 changes: 19 additions & 0 deletions lib/tasks/db/importer.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace :db do
namespace :importer do
desc 'インポータ(データソースのインポートはスコープ外)'
task execute: :environment do
ActiveRecord::Base.transaction do
show_message_and_execute_on_importer('Character')
show_message_and_execute_on_importer('Star')
end
end
end
end

def show_message_and_execute_on_importer(class_name_string)
puts "[#{Time.zone.now}] #{class_name_string} の実行を開始します。"

`bundle exec rails runner "ImportService::#{class_name_string}.new.execute"`

puts "[#{Time.zone.now}] #{class_name_string} の実行が終了しました。"
end
8 changes: 7 additions & 1 deletion spec/models/star_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require 'rails_helper'

RSpec.describe Star, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
describe 'Star クラス' do
it 'レコードの数が 108 であること' do
stars = Star.all

expect(stars.count).to eq 108
end
end
end