Note we don't cast negative votes when users remove their support. That way we provide compatibility for institutions who have implemented real negative votes (in case there are / will be any), and we also keep the database meaningful: it's not that users downvoted something; they simply removed their upvote. Co-Authored-By: Javi Martín <javim@elretirao.net> Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
44 lines
1.6 KiB
Ruby
44 lines
1.6 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Budgets::Investments::VotesComponent, type: :component do
|
|
describe "vote link" do
|
|
context "when investment shows votes" do
|
|
let(:investment) { create(:budget_investment, title: "Renovate sidewalks in Main Street") }
|
|
let(:component) { Budgets::Investments::VotesComponent.new(investment) }
|
|
|
|
before { allow(investment).to receive(:should_show_votes?).and_return(true) }
|
|
|
|
it "displays a button to support the investment to identified users" do
|
|
allow(controller).to receive(:current_user).and_return(create(:user))
|
|
|
|
render_inline component
|
|
|
|
expect(page).to have_button count: 1
|
|
expect(page).to have_button "Support", title: "Support this project", disabled: false
|
|
expect(page).to have_button "Support Renovate sidewalks in Main Street"
|
|
end
|
|
|
|
it "disables the button to support the investment to unidentified users" do
|
|
allow(controller).to receive(:current_user).and_return(nil)
|
|
|
|
render_inline component
|
|
|
|
expect(page).to have_button count: 1, disabled: :all
|
|
expect(page).to have_button "Support", disabled: true
|
|
end
|
|
|
|
it "shows the button to remove support when users have supported the investment" do
|
|
user = create(:user)
|
|
user.up_votes(investment)
|
|
allow(controller).to receive(:current_user).and_return(user)
|
|
|
|
render_inline component
|
|
|
|
expect(page).to have_button count: 1, disabled: :all
|
|
expect(page).to have_button "Remove your support"
|
|
expect(page).to have_button "Remove your support to Renovate sidewalks in Main Street"
|
|
end
|
|
end
|
|
end
|
|
end
|