Skip to content

Commit

Permalink
Don't delegate preview methods to controller. (#9097)
Browse files Browse the repository at this point in the history
The controller will try to load the Election from the params but when
rendering an election that's the single one in a voting there are no
params. Instead, it's better to use the model in the cell.
  • Loading branch information
oriolgual authored and andreslucena committed May 6, 2022
1 parent 498ae41 commit 4ba7f55
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ module Elections
# This cell renders the results
# for a given instance of an Election
class ElectionVoteCtaCell < Decidim::ViewModel
include Decidim::Elections::HasVoteFlow

delegate :current_user,
:current_participatory_space,
:preview_mode?,
:can_preview?,
:vote_flow,
:allowed_to?,
to: :controller

private

# This is needed by HasVoteFlow
def election
model
end

def last_vote
@last_vote ||= Decidim::Elections::Votes::LastVoteForVoter.for(model, vote_flow.voter_id) if vote_flow.has_voter?
end
Expand Down
28 changes: 21 additions & 7 deletions decidim-elections/spec/system/homepage_content_blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@
let(:organization) { create(:organization) }
let(:show_statistics) { true }
let!(:promoted_voting) { create(:voting, :promoted, organization: organization) }
let!(:unpromoted_voting) { create(:voting, organization: organization) }
let!(:promoted_external_voting) { create(:voting, :promoted) }

before do
create :content_block, organization: organization, scope_name: :homepage, manifest_name: :highlighted_votings
switch_to_host(organization.host)
end

it "includes active votings to the homepage" do
visit decidim.root_path
context "when there are multiple votings" do
let!(:unpromoted_voting) { create(:voting, organization: organization) }
let!(:promoted_external_voting) { create(:voting, :promoted) }

it "includes active votings to the homepage" do
visit decidim.root_path

within "#highlighted-votings" do
expect(page).to have_i18n_content(promoted_voting.title)
expect(page).to have_i18n_content(unpromoted_voting.title)
expect(page).not_to have_i18n_content(promoted_external_voting.title)
end
end
end

context "when there's only one voting" do
it "redirects to the voting page" do
visit decidim.root_path
click_link "Votings"

within "#highlighted-votings" do
expect(page).to have_i18n_content(promoted_voting.title)
expect(page).to have_i18n_content(unpromoted_voting.title)
expect(page).not_to have_i18n_content(promoted_external_voting.title)
expect(page).to have_i18n_content(promoted_voting.description)
expect(page).to have_current_path(decidim_votings.voting_path(promoted_voting))
end
end
end

0 comments on commit 4ba7f55

Please sign in to comment.