OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
rework spec for Authorization::EnterpriseService
Ivan Kuchinb67088b17fd8
diff --git a/spec/services/authorization/enterprise_service_spec.rb b/spec/services/authorization/enterprise_service_spec.rbindex 027e251c235..d2cfb8a3b6e 100644--- a/spec/services/authorization/enterprise_service_spec.rb+++ b/spec/services/authorization/enterprise_service_spec.rb@@ -29,19 +29,10 @@require "spec_helper"RSpec.describe Authorization::EnterpriseService do- let(:token_object) do- token = OpenProject::Token.new- token.subscriber = "Foobar"- token.mail = "[email protected]"- token.starts_at = Date.today- token.expires_at = nil-- token- end- let(:token) { double("EnterpriseToken", token_object:) }let(:instance) { described_class.new(token) }- let(:result) { instance.call(action) }- let(:action) { :an_action }+ let(:token) { instance_double(EnterpriseToken, token_object:, expired?: expired?) }+ let(:token_object) { OpenProject::Token.new }+ let(:expired?) { false }describe "GUARDED_ACTIONS" doit "is in alphabetical order" do@@ -57,57 +48,73 @@ RSpec.describe Authorization::EnterpriseService doendend- describe "expiry" do- before do- allow(token).to receive(:expired?).and_return(expired)- end+ describe "#call" do+ let(:result) { instance.call(action) }- context "when expired" do- let(:expired) { true }+ shared_examples "true result" do+ it "returns a true result" do+ expect(result).to be_a ServiceResult+ expect(result).to be_success+ expect(result).to have_attributes(result: true)+ end+ end+ shared_examples "false result" doit "returns a false result" doexpect(result).to be_a ServiceResult- expect(result.result).to be_falsey- expect(result.success?).to be_falsey+ expect(result).not_to be_success+ expect(result).to have_attributes(result: false)endend- context "when active" do- let(:expired) { false }+ shared_examples "false result for any action" do+ guarded_action = described_class::GUARDED_ACTIONS.sample- context "invalid action" do- it "returns false" do- expect(result.result).to be_falsey- end+ context "for known action #{guarded_action}" do+ let(:action) { guarded_action }++ include_examples "false result"+ end++ context "for unknown action" do+ let(:action) { "foo" }++ include_examples "false result"end+ end- %i(baseline_comparison- board_view- conditional_highlighting- custom_actions- custom_fields_in_projects_list- date_alerts- define_custom_style- edit_attribute_groups- grid_widget_wp_graph- ldap_groups- openid_providers- placeholder_users- readonly_work_packages- team_planner_view- two_factor_authentication- work_package_query_relation_columns- work_package_sharing).each do |guarded_action|- context "guarded action #{guarded_action}" do+ context "for a valid token" do+ described_class::GUARDED_ACTIONS.each do |guarded_action|+ context "for known action #{guarded_action}" dolet(:action) { guarded_action }- it "returns a true result" do- expect(result).to be_a ServiceResult- expect(result.result).to be_truthy- expect(result.success?).to be_truthy- end+ include_examples "true result"endend++ context "for unknown action" do+ let(:action) { "foo" }++ include_examples "false result"+ end+ end++ context "for an expired token" do+ let(:expired?) { true }++ include_examples "false result for any action"+ end++ context "without a token_object" do+ let(:token_object) { nil }++ include_examples "false result for any action"+ end++ context "without a token" do+ let(:token) { nil }++ include_examples "false result for any action"endendend