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
Move spec to component
Oliver Günther24af829f6fce
diff --git a/app/components/users/profile/projects_component.rb b/app/components/users/profile/projects_component.rbindex e8292945be6..ca439b79a34 100644--- a/app/components/users/profile/projects_component.rb+++ b/app/components/users/profile/projects_component.rb@@ -46,7 +46,6 @@ module Users.where.not(project_id: nil).where(id: Member.visible(User.current)).order("projects.created_at DESC")-enddef render?diff --git a/app/components/users/profile_component.rb b/app/components/users/profile_component.rbindex b6ec7b6d3db..97912c98567 100644--- a/app/components/users/profile_component.rb+++ b/app/components/users/profile_component.rb@@ -27,7 +27,7 @@#++module Users- class ProfileComponent < ApplicationComponent+ class ProfileComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponentinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpersdiff --git a/spec/components/users/profile/attributes_component_spec.rb b/spec/components/users/profile/attributes_component_spec.rbnew file mode 100644index 00000000000..8195719d7c0--- /dev/null+++ b/spec/components/users/profile/attributes_component_spec.rb@@ -0,0 +1,99 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require "rails_helper"++RSpec.describe Users::Profile::AttributesComponent, type: :component do+ let(:component) { described_class.new(user:) }++ describe "visible_user_information?" do+ subject { component.visible_user_information? }++ context "when user has hide_mail = false in their preferences" do+ let(:user) { build(:user, preferences: { hide_mail: false }) }++ it { is_expected.to be(true) }+ end++ context "when user has hide_mail = true in their preferences" do+ let(:user) { build(:user, preferences: { hide_mail: true }) }++ it { is_expected.to be(false) }+ end++ context "when user has a custom field with a present value" do+ let(:custom_field) { create(:user_custom_field, :string) }+ let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: "Hello")]) }++ it { is_expected.to be(true) }+ end++ context "when user has a custom field with a blank value" do+ let(:custom_field) { create(:user_custom_field, :string) }+ let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: " ")]) }++ it { is_expected.to be(false) }+ end++ context "when user has a non-visible custom field with a present value" do+ let(:custom_field) { create(:user_custom_field, :string, visible: false) }+ let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: "Hello")]) }++ it { is_expected.to be(false) }+ end+ end++ describe "Custom fields" do+ let(:custom_field) { create(:user_custom_field, :string, visible:) }+ let(:user) { build_stubbed(:user, custom_values: [build(:custom_value, custom_field:, value: "Hello custom field")]) }++ current_user { build(:admin) }++ before do+ render_inline(component)+ end++ context "when visible" do+ let(:visible) { true }++ it "renders the field" do+ expect(page).to have_text("Hello custom field")+ end+ end++ context "when not visible" do+ let(:visible) { false }++ it "does not render the field" do+ expect(page).to have_no_text("Hello custom field")+ end+ end+ end+enddiff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rbindex e367c9b4191..db9a5161e9b 100644--- a/spec/helpers/users_helper_spec.rb+++ b/spec/helpers/users_helper_spec.rb@@ -114,41 +114,4 @@ RSpec.describe UsersHelper doendendend-- describe "#visible_user_information?" do- subject { visible_user_information?(user) }-- context "when user has hide_mail = false in their preferences" do- let(:user) { build(:user, preferences: { hide_mail: false }) }-- it { is_expected.to be(true) }- end-- context "when user has hide_mail = true in their preferences" do- let(:user) { build(:user, preferences: { hide_mail: true }) }-- it { is_expected.to be(false) }- end-- context "when user has a custom field with a present value" do- let(:custom_field) { create(:user_custom_field, :string) }- let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: "Hello")]) }-- it { is_expected.to be(true) }- end-- context "when user has a custom field with a blank value" do- let(:custom_field) { create(:user_custom_field, :string) }- let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: " ")]) }-- it { is_expected.to be(false) }- end-- context "when user has a non-visible custom field with a present value" do- let(:custom_field) { create(:user_custom_field, :string, visible: false) }- let(:user) { build(:user, custom_values: [build(:custom_value, custom_field:, value: "Hello")]) }-- it { is_expected.to be(false) }- end- endenddiff --git a/spec/support/component_specs.rb b/spec/support/component_specs.rbnew file mode 100644index 00000000000..15775e7c47a--- /dev/null+++ b/spec/support/component_specs.rb@@ -0,0 +1,10 @@+# spec/rails_helper.rb+require "view_component/test_helpers"+require "view_component/system_test_helpers"+require "capybara/rspec"++RSpec.configure do |config|+ config.include ViewComponent::TestHelpers, type: :component+ config.include ViewComponent::SystemTestHelpers, type: :component+ config.include Capybara::RSpecMatchers, type: :component+enddiff --git a/spec/views/users/show.html.erb_spec.rb b/spec/views/users/show.html.erb_spec.rbdeleted file mode 100644index f7a9cf85260..00000000000--- a/spec/views/users/show.html.erb_spec.rb+++ /dev/null@@ -1,57 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2024 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--require "spec_helper"--RSpec.describe "users/show" do- let(:project) { create(:valid_project) }- let(:user) { create(:admin, member_with_permissions: { project => %i[view_work_packages edit_work_packages] }) }- let(:custom_field) { create(:user_custom_field, :text) }- let(:visibility_custom_value) do- create(:principal_custom_value,- customized: user,- custom_field:,- value: "TextUserCustomFieldValue")- end-- before do- visibility_custom_value- user.reload-- assign(:user, user)- assign(:memberships, user.memberships)- assign(:events, [])- assign(:groups, [])- end-- it "renders the visible custom values" do- render-- expect(rendered).to have_css("li", text: "TextUserCustomField")- end-end