Skip to content

Commit

Permalink
分報チャンネルが分報カテゴリー内に作成されるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmtd0x0b committed Jun 11, 2023
1 parent 8808d01 commit 9623033
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
5 changes: 1 addition & 4 deletions app/models/discord/times_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

module Discord
class TimesChannel
include ActiveSupport::Configurable
config_accessor :category_id, instance_accessor: false

class << self
def to_channel_name(username)
username.downcase
Expand All @@ -18,7 +15,7 @@ def initialize(username)
def save
@channel = Discord::Server.create_text_channel(
name: @name,
parent: Discord::TimesChannel.category_id
parent: Discord::TimesCategory.categorize_by_initials(@name)
)

!!@channel
Expand Down
35 changes: 15 additions & 20 deletions test/models/discord/times_channel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
module Discord
class TimesChannelTest < ActiveSupport::TestCase
setup do
@category_id = Discord::TimesChannel.category_id
Discord::TimesChannel.category_id = nil

@stub_create_text_channel = lambda { |name:, parent:|
Discordrb::Channel.new({
id: '1234567890',
Expand All @@ -17,27 +14,25 @@ class TimesChannelTest < ActiveSupport::TestCase
}
end

teardown do
Discord::TimesChannel.category_id = @category_id
end

test '#save return true' do
Discord::TimesChannel.category_id = '9876543210'
Discord::Server.stub(:create_text_channel, @stub_create_text_channel) do
times_channel = Discord::TimesChannel.new('piyo')

assert_equal true, times_channel.save
assert_equal '1234567890', times_channel.id
assert_equal '9876543210', times_channel.category_id
Discord::TimesCategory.stub(:categorize_by_initials, ->(_) { '9876543210' }) do
Discord::Server.stub(:create_text_channel, @stub_create_text_channel) do
times_channel = Discord::TimesChannel.new('piyo')

assert_equal true, times_channel.save
assert_equal '1234567890', times_channel.id
assert_equal '9876543210', times_channel.category_id
end
end

Discord::TimesChannel.category_id = nil
Discord::Server.stub(:create_text_channel, @stub_create_text_channel) do
times_channel = Discord::TimesChannel.new('piyo')
Discord::TimesCategory.stub(:categorize_by_initials, ->(_) { nil }) do
Discord::Server.stub(:create_text_channel, @stub_create_text_channel) do
times_channel = Discord::TimesChannel.new('piyo')

assert_equal true, times_channel.save
assert_equal '1234567890', times_channel.id
assert_nil times_channel.category_id
assert_equal true, times_channel.save
assert_equal '1234567890', times_channel.id
assert_nil times_channel.category_id
end
end
end

Expand Down

0 comments on commit 9623033

Please sign in to comment.