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}