diff --git a/spec/commands/concerns/decidim/privacy/reply_to_conversation_extensions_spec.rb b/spec/commands/concerns/decidim/privacy/reply_to_conversation_extensions_spec.rb new file mode 100644 index 0000000..c1d6597 --- /dev/null +++ b/spec/commands/concerns/decidim/privacy/reply_to_conversation_extensions_spec.rb @@ -0,0 +1,103 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Privacy::ReplyToConversationExtensions do + let(:organization) { create(:organization) } + let!(:user) { create(:user, :admin, :confirmed, organization: organization) } + let!(:receiver) { create(:user, :confirmed, organization: organization) } + + let(:form_params) do + { body: "Hello there receiver!" } + end + + let(:form) do + Decidim::Messaging::MessageForm.from_params( + form_params + ).with_context( + current_user: user, + sender: user + ) + end + + let(:conversation) do + Decidim::Messaging::Conversation.start!( + originator: user, + interlocutors: [receiver], + body: "Initial message" + ) + end + + let!(:participationuser) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: user.id) } + let!(:participationreceiver) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: receiver.id) } + + let(:command) { Decidim::Messaging::ReplyToConversation.new(conversation, form) } + + before do + user.update(published_at: Time.current) + end + + context "when public user with messages enabled" do + it "broadcasts ok" do + receiver.update(published_at: Time.current) + + expect do + command.call + end.to broadcast(:ok) + end + end + + context "when a private user" do + it "broadcasts invalid" do + expect do + command.call + end.to broadcast(:invalid) + end + end + + context "when public user with messages disabled" do + it "broadcasts invalid" do + receiver.update(published_at: Time.current, allow_private_messaging: false) + + expect do + command.call + end.to broadcast(:invalid) + end + end + + context "when multiple participants in a initialized conversation" do + let(:participant) { create(:user, :confirmed, organization: organization) } + let(:conversation) do + Decidim::Messaging::Conversation.start!( + originator: user, + interlocutors: [receiver, participant], + body: "Initial message" + ) + end + + let(:form_params) do + { body: "Hello there people!" } + end + + context "when 1 participant has private messaging disabled" do + it "broadcasts ok" do + receiver.update(published_at: Time.current, allow_private_messaging: false) + participant.update(published_at: Time.current) + + expect do + command.call + end.to broadcast(:ok) + end + end + + context "when 1 participant is private" do + it "broadcasts ok" do + participant.update(published_at: Time.current) + + expect do + command.call + end.to broadcast(:ok) + end + end + end +end diff --git a/spec/commands/concerns/decidim/privacy/start_conversation_extensions_spec.rb b/spec/commands/concerns/decidim/privacy/start_conversation_extensions_spec.rb new file mode 100644 index 0000000..7f76856 --- /dev/null +++ b/spec/commands/concerns/decidim/privacy/start_conversation_extensions_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Privacy::StartConversationExtensions do + let(:organization) { create(:organization) } + let!(:user) { create(:user, :admin, :confirmed, organization: organization) } + let!(:receiver) { create(:user, :confirmed, organization: organization) } + + let(:form_params) do + { + body: "Hello there receiver!", + recipient_id: receiver.id + } + end + + let(:form) do + Decidim::Messaging::ConversationForm.from_params( + form_params + ).with_context( + current_user: user, + sender: user + ) + end + + let(:command) { Decidim::Messaging::StartConversation.new(form) } + + before do + user.update(published_at: Time.current) + end + + context "when public user with messages enabled" do + it "broadcasts ok" do + receiver.update(published_at: Time.current) + + expect do + command.call + end.to broadcast(:ok) + end + end + + context "when a private user" do + it "broadcasts invalid" do + expect do + command.call + end.to broadcast(:invalid) + end + end + + context "when public user with messages disabled" do + it "broadcasts invalid" do + receiver.update(published_at: Time.current, allow_private_messaging: false) + + expect do + command.call + end.to broadcast(:invalid) + end + end + + context "when starting a conversation to multiple participants" do + let(:participant) { create(:user, :confirmed, organization: organization) } + + let(:form_params) do + { + body: "Hello there people!", + recipient_id: [receiver.id, participant.id] + } + end + + context "when 1 participant has private messaging disabled" do + it "broadcasts invalid" do + receiver.update(published_at: Time.current, allow_private_messaging: false) + participant.update(published_at: Time.current) + + expect do + command.call + end.to broadcast(:invalid) + end + end + + context "when 1 participant is private" do + it "broadcasts invalid" do + receiver.update(published_at: Time.current) + command.call + + expect do + command.call + end.to broadcast(:invalid) + end + end + end +end diff --git a/spec/commands/concerns/endorse_resource_spec.rb b/spec/commands/concerns/endorse_resource_spec.rb deleted file mode 100644 index 9177dd2..0000000 --- a/spec/commands/concerns/endorse_resource_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Privacy - describe Decidim::EndorseResource do - let(:resource) { create(:dummy_resource) } - let(:current_user) { create(:user, :confirmed, :published, organization: resource.component.organization) } - let(:command) { described_class.new(resource, current_user) } - - context "when user public" do - it "broadcasts ok" do - expect { command.call }.to broadcast(:ok) - end - end - - context "when user private" do - let!(:current_user) { create(:user, :confirmed, organization: resource.organization) } - - it "broadcasts invalid" do - expect { command.call }.to broadcast(:invalid) - end - end - end - end -end diff --git a/spec/commands/concerns/reply_to_conversation_spec.rb b/spec/commands/concerns/reply_to_conversation_spec.rb deleted file mode 100644 index 7e2707a..0000000 --- a/spec/commands/concerns/reply_to_conversation_spec.rb +++ /dev/null @@ -1,107 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Privacy - describe ReplyToConversationExtensions do - let(:organization) { create(:organization) } - let!(:user) { create(:user, :admin, :confirmed, organization: organization) } - let!(:receiver) { create(:user, :confirmed, organization: organization) } - - let(:form_params) do - { body: "Hello there receiver!" } - end - - let(:form) do - Decidim::Messaging::MessageForm.from_params( - form_params - ).with_context( - current_user: user, - sender: user - ) - end - - let(:conversation) do - Decidim::Messaging::Conversation.start!( - originator: user, - interlocutors: [receiver], - body: "Initial message" - ) - end - - let!(:participationuser) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: user.id) } - let!(:participationreceiver) { Decidim::Messaging::Participation.new(decidim_conversation_id: conversation.id, decidim_participant_id: receiver.id) } - - let(:command) { Decidim::Messaging::ReplyToConversation.new(conversation, form) } - - before do - user.update(published_at: Time.current) - end - - context "when public user with messages enabled" do - it "broadcasts ok" do - receiver.update(published_at: Time.current) - - expect do - command.call - end.to broadcast(:ok) - end - end - - context "when a private user" do - it "broadcasts invalid" do - expect do - command.call - end.to broadcast(:invalid) - end - end - - context "when public user with messages disabled" do - it "broadcasts invalid" do - receiver.update(published_at: Time.current, allow_private_messaging: false) - - expect do - command.call - end.to broadcast(:invalid) - end - end - - context "when multiple participants in a initialized conversation" do - let(:participant) { create(:user, :confirmed, organization: organization) } - let(:conversation) do - Decidim::Messaging::Conversation.start!( - originator: user, - interlocutors: [receiver, participant], - body: "Initial message" - ) - end - - let(:form_params) do - { body: "Hello there people!" } - end - - context "when 1 participant has private messaging disabled" do - it "broadcasts ok" do - receiver.update(published_at: Time.current, allow_private_messaging: false) - participant.update(published_at: Time.current) - - expect do - command.call - end.to broadcast(:ok) - end - end - - context "when 1 participant is private" do - it "broadcasts ok" do - participant.update(published_at: Time.current) - - expect do - command.call - end.to broadcast(:ok) - end - end - end - end - end -end diff --git a/spec/commands/concerns/start_conversation_spec.rb b/spec/commands/concerns/start_conversation_spec.rb deleted file mode 100644 index b330509..0000000 --- a/spec/commands/concerns/start_conversation_spec.rb +++ /dev/null @@ -1,96 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Privacy - describe StartConversationExtensions do - let(:organization) { create(:organization) } - let!(:user) { create(:user, :admin, :confirmed, organization: organization) } - let!(:receiver) { create(:user, :confirmed, organization: organization) } - - let(:form_params) do - { - body: "Hello there receiver!", - recipient_id: receiver.id - } - end - - let(:form) do - Decidim::Messaging::ConversationForm.from_params( - form_params - ).with_context( - current_user: user, - sender: user - ) - end - - let(:command) { Decidim::Messaging::StartConversation.new(form) } - - before do - user.update(published_at: Time.current) - end - - context "when public user with messages enabled" do - it "broadcasts ok" do - receiver.update(published_at: Time.current) - - expect do - command.call - end.to broadcast(:ok) - end - end - - context "when a private user" do - it "broadcasts invalid" do - expect do - command.call - end.to broadcast(:invalid) - end - end - - context "when public user with messages disabled" do - it "broadcasts invalid" do - receiver.update(published_at: Time.current, allow_private_messaging: false) - - expect do - command.call - end.to broadcast(:invalid) - end - end - - context "when starting a conversation to multiple participants" do - let(:participant) { create(:user, :confirmed, organization: organization) } - - let(:form_params) do - { - body: "Hello there people!", - recipient_id: [receiver.id, participant.id] - } - end - - context "when 1 participant has private messaging disabled" do - it "broadcasts invalid" do - receiver.update(published_at: Time.current, allow_private_messaging: false) - participant.update(published_at: Time.current) - - expect do - command.call - end.to broadcast(:invalid) - end - end - - context "when 1 participant is private" do - it "broadcasts invalid" do - receiver.update(published_at: Time.current) - command.call - - expect do - command.call - end.to broadcast(:invalid) - end - end - end - end - end -end diff --git a/spec/commands/decidim/endorse_resource_spec.rb b/spec/commands/decidim/endorse_resource_spec.rb new file mode 100644 index 0000000..ec03906 --- /dev/null +++ b/spec/commands/decidim/endorse_resource_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::EndorseResource do + let(:resource) { create(:dummy_resource) } + let(:current_user) { create(:user, :confirmed, :published, organization: resource.component.organization) } + let(:command) { described_class.new(resource, current_user) } + + context "when user public" do + it "broadcasts ok" do + expect { command.call }.to broadcast(:ok) + end + end + + context "when user private" do + let!(:current_user) { create(:user, :confirmed, organization: resource.organization) } + + it "broadcasts invalid" do + expect { command.call }.to broadcast(:invalid) + end + end +end diff --git a/spec/controllers/concerns/application_controller_spec.rb b/spec/controllers/concerns/application_controller_spec.rb deleted file mode 100644 index 39191eb..0000000 --- a/spec/controllers/concerns/application_controller_spec.rb +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - class ApplicationController < ::DecidimController - include ::Decidim::Privacy::ApplicationControllerExtensions - end - describe ApplicationController, type: :controller do - let!(:organization) { create :organization } - let!(:user) { create :user, :confirmed, organization: organization } - - controller Decidim::ApplicationController do - def show - render plain: "Hello World" - end - end - - before do - request.env["decidim.current_organization"] = organization - routes.draw do - get "show" => "decidim/application#show" - end - end - - context "when not signed in" do - it "does does not add publish_account_modal to snippets" do - get :show - - expect(snippets_instance).to include(%()) - expect(snippets_instance).not_to include(an_instance_of(Decidim::Privacy::PublishAccountModalCell)) - end - end - - context "when private user signed in" do - before do - sign_in user - end - - it "addes publish_account_modal to snippets to the snippets" do - get :show - - expect(snippets_instance).to include(%()) - expect(snippets_instance).to include(an_instance_of(Decidim::Privacy::PublishAccountModalCell)) - end - end - - context "when public user signed in" do - let!(:user) { create :user, :confirmed, :published, organization: organization } - - before do - sign_in user - end - - it "does does not add publish_account_modal to snippets" do - get :show - - expect(assigns(:snippets).instance_variable_get(:@snippets)).to be_nil - end - end - - private - - def asset_path(asset) - ::Webpacker.instance.manifest.lookup!(asset) - end - - def snippets_instance - assigns(:snippets).instance_variable_get(:@snippets)[:foot] - end - end -end diff --git a/spec/controllers/concerns/assembly_members_controller_spec.rb b/spec/controllers/concerns/assembly_members_controller_spec.rb deleted file mode 100644 index 2624e30..0000000 --- a/spec/controllers/concerns/assembly_members_controller_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Assemblies - class AssemblyMembersController - include ::Decidim::Privacy::AssemblyMembersControllerExtensions - end - describe AssemblyMembersController, type: :controller do - routes { Decidim::Assemblies::Engine.routes } - - let(:organization) { create(:organization) } - - let!(:assembly) do - create( - :assembly, - :published, - organization: organization - ) - end - - before do - request.env["decidim.current_organization"] = organization - end - - describe "GET index" do - context "when assembly has no members" do - it "displays an empty array of members" do - get :index, params: { assembly_slug: assembly.slug } - - expect(controller.helpers.collection).to match_array([]) - end - end - - context "when there are members" do - let!(:member1) { create(:assembly_member, :with_user, assembly: assembly) } - let!(:member2) { create(:assembly_member, assembly: assembly) } - let!(:non_member) { create(:assembly_member) } - - context "when assembly has no public members" do - it "displays an empty array of members" do - get :index, params: { assembly_slug: assembly.slug } - - expect(controller.helpers.collection).to match_array([]) - end - end - - context "when assembly has some public members" do - before do - member1.user.update!(published_at: Time.current) - end - - context "when user has permissions" do - it "displays only public members" do - get :index, params: { assembly_slug: assembly.slug } - - expect(controller.helpers.collection).to match_array([member1]) - end - end - end - end - end - end - end -end diff --git a/spec/controllers/concerns/comments_controller_spec.rb b/spec/controllers/concerns/comments_controller_spec.rb deleted file mode 100644 index 83bf3de..0000000 --- a/spec/controllers/concerns/comments_controller_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Comments - describe CommentsController, type: :controller do - routes { Decidim::Comments::Engine.routes } - - let(:organization) { create(:organization) } - let(:participatory_process) { create :participatory_process, organization: organization } - let(:component) { create(:component, participatory_space: participatory_process) } - let(:commentable) { create(:dummy_resource, component: component) } - - before do - request.env["decidim.current_organization"] = organization - end - - describe "POST create" do - let(:user) { create(:user, :confirmed, locale: "en", organization: organization) } - let(:comment) { Decidim::Comments::Comment.last } - let(:params) do - { comment: comment_params, xhr: true } - end - let(:comment_alignment) { 0 } - let(:comment_params) do - { - commentable_gid: commentable.to_signed_global_id.to_s, - body: "This is a new comment", - alignment: comment_alignment - } - end - - context "when private user" do - before do - sign_in user - end - - it "does not permit create action" do - post :create, xhr: true, params: params - expect(response).to render_template("decidim/privacy/privacy_block") - end - end - - context "when public user" do - before do - user.update!(published_at: Time.current) - sign_in user - end - - it "permits create action" do - post :create, xhr: true, params: params - expect(response).to have_http_status(:ok).or have_http_status(:no_content) - end - end - end - end - end -end diff --git a/spec/controllers/concerns/conversations_controller_spec.rb b/spec/controllers/concerns/conversations_controller_spec.rb deleted file mode 100644 index 0ea620a..0000000 --- a/spec/controllers/concerns/conversations_controller_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Messaging - class ConversationsController < Decidim::ApplicationController - include ::Decidim::Privacy::ConversationsControllerExtensions - end - describe ConversationsController, type: :controller do - routes { Decidim::Core::Engine.routes } - - let(:organization) { create(:organization) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:user1) { create(:user, organization: organization) } - let!(:conversation2) do - Messaging::Conversation.start!( - originator: user, - interlocutors: [user1], - body: "Hi!" - ) - end - - before do - request.env["decidim.current_organization"] = organization - sign_in user - end - - describe "GET new" do - subject { get :new, params: { recipient_id: user.id } } - context "when is private user" do - it "renders 404 error" do - expect(subject).to render_template("decidim/privacy/message_block") - end - end - - context "when messaging is disabled" do - let!(:user) { create(:user, :confirmed, organization: organization, allow_private_messaging: false, published_at: Time.current) } - - it "renders 404 error" do - expect(subject).to render_template("decidim/privacy/message_block") - end - end - - context "when is public and private messaing is enabled" do - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } - - context "when is the same user" do - it "redirects to previous 2 participant created conversation" do - expect(subject).to redirect_to profile_path(user.nickname) - end - end - - context "when conversation with a private user" do - subject { get :new, params: { recipient_id: user1.id } } - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } - - it "redirects to previous 2 participant created conversation" do - expect(subject).to redirect_to profile_path(user.nickname) - end - end - - context "when conversation with a public user" do - subject { get :new, params: { recipient_id: user1.id } } - let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } - let!(:user1) { create(:user, organization: organization, published_at: Time.current) } - - it "redirects to previous 2 participant created conversation" do - expect(subject).to redirect_to conversation_path(conversation2) - end - end - end - end - end - end -end diff --git a/spec/controllers/concerns/debates_controller_spec.rb b/spec/controllers/concerns/debates_controller_spec.rb deleted file mode 100644 index 18e70b4..0000000 --- a/spec/controllers/concerns/debates_controller_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Debates - describe DebatesController, type: :controller do - routes { Decidim::Debates::Engine.routes } - - let(:organization) { create(:organization) } - let(:component) { create(:debates_component, :with_creation_enabled, organization: organization) } - let!(:debate) { create(:debate, component: component, author: user) } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:params) { { component_id: component.id } } - - before do - request.env["decidim.current_organization"] = organization - request.env["decidim.current_participatory_space"] = component.participatory_space - request.env["decidim.current_component"] = component - end - - it_behaves_like "permittable create actions" - it_behaves_like "permittable new actions" - - describe "#edit" do - let(:params) do - { - id: debate.id, - component_id: component.id, - debate: { - title: "Test debates creation1", - description: "Test debates creation1 description" - } - } - end - - it_behaves_like "permittable update actions" - it_behaves_like "permittable edit actions" - end - end - end -end diff --git a/spec/controllers/concerns/impersonatable_users_controller_spec.rb b/spec/controllers/concerns/impersonatable_users_controller_spec.rb deleted file mode 100644 index e4160de..0000000 --- a/spec/controllers/concerns/impersonatable_users_controller_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Admin - class ImpersonatableUsersController < Decidim::Admin::ApplicationController - include ::Decidim::Privacy::ImpersonatableUsersControllerExtensions - end - describe ImpersonatableUsersController, type: :controller do - routes { Decidim::Admin::Engine.routes } - - let(:organization) { create :organization } - let(:admin_user) { create(:user, :admin, :confirmed, organization: organization) } - let(:private_user) { create(:user, organization: organization) } - let(:public_user) { create(:user, organization: organization, published_at: Time.current) } - let(:another_admin) { create(:user, :admin, :confirmed, organization: organization) } - - describe "#index" do - before do - request.env["decidim.current_organization"] = organization - sign_in admin_user - end - - it "collects only non-admin public users" do - get :index - expect(assigns(:collection)).to eq([public_user]) - end - end - end - end -end diff --git a/spec/controllers/concerns/meetings_controller_spec.rb b/spec/controllers/concerns/meetings_controller_spec.rb deleted file mode 100644 index cac708b..0000000 --- a/spec/controllers/concerns/meetings_controller_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Meetings - describe MeetingsController, type: :controller do - routes { Decidim::Meetings::Engine.routes } - - let(:organization) { create(:organization) } - let(:participatory_process) { create :participatory_process, organization: organization } - let(:meeting_component) { create(:meeting_component, :with_creation_enabled, participatory_space: participatory_process) } - let(:meeting) { create :meeting, :online, :not_official, :published, author: user, component: meeting_component } - let(:user) { create(:user, :confirmed, organization: organization) } - let(:params) { { component_id: meeting_component.id } } - - before do - request.env["decidim.current_organization"] = organization - request.env["decidim.current_participatory_space"] = participatory_process - request.env["decidim.current_component"] = meeting_component - end - - it_behaves_like "permittable create actions" - it_behaves_like "permittable new actions" - - describe "#update" do - let(:params) do - { - id: meeting.id, - component_id: meeting_component.id, - meeting: { - title: generate_localized_title, - description: ::Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title }, - type_of_meeting: meeting.type_of_meeting, - online_meeting_url: meeting.online_meeting_url, - start_time: meeting.start_time, - end_time: meeting.end_time, - registration_type: meeting.registration_type, - available_slots: meeting.available_slots, - registration_terms: meeting.registration_terms - } - } - end - - it_behaves_like "permittable update actions" - it_behaves_like "permittable edit actions" - end - end - end -end diff --git a/spec/controllers/concerns/organization_controller_spec.rb b/spec/controllers/concerns/organization_controller_spec.rb deleted file mode 100644 index bf51206..0000000 --- a/spec/controllers/concerns/organization_controller_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -module Decidim - module Admin - class OrganizationController < Decidim::Admin::ApplicationController - include ::Decidim::Privacy::AdminOrganizationControllerExtensions - end - - describe OrganizationController, type: :controller do - routes { Decidim::Admin::Engine.routes } - - let(:organization) { create :organization } - let(:current_user) { create(:user, :admin, :confirmed, organization: organization) } - - before do - request.env["decidim.current_organization"] = organization - sign_in current_user, scope: :user - end - - describe "GET users and user groups in json format" do - let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } - - context "when user is blocked" do - let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to eq([]) - end - end - - context "when user is managed" do - let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to eq([]) - end - end - - context "when user is deleted" do - let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to eq([]) - end - end - end - - describe "GET users in json format" do - let!(:user) { create(:user, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - let!(:public_user) { create(:user, name: "Daisy Public", nickname: "daisy_p", organization: organization, published_at: Time.current) } - let!(:other_organization_user) { create(:user, name: "Daisy Foo", nickname: "daisy_f", published_at: Time.current) } - - let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } - - context "when searching by name" do - it "returns the id, name and nickname for filtered users" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) - expect(parsed_response).to include({ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }) - end - end - - context "when searching by nickname" do - it "returns the id, name and nickname for filtered users" do - get :users, format: :json, params: { term: "@daisy" } - expect(parsed_response).to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) - expect(parsed_response).to include({ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }) - end - end - - context "when searching by email" do - it "returns the id, name and nickname for filtered users" do - get :users, format: :json, params: { term: user.email } - expect(parsed_response).to eq([{ value: user.id, label: "#{user.name} (@#{user.nickname})" }]) - end - end - - context "when user is blocked" do - let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to eq([{ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }]) - end - end - - context "when user is managed" do - let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).to eq([{ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }]) - end - end - - context "when user is deleted" do - let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } - - it "returns an empty json array" do - get :users, format: :json, params: { term: "daisy" } - expect(parsed_response).not_to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) - end - end - end - end - end -end diff --git a/spec/controllers/concerns/own_user_groups_controller_spec.rb b/spec/controllers/concerns/own_user_groups_controller_spec.rb deleted file mode 100644 index 6d3e769..0000000 --- a/spec/controllers/concerns/own_user_groups_controller_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - class OwnUserGroupsController < ApplicationController - include ::Decidim::Privacy::OwnUserGroupsControllerExtensions - end - describe OwnUserGroupsController, type: :controller do - routes { Decidim::Core::Engine.routes } - - let!(:organization) { create(:organization) } - let!(:current_user) { create(:user, :admin, :confirmed, organization: organization) } - let!(:private_user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user]) } - let!(:user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user], published_at: Time.current) } - - before do - request.env["decidim.current_organization"] = organization - sign_in current_user - end - - describe "#index" do - before do - allow(organization).to receive(:user_groups_enabled?).and_return(true) - end - - it "finds entire collection" do - get :index - expect(assigns(:user_groups)).to include(user_group) - expect(assigns(:user_groups)).to include(private_user_group) - end - end - end -end diff --git a/spec/controllers/concerns/proposals_controller_spec.rb b/spec/controllers/concerns/proposals_controller_spec.rb deleted file mode 100644 index 6ce484a..0000000 --- a/spec/controllers/concerns/proposals_controller_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Proposals - class ProposalsController - include ::Decidim::Privacy::PrivacyActionsExtensions - end - describe ProposalsController, type: :controller do - routes { Decidim::Proposals::Engine.routes } - - let!(:user) { create(:user, :confirmed, organization: component.organization) } - let!(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } - - let(:proposal_params) do - { - component_id: component.id - } - end - let(:params) { { proposal: proposal_params } } - - before do - request.env["decidim.current_organization"] = component.organization - request.env["decidim.current_participatory_space"] = component.participatory_space - request.env["decidim.current_component"] = component - end - - it_behaves_like "permittable create actions" - it_behaves_like "permittable new actions" - - context "when updating" do - let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } - let!(:proposal) { create(:proposal, component: component, users: [user]) } - let(:proposal_params) do - { - title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", - body: "Ut sed dolor vitae purus volutpat venenatis. Donec sit amet sagittis sapien. Curabitur rhoncus ullamcorper feugiat. Aliquam et magna metus." - } - end - let(:params) do - { - id: proposal.id, - proposal: proposal_params - } - end - - it_behaves_like "permittable update actions" - it_behaves_like "permittable edit actions" - end - end - end -end diff --git a/spec/controllers/concerns/user_activities_controller_spec.rb b/spec/controllers/concerns/user_activities_controller_spec.rb deleted file mode 100644 index 91d6e8a..0000000 --- a/spec/controllers/concerns/user_activities_controller_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe UserActivitiesController, type: :controller do - routes { Decidim::Core::Engine.routes } - - let(:organization) { create(:organization) } - let!(:user) { create(:user, nickname: "Nick", organization: organization, published_at: Time.current) } - - before do - request.env["decidim.current_organization"] = organization - end - - describe "#show" do - context "when user is private" do - let!(:user) { create(:user, nickname: "Nick", organization: organization) } - - it "renders private view" do - expect do - get :index, params: { nickname: "NICK" } - end.to raise_error(ActionController::RoutingError, "Missing user: NICK") - end - end - - context "with an unknown user" do - it "raises an ActionController::RoutingError" do - expect do - get :index, params: { nickname: "foobar" } - end.to raise_error(ActionController::RoutingError, "Missing user: foobar") - end - end - - context "with an user with uppercase" do - it "returns the lowercased user" do - get :index, params: { nickname: "NICK" } - expect(response).to render_template(:index) - end - end - end - end -end diff --git a/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb b/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb new file mode 100644 index 0000000..ed4c05e --- /dev/null +++ b/spec/controllers/decidim/admin/impersonatable_users_controller_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Admin + class ImpersonatableUsersController < Decidim::Admin::ApplicationController + include ::Decidim::Privacy::ImpersonatableUsersControllerExtensions + end + end +end + +describe Decidim::Admin::ImpersonatableUsersController, type: :controller do + routes { Decidim::Admin::Engine.routes } + + let(:organization) { create :organization } + let(:admin_user) { create(:user, :admin, :confirmed, organization: organization) } + let(:private_user) { create(:user, organization: organization) } + let(:public_user) { create(:user, organization: organization, published_at: Time.current) } + let(:another_admin) { create(:user, :admin, :confirmed, organization: organization) } + + describe "#index" do + before do + request.env["decidim.current_organization"] = organization + sign_in admin_user + end + + it "collects only non-admin public users" do + get :index + expect(assigns(:collection)).to eq([public_user]) + end + end +end diff --git a/spec/controllers/decidim/admin/organization_controller_spec.rb b/spec/controllers/decidim/admin/organization_controller_spec.rb new file mode 100644 index 0000000..ce067e9 --- /dev/null +++ b/spec/controllers/decidim/admin/organization_controller_spec.rb @@ -0,0 +1,112 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Admin + class OrganizationController < Decidim::Admin::ApplicationController + include ::Decidim::Privacy::AdminOrganizationControllerExtensions + end + end +end + +describe Decidim::Admin::OrganizationController, type: :controller do + routes { Decidim::Admin::Engine.routes } + + let(:organization) { create :organization } + let(:current_user) { create(:user, :admin, :confirmed, organization: organization) } + + before do + request.env["decidim.current_organization"] = organization + sign_in current_user, scope: :user + end + + describe "GET users and user groups in json format" do + let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } + + context "when user is blocked" do + let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to eq([]) + end + end + + context "when user is managed" do + let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to eq([]) + end + end + + context "when user is deleted" do + let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to eq([]) + end + end + end + + describe "GET users in json format" do + let!(:user) { create(:user, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + let!(:public_user) { create(:user, name: "Daisy Public", nickname: "daisy_p", organization: organization, published_at: Time.current) } + let!(:other_organization_user) { create(:user, name: "Daisy Foo", nickname: "daisy_f", published_at: Time.current) } + + let(:parsed_response) { JSON.parse(response.body).map(&:symbolize_keys) } + + context "when searching by name" do + it "returns the id, name and nickname for filtered users" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) + expect(parsed_response).to include({ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }) + end + end + + context "when searching by nickname" do + it "returns the id, name and nickname for filtered users" do + get :users, format: :json, params: { term: "@daisy" } + expect(parsed_response).to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) + expect(parsed_response).to include({ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }) + end + end + + context "when searching by email" do + it "returns the id, name and nickname for filtered users" do + get :users, format: :json, params: { term: user.email } + expect(parsed_response).to eq([{ value: user.id, label: "#{user.name} (@#{user.nickname})" }]) + end + end + + context "when user is blocked" do + let!(:user) { create(:user, :blocked, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to eq([{ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }]) + end + end + + context "when user is managed" do + let!(:user) { create(:user, :managed, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).to eq([{ value: public_user.id, label: "#{public_user.name} (@#{public_user.nickname})" }]) + end + end + + context "when user is deleted" do + let!(:user) { create(:user, :deleted, name: "Daisy Miller", nickname: "daisy_m", organization: organization) } + + it "returns an empty json array" do + get :users, format: :json, params: { term: "daisy" } + expect(parsed_response).not_to include({ value: user.id, label: "#{user.name} (@#{user.nickname})" }) + end + end + end +end diff --git a/spec/controllers/decidim/application_controller_spec.rb b/spec/controllers/decidim/application_controller_spec.rb new file mode 100644 index 0000000..77622ab --- /dev/null +++ b/spec/controllers/decidim/application_controller_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + class ApplicationController < ::DecidimController + include ::Decidim::Privacy::ApplicationControllerExtensions + end +end + +describe Decidim::ApplicationController, type: :controller do + let!(:organization) { create :organization } + let!(:user) { create :user, :confirmed, organization: organization } + + controller Decidim::ApplicationController do + def show + render plain: "Hello World" + end + end + + before do + request.env["decidim.current_organization"] = organization + routes.draw do + get "show" => "decidim/application#show" + end + end + + context "when not signed in" do + it "does does not add publish_account_modal to snippets" do + get :show + + expect(snippets_instance).to include(%()) + expect(snippets_instance).not_to include(an_instance_of(Decidim::Privacy::PublishAccountModalCell)) + end + end + + context "when private user signed in" do + before do + sign_in user + end + + it "addes publish_account_modal to snippets to the snippets" do + get :show + + expect(snippets_instance).to include(%()) + expect(snippets_instance).to include(an_instance_of(Decidim::Privacy::PublishAccountModalCell)) + end + end + + context "when public user signed in" do + let!(:user) { create :user, :confirmed, :published, organization: organization } + + before do + sign_in user + end + + it "does does not add publish_account_modal to snippets" do + get :show + + expect(assigns(:snippets).instance_variable_get(:@snippets)).to be_nil + end + end + + private + + def asset_path(asset) + ::Webpacker.instance.manifest.lookup!(asset) + end + + def snippets_instance + assigns(:snippets).instance_variable_get(:@snippets)[:foot] + end +end diff --git a/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb b/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb new file mode 100644 index 0000000..b187bc7 --- /dev/null +++ b/spec/controllers/decidim/assemblies/assembly_members_controller_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Assemblies + class AssemblyMembersController + include ::Decidim::Privacy::AssemblyMembersControllerExtensions + end + end +end + +describe Decidim::Assemblies::AssemblyMembersController, type: :controller do + routes { Decidim::Assemblies::Engine.routes } + + let(:organization) { create(:organization) } + + let!(:assembly) do + create( + :assembly, + :published, + organization: organization + ) + end + + before do + request.env["decidim.current_organization"] = organization + end + + describe "GET index" do + context "when assembly has no members" do + it "displays an empty array of members" do + get :index, params: { assembly_slug: assembly.slug } + + expect(controller.helpers.collection).to match_array([]) + end + end + + context "when there are members" do + let!(:member1) { create(:assembly_member, :with_user, assembly: assembly) } + let!(:member2) { create(:assembly_member, assembly: assembly) } + let!(:non_member) { create(:assembly_member) } + + context "when assembly has no public members" do + it "displays an empty array of members" do + get :index, params: { assembly_slug: assembly.slug } + + expect(controller.helpers.collection).to match_array([]) + end + end + + context "when assembly has some public members" do + before do + member1.user.update!(published_at: Time.current) + end + + context "when user has permissions" do + it "displays only public members" do + get :index, params: { assembly_slug: assembly.slug } + + expect(controller.helpers.collection).to match_array([member1]) + end + end + end + end + end +end diff --git a/spec/controllers/decidim/comments/comments_controller_spec.rb b/spec/controllers/decidim/comments/comments_controller_spec.rb new file mode 100644 index 0000000..3e1524c --- /dev/null +++ b/spec/controllers/decidim/comments/comments_controller_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Comments::CommentsController, type: :controller do + routes { Decidim::Comments::Engine.routes } + + let(:organization) { create(:organization) } + let(:participatory_process) { create :participatory_process, organization: organization } + let(:component) { create(:component, participatory_space: participatory_process) } + let(:commentable) { create(:dummy_resource, component: component) } + + before do + request.env["decidim.current_organization"] = organization + end + + describe "POST create" do + let(:user) { create(:user, :confirmed, locale: "en", organization: organization) } + let(:comment) { Decidim::Comments::Comment.last } + let(:params) do + { comment: comment_params, xhr: true } + end + let(:comment_alignment) { 0 } + let(:comment_params) do + { + commentable_gid: commentable.to_signed_global_id.to_s, + body: "This is a new comment", + alignment: comment_alignment + } + end + + context "when private user" do + before do + sign_in user + end + + it "does not permit create action" do + post :create, xhr: true, params: params + expect(response).to render_template("decidim/privacy/privacy_block") + end + end + + context "when public user" do + before do + user.update!(published_at: Time.current) + sign_in user + end + + it "permits create action" do + post :create, xhr: true, params: params + expect(response).to have_http_status(:ok).or have_http_status(:no_content) + end + end + end +end diff --git a/spec/controllers/decidim/debates/debates_controller_spec.rb b/spec/controllers/decidim/debates/debates_controller_spec.rb new file mode 100644 index 0000000..e05a00d --- /dev/null +++ b/spec/controllers/decidim/debates/debates_controller_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Debates::DebatesController, type: :controller do + routes { Decidim::Debates::Engine.routes } + + let(:organization) { create(:organization) } + let(:component) { create(:debates_component, :with_creation_enabled, organization: organization) } + let!(:debate) { create(:debate, component: component, author: user) } + let(:user) { create(:user, :confirmed, organization: organization) } + let(:params) { { component_id: component.id } } + + before do + request.env["decidim.current_organization"] = organization + request.env["decidim.current_participatory_space"] = component.participatory_space + request.env["decidim.current_component"] = component + end + + it_behaves_like "permittable create actions" + it_behaves_like "permittable new actions" + + describe "#edit" do + let(:params) do + { + id: debate.id, + component_id: component.id, + debate: { + title: "Test debates creation1", + description: "Test debates creation1 description" + } + } + end + + it_behaves_like "permittable update actions" + it_behaves_like "permittable edit actions" + end +end diff --git a/spec/controllers/decidim/meetings/meetings_controller_spec.rb b/spec/controllers/decidim/meetings/meetings_controller_spec.rb new file mode 100644 index 0000000..790dd2e --- /dev/null +++ b/spec/controllers/decidim/meetings/meetings_controller_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Meetings::MeetingsController, type: :controller do + routes { Decidim::Meetings::Engine.routes } + + let(:organization) { create(:organization) } + let(:participatory_process) { create :participatory_process, organization: organization } + let(:meeting_component) { create(:meeting_component, :with_creation_enabled, participatory_space: participatory_process) } + let(:meeting) { create :meeting, :online, :not_official, :published, author: user, component: meeting_component } + let(:user) { create(:user, :confirmed, organization: organization) } + let(:params) { { component_id: meeting_component.id } } + + before do + request.env["decidim.current_organization"] = organization + request.env["decidim.current_participatory_space"] = participatory_process + request.env["decidim.current_component"] = meeting_component + end + + it_behaves_like "permittable create actions" + it_behaves_like "permittable new actions" + + describe "#update" do + let(:params) do + { + id: meeting.id, + component_id: meeting_component.id, + meeting: { + title: generate_localized_title, + description: ::Decidim::Faker::Localized.wrapped("

", "

") { generate_localized_title }, + type_of_meeting: meeting.type_of_meeting, + online_meeting_url: meeting.online_meeting_url, + start_time: meeting.start_time, + end_time: meeting.end_time, + registration_type: meeting.registration_type, + available_slots: meeting.available_slots, + registration_terms: meeting.registration_terms + } + } + end + + it_behaves_like "permittable update actions" + it_behaves_like "permittable edit actions" + end +end diff --git a/spec/controllers/decidim/messaging/conversations_controller_spec.rb b/spec/controllers/decidim/messaging/conversations_controller_spec.rb new file mode 100644 index 0000000..30236a0 --- /dev/null +++ b/spec/controllers/decidim/messaging/conversations_controller_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Messaging + class ConversationsController < Decidim::ApplicationController + include ::Decidim::Privacy::ConversationsControllerExtensions + end + end +end + +describe Decidim::Messaging::ConversationsController, type: :controller do + routes { Decidim::Core::Engine.routes } + + let(:organization) { create(:organization) } + let(:user) { create(:user, :confirmed, organization: organization) } + let(:user1) { create(:user, organization: organization) } + let!(:conversation2) do + Decidim::Messaging::Conversation.start!( + originator: user, + interlocutors: [user1], + body: "Hi!" + ) + end + + before do + request.env["decidim.current_organization"] = organization + sign_in user + end + + describe "GET new" do + subject { get :new, params: { recipient_id: user.id } } + + context "when is private user" do + it "renders 404 error" do + expect(subject).to render_template("decidim/privacy/message_block") + end + end + + context "when messaging is disabled" do + let!(:user) { create(:user, :confirmed, organization: organization, allow_private_messaging: false, published_at: Time.current) } + + it "renders 404 error" do + expect(subject).to render_template("decidim/privacy/message_block") + end + end + + context "when is public and private messaing is enabled" do + let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } + + context "when is the same user" do + it "redirects to previous 2 participant created conversation" do + expect(subject).to redirect_to profile_path(user.nickname) + end + end + + context "when conversation with a private user" do + subject { get :new, params: { recipient_id: user1.id } } + + let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } + + it "redirects to previous 2 participant created conversation" do + expect(subject).to redirect_to profile_path(user.nickname) + end + end + + context "when conversation with a public user" do + subject { get :new, params: { recipient_id: user1.id } } + + let!(:user) { create(:user, :confirmed, organization: organization, published_at: Time.current) } + let!(:user1) { create(:user, organization: organization, published_at: Time.current) } + + it "redirects to previous 2 participant created conversation" do + expect(subject).to redirect_to conversation_path(conversation2) + end + end + end + end +end diff --git a/spec/controllers/decidim/own_user_groups_controller_spec.rb b/spec/controllers/decidim/own_user_groups_controller_spec.rb new file mode 100644 index 0000000..cef0b17 --- /dev/null +++ b/spec/controllers/decidim/own_user_groups_controller_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + class OwnUserGroupsController < ApplicationController + include ::Decidim::Privacy::OwnUserGroupsControllerExtensions + end +end + +describe Decidim::OwnUserGroupsController, type: :controller do + routes { Decidim::Core::Engine.routes } + + let!(:organization) { create(:organization) } + let!(:current_user) { create(:user, :admin, :confirmed, organization: organization) } + let!(:private_user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user]) } + let!(:user_group) { create(:user_group, decidim_organization_id: organization.id, users: [current_user], published_at: Time.current) } + + before do + request.env["decidim.current_organization"] = organization + sign_in current_user + end + + describe "#index" do + before do + allow(organization).to receive(:user_groups_enabled?).and_return(true) + end + + it "finds entire collection" do + get :index + expect(assigns(:user_groups)).to include(user_group) + expect(assigns(:user_groups)).to include(private_user_group) + end + end +end diff --git a/spec/controllers/decidim/proposals/proposals_controller_spec.rb b/spec/controllers/decidim/proposals/proposals_controller_spec.rb new file mode 100644 index 0000000..a3e69c9 --- /dev/null +++ b/spec/controllers/decidim/proposals/proposals_controller_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim + module Proposals + class ProposalsController + include ::Decidim::Privacy::PrivacyActionsExtensions + end + end +end + +describe Decidim::Proposals::ProposalsController, type: :controller do + routes { Decidim::Proposals::Engine.routes } + + let!(:user) { create(:user, :confirmed, organization: component.organization) } + let!(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } + + let(:proposal_params) do + { + component_id: component.id + } + end + let(:params) { { proposal: proposal_params } } + + before do + request.env["decidim.current_organization"] = component.organization + request.env["decidim.current_participatory_space"] = component.participatory_space + request.env["decidim.current_component"] = component + end + + it_behaves_like "permittable create actions" + it_behaves_like "permittable new actions" + + context "when updating" do + let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) } + let!(:proposal) { create(:proposal, component: component, users: [user]) } + let(:proposal_params) do + { + title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + body: "Ut sed dolor vitae purus volutpat venenatis. Donec sit amet sagittis sapien. Curabitur rhoncus ullamcorper feugiat. Aliquam et magna metus." + } + end + let(:params) do + { + id: proposal.id, + proposal: proposal_params + } + end + + it_behaves_like "permittable update actions" + it_behaves_like "permittable edit actions" + end +end diff --git a/spec/controllers/decidim/user_activities_controller_spec.rb b/spec/controllers/decidim/user_activities_controller_spec.rb new file mode 100644 index 0000000..131d5e0 --- /dev/null +++ b/spec/controllers/decidim/user_activities_controller_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::UserActivitiesController, type: :controller do + routes { Decidim::Core::Engine.routes } + + let(:organization) { create(:organization) } + let!(:user) { create(:user, nickname: "Nick", organization: organization, published_at: Time.current) } + + before do + request.env["decidim.current_organization"] = organization + end + + describe "#show" do + context "when user is private" do + let!(:user) { create(:user, nickname: "Nick", organization: organization) } + + it "renders private view" do + expect do + get :index, params: { nickname: "NICK" } + end.to raise_error(ActionController::RoutingError, "Missing user: NICK") + end + end + + context "with an unknown user" do + it "raises an ActionController::RoutingError" do + expect do + get :index, params: { nickname: "foobar" } + end.to raise_error(ActionController::RoutingError, "Missing user: foobar") + end + end + + context "with an user with uppercase" do + it "returns the lowercased user" do + get :index, params: { nickname: "NICK" } + expect(response).to render_template(:index) + end + end + end +end diff --git a/spec/forms/concerns/account_form_spec.rb b/spec/forms/concerns/account_form_spec.rb deleted file mode 100644 index 0296923..0000000 --- a/spec/forms/concerns/account_form_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe AccountForm do - subject do - described_class.new( - name: name, - email: email, - nickname: nickname, - password: password, - password_confirmation: password_confirmation, - avatar: avatar, - remove_avatar: remove_avatar, - personal_url: personal_url, - about: about, - locale: "es" - ).with_context( - current_organization: organization, - current_user: user - ) - end - - let(:user) { create(:user) } - let(:organization) { user.organization } - - let(:name) { "Lord of the Foo" } - let(:email) { "depths@ofthe.bar" } - let(:nickname) { "foo_bar" } - let(:password) { "Rf9kWTqQfyqkwseH" } - let(:password_confirmation) { password } - let(:avatar) { upload_test_file(Decidim::Dev.test_file("avatar.jpg", "image/jpeg")) } - let(:remove_avatar) { false } - let(:personal_url) { "http://example.org" } - let(:about) { "This is a description about me" } - - context "with correct data" do - it "is valid" do - expect(subject).to be_valid - end - end - - describe "email" do - context "when it's already in use in the same organization" do - context "and belongs to a private user" do - let!(:existing_user) { create(:user, email: email, organization: organization) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "and belongs to a public user" do - let!(:existing_user) { create(:user, email: email, organization: organization, published_at: Time.current) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "and belongs to a group" do - let!(:existing_group) { create(:user_group, email: email, organization: organization) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - end - - context "when it's already in use in another organization" do - let!(:existing_user) { create(:user, email: email) } - - it "is valid" do - expect(subject).to be_valid - end - end - end - - describe "nickname" do - context "when it's already in use in the same organization" do - context "and belongs to a private user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "and belongs to a public user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "and belongs to a group" do - let!(:existing_group) { create(:user_group, nickname: nickname, organization: organization) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - end - end - end -end diff --git a/spec/forms/concerns/conference_speaker_form_spec.rb b/spec/forms/concerns/conference_speaker_form_spec.rb deleted file mode 100644 index adc7eed..0000000 --- a/spec/forms/concerns/conference_speaker_form_spec.rb +++ /dev/null @@ -1,106 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "decidim/conferences/test/factories" - -module Decidim - module Conferences - module Admin - describe ConferenceSpeakerForm do - subject(:form) { described_class.from_params(attributes).with_context(context) } - - let(:organization) { create :organization } - let(:conference) { create :conference, organization: organization } - let(:current_participatory_space) { conference } - let(:meeting_component) do - create(:component, manifest_name: :meetings, participatory_space: conference) - end - - let(:meetings) do - create_list( - :meeting, - 3, - component: meeting_component - ) - end - - let(:conference_meetings) do - meetings.each do |meeting| - meeting.becomes(Decidim::ConferenceMeeting) - end - end - - let(:conference_meeting_ids) { conference_meetings.map(&:id) } - - let(:context) do - { - current_participatory_space: conference, - current_organization: organization - } - end - - let(:full_name) { "Full name" } - let(:position) { Decidim::Faker::Localized.word } - let(:affiliation) { Decidim::Faker::Localized.word } - let(:short_bio) { Decidim::Faker::Localized.sentence } - let(:twitter_handle) { "full_name" } - let(:personal_url) { "http://decidim.org" } - let(:avatar) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) } - let(:existing_user) { false } - let(:user_id) { nil } - let(:attributes) do - { - "conference_speaker" => { - "full_name" => full_name, - "position" => position, - "affiliation" => affiliation, - "short_bio" => short_bio, - "twitter_handle" => twitter_handle, - "personal_url" => personal_url, - "avatar" => avatar, - "existing_user" => existing_user, - "user_id" => user_id, - "conference_meeting_ids" => conference_meeting_ids - } - } - end - - context "when everything is OK" do - it { is_expected.to be_valid } - end - - context "when existing user is present" do - let(:existing_user) { true } - - context "and a private user exists" do - let(:user_id) { create(:user, organization: organization).id } - - it { is_expected.to be_valid } - end - - context "and a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } - - it { is_expected.to be_valid } - end - end - - describe "user" do - subject { form.user } - - context "when a private user exists" do - let(:user_id) { create(:user, organization: organization).id } - - it { is_expected.to be_kind_of(Decidim::User) } - end - - context "when a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } - - it { is_expected.to be_kind_of(Decidim::User) } - end - end - end - end - end -end diff --git a/spec/forms/concerns/conversation_form_spec.rb b/spec/forms/concerns/conversation_form_spec.rb deleted file mode 100644 index 7d5fb82..0000000 --- a/spec/forms/concerns/conversation_form_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Messaging - describe ConversationForm do - subject { form } - - let(:body) { "Hi!" } - let(:recipient_id) { create(:user, organization: sender.organization, published_at: Time.current).id } - let(:sender) { create(:user) } - let(:params) do - { - body: body, - recipient_id: recipient_id - } - end - let(:form) do - described_class.from_params(params).with_context(sender: sender) - end - - context "when everything is OK" do - it { is_expected.to be_valid } - end - - context "when private recipient" do - let!(:recipient_id) { create(:user, organization: sender.organization).id } - - it { is_expected.to be_invalid } - end - end - end -end diff --git a/spec/forms/concerns/meetings_registeration_invite_form_spec.rb b/spec/forms/concerns/meetings_registeration_invite_form_spec.rb deleted file mode 100644 index 53601aa..0000000 --- a/spec/forms/concerns/meetings_registeration_invite_form_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim::Meetings - describe Admin::MeetingRegistrationInviteForm do - subject(:form) { described_class.from_params(attributes).with_context(context) } - - let(:organization) { create :organization } - let(:context) do - { - current_organization: organization - } - end - - let(:name) { "Foo" } - let(:email) { "foo@example.org" } - let(:existing_user) { true } - let(:user_id) { nil } - let(:attributes) do - { - name: name, - email: email, - existing_user: existing_user, - user_id: user_id - } - end - - context "when existing user is present" do - context "and no user is provided" do - it { is_expected.to be_invalid } - end - - context "and a private user exists" do - let(:user_id) { create(:user, organization: organization).id } - - it { is_expected.to be_valid } - end - - context "and a public user exists" do - let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } - - it { is_expected.to be_valid } - end - end - end -end diff --git a/spec/forms/concerns/user_groups_form_spec.rb b/spec/forms/concerns/user_groups_form_spec.rb deleted file mode 100644 index e68b774..0000000 --- a/spec/forms/concerns/user_groups_form_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -# frozen_string_literal: true - -# bfrozen_string_literal: true - -require "spec_helper" - -module Decidim - describe UserGroupForm do - subject do - described_class.new( - name: name, - email: email, - nickname: nickname, - phone: phone, - document_number: document_number, - avatar: avatar, - about: about - ).with_context( - current_organization: organization, - current_user: user - ) - end - - let(:user) { create(:user) } - let(:organization) { user.organization } - - let(:name) { "Lord of the Foo" } - let(:email) { "depths@ofthe.bar" } - let(:nickname) { "foo_bar" } - let(:phone) { "987654321" } - let(:document_number) { "12345678X" } - let(:avatar) { upload_test_file(Decidim::Dev.test_file("avatar.jpg", "image/jpeg")) } - let(:about) { "This is a description about me" } - - context "with correct data" do - it "is valid" do - expect(subject).to be_valid - end - end - - describe "nickname" do - context "with an empty nickname" do - let(:nickname) { "" } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "when it's already in use in the same organization" do - context "when private user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - - context "when public user" do - let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } - - it "is invalid" do - expect(subject).not_to be_valid - end - end - end - - context "when it's already in use in another organization" do - let!(:existing_user) { create(:user, nickname: nickname) } - - it "is valid" do - expect(subject).to be_valid - end - end - end - end -end diff --git a/spec/forms/decidim/account_form_spec.rb b/spec/forms/decidim/account_form_spec.rb new file mode 100644 index 0000000..de36cf5 --- /dev/null +++ b/spec/forms/decidim/account_form_spec.rb @@ -0,0 +1,106 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::AccountForm do + subject do + described_class.new( + name: name, + email: email, + nickname: nickname, + password: password, + password_confirmation: password_confirmation, + avatar: avatar, + remove_avatar: remove_avatar, + personal_url: personal_url, + about: about, + locale: "es" + ).with_context( + current_organization: organization, + current_user: user + ) + end + + let(:user) { create(:user) } + let(:organization) { user.organization } + + let(:name) { "Lord of the Foo" } + let(:email) { "depths@ofthe.bar" } + let(:nickname) { "foo_bar" } + let(:password) { "Rf9kWTqQfyqkwseH" } + let(:password_confirmation) { password } + let(:avatar) { upload_test_file(Decidim::Dev.test_file("avatar.jpg", "image/jpeg")) } + let(:remove_avatar) { false } + let(:personal_url) { "http://example.org" } + let(:about) { "This is a description about me" } + + context "with correct data" do + it "is valid" do + expect(subject).to be_valid + end + end + + describe "email" do + context "when it's already in use in the same organization" do + context "and belongs to a private user" do + let!(:existing_user) { create(:user, email: email, organization: organization) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "and belongs to a public user" do + let!(:existing_user) { create(:user, email: email, organization: organization, published_at: Time.current) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "and belongs to a group" do + let!(:existing_group) { create(:user_group, email: email, organization: organization) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + end + + context "when it's already in use in another organization" do + let!(:existing_user) { create(:user, email: email) } + + it "is valid" do + expect(subject).to be_valid + end + end + end + + describe "nickname" do + context "when it's already in use in the same organization" do + context "and belongs to a private user" do + let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "and belongs to a public user" do + let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "and belongs to a group" do + let!(:existing_group) { create(:user_group, nickname: nickname, organization: organization) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + end + end +end diff --git a/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb b/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb new file mode 100644 index 0000000..9150802 --- /dev/null +++ b/spec/forms/decidim/conferences/admin/conference_speaker_form_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +require "spec_helper" +require "decidim/conferences/test/factories" + +describe Decidim::Conferences::Admin::ConferenceSpeakerForm do + subject(:form) { described_class.from_params(attributes).with_context(context) } + + let(:organization) { create :organization } + let(:conference) { create :conference, organization: organization } + let(:current_participatory_space) { conference } + let(:meeting_component) do + create(:component, manifest_name: :meetings, participatory_space: conference) + end + + let(:meetings) do + create_list( + :meeting, + 3, + component: meeting_component + ) + end + + let(:conference_meetings) do + meetings.each do |meeting| + meeting.becomes(Decidim::ConferenceMeeting) + end + end + + let(:conference_meeting_ids) { conference_meetings.map(&:id) } + + let(:context) do + { + current_participatory_space: conference, + current_organization: organization + } + end + + let(:full_name) { "Full name" } + let(:position) { Decidim::Faker::Localized.word } + let(:affiliation) { Decidim::Faker::Localized.word } + let(:short_bio) { Decidim::Faker::Localized.sentence } + let(:twitter_handle) { "full_name" } + let(:personal_url) { "http://decidim.org" } + let(:avatar) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) } + let(:existing_user) { false } + let(:user_id) { nil } + let(:attributes) do + { + "conference_speaker" => { + "full_name" => full_name, + "position" => position, + "affiliation" => affiliation, + "short_bio" => short_bio, + "twitter_handle" => twitter_handle, + "personal_url" => personal_url, + "avatar" => avatar, + "existing_user" => existing_user, + "user_id" => user_id, + "conference_meeting_ids" => conference_meeting_ids + } + } + end + + context "when everything is OK" do + it { is_expected.to be_valid } + end + + context "when existing user is present" do + let(:existing_user) { true } + + context "and a private user exists" do + let(:user_id) { create(:user, organization: organization).id } + + it { is_expected.to be_valid } + end + + context "and a public user exists" do + let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + + it { is_expected.to be_valid } + end + end + + describe "user" do + subject { form.user } + + context "when a private user exists" do + let(:user_id) { create(:user, organization: organization).id } + + it { is_expected.to be_kind_of(Decidim::User) } + end + + context "when a public user exists" do + let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + + it { is_expected.to be_kind_of(Decidim::User) } + end + end +end diff --git a/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb b/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb new file mode 100644 index 0000000..a2b1a6e --- /dev/null +++ b/spec/forms/decidim/meetings/admin/meeting_registration_invite_form_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Meetings::Admin::MeetingRegistrationInviteForm do + subject(:form) { described_class.from_params(attributes).with_context(context) } + + let(:organization) { create :organization } + let(:context) do + { + current_organization: organization + } + end + + let(:name) { "Foo" } + let(:email) { "foo@example.org" } + let(:existing_user) { true } + let(:user_id) { nil } + let(:attributes) do + { + name: name, + email: email, + existing_user: existing_user, + user_id: user_id + } + end + + context "when existing user is present" do + context "and no user is provided" do + it { is_expected.to be_invalid } + end + + context "and a private user exists" do + let(:user_id) { create(:user, organization: organization).id } + + it { is_expected.to be_valid } + end + + context "and a public user exists" do + let(:user_id) { create(:user, organization: organization, published_at: Time.current).id } + + it { is_expected.to be_valid } + end + end +end diff --git a/spec/forms/decidim/messaging/conversation_form_spec.rb b/spec/forms/decidim/messaging/conversation_form_spec.rb new file mode 100644 index 0000000..7f0dc19 --- /dev/null +++ b/spec/forms/decidim/messaging/conversation_form_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Messaging::ConversationForm do + subject { form } + + let(:body) { "Hi!" } + let(:recipient_id) { create(:user, organization: sender.organization, published_at: Time.current).id } + let(:sender) { create(:user) } + let(:params) do + { + body: body, + recipient_id: recipient_id + } + end + let(:form) do + described_class.from_params(params).with_context(sender: sender) + end + + context "when everything is OK" do + it { is_expected.to be_valid } + end + + context "when private recipient" do + let!(:recipient_id) { create(:user, organization: sender.organization).id } + + it { is_expected.to be_invalid } + end +end diff --git a/spec/forms/decidim/privacy/privacy_settings_form_spec.rb b/spec/forms/decidim/privacy/privacy_settings_form_spec.rb index c550f71..ed11719 100644 --- a/spec/forms/decidim/privacy/privacy_settings_form_spec.rb +++ b/spec/forms/decidim/privacy/privacy_settings_form_spec.rb @@ -2,38 +2,35 @@ require "spec_helper" -module Decidim - module Privacy - describe PrivacySettingsForm do - subject { described_class.from_model(user).with_context(context) } - let(:organization) { create(:organization) } - let(:context) { { current_organization: organization } } - let(:user) { create(:user, organization: organization) } - - describe "#map_model" do - context "when private user" do - it "maps the model correctly" do - expect(subject.published_at).to be(false) - expect(subject.allow_private_messaging).to be(true) - expect(subject.allow_public_contact).to be(true) - end - end - - context "with public user" do - let!(:user) { create(:user, organization: organization, published_at: Time.current) } - - it "maps the model correctly" do - expect(subject.published_at).to be(true) - end - end - - context "with no direct message allowed" do - let!(:user) { create(:user, organization: organization, direct_message_types: "followed-only") } - - it "maps the model correctly" do - expect(subject.published_at).to be(false) - end - end +describe Decidim::Privacy::PrivacySettingsForm do + subject { described_class.from_model(user).with_context(context) } + + let(:organization) { create(:organization) } + let(:context) { { current_organization: organization } } + let(:user) { create(:user, organization: organization) } + + describe "#map_model" do + context "when private user" do + it "maps the model correctly" do + expect(subject.published_at).to be(false) + expect(subject.allow_private_messaging).to be(true) + expect(subject.allow_public_contact).to be(true) + end + end + + context "with public user" do + let!(:user) { create(:user, organization: organization, published_at: Time.current) } + + it "maps the model correctly" do + expect(subject.published_at).to be(true) + end + end + + context "with no direct message allowed" do + let!(:user) { create(:user, organization: organization, direct_message_types: "followed-only") } + + it "maps the model correctly" do + expect(subject.published_at).to be(false) end end end diff --git a/spec/forms/decidim/privacy/publish_account_form_spec.rb b/spec/forms/decidim/privacy/publish_account_form_spec.rb index 4acf0e0..92d1a47 100644 --- a/spec/forms/decidim/privacy/publish_account_form_spec.rb +++ b/spec/forms/decidim/privacy/publish_account_form_spec.rb @@ -2,39 +2,35 @@ require "spec_helper" -module Decidim - module Privacy - describe PublishAccountForm do - subject(:form) { described_class.from_params(attributes) } +describe Decidim::Privacy::PublishAccountForm do + subject(:form) { described_class.from_params(attributes) } - let(:attributes) do - { agree_public_profile: agree_public_profile } - end + let(:attributes) do + { agree_public_profile: agree_public_profile } + end - describe "#agree_public_profile" do - context "when everything is ok" do - let(:agree_public_profile) { true } + describe "#agree_public_profile" do + context "when everything is ok" do + let(:agree_public_profile) { true } - it "is valid" do - expect(subject).to be_valid - end - end + it "is valid" do + expect(subject).to be_valid + end + end - context "when nil" do - let(:agree_public_profile) { nil } + context "when nil" do + let(:agree_public_profile) { nil } - it "is invalid" do - expect(subject).to be_invalid - end - end + it "is invalid" do + expect(subject).to be_invalid + end + end - context "when is false" do - let(:agree_public_profile) { false } + context "when is false" do + let(:agree_public_profile) { false } - it "is valid" do - expect(subject).to be_invalid - end - end + it "is valid" do + expect(subject).to be_invalid end end end diff --git a/spec/forms/decidim/user_group_form_spec.rb b/spec/forms/decidim/user_group_form_spec.rb new file mode 100644 index 0000000..9f1cd18 --- /dev/null +++ b/spec/forms/decidim/user_group_form_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::UserGroupForm do + subject do + described_class.new( + name: name, + email: email, + nickname: nickname, + phone: phone, + document_number: document_number, + avatar: avatar, + about: about + ).with_context( + current_organization: organization, + current_user: user + ) + end + + let(:user) { create(:user) } + let(:organization) { user.organization } + + let(:name) { "Lord of the Foo" } + let(:email) { "depths@ofthe.bar" } + let(:nickname) { "foo_bar" } + let(:phone) { "987654321" } + let(:document_number) { "12345678X" } + let(:avatar) { upload_test_file(Decidim::Dev.test_file("avatar.jpg", "image/jpeg")) } + let(:about) { "This is a description about me" } + + context "with correct data" do + it "is valid" do + expect(subject).to be_valid + end + end + + describe "nickname" do + context "with an empty nickname" do + let(:nickname) { "" } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "when it's already in use in the same organization" do + context "when private user" do + let!(:existing_user) { create(:user, nickname: nickname, organization: organization) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + + context "when public user" do + let!(:existing_user) { create(:user, nickname: nickname, organization: organization, published_at: Time.current) } + + it "is invalid" do + expect(subject).not_to be_valid + end + end + end + + context "when it's already in use in another organization" do + let!(:existing_user) { create(:user, nickname: nickname) } + + it "is valid" do + expect(subject).to be_valid + end + end + end +end diff --git a/spec/helpers/concerns/action_authorization_helper_spec.rb b/spec/helpers/concerns/action_authorization_helper_spec.rb deleted file mode 100644 index 5f7560a..0000000 --- a/spec/helpers/concerns/action_authorization_helper_spec.rb +++ /dev/null @@ -1,177 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe ActionAuthorizationHelper do - let(:component) { create(:component) } - let(:resource) { nil } - let(:permissions_holder) { nil } - let(:user) { create(:user) } - let(:action) { "foo" } - let(:status) { double(ok?: authorized) } - let(:authorized) { true } - - let(:widget_text) { "Link" } - let(:path) { "fake_path" } - - before do - allow(helper).to receive(:current_component).and_return(component) - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:action_authorized_to).with(action, resource: resource, permissions_holder: permissions_holder).and_return(status) - end - - shared_examples "an action authorization widget helper" do |params| - if params[:has_action] - context "when the action is not authorized" do - let(:authorized) { false } - - it "renders a widget toggling the authorization modal" do - expect(subject).not_to include(path) - expect(subject).to include('data-open="authorizationModal"') - expect(subject).to include("data-open-url=\"/authorization_modals/#{action}/f/#{component.id}\"") - expect(subject).to include(*params[:widget_parts]) - end - - context "when called with a resource" do - let(:resource) { create(:dummy_resource, component: component) } - - it "renders a widget toggling the authorization modal" do - expect(subject).not_to include(path) - expect(subject).to include('data-open="authorizationModal"') - expect(subject).to include("data-open-url=\"/authorization_modals/#{action}/f/#{component.id}/#{resource.resource_manifest.name}/#{resource.id}\"") - expect(subject).to include(*params[:widget_parts]) - end - end - - context "when called with no component and permissions_holder" do - let(:component) { nil } - let(:resource) { create(:dummy_resource) } - let(:permissions_holder) { resource } - - it "renders a widget toggling the authorization modal of free resources not related with a component" do - expect(subject).not_to include(path) - expect(subject).to include('data-open="authorizationModal"') - expect(subject).to include("data-open-url=\"/free_resource_authorization_modals/#{action}/f/#{resource.resource_manifest.name}/#{resource.id}\"") - expect(subject).to include(*params[:widget_parts]) - end - end - - describe "#allowed_publicly_to?" do - before do - allow(controller).to receive(:allowed_publicly_to?).and_return(allowed_publicly_to?) - allow(Digest::MD5).to receive(:hexdigest).and_return("dummy12345678") - end - - context "when not allowed publicly" do - let(:allowed_publicly_to?) { false } - let(:expected_data_privacy) do - { - open: "authorizationModal", - openUrl: "/authorization_modals/foo/f/#{component.id}" - }.compact.to_json - end - - it "renders a widget toggling the publish account modal" do - expect(subject).not_to include(path) - expect(CGI.unescapeHTML(subject)).to include("data-privacy=\"#{expected_data_privacy}\"") - expect(subject).to include('data-open="publishAccountModal"') - expect(subject).not_to include("data-open-url") - expect(subject).to include('id="authorize-dummy12345678"') - end - - context "when authorized but public action" do - let(:authorized) { true } - - it "adds data-open without data-privacy" do - expect(subject).not_to include(path) - expect(subject).to include("data-privacy=\"{}\"") - expect(subject).to include('data-open="publishAccountModal"') - expect(subject).not_to include("data-open-url") - expect(subject).to include('id="authorize-dummy12345678"') - end - end - end - end - end - - else - let(:action) { nil } - end - - context "when #{params[:has_action] ? "the action is authorized" : "the user is logged"}" do - it "renders a regular widget" do - expect(subject).not_to include("data-open") - expect(subject).to include(path) - expect(subject).to include(*params[:widget_parts]) - end - end - - context "when there is not a logged user" do - let(:user) { nil } - - it "renders a widget toggling the login modal" do - expect(subject).not_to include(path) - expect(subject).to include('data-open="loginModal"') - expect(subject).to include(*params[:widget_parts]) - end - end - end - - describe "action_authorized_link_to" do - context "when called with text" do - subject(:rendered) { helper.action_authorized_link_to(action, widget_text, path, resource: resource, permissions_holder: permissions_holder) } - - it_behaves_like "an action authorization widget helper", has_action: true, widget_parts: %w(Private participant" - end - end - - context "when public user" do - let(:user) { create :user, :confirmed, :published } - - it "includes the user name" do - expect(helper.username_list(participants)).to eq "#{user.name}" - end - end - - context "when user is deleted" do - let(:user) { create :user, :deleted } - - it "does not include the user name" do - expect(helper.username_list(participants)).to eq "Participant deleted" - end - end - end - - describe "#conversation_name_for" do - let(:user) { create :user, :confirmed } - let(:participants) { [user] } - - before do - helper.instance_variable_set(:@virtual_path, "decidim.messaging.conversations.show") - end - - context "when user is public" do - let(:user) { create :user, :confirmed, :published } - - it "includes the user name" do - expect(helper.conversation_name_for(participants)).to eq "#{user.name}
@#{user.nickname}" - end - end - - context "when private user" do - it "includes the user name" do - expect(helper.conversation_name_for(participants)).to eq "Private participant
This participant has decided to make their profile private. New messages to this conversation have been therefore disabled." - end - end - - context "when user is deleted" do - let(:user) { create :user, :deleted } - - it "does not include the user name" do - expect(helper.conversation_name_for(participants)).to eq "Participant deleted" - end - end - end - end - end -end diff --git a/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb b/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb new file mode 100644 index 0000000..ebbab15 --- /dev/null +++ b/spec/helpers/concerns/decidim/privacy/endorsable_helper_extensions_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Privacy::EndorsableHelperExtensions do + let(:endorsements_enabled) { true } + let(:user) { create(:user, :confirmed) } + + describe "#endorsements_enabled?" do + subject { helper.endorsements_enabled? } + + before do + allow(helper).to receive(:current_settings).and_return(double(endorsements_enabled: endorsements_enabled)) + allow(helper).to receive(:current_user).and_return(user) + end + + context "when user is private" do + it "does not allow endorsing" do + expect(subject).to be(false) + end + end + + context "when user is public" do + let(:user) { create(:user, :confirmed, :published) } + + it "allows endorsing" do + expect(subject).to be(true) + end + end + end + + describe "#show_endorsements_card?" do + subject { helper.show_endorsements_card? } + + context "when user not logged in" do + it "returns false" do + allow(helper).to receive(:current_user).and_return(nil) + + expect(subject).to be(false) + end + end + + context "when user logged in" do + it "returns true" do + allow(helper).to receive(:current_user).and_return(user) + + expect(subject).to be(true) + end + end + end +end diff --git a/spec/helpers/concerns/endorsable_helper_spec.rb b/spec/helpers/concerns/endorsable_helper_spec.rb deleted file mode 100644 index fa0977b..0000000 --- a/spec/helpers/concerns/endorsable_helper_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Privacy - describe EndorsableHelperExtensions do - let(:endorsements_enabled) { true } - let(:user) { create(:user, :confirmed) } - - describe "#endorsements_enabled?" do - subject { helper.endorsements_enabled? } - - before do - allow(helper).to receive(:current_settings).and_return(double(endorsements_enabled: endorsements_enabled)) - allow(helper).to receive(:current_user).and_return(user) - end - - context "when user is private" do - it "does not allow endorsing" do - expect(subject).to be(false) - end - end - - context "when user is public" do - let(:user) { create(:user, :confirmed, :published) } - - it "allows endorsing" do - expect(subject).to be(true) - end - end - end - - describe "#show_endorsements_card?" do - subject { helper.show_endorsements_card? } - - context "when user not logged in" do - it "returns false" do - allow(helper).to receive(:current_user).and_return(nil) - - expect(subject).to be(false) - end - end - - context "when user logged in" do - it "returns true" do - allow(helper).to receive(:current_user).and_return(user) - - expect(subject).to be(true) - end - end - end - end - end -end diff --git a/spec/helpers/decidim/action_authorization_helper_spec.rb b/spec/helpers/decidim/action_authorization_helper_spec.rb new file mode 100644 index 0000000..f3244e3 --- /dev/null +++ b/spec/helpers/decidim/action_authorization_helper_spec.rb @@ -0,0 +1,175 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::ActionAuthorizationHelper do + let(:component) { create(:component) } + let(:resource) { nil } + let(:permissions_holder) { nil } + let(:user) { create(:user) } + let(:action) { "foo" } + let(:status) { double(ok?: authorized) } + let(:authorized) { true } + + let(:widget_text) { "Link" } + let(:path) { "fake_path" } + + before do + allow(helper).to receive(:current_component).and_return(component) + allow(helper).to receive(:current_user).and_return(user) + allow(helper).to receive(:action_authorized_to).with(action, resource: resource, permissions_holder: permissions_holder).and_return(status) + end + + shared_examples "an action authorization widget helper" do |params| + if params[:has_action] + context "when the action is not authorized" do + let(:authorized) { false } + + it "renders a widget toggling the authorization modal" do + expect(subject).not_to include(path) + expect(subject).to include('data-open="authorizationModal"') + expect(subject).to include("data-open-url=\"/authorization_modals/#{action}/f/#{component.id}\"") + expect(subject).to include(*params[:widget_parts]) + end + + context "when called with a resource" do + let(:resource) { create(:dummy_resource, component: component) } + + it "renders a widget toggling the authorization modal" do + expect(subject).not_to include(path) + expect(subject).to include('data-open="authorizationModal"') + expect(subject).to include("data-open-url=\"/authorization_modals/#{action}/f/#{component.id}/#{resource.resource_manifest.name}/#{resource.id}\"") + expect(subject).to include(*params[:widget_parts]) + end + end + + context "when called with no component and permissions_holder" do + let(:component) { nil } + let(:resource) { create(:dummy_resource) } + let(:permissions_holder) { resource } + + it "renders a widget toggling the authorization modal of free resources not related with a component" do + expect(subject).not_to include(path) + expect(subject).to include('data-open="authorizationModal"') + expect(subject).to include("data-open-url=\"/free_resource_authorization_modals/#{action}/f/#{resource.resource_manifest.name}/#{resource.id}\"") + expect(subject).to include(*params[:widget_parts]) + end + end + + describe "#allowed_publicly_to?" do + before do + allow(controller).to receive(:allowed_publicly_to?).and_return(allowed_publicly_to?) + allow(Digest::MD5).to receive(:hexdigest).and_return("dummy12345678") + end + + context "when not allowed publicly" do + let(:allowed_publicly_to?) { false } + let(:expected_data_privacy) do + { + open: "authorizationModal", + openUrl: "/authorization_modals/foo/f/#{component.id}" + }.compact.to_json + end + + it "renders a widget toggling the publish account modal" do + expect(subject).not_to include(path) + expect(CGI.unescapeHTML(subject)).to include("data-privacy=\"#{expected_data_privacy}\"") + expect(subject).to include('data-open="publishAccountModal"') + expect(subject).not_to include("data-open-url") + expect(subject).to include('id="authorize-dummy12345678"') + end + + context "when authorized but public action" do + let(:authorized) { true } + + it "adds data-open without data-privacy" do + expect(subject).not_to include(path) + expect(subject).to include("data-privacy=\"{}\"") + expect(subject).to include('data-open="publishAccountModal"') + expect(subject).not_to include("data-open-url") + expect(subject).to include('id="authorize-dummy12345678"') + end + end + end + end + end + + else + let(:action) { nil } + end + + context "when #{params[:has_action] ? "the action is authorized" : "the user is logged"}" do + it "renders a regular widget" do + expect(subject).not_to include("data-open") + expect(subject).to include(path) + expect(subject).to include(*params[:widget_parts]) + end + end + + context "when there is not a logged user" do + let(:user) { nil } + + it "renders a widget toggling the login modal" do + expect(subject).not_to include(path) + expect(subject).to include('data-open="loginModal"') + expect(subject).to include(*params[:widget_parts]) + end + end + end + + describe "action_authorized_link_to" do + context "when called with text" do + subject(:rendered) { helper.action_authorized_link_to(action, widget_text, path, resource: resource, permissions_holder: permissions_holder) } + + it_behaves_like "an action authorization widget helper", has_action: true, widget_parts: %w(Private participant" + end + end + + context "when public user" do + let(:user) { create :user, :confirmed, :published } + + it "includes the user name" do + expect(helper.username_list(participants)).to eq "#{user.name}" + end + end + + context "when user is deleted" do + let(:user) { create :user, :deleted } + + it "does not include the user name" do + expect(helper.username_list(participants)).to eq "Participant deleted" + end + end + end + + describe "#conversation_name_for" do + let(:user) { create :user, :confirmed } + let(:participants) { [user] } + + before do + helper.instance_variable_set(:@virtual_path, "decidim.messaging.conversations.show") + end + + context "when user is public" do + let(:user) { create :user, :confirmed, :published } + + it "includes the user name" do + expect(helper.conversation_name_for(participants)).to eq "#{user.name}
@#{user.nickname}" + end + end + + context "when private user" do + it "includes the user name" do + expect(helper.conversation_name_for(participants)).to eq "Private participant
This participant has decided to make their profile private. New messages to this conversation have been therefore disabled." + end + end + + context "when user is deleted" do + let(:user) { create :user, :deleted } + + it "does not include the user name" do + expect(helper.conversation_name_for(participants)).to eq "Participant deleted" + end + end + end +end diff --git a/spec/models/concerns/collaborative_draft_spec.rb b/spec/models/concerns/collaborative_draft_spec.rb deleted file mode 100644 index 07991e0..0000000 --- a/spec/models/concerns/collaborative_draft_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Proposals - describe CollaborativeDraft do - subject { collaborative_draft } - - let(:organization) { component.participatory_space.organization } - let(:component) { create :proposal_component } - let(:collaborative_draft) { create(:collaborative_draft, component: component, users: authors) } - - describe "#authors" do - let(:private_user) { create(:user, :confirmed, organization: organization) } - let(:public_users) { create_list(:user, 3, :confirmed, :published, organization: organization) } - let(:authors) { public_users + [private_user] } - - it "filters out private authors" do - expect(subject.authors).not_to include(private_user) - expect(subject.authors).to match_array(public_users) - end - end - - describe "editable_by" do - let(:authors) { [private_user, public_user] } - let(:public_user) { create(:user, :confirmed, :published, organization: organization) } - let(:private_user) { create(:user, :confirmed, organization: organization) } - - it "is editable by public author" do - expect(subject.editable_by?(public_user)).to be true - end - - it "is not editable by private author" do - expect(subject.editable_by?(private_user)).not_to be true - end - end - end - end -end diff --git a/spec/models/concerns/comment_spec.rb b/spec/models/concerns/comment_spec.rb deleted file mode 100644 index 4626bc7..0000000 --- a/spec/models/concerns/comment_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Comments - describe Comment do - let!(:commentable) { create(:dummy_resource) } - let!(:author) { create(:user, :published, organization: commentable.organization) } - let!(:comment) { create(:comment, commentable: commentable, author: author) } - - describe "#author" do - subject { comment } - - context "when private" do - before do - author.update(published_at: nil) - end - - it "returns privateuser instance" do - expect(subject.author).to be_an_instance_of(::Decidim::Privacy::PrivateUser) - end - end - - context "when public" do - it "returns author" do - expect(subject.author).to eq(author) - end - end - end - end - end -end diff --git a/spec/models/concerns/conversation_spec.rb b/spec/models/concerns/conversation_spec.rb deleted file mode 100644 index 141a37a..0000000 --- a/spec/models/concerns/conversation_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -module Decidim - module Messaging - describe Conversation do - describe ".start_conversation" do - subject { conversation } - let(:originator) { create(:user) } - let(:public_interlocutor) { create(:user, :published) } - let(:private_interlocutor) { create(:user) } - let(:from) { nil } - let(:receipts) { conversation.receipts } - - let(:conversation) do - described_class.start!( - originator: originator, - interlocutors: [public_interlocutor, private_interlocutor], - body: "Hei!" - ) - end - - describe "#participants" do - before do - allow(public_interlocutor).to receive(:accepts_conversation?).and_return(true) - allow(private_interlocutor).to receive(:accepts_conversation?).and_return(true) - end - - it "contains entire collection" do - expect(subject.participants).to include(private_interlocutor) - expect(subject.participants).to include(public_interlocutor) - end - end - end - end - end -end diff --git a/spec/models/concerns/initiative_spec.rb b/spec/models/concerns/initiative_spec.rb deleted file mode 100644 index 5cd4bd6..0000000 --- a/spec/models/concerns/initiative_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe Initiative do - subject { initiative } - let(:organization) { create(:organization) } - let(:initiative) { create(:initiative, organization: organization, author: private_user) } - - describe "#author_users" do - let(:private_user) { create(:user, :confirmed, organization: organization) } - let(:rejected_user) { create(:user, :confirmed, organization: organization) } - let(:public_user) { create(:user, :confirmed, :published, organization: organization) } - let(:private_member) { create(:initiatives_committee_member, :accepted, initiative: initiative, user: private_user) } - let(:public_member) { create(:initiatives_committee_member, :accepted, initiative: initiative, user: public_user) } - let(:rejected_member) { create(:initiatives_committee_member, :rejected, initiative: initiative) } - - context "when private author" do - it "returns public authors" do - expect(subject.author_users).not_to include(private_member) - expect(subject.author_users).not_to include(public_member) - expect(subject.author_users).not_to include(rejected_member) - expect(subject.author_users).to include(an_instance_of(Decidim::Privacy::PrivateUser)) - end - end - - context "when public author" do - let(:initiative) { create(:initiative, organization: organization, author: public_user) } - - it "returns public authors" do - expect(subject.author_users).to include(public_user) - expect(subject.author_users).not_to include(an_instance_of(Decidim::Privacy::PrivateUser)) - expect(subject.author_users).not_to include(private_member) - expect(subject.author_users).not_to include(rejected_member) - end - end - end - end -end diff --git a/spec/models/concerns/organization_spec.rb b/spec/models/concerns/organization_spec.rb deleted file mode 100644 index d2ff12b..0000000 --- a/spec/models/concerns/organization_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe Organization do - subject { organization } - - let!(:organization) { create(:organization) } - let!(:private_admin) { create(:user, :admin, organization: organization) } - let!(:public_admin) { create(:user, :admin, :published, organization: organization) } - let!(:private_user) { create(:user, :user_manager, organization: organization) } - let!(:public_user) { create(:user, :user_manager, :published, organization: organization) } - - describe "#admin" do - it "returns entire collection" do - expect(subject.admins).to include(private_admin) - expect(subject.admins).to include(public_admin) - end - end - - describe "#users_with_any_role" do - it "return entire collection of rolled users" do - expect(subject.users_with_any_role).not_to include(private_admin) - expect(subject.users_with_any_role).not_to include(public_admin) - expect(subject.users_with_any_role).to include(private_user) - expect(subject.users_with_any_role).to include(public_user) - end - end - end -end diff --git a/spec/models/concerns/user_base_entity_spec.rb b/spec/models/concerns/user_base_entity_spec.rb deleted file mode 100644 index 4fd70b4..0000000 --- a/spec/models/concerns/user_base_entity_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe UserBaseEntity do - subject { described_class } - let(:organization) { create(:organization) } - let(:published_user) { create(:user, :confirmed, :published, organization: organization) } - let(:private_user) { create(:user, :confirmed, organization: organization) } - let(:user_group) { create(:user_group, organization: organization) } - - describe "#default_scope" do - it "returns only published profiles by default" do - expect(subject.all).to include(published_user) - expect(subject.all).not_to include(private_user) - expect(subject.all).to include(user_group) - end - end - - describe "#entire_collection" do - it "returns entire collection" do - expect(subject.entire_collection.all).to include(published_user) - expect(subject.entire_collection.all).to include(private_user) - expect(subject.entire_collection.all).to include(user_group) - end - end - end -end diff --git a/spec/models/concerns/user_group_spec.rb b/spec/models/concerns/user_group_spec.rb deleted file mode 100644 index be18878..0000000 --- a/spec/models/concerns/user_group_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe UserGroup do - subject { described_class } - describe "usergroup extension" do - let!(:organization) { create(:organization) } - let(:private_verified) { create(:user_group, :verified, organization: organization) } - - let(:private_confirmed) { create(:user_group, :confirmed, organization: organization) } - let(:public_verified) { create(:user_group, :confirmed, :verified, published_at: Time.current, organization: organization) } - let!(:public_confirmed) { create(:user_group, :confirmed, published_at: Time.current, organization: organization) } - - describe "#scopes" do - it "returns visibles by default" do - result = subject.all - - expect(result).to include(public_verified) - expect(result).not_to include(private_verified) - expect(result).not_to include(private_confirmed) - expect(result).not_to include(public_confirmed) - end - - it "returns entire collextion correctly" do - result = subject.entire_collection - - expect(result).to include(public_verified) - expect(result).to include(private_verified) - expect(result).to include(private_confirmed) - expect(result).to include(public_confirmed) - end - end - end - end -end diff --git a/spec/models/concerns/user_spec.rb b/spec/models/concerns/user_spec.rb deleted file mode 100644 index 0fce09f..0000000 --- a/spec/models/concerns/user_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - describe User do - subject { described_class } - let!(:organization) { create(:organization) } - let!(:published_user) { create(:user, :confirmed, :published, organization: organization) } - let!(:private_user) { create(:user, :confirmed, organization: organization) } - - describe "#default_scope" do - it "returns published users by default" do - result = subject.all - expect(result).to include(published_user) - expect(result).not_to include(private_user) - end - end - - describe "#entire_collection" do - it "rerutns entire_collection when scoped" do - result = subject.entire_collection.all - expect(result).to include(published_user) - expect(result).to include(private_user) - end - end - - describe "#profile_private" do - it "returns private when scoped" do - result = subject.profile_private.all - expect(result).not_to include(published_user) - expect(result).to include(private_user) - end - end - - describe "#public?" do - it "return true if user is public" do - expect(private_user).not_to be_public - expect(published_user).to be_public - end - end - - describe "#private_messaging_disabled?" do - it "returns true only if use is public and disabled messaging" do - expect(private_user).not_to be_private_messaging_disabled - expect do - published_user.update(allow_private_messaging: false) - end.to change(published_user, :private_messaging_disabled?).from(false).to(true) - end - end - - describe "#private_or_no_messaging?" do - it "returns true if private or no_messaging" do - expect(private_user).to be_private_or_no_messaging - expect do - published_user.update(allow_private_messaging: false) - end.to change(published_user, :private_or_no_messaging?).from(false).to(true) - end - end - - describe "#accepts_conversation?" do - let!(:user) { create(:user, :published, :confirmed, organization: organization) } - - it "returns false if private messaging is turned off" do - published_user.update(allow_private_messaging: false) - - expect(published_user.accepts_conversation?(user)).to be(false) - end - end - end -end diff --git a/spec/models/decidim/comments/comment_spec.rb b/spec/models/decidim/comments/comment_spec.rb new file mode 100644 index 0000000..2df069a --- /dev/null +++ b/spec/models/decidim/comments/comment_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Comments::Comment do + let!(:commentable) { create(:dummy_resource) } + let!(:author) { create(:user, :published, organization: commentable.organization) } + let!(:comment) { create(:comment, commentable: commentable, author: author) } + + describe "#author" do + subject { comment } + + context "when private" do + before do + author.update(published_at: nil) + end + + it "returns privateuser instance" do + expect(subject.author).to be_an_instance_of(::Decidim::Privacy::PrivateUser) + end + end + + context "when public" do + it "returns author" do + expect(subject.author).to eq(author) + end + end + end +end diff --git a/spec/models/decidim/initiative_spec.rb b/spec/models/decidim/initiative_spec.rb new file mode 100644 index 0000000..910440b --- /dev/null +++ b/spec/models/decidim/initiative_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Initiative do + subject { initiative } + + let(:organization) { create(:organization) } + let(:initiative) { create(:initiative, organization: organization, author: private_user) } + + describe "#author_users" do + let(:private_user) { create(:user, :confirmed, organization: organization) } + let(:rejected_user) { create(:user, :confirmed, organization: organization) } + let(:public_user) { create(:user, :confirmed, :published, organization: organization) } + let(:private_member) { create(:initiatives_committee_member, :accepted, initiative: initiative, user: private_user) } + let(:public_member) { create(:initiatives_committee_member, :accepted, initiative: initiative, user: public_user) } + let(:rejected_member) { create(:initiatives_committee_member, :rejected, initiative: initiative) } + + context "when private author" do + it "returns public authors" do + expect(subject.author_users).not_to include(private_member) + expect(subject.author_users).not_to include(public_member) + expect(subject.author_users).not_to include(rejected_member) + expect(subject.author_users).to include(an_instance_of(Decidim::Privacy::PrivateUser)) + end + end + + context "when public author" do + let(:initiative) { create(:initiative, organization: organization, author: public_user) } + + it "returns public authors" do + expect(subject.author_users).to include(public_user) + expect(subject.author_users).not_to include(an_instance_of(Decidim::Privacy::PrivateUser)) + expect(subject.author_users).not_to include(private_member) + expect(subject.author_users).not_to include(rejected_member) + end + end + end +end diff --git a/spec/models/decidim/messaging/conversation_spec.rb b/spec/models/decidim/messaging/conversation_spec.rb new file mode 100644 index 0000000..f1b4a76 --- /dev/null +++ b/spec/models/decidim/messaging/conversation_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Messaging::Conversation do + describe ".start_conversation" do + subject { conversation } + + let(:originator) { create(:user) } + let(:public_interlocutor) { create(:user, :published) } + let(:private_interlocutor) { create(:user) } + let(:from) { nil } + let(:receipts) { conversation.receipts } + + let(:conversation) do + described_class.start!( + originator: originator, + interlocutors: [public_interlocutor, private_interlocutor], + body: "Hei!" + ) + end + + describe "#participants" do + before do + allow(public_interlocutor).to receive(:accepts_conversation?).and_return(true) + allow(private_interlocutor).to receive(:accepts_conversation?).and_return(true) + end + + it "contains entire collection" do + expect(subject.participants).to include(private_interlocutor) + expect(subject.participants).to include(public_interlocutor) + end + end + end +end diff --git a/spec/models/decidim/organization_spec.rb b/spec/models/decidim/organization_spec.rb new file mode 100644 index 0000000..9c0955c --- /dev/null +++ b/spec/models/decidim/organization_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Organization do + subject { organization } + + let!(:organization) { create(:organization) } + let!(:private_admin) { create(:user, :admin, organization: organization) } + let!(:public_admin) { create(:user, :admin, :published, organization: organization) } + let!(:private_user) { create(:user, :user_manager, organization: organization) } + let!(:public_user) { create(:user, :user_manager, :published, organization: organization) } + + describe "#admin" do + it "returns entire collection" do + expect(subject.admins).to include(private_admin) + expect(subject.admins).to include(public_admin) + end + end + + describe "#users_with_any_role" do + it "return entire collection of rolled users" do + expect(subject.users_with_any_role).not_to include(private_admin) + expect(subject.users_with_any_role).not_to include(public_admin) + expect(subject.users_with_any_role).to include(private_user) + expect(subject.users_with_any_role).to include(public_user) + end + end +end diff --git a/spec/models/decidim/proposals/collaborative_draft_spec.rb b/spec/models/decidim/proposals/collaborative_draft_spec.rb new file mode 100644 index 0000000..c9e4ea7 --- /dev/null +++ b/spec/models/decidim/proposals/collaborative_draft_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Proposals::CollaborativeDraft do + subject { collaborative_draft } + + let(:organization) { component.participatory_space.organization } + let(:component) { create :proposal_component } + let(:collaborative_draft) { create(:collaborative_draft, component: component, users: authors) } + + describe "#authors" do + let(:private_user) { create(:user, :confirmed, organization: organization) } + let(:public_users) { create_list(:user, 3, :confirmed, :published, organization: organization) } + let(:authors) { public_users + [private_user] } + + it "filters out private authors" do + expect(subject.authors).not_to include(private_user) + expect(subject.authors).to match_array(public_users) + end + end + + describe "editable_by" do + let(:authors) { [private_user, public_user] } + let(:public_user) { create(:user, :confirmed, :published, organization: organization) } + let(:private_user) { create(:user, :confirmed, organization: organization) } + + it "is editable by public author" do + expect(subject.editable_by?(public_user)).to be true + end + + it "is not editable by private author" do + expect(subject.editable_by?(private_user)).not_to be true + end + end +end diff --git a/spec/models/decidim/user_base_entity_spec.rb b/spec/models/decidim/user_base_entity_spec.rb new file mode 100644 index 0000000..35d9a7e --- /dev/null +++ b/spec/models/decidim/user_base_entity_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::UserBaseEntity do + subject { described_class } + + let(:organization) { create(:organization) } + let(:published_user) { create(:user, :confirmed, :published, organization: organization) } + let(:private_user) { create(:user, :confirmed, organization: organization) } + let(:user_group) { create(:user_group, organization: organization) } + + describe "#default_scope" do + it "returns only published profiles by default" do + expect(subject.all).to include(published_user) + expect(subject.all).not_to include(private_user) + expect(subject.all).to include(user_group) + end + end + + describe "#entire_collection" do + it "returns entire collection" do + expect(subject.entire_collection.all).to include(published_user) + expect(subject.entire_collection.all).to include(private_user) + expect(subject.entire_collection.all).to include(user_group) + end + end +end diff --git a/spec/models/decidim/user_group_spec.rb b/spec/models/decidim/user_group_spec.rb new file mode 100644 index 0000000..27bb447 --- /dev/null +++ b/spec/models/decidim/user_group_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::UserGroup do + subject { described_class } + + describe "usergroup extension" do + let!(:organization) { create(:organization) } + let(:private_verified) { create(:user_group, :verified, organization: organization) } + + let(:private_confirmed) { create(:user_group, :confirmed, organization: organization) } + let(:public_verified) { create(:user_group, :confirmed, :verified, published_at: Time.current, organization: organization) } + let!(:public_confirmed) { create(:user_group, :confirmed, published_at: Time.current, organization: organization) } + + describe "#scopes" do + it "returns visibles by default" do + result = subject.all + + expect(result).to include(public_verified) + expect(result).not_to include(private_verified) + expect(result).not_to include(private_confirmed) + expect(result).not_to include(public_confirmed) + end + + it "returns entire collextion correctly" do + result = subject.entire_collection + + expect(result).to include(public_verified) + expect(result).to include(private_verified) + expect(result).to include(private_confirmed) + expect(result).to include(public_confirmed) + end + end + end +end diff --git a/spec/models/decidim/user_spec.rb b/spec/models/decidim/user_spec.rb new file mode 100644 index 0000000..a892790 --- /dev/null +++ b/spec/models/decidim/user_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::User do + subject { described_class } + + let!(:organization) { create(:organization) } + let!(:published_user) { create(:user, :confirmed, :published, organization: organization) } + let!(:private_user) { create(:user, :confirmed, organization: organization) } + + describe "#default_scope" do + it "returns published users by default" do + result = subject.all + expect(result).to include(published_user) + expect(result).not_to include(private_user) + end + end + + describe "#entire_collection" do + it "rerutns entire_collection when scoped" do + result = subject.entire_collection.all + expect(result).to include(published_user) + expect(result).to include(private_user) + end + end + + describe "#profile_private" do + it "returns private when scoped" do + result = subject.profile_private.all + expect(result).not_to include(published_user) + expect(result).to include(private_user) + end + end + + describe "#public?" do + it "return true if user is public" do + expect(private_user).not_to be_public + expect(published_user).to be_public + end + end + + describe "#private_messaging_disabled?" do + it "returns true only if use is public and disabled messaging" do + expect(private_user).not_to be_private_messaging_disabled + expect do + published_user.update(allow_private_messaging: false) + end.to change(published_user, :private_messaging_disabled?).from(false).to(true) + end + end + + describe "#private_or_no_messaging?" do + it "returns true if private or no_messaging" do + expect(private_user).to be_private_or_no_messaging + expect do + published_user.update(allow_private_messaging: false) + end.to change(published_user, :private_or_no_messaging?).from(false).to(true) + end + end + + describe "#accepts_conversation?" do + let!(:user) { create(:user, :published, :confirmed, organization: organization) } + + it "returns false if private messaging is turned off" do + published_user.update(allow_private_messaging: false) + + expect(published_user.accepts_conversation?(user)).to be(false) + end + end +end diff --git a/spec/presenters/decidim/user_presenter_spec.rb b/spec/presenters/decidim/user_presenter_spec.rb index 7f8c73b..860766d 100644 --- a/spec/presenters/decidim/user_presenter_spec.rb +++ b/spec/presenters/decidim/user_presenter_spec.rb @@ -2,102 +2,100 @@ require "spec_helper" -module Decidim - describe UserPresenter, type: :helper do - let(:user) { build(:user) } +describe Decidim::UserPresenter, type: :helper do + let(:user) { build(:user) } - describe "#nickname" do - subject { described_class.new(user).nickname } + describe "#nickname" do + subject { described_class.new(user).nickname } - context "when blocked" do - before do - user.blocked = true - end - - it { is_expected.to eq("") } - end - - context "when private" do - it { is_expected.to eq("") } + context "when blocked" do + before do + user.blocked = true end - context "when not blocked & public" do - before do - user.published_at = Time.current - end - - it { is_expected.to eq("@#{user.nickname}") } - end + it { is_expected.to eq("") } end - describe "#profile_url" do - subject { described_class.new(user).profile_url } + context "when private" do + it { is_expected.to eq("") } + end - context "when private" do - it { is_expected.to eq("") } + context "when not blocked & public" do + before do + user.published_at = Time.current end - context "when public" do - before do - user.published_at = Time.current - end - - it { is_expected.to eq("http://#{user.organization.host}:#{Capybara.server_port}/profiles/#{user.nickname}") } - end + it { is_expected.to eq("@#{user.nickname}") } end + end - describe "#default_avatar_url" do - subject { described_class.new(user).default_avatar_url } + describe "#profile_url" do + subject { described_class.new(user).profile_url } - it { is_expected.to eq("//#{user.organization.host}:#{Capybara.server_port}#{ActionController::Base.helpers.asset_pack_path("media/images/default-avatar.svg")}") } + context "when private" do + it { is_expected.to eq("") } end - describe "#user_avatar_url" do - let(:avatar_image) do - ActiveStorage::Blob.create_and_upload!( - io: File.open(Decidim::Dev.asset("city.jpeg")), - filename: "city.jpeg", - content_type: "image/jpeg" - ) - end - + context "when public" do before do - user.avatar.attach(avatar_image) + user.published_at = Time.current end - subject { described_class.new(user).avatar_url } + it { is_expected.to eq("http://#{user.organization.host}:#{Capybara.server_port}/profiles/#{user.nickname}") } + end + end + + describe "#default_avatar_url" do + subject { described_class.new(user).default_avatar_url } - it { is_expected.to eq(described_class.new(user).default_avatar_url) } + it { is_expected.to eq("//#{user.organization.host}:#{Capybara.server_port}#{ActionController::Base.helpers.asset_pack_path("media/images/default-avatar.svg")}") } + end - context "when public" do - before do - user.published_at = Time.current - end + describe "#user_avatar_url" do + subject { described_class.new(user).avatar_url } - it { is_expected.to eq("/rails/active_storage/blobs/redirect/#{avatar_image.signed_id}/city.jpeg") } - end + let(:avatar_image) do + ActiveStorage::Blob.create_and_upload!( + io: File.open(Decidim::Dev.asset("city.jpeg")), + filename: "city.jpeg", + content_type: "image/jpeg" + ) end - describe "#profile_path" do - subject { described_class.new(user).profile_path } + before do + user.avatar.attach(avatar_image) + end - context "when user is deleted" do - let(:user) { build(:user, :deleted) } + it { is_expected.to eq(described_class.new(user).default_avatar_url) } - it { is_expected.to eq("") } + context "when public" do + before do + user.published_at = Time.current end - context "when user is private" do - it { is_expected.to eq("") } - end + it { is_expected.to eq("/rails/active_storage/blobs/redirect/#{avatar_image.signed_id}/city.jpeg") } + end + end - context "when public account" do - before do - user.published_at = Time.current - end + describe "#profile_path" do + subject { described_class.new(user).profile_path } - it { is_expected.to eq("/profiles/#{user.nickname}") } + context "when user is deleted" do + let(:user) { build(:user, :deleted) } + + it { is_expected.to eq("") } + end + + context "when user is private" do + it { is_expected.to eq("") } + end + + context "when public account" do + before do + user.published_at = Time.current end + + it { is_expected.to eq("/profiles/#{user.nickname}") } end end end diff --git a/spec/serializers/comment_serializer_spec.rb b/spec/serializers/comment_serializer_spec.rb deleted file mode 100644 index fb01a99..0000000 --- a/spec/serializers/comment_serializer_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Comments - describe CommentSerializer do - subject do - described_class.new(comment) - end - - let!(:commentable) { create(:dummy_resource) } - let!(:author) { create(:user, :published, organization: commentable.organization) } - let!(:comment) { create(:comment, commentable: commentable, author: author) } - - describe "#serialize" do - let(:serialized) { subject.serialize } - - context "when there's a private user in data" do - it "hides author's information" do - author.update(published_at: nil) - expect(serialized[:author]).to include(id: 0, name: "Anonymous") - end - end - - context "when there's a public user in data" do - it "shows author's information" do - expect(serialized[:author]).to include(id: author.id, name: author.name) - end - end - end - end - end -end diff --git a/spec/serializers/decidim/comments/comment_serializer_spec.rb b/spec/serializers/decidim/comments/comment_serializer_spec.rb new file mode 100644 index 0000000..ad58292 --- /dev/null +++ b/spec/serializers/decidim/comments/comment_serializer_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Comments::CommentSerializer do + subject do + described_class.new(comment) + end + + let!(:commentable) { create(:dummy_resource) } + let!(:author) { create(:user, :published, organization: commentable.organization) } + let!(:comment) { create(:comment, commentable: commentable, author: author) } + + describe "#serialize" do + let(:serialized) { subject.serialize } + + context "when there's a private user in data" do + it "hides author's information" do + author.update(published_at: nil) + expect(serialized[:author]).to include(id: 0, name: "Anonymous") + end + end + + context "when there's a public user in data" do + it "shows author's information" do + expect(serialized[:author]).to include(id: author.id, name: author.name) + end + end + end +end diff --git a/spec/serializers/decidim/initiatives/initiative_serializer_spec.rb b/spec/serializers/decidim/initiatives/initiative_serializer_spec.rb new file mode 100644 index 0000000..48b78ea --- /dev/null +++ b/spec/serializers/decidim/initiatives/initiative_serializer_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Decidim::Initiatives::InitiativeSerializer do + subject do + described_class.new(initiative) + end + + let(:organization) { create(:organization) } + let!(:author) { create(:user, :published, :confirmed, organization: organization) } + let!(:initiative) { create(:initiative, organization: organization, author: author) } + + describe "#serialize" do + let(:serialized) { subject.serialize } + + context "when there's a private user in data" do + it "hides author's information" do + author.update(published_at: nil) + expect(serialized[:authors]).to include(id: [0], name: ["Anonymous"]) + end + end + + context "when there's a public user in data" do + it "shows author's information" do + expect(serialized[:authors]).to include(id: [author.id], name: [author.name]) + end + end + end +end diff --git a/spec/serializers/initiative_serializer_spec.rb b/spec/serializers/initiative_serializer_spec.rb deleted file mode 100644 index 7a97e20..0000000 --- a/spec/serializers/initiative_serializer_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -module Decidim - module Initiatives - describe InitiativeSerializer do - subject do - described_class.new(initiative) - end - - let(:organization) { create(:organization) } - let!(:author) { create(:user, :published, :confirmed, organization: organization) } - let!(:initiative) { create(:initiative, organization: organization, author: author) } - - describe "#serialize" do - let(:serialized) { subject.serialize } - - context "when there's a private user in data" do - it "hides author's information" do - author.update(published_at: nil) - expect(serialized[:authors]).to include(id: [0], name: ["Anonymous"]) - end - end - - context "when there's a public user in data" do - it "shows author's information" do - expect(serialized[:authors]).to include(id: [author.id], name: [author.name]) - end - end - end - end - end -end diff --git a/spec/types/decidim/core/user_entity_input_filter_spec.rb b/spec/types/decidim/core/user_entity_input_filter_spec.rb new file mode 100644 index 0000000..e745e3a --- /dev/null +++ b/spec/types/decidim/core/user_entity_input_filter_spec.rb @@ -0,0 +1,152 @@ +# frozen_string_literal: true + +require "spec_helper" +require "decidim/api/test/type_context" +require "decidim/core/test" + +describe Decidim::Core::UserEntityInputFilter, type: :graphql do + include_context "with a graphql class type" + + let(:type_class) { Decidim::Api::QueryType } + + let(:user) { create(:user, :confirmed, organization: current_organization) } + let(:user_group) { create(:user_group, :confirmed, :verified, organization: current_organization) } + let!(:models) { [user, user_group] } + + context "when user or groups are not confirmed" do + let(:user) { create(:user, organization: current_organization) } + let(:user_group) { create(:user_group, organization: current_organization) } + let(:query) { %({ users { id } }) } + + it "returns all the types" do + users = response["users"] + expect(users).to eq([]) + end + end + + context "when user or groups are deleted" do + let(:user) { create(:user, :deleted, organization: current_organization) } + let(:user_group) { create(:user_group, :confirmed, :verified, deleted_at: Time.current, organization: current_organization) } + let(:query) { %({ users { id } }) } + + it "returns all the types" do + users = response["users"] + expect(users).to eq([]) + end + end + + context "when user is published, and user group is verified" do + let(:user) { create(:user, :confirmed, :published, organization: current_organization) } + let(:user_group) { create(:user_group, :confirmed, :verified, organization: current_organization) } + let(:query) { %({ users { id } }) } + + it "returns all the types" do + users = response["users"] + expect(users).to include("id" => user.id.to_s) + expect(users).to include("id" => user_group.id.to_s) + end + + context "when filtering by type User" do + let(:query) { %[{ users(filter: { type: "user" }) { id } }] } + + it "returns the types requested" do + users = response["users"] + expect(users).to include("id" => user.id.to_s) + expect(users).not_to include("id" => user_group.id.to_s) + end + + context "when user is blocked" do + let(:user) { create(:user, :blocked, :confirmed, organization: current_organization) } + + it "does not returns all the types" do + users = response["users"] + expect(users).to eq([]) + end + end + end + + context "when filtering by type UserGroup" do + let(:query) { %[{ users(filter: { type: "group" }) { id } }] } + + it "returns the types requested" do + users = response["users"] + expect(users).to include("id" => user_group.id.to_s) + expect(users).not_to include("id" => user.id.to_s) + end + end + + context "when search a user by nickname" do + let!(:user1) { create(:user, :confirmed, :published, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + let!(:user2) { create(:user, nickname: "_foo_user_2", name: "FooBar User 2", organization: current_organization) } + let!(:user3) { create(:user_group, :confirmed, :verified, nickname: "_bar_user_3", name: "FooBar User 3", organization: current_organization) } + let!(:user4) { create(:user, :confirmed, :published, nickname: "_foo_user_4", name: "FooBar User 4") } + let!(:user5) { create(:user, :confirmed, :published, nickname: "_foo_user_5", name: "FooBar User 5", organization: current_organization) } + let!(:user6) { create(:user, :confirmed, :published, nickname: "_foo_user_6", name: "FooBar User 6", organization: current_organization) } + let(:query) { %({ users(filter: { nickname: \"#{term}\" }) { name }}) } + let(:term) { "foo_user" } + + it "returns matching users" do + expect(response["users"]).to include("name" => user1.name) + expect(response["users"]).not_to include("name" => user2.name) + expect(response["users"]).not_to include("name" => user3.name) + expect(response["users"]).not_to include("name" => user4.name) + expect(response["users"]).to include("name" => user5.name) + expect(response["users"]).to include("name" => user6.name) + end + + context "when user is blocked" do + let!(:user1) { create(:user, :blocked, :published, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + + it "does not returns matching users" do + expect(response["users"]).not_to include("name" => user1.name) + end + end + + context "when user is deleted" do + let!(:user1) { create(:user, :deleted, :confirmed, :published, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + + it "does not returns matching users" do + expect(response["users"]).not_to include("name" => user1.name) + end + end + + context "when user is private" do + let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + + it "does not returns matching users" do + expect(response["users"]).not_to include("name" => user1.name) + end + end + + context "when search a user by name" do + let(:query) { %({ users(filter: { name: \"#{term}\" }) { name }}) } + let(:term) { "FooBar User" } + + it "returns matching users" do + expect(response["users"]).to include("name" => user1.name) + expect(response["users"]).not_to include("name" => user2.name) + expect(response["users"]).to include("name" => user3.name) + expect(response["users"]).not_to include("name" => user4.name) + expect(response["users"]).to include("name" => user5.name) + expect(response["users"]).to include("name" => user6.name) + end + + context "when user is blocked" do + let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + + it "does not returns matching users" do + expect(response["users"]).not_to include("name" => user1.name) + end + end + + context "when user is private" do + let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } + + it "does not returns matching users" do + expect(response["users"]).not_to include("name" => user1.name) + end + end + end + end + end +end diff --git a/spec/types/decidim/meetings/meeting_type_spec.rb b/spec/types/decidim/meetings/meeting_type_spec.rb new file mode 100644 index 0000000..800f0ab --- /dev/null +++ b/spec/types/decidim/meetings/meeting_type_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "spec_helper" +require "decidim/api/test/type_context" + +require "decidim/core/test/shared_examples/authorable_interface_examples" + +describe Decidim::Meetings::MeetingType, type: :graphql do + include_context "with a graphql class type" + let(:component) { create(:meeting_component) } + let(:model) { create(:meeting, component: component) } + + include_examples "authorable interface" +end diff --git a/spec/types/decidim/proposals/proposal_type_spec.rb b/spec/types/decidim/proposals/proposal_type_spec.rb new file mode 100644 index 0000000..e2006c6 --- /dev/null +++ b/spec/types/decidim/proposals/proposal_type_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "spec_helper" +require "decidim/api/test/type_context" +require "decidim/core/test/shared_examples/coauthorable_interface_examples" + +describe Decidim::Proposals::ProposalType, type: :graphql do + include_context "with a graphql class type" + let(:component) { create(:proposal_component) } + let(:model) { create(:proposal, :with_votes, :with_endorsements, :with_amendments, component: component, users: [creator], user_groups: [user_group].compact) } + let(:creator) { create(:user, :confirmed, :published, organization: component.organization) } + let(:user_group) { nil } + + include_examples "coauthorable interface" + + context "with a private author" do + let(:creator) { create(:user, :confirmed, organization: component.organization) } + + let(:query) { "{ author { name } }" } + + it "returns the user's name as the author name" do + expect(response["author"]).to be_nil + end + end +end diff --git a/spec/types/meeting_type_spec.rb b/spec/types/meeting_type_spec.rb deleted file mode 100644 index fd6188e..0000000 --- a/spec/types/meeting_type_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "decidim/api/test/type_context" - -require "decidim/core/test/shared_examples/authorable_interface_examples" - -module Decidim - module Meetings - describe MeetingType, type: :graphql do - include_context "with a graphql class type" - let(:component) { create(:meeting_component) } - let(:model) { create(:meeting, component: component) } - - include_examples "authorable interface" - end - end -end diff --git a/spec/types/proposal_type_spec.rb b/spec/types/proposal_type_spec.rb deleted file mode 100644 index cea5119..0000000 --- a/spec/types/proposal_type_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "decidim/api/test/type_context" -require "decidim/core/test/shared_examples/coauthorable_interface_examples" - -module Decidim - module Proposals - describe ProposalType, type: :graphql do - include_context "with a graphql class type" - let(:component) { create(:proposal_component) } - let(:model) { create(:proposal, :with_votes, :with_endorsements, :with_amendments, component: component, users: [creator], user_groups: [user_group].compact) } - let(:creator) { create(:user, :confirmed, :published, organization: component.organization) } - let(:user_group) { nil } - - include_examples "coauthorable interface" - - context "with a private author" do - let(:creator) { create(:user, :confirmed, organization: component.organization) } - - let(:query) { "{ author { name } }" } - - it "returns the user's name as the author name" do - expect(response["author"]).to be_nil - end - end - end - end -end diff --git a/spec/types/user_entity_input_filter_spec.rb b/spec/types/user_entity_input_filter_spec.rb deleted file mode 100644 index 4a028cc..0000000 --- a/spec/types/user_entity_input_filter_spec.rb +++ /dev/null @@ -1,155 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "decidim/api/test/type_context" -require "decidim/core/test" - -module Decidim - module Core - describe UserEntityInputFilter, type: :graphql do - include_context "with a graphql class type" - let(:type_class) { Decidim::Api::QueryType } - - let(:user) { create(:user, :confirmed, organization: current_organization) } - let(:user_group) { create(:user_group, :confirmed, :verified, organization: current_organization) } - let!(:models) { [user, user_group] } - - context "when user or groups are not confirmed" do - let(:user) { create(:user, organization: current_organization) } - let(:user_group) { create(:user_group, organization: current_organization) } - let(:query) { %({ users { id } }) } - - it "returns all the types" do - users = response["users"] - expect(users).to eq([]) - end - end - - context "when user or groups are deleted" do - let(:user) { create(:user, :deleted, organization: current_organization) } - let(:user_group) { create(:user_group, :confirmed, :verified, deleted_at: Time.current, organization: current_organization) } - let(:query) { %({ users { id } }) } - - it "returns all the types" do - users = response["users"] - expect(users).to eq([]) - end - end - - context "when user is published, and user group is verified" do - let(:user) { create(:user, :confirmed, :published, organization: current_organization) } - let(:user_group) { create(:user_group, :confirmed, :verified, organization: current_organization) } - let(:query) { %({ users { id } }) } - - it "returns all the types" do - users = response["users"] - expect(users).to include("id" => user.id.to_s) - expect(users).to include("id" => user_group.id.to_s) - end - - context "when filtering by type User" do - let(:query) { %[{ users(filter: { type: "user" }) { id } }] } - - it "returns the types requested" do - users = response["users"] - expect(users).to include("id" => user.id.to_s) - expect(users).not_to include("id" => user_group.id.to_s) - end - - context "when user is blocked" do - let(:user) { create(:user, :blocked, :confirmed, organization: current_organization) } - - it "does not returns all the types" do - users = response["users"] - expect(users).to eq([]) - end - end - end - - context "when filtering by type UserGroup" do - let(:query) { %[{ users(filter: { type: "group" }) { id } }] } - - it "returns the types requested" do - users = response["users"] - expect(users).to include("id" => user_group.id.to_s) - expect(users).not_to include("id" => user.id.to_s) - end - end - - context "when search a user by nickname" do - let!(:user1) { create(:user, :confirmed, :published, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - let!(:user2) { create(:user, nickname: "_foo_user_2", name: "FooBar User 2", organization: current_organization) } - let!(:user3) { create(:user_group, :confirmed, :verified, nickname: "_bar_user_3", name: "FooBar User 3", organization: current_organization) } - let!(:user4) { create(:user, :confirmed, :published, nickname: "_foo_user_4", name: "FooBar User 4") } - let!(:user5) { create(:user, :confirmed, :published, nickname: "_foo_user_5", name: "FooBar User 5", organization: current_organization) } - let!(:user6) { create(:user, :confirmed, :published, nickname: "_foo_user_6", name: "FooBar User 6", organization: current_organization) } - let(:query) { %({ users(filter: { nickname: \"#{term}\" }) { name }}) } - let(:term) { "foo_user" } - - it "returns matching users" do - expect(response["users"]).to include("name" => user1.name) - expect(response["users"]).not_to include("name" => user2.name) - expect(response["users"]).not_to include("name" => user3.name) - expect(response["users"]).not_to include("name" => user4.name) - expect(response["users"]).to include("name" => user5.name) - expect(response["users"]).to include("name" => user6.name) - end - - context "when user is blocked" do - let!(:user1) { create(:user, :blocked, :published, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - - it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) - end - end - - context "when user is deleted" do - let!(:user1) { create(:user, :deleted, :confirmed, :published, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - - it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) - end - end - - context "when user is private" do - let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - - it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) - end - end - - context "when search a user by name" do - let(:query) { %({ users(filter: { name: \"#{term}\" }) { name }}) } - let(:term) { "FooBar User" } - - it "returns matching users" do - expect(response["users"]).to include("name" => user1.name) - expect(response["users"]).not_to include("name" => user2.name) - expect(response["users"]).to include("name" => user3.name) - expect(response["users"]).not_to include("name" => user4.name) - expect(response["users"]).to include("name" => user5.name) - expect(response["users"]).to include("name" => user6.name) - end - - context "when user is blocked" do - let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - - it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) - end - end - - context "when user is private" do - let!(:user1) { create(:user, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) } - - it "does not returns matching users" do - expect(response["users"]).not_to include("name" => user1.name) - end - end - end - end - end - end - end -end