From 99fb6aae285759dd017f7e191347b76ad8dea544 Mon Sep 17 00:00:00 2001 From: Andreas Pfohl Date: Thu, 13 Jun 2024 13:35:05 +0200 Subject: [PATCH] [48619] Fixed unit tests for new access token --- spec/controllers/my_controller_spec.rb | 18 +++++++++--------- spec/factories/token_factory.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb index da6e9fadc751..af11f256d7ce 100644 --- a/spec/controllers/my_controller_spec.rb +++ b/spec/controllers/my_controller_spec.rb @@ -305,7 +305,7 @@ it "creates a key" do expect(user.api_tokens).to be_empty - post :generate_api_key + post :generate_api_key, params: { token_api: { token_name: "One heck of a token" } } new_token = user.reload.api_tokens.last expect(new_token).to be_present @@ -317,12 +317,12 @@ end context "with existing key" do - let!(:key) { Token::API.create user: } + let!(:key) { Token::API.create(user:, data: { name: "One heck of a token" }) } it "must add the new key" do expect(user.reload.api_tokens.last).to eq(key) - post :generate_api_key + post :generate_api_key, params: { token_api: { token_name: "Two heck of a token" } } new_token = user.reload.api_tokens.last expect(new_token).not_to eq(key) @@ -353,18 +353,18 @@ it "revoke specific ical tokens" do expect(user.ical_tokens).to contain_exactly( - ical_token_for_query, another_ical_token_for_query, ical_token_for_another_query - ) + ical_token_for_query, another_ical_token_for_query, ical_token_for_another_query + ) delete :revoke_ical_token, params: { id: another_ical_token_for_query.id } expect(user.ical_tokens.reload).to contain_exactly( - ical_token_for_query, ical_token_for_another_query - ) + ical_token_for_query, ical_token_for_another_query + ) expect(user.ical_tokens.reload).not_to contain_exactly( - ical_token_for_another_query - ) + ical_token_for_another_query + ) expect(flash[:info]).to be_present expect(flash[:error]).not_to be_present diff --git a/spec/factories/token_factory.rb b/spec/factories/token_factory.rb index 110738886808..51fd7e0d7657 100644 --- a/spec/factories/token_factory.rb +++ b/spec/factories/token_factory.rb @@ -35,6 +35,14 @@ factory :api_token, class: "::Token::API" do user + + transient do + name { "Default Token Name" } + end + + after(:build) do |token, evaluator| + token.data = { name: evaluator.name } + end end factory :rss_token, class: "::Token::RSS" do