From 6922a09a222ef500f070a39acfcdd2222f77ea1b Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Wed, 29 May 2024 03:54:38 +0900 Subject: [PATCH 1/6] Fixed tests that were not updated to follow changes in the slack-ruby-client. --- lib/arisaid/userable.rb | 17 ++++++----- test/arisaid/bots_test.rb | 4 +-- test/arisaid/guests_test.rb | 4 +-- test/arisaid/usergroups_test.rb | 28 +++++++++++++------ test/arisaid/users_test.rb | 4 +-- ...00-0000000000-000000 => usergroups.create} | 1 + ...0000-0000000000-000000 => usergroups.list} | 0 test/fixtures/usergroups.users.update | 28 +++++++++++++++++++ ...000000000-0000000000-000000 => users.list} | 0 test/helper.rb | 6 ++-- 10 files changed, 68 insertions(+), 24 deletions(-) rename test/fixtures/{usergroups.create?description=Yo%20Members&handle=yo&name=yo&token=xoxo-0000000000-0000000000-0000000000-000000 => usergroups.create} (62%) rename test/fixtures/{usergroups.list?include_disabled=1&include_users=1&token=xoxo-0000000000-0000000000-0000000000-000000 => usergroups.list} (100%) create mode 100644 test/fixtures/usergroups.users.update rename test/fixtures/{users.list?token=xoxo-0000000000-0000000000-0000000000-000000 => users.list} (100%) diff --git a/lib/arisaid/userable.rb b/lib/arisaid/userable.rb index 3850f8d..86790d4 100644 --- a/lib/arisaid/userable.rb +++ b/lib/arisaid/userable.rb @@ -7,11 +7,6 @@ def users end def users! - all_users = [] - client.users_list(presence: true, max_retries: 20) do |response| - all_users.concat(response.members) - end - @users = all_users.select { |u| u.deleted == false && u.is_bot == false && u.is_restricted == false } @@ -22,7 +17,7 @@ def guests end def guests! - @guests = client.users.select { |u| + @guests = all_users.select { |u| u.deleted == false && u.is_bot == false && u.is_restricted == true } end @@ -32,9 +27,17 @@ def bots end def bots! - @bots = client.users.select { |u| + @bots = all_users.select { |u| u.deleted == false && u.is_bot == true && u.is_restricted == false } end + + def all_users + all_users = [] + client.users_list(presence: true, max_retries: 20) do |response| + all_users.concat(response.members) + end + all_users + end end end diff --git a/test/arisaid/bots_test.rb b/test/arisaid/bots_test.rb index 8bfaa6a..a2a8ee9 100644 --- a/test/arisaid/bots_test.rb +++ b/test/arisaid/bots_test.rb @@ -11,7 +11,7 @@ class Arisaid_BotsTest < Minitest::Test YML def test_show - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_output(@@yml) do Arisaid.bots.show @@ -19,7 +19,7 @@ def test_show end def test_save - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_silent do Arisaid.bots.save diff --git a/test/arisaid/guests_test.rb b/test/arisaid/guests_test.rb index 7ba3c6c..a20ec92 100644 --- a/test/arisaid/guests_test.rb +++ b/test/arisaid/guests_test.rb @@ -12,7 +12,7 @@ class Arisaid_GuestsTest < Minitest::Test YML def test_show - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_output(@@yml) do Arisaid.guests.show @@ -20,7 +20,7 @@ def test_show end def test_save - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_silent do Arisaid.guests.save diff --git a/test/arisaid/usergroups_test.rb b/test/arisaid/usergroups_test.rb index 2d6a6f5..fd56ef0 100644 --- a/test/arisaid/usergroups_test.rb +++ b/test/arisaid/usergroups_test.rb @@ -2,9 +2,10 @@ class Arisaid_UsergroupsTest < Minitest::Test def test_apply - stub_get "users.list?token=#{Arisaid.slack_token}" - stub_get "usergroups.list?include_disabled=1&include_users=1&token=#{Arisaid.slack_token}" - stub_get "usergroups.create?description=Yo%20Members&handle=yo&name=yo&token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token + stub_get "usergroups.list", Arisaid.slack_token + stub_get "usergroups.create", Arisaid.slack_token + stub_get "usergroups.users.update", Arisaid.slack_token File.write 'usergroups.yml', <<-YML.lstrip --- @@ -21,15 +22,26 @@ def test_apply - foobar2 YML - assert_silent do + output = <<-YML.lstrip +==== Fetch all setting and enable groups ==== + - tokyo + - yo +==== Update usergroups ==== + - tokyo + - yo +==== Disable usergroups ==== + - tokyo +YML + + assert_output(output) do Arisaid.usergroups.apply end File.delete 'usergroups.yml' end def test_show - stub_get "users.list?token=#{Arisaid.slack_token}" - stub_get "usergroups.list?include_disabled=1&include_users=1&token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token + stub_get "usergroups.list", Arisaid.slack_token output = <<-YML.lstrip --- @@ -47,8 +59,8 @@ def test_show end def test_save - stub_get "users.list?token=#{Arisaid.slack_token}" - stub_get "usergroups.list?include_disabled=1&include_users=1&token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token + stub_get "usergroups.list" ,Arisaid.slack_token conf = <<-YML.lstrip --- diff --git a/test/arisaid/users_test.rb b/test/arisaid/users_test.rb index 42fa49b..1ff881b 100644 --- a/test/arisaid/users_test.rb +++ b/test/arisaid/users_test.rb @@ -15,7 +15,7 @@ class Arisaid_UsersTest < Minitest::Test YML def test_show - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_output(@@yml) do Arisaid.users.show @@ -23,7 +23,7 @@ def test_show end def test_save - stub_get "users.list?token=#{Arisaid.slack_token}" + stub_get "users.list", Arisaid.slack_token assert_silent do Arisaid.users.save diff --git a/test/fixtures/usergroups.create?description=Yo%20Members&handle=yo&name=yo&token=xoxo-0000000000-0000000000-0000000000-000000 b/test/fixtures/usergroups.create similarity index 62% rename from test/fixtures/usergroups.create?description=Yo%20Members&handle=yo&name=yo&token=xoxo-0000000000-0000000000-0000000000-000000 rename to test/fixtures/usergroups.create index 633a965..d583cf6 100644 --- a/test/fixtures/usergroups.create?description=Yo%20Members&handle=yo&name=yo&token=xoxo-0000000000-0000000000-0000000000-000000 +++ b/test/fixtures/usergroups.create @@ -1,5 +1,6 @@ { "ok":true, "usergroup": { + "id": "S0615G0KT" } } diff --git a/test/fixtures/usergroups.list?include_disabled=1&include_users=1&token=xoxo-0000000000-0000000000-0000000000-000000 b/test/fixtures/usergroups.list similarity index 100% rename from test/fixtures/usergroups.list?include_disabled=1&include_users=1&token=xoxo-0000000000-0000000000-0000000000-000000 rename to test/fixtures/usergroups.list diff --git a/test/fixtures/usergroups.users.update b/test/fixtures/usergroups.users.update new file mode 100644 index 0000000..41d8f68 --- /dev/null +++ b/test/fixtures/usergroups.users.update @@ -0,0 +1,28 @@ +{ + "ok": true, + "usergroup": { + "id": "S0616NG6M", + "team_id": "T060R4BHN", + "is_usergroup": true, + "name": "Marketing Team", + "description": "Marketing gurus, PR experts and product advocates.", + "handle": "marketing-team", + "is_external": false, + "date_create": 1447096577, + "date_update": 1447102109, + "date_delete": 0, + "auto_type": null, + "created_by": "U060R4BJ4", + "updated_by": "U060R4BJ4", + "deleted_by": null, + "prefs": { + "channels": [], + "groups": [] + }, + "users": [ + "U060R4BJ4", + "U060RNRCZ" + ], + "user_count": 1 + } +} diff --git a/test/fixtures/users.list?token=xoxo-0000000000-0000000000-0000000000-000000 b/test/fixtures/users.list similarity index 100% rename from test/fixtures/users.list?token=xoxo-0000000000-0000000000-0000000000-000000 rename to test/fixtures/users.list diff --git a/test/helper.rb b/test/helper.rb index f4bf934..1aefe2c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -25,12 +25,12 @@ def json_response(file) def slack_url(url) return url if url =~ /^http/ - url = File.join(Slack::Web::Client.new.api_endpoint, url) + url = File.join(Slack::Web::Config.endpoint, url) uri = Addressable::URI.parse(url) uri.to_s end -def stub_get(endpoint) - stub_request(:get, slack_url(endpoint)). +def stub_get(endpoint, token) + stub_request(:post, slack_url(endpoint)). to_return json_response("#{endpoint}") end From 266782b0f7ce67a77619d19b1137710a1067f3ab Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Wed, 29 May 2024 03:57:28 +0900 Subject: [PATCH 2/6] Fix product code assuming tests are correct. --- lib/arisaid/bots.rb | 2 +- lib/arisaid/guests.rb | 2 +- lib/arisaid/users.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/arisaid/bots.rb b/lib/arisaid/bots.rb index 15d1486..0f8cb97 100644 --- a/lib/arisaid/bots.rb +++ b/lib/arisaid/bots.rb @@ -14,7 +14,7 @@ def remote! class << self def bot_valid_attributes - %i( + %w( name ) end diff --git a/lib/arisaid/guests.rb b/lib/arisaid/guests.rb index 82cbb35..92e8880 100644 --- a/lib/arisaid/guests.rb +++ b/lib/arisaid/guests.rb @@ -15,7 +15,7 @@ def remote! class << self def user_valid_attributes - %i( + %w( name ) end diff --git a/lib/arisaid/users.rb b/lib/arisaid/users.rb index 0da390f..ee2b7dc 100644 --- a/lib/arisaid/users.rb +++ b/lib/arisaid/users.rb @@ -15,7 +15,7 @@ def remote! class << self def user_valid_attributes - %i( + %w( name ) end From 74f8564881fdf2552b404f0c538d5df222d153f3 Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Wed, 29 May 2024 04:00:02 +0900 Subject: [PATCH 3/6] Fix circular require --- lib/arisaid/cli.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/arisaid/cli.rb b/lib/arisaid/cli.rb index b0f78dd..a805f53 100644 --- a/lib/arisaid/cli.rb +++ b/lib/arisaid/cli.rb @@ -1,4 +1,3 @@ -require 'arisaid' require 'thor' module Arisaid From 898173eb368808722b0a8a10b4568fc932e06943 Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Wed, 29 May 2024 14:03:15 +0900 Subject: [PATCH 4/6] add ci --- .github/workflows/ci.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..8d7f039 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,27 @@ +name: Test + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3"] + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Install dependencies + run: bundle install + - name: Run tests + run: bundle exec rake + From d220e8eddcb21251be6d3a415e8fad7e8cd95e44 Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Wed, 29 May 2024 14:04:20 +0900 Subject: [PATCH 5/6] Remove .travis.yml --- .travis.yml | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8d3af5d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: ruby -sudo: false -rvm: - - 2.4.5 - - 2.5.3 - - 2.6.1 -before_install: gem update bundler --no-document -script: - - bundle exec rake test -cache: bundler -notifications: - slack: pepabo:CQkcN0cdvPSJvVsK2D48qYyV - email: false From 76db54240c42fdb50bcb0f7155cccc30f044e0ad Mon Sep 17 00:00:00 2001 From: Kenichi Takahashi Date: Mon, 3 Jun 2024 20:18:35 +0900 Subject: [PATCH 6/6] Test only the currently maintained Ruby versions --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8d7f039..a706bc6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - ruby-version: ["2.7", "3.0", "3.1", "3.2", "3.3"] + ruby-version: ["3.1", "3.2", "3.3", "head"] steps: - uses: actions/checkout@v2 - name: Set up Ruby ${{ matrix.ruby-version }}