Sha256: 2958d7493603cc8dec15b58cfa08c9aa2e8a451f49486c35def3f57b5842e48d

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

# When using these shared examples, make sure there are no prior requests within
# the same group of examples where this is included. Otherwise you may end up
# in race conditions that cause these to fail as explained at:
# https://github.com/decidim/decidim/pull/6161
shared_examples "followable content for users" do
  before do
    switch_to_host(organization.host)
    login_as user, scope: :user
  end

  context "when not following the followable" do
    context "when user clicks the Follow button" do
      it "makes the user follow the followable" do
        visit followable_path
        expect do
          click_link "Follow"
          expect(page).to have_content "Stop following"
        end.to change(Decidim::Follow, :count).by(1)
      end
    end
  end

  context "when the user is following the followable" do
    before do
      create(:follow, followable:, user:)
    end

    context "when user clicks the Follow button" do
      it "makes the user follow the followable" do
        visit followable_path
        expect do
          click_link "Stop following"
          expect(page).to have_content "Follow"
        end.to change(Decidim::Follow, :count).by(-1)
      end
    end
  end
end

shared_examples "followable content for users with a component" do
  include_context "with a component"
  include_examples "followable content for users"

  context "when the user is following the followable's participatory space" do
    before do
      create(:follow, followable: followable.participatory_space, user:)
    end

    context "when user clicks the Follow button" do
      it "makes the user follow the followable" do
        visit followable_path
        expect do
          click_link "Follow"
          expect(page).to have_content "Stop following"
        end.to change(Decidim::Follow, :count).by(1)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.28.5 lib/decidim/core/test/shared_examples/follows_examples.rb
decidim-core-0.28.4 lib/decidim/core/test/shared_examples/follows_examples.rb
decidim-core-0.28.3 lib/decidim/core/test/shared_examples/follows_examples.rb