- <%= link_to follow_entity_text(entity_name(followable)), follows_path("#{entity_name(followable)}_id": followable.id), method: :post, remote: true, id: "follow-#{entity_name(followable)}-#{ followable.id }" %>
+
+ <%= link_to follow_entity_text(followable), follows_path(followable_id: followable.id, followable_type: followable.class.name), method: :post, remote: true, id: "follow-#{entity}-#{ followable.id }" %>
<% end %>
<% if show_unfollow_action? followable %>
<% follow = followable.follows.where(user: current_user).first %>
-
- <%= link_to unfollow_entity_text(entity_name(followable)), follow_path(follow), method: :delete, remote: true, id: "unfollow-#{entity_name(followable)}-#{ followable.id }" %>
+
+ <%= link_to unfollow_entity_text(followable), follow_path(follow), method: :delete, remote: true, id: "unfollow-#{entity}-#{ followable.id }" %>
<% end %>
diff --git a/spec/factories.rb b/spec/factories.rb
index b7caa73b4..d9521847d 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -355,6 +355,10 @@ FactoryGirl.define do
trait :followed_proposal do
association :followable, factory: :proposal
end
+
+ trait :followed_investment do
+ association :followable, factory: :budget_investment
+ end
end
factory :comment do
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index dfb64a755..347f9ae44 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -420,6 +420,74 @@ feature 'Budget Investments' do
end
end
+ feature "Follows" do
+
+ scenario "Should not show follow button when there is no logged user" do
+ investment = create(:budget_investment)
+
+ visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
+
+ within "#budget_investment_#{investment.id}" do
+ expect(page).not_to have_link("Follow citizen proposal")
+ end
+ end
+
+ scenario "Following", :js do
+ user = create(:user)
+ investment = create(:budget_investment)
+ login_as(user)
+
+ visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
+ within "#budget_investment_#{investment.id}" do
+ page.find("#follow-expand-investment-#{investment.id}").click
+ page.find("#follow-investment-#{investment.id}").click
+
+ expect(page).to have_css("#unfollow-expand-investment-#{investment.id}")
+ end
+
+ expect(Follow.followed?(user, investment)).to be
+ end
+
+ scenario "Show unfollow button when user already follow this investment" do
+ user = create(:user)
+ investment = create(:budget_investment)
+ follow = create(:follow, :followed_investment, user: user, followable: investment)
+ login_as(user)
+
+ visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
+
+ expect(page).to have_link("Unfollow investment")
+ end
+
+ scenario "Unfollowing", :js do
+ user = create(:user)
+ investment = create(:budget_investment)
+ follow = create(:follow, :followed_investment, user: user, followable: investment)
+ login_as(user)
+
+ visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
+ within "#budget_investment_#{investment.id}" do
+ page.find("#unfollow-expand-investment-#{investment.id}").click
+ page.find("#unfollow-investment-#{investment.id}").click
+
+ expect(page).to have_css("#follow-expand-investment-#{investment.id}")
+ end
+
+ expect(Follow.followed?(user, investment)).not_to be
+ end
+
+ scenario "Show follow button when user is not following this investment" do
+ user = create(:user)
+ investment = create(:budget_investment)
+ login_as(user)
+
+ visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
+
+ expect(page).to have_link("Follow investment")
+ end
+
+ end
+
context "Destroy" do
scenario "Admin cannot destroy budget investments" do
diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb
index 07e891dd8..4ea0238ec 100644
--- a/spec/models/follow_spec.rb
+++ b/spec/models/follow_spec.rb
@@ -4,8 +4,6 @@ describe Follow do
let(:follow) { build(:follow, :followed_proposal) }
- # it_behaves_like "has_public_author"
-
it "should be valid" do
expect(follow).to be_valid
end
@@ -25,110 +23,4 @@ describe Follow do
expect(follow).to_not be_valid
end
-
- # describe "proposal" do
- #
- # let(:proposal) { create(:proposal) }
- #
- # describe 'create' do
- #
- # it 'creates a interest when there is none' do
- # expect { described_class.follow(user, proposal) }.to change{ Interest.count }.by(1)
- # expect(Interest.last.user).to eq(user)
- # expect(Interest.last.interestable).to eq(proposal)
- # end
- #
- # it 'does nothing if the interest already exists' do
- # described_class.follow(user, proposal)
- # expect(described_class.follow(user, proposal)).to eq(false)
- # expect(Interest.by_user_and_interestable(user, proposal).count).to eq(1)
- # end
- #
- # it 'increases the interest count' do
- # expect { described_class.follow(user, proposal) }.to change{ proposal.reload.interests_count }.by(1)
- # end
- # end
- #
- # describe 'destroy' do
- # it 'raises an error if the interest does not exist' do
- # expect(described_class.unfollow(user, proposal)).to eq(false)
- # end
- #
- # describe 'when the interest already exists' do
- # before(:each) { described_class.follow(user, proposal) }
- #
- # it 'removes an existing interest' do
- # expect { described_class.unfollow(user, proposal) }.to change{ Interest.count }.by(-1)
- # end
- #
- # it 'decreases the interest count' do
- # expect { described_class.unfollow(user, proposal) }.to change{ proposal.reload.interests_count }.by(-1)
- # end
- # end
- # end
- #
- # describe '.interested?' do
- # it 'returns false when the user has not flagged the proposal' do
- # expect(described_class.interested?(user, proposal)).to_not be
- # end
- #
- # it 'returns true when the user has interested the proposal' do
- # described_class.follow(user, proposal)
- # expect(described_class.interested?(user, proposal)).to be
- # end
- # end
- # end
- #
- # describe "debate" do
- #
- # let(:debate) { create(:debate) }
- #
- # describe 'create' do
- #
- # it 'creates a interest when there is none' do
- # expect { described_class.follow(user, debate) }.to change{ Interest.count }.by(1)
- # expect(Interest.last.user).to eq(user)
- # expect(Interest.last.interestable).to eq(debate)
- # end
- #
- # it 'does nothing if the interest already exists' do
- # described_class.follow(user, debate)
- # expect(described_class.follow(user, debate)).to eq(false)
- # expect(Interest.by_user_and_interestable(user, debate).count).to eq(1)
- # end
- #
- # it 'increases the interest count' do
- # expect { described_class.follow(user, debate) }.to change{ debate.reload.interests_count }.by(1)
- # end
- # end
- #
- # describe 'destroy' do
- # it 'raises an error if the interest does not exist' do
- # expect(described_class.unfollow(user, debate)).to eq(false)
- # end
- #
- # describe 'when the interest already exists' do
- # before(:each) { described_class.follow(user, debate) }
- #
- # it 'removes an existing interest' do
- # expect { described_class.unfollow(user, debate) }.to change{ Interest.count }.by(-1)
- # end
- #
- # it 'decreases the interest count' do
- # expect { described_class.unfollow(user, debate) }.to change{ debate.reload.interests_count }.by(-1)
- # end
- # end
- # end
- #
- # describe '.interested?' do
- # it 'returns false when the user has not flagged the debate' do
- # expect(described_class.interested?(user, debate)).to_not be
- # end
- #
- # it 'returns true when the user has interested the debate' do
- # described_class.follow(user, debate)
- # expect(described_class.interested?(user, debate)).to be
- # end
- # end
- # end
end