Skip to content

Commit

Permalink
Fix model
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 6, 2023
1 parent 23eb7d3 commit c1977b5
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions spec/proposals/models/decidim/proposals/proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ module Proposals
let(:author) { create(:user, organization: organization) }

context "when user is author" do
let(:proposal) { create :proposal, component: component, users: [author], updated_at: Time.current }
let(:proposal) { create :extended_proposal, component: component, users: [author], updated_at: Time.current }

it { is_expected.to be_editable_by(author) }

context "when the proposal has been linked to another one" do
let(:proposal) { create :proposal, component: component, users: [author], updated_at: Time.current }
let(:proposal) { create :extended_proposal, component: component, users: [author], updated_at: Time.current }
let(:original_proposal) do
original_component = create(:extended_proposal_component, organization: organization, participatory_space: component.participatory_space)
create(:extended_proposal, component: original_component)
Expand All @@ -143,25 +143,25 @@ module Proposals

context "when proposal is from user group and user is admin" do
let(:user_group) { create :user_group, :verified, users: [author], organization: author.organization }
let(:proposal) { create :proposal, component: component, updated_at: Time.current, users: [author], user_groups: [user_group] }
let(:proposal) { create :extended_proposal, component: component, updated_at: Time.current, users: [author], user_groups: [user_group] }

it { is_expected.to be_editable_by(author) }
end

context "when user is not the author" do
let(:proposal) { create :proposal, component: component, updated_at: Time.current }
let(:proposal) { create :extended_proposal, component: component, updated_at: Time.current }

it { is_expected.not_to be_editable_by(author) }
end

context "when proposal is answered" do
let(:proposal) { build :proposal, :with_answer, component: component, updated_at: Time.current, users: [author] }
let(:proposal) { build :extended_proposal, :with_answer, component: component, updated_at: Time.current, users: [author] }

it { is_expected.not_to be_editable_by(author) }
end

context "when proposal editing time has run out" do
let(:proposal) { build :proposal, updated_at: 10.minutes.ago, component: component, users: [author] }
let(:proposal) { build :extended_proposal, updated_at: 10.minutes.ago, component: component, users: [author] }

it { is_expected.not_to be_editable_by(author) }
end
Expand All @@ -172,7 +172,7 @@ module Proposals
component.save!
end

let(:proposal) { build :proposal, updated_at: 10.years.ago, component: component, users: [author] }
let(:proposal) { build :extended_proposal, updated_at: 10.years.ago, component: component, users: [author] }

it do
proposal.add_coauthor(author)
Expand All @@ -184,13 +184,13 @@ module Proposals

describe "#withdrawn?" do
context "when proposal is withdrawn" do
let(:proposal) { build :proposal, :withdrawn }
let(:proposal) { build :extended_proposal, :withdrawn }

it { is_expected.to be_withdrawn }
end

context "when proposal is not withdrawn" do
let(:proposal) { build :proposal }
let(:proposal) { build :extended_proposal }

it { is_expected.not_to be_withdrawn }
end
Expand All @@ -200,33 +200,33 @@ module Proposals
let(:author) { create(:user, organization: organization) }

context "when user is author" do
let(:proposal) { create :proposal, component: component, users: [author], created_at: Time.current }
let(:proposal) { create :extended_proposal, component: component, users: [author], created_at: Time.current }

it { is_expected.to be_withdrawable_by(author) }
end

context "when user is admin" do
let(:admin) { build(:user, :admin, organization: organization) }
let(:proposal) { build :proposal, component: component, users: [author], created_at: Time.current }
let(:proposal) { build :extended_proposal, component: component, users: [author], created_at: Time.current }

it { is_expected.not_to be_withdrawable_by(admin) }
end

context "when user is not the author" do
let(:someone_else) { build(:user, organization: organization) }
let(:proposal) { build :proposal, component: component, users: [author], created_at: Time.current }
let(:proposal) { build :extended_proposal, component: component, users: [author], created_at: Time.current }

it { is_expected.not_to be_withdrawable_by(someone_else) }
end

context "when proposal is already withdrawn" do
let(:proposal) { build :proposal, :withdrawn, component: component, users: [author], created_at: Time.current }
let(:proposal) { build :extended_proposal, :withdrawn, component: component, users: [author], created_at: Time.current }

it { is_expected.not_to be_withdrawable_by(author) }
end

context "when the proposal has been linked to another one" do
let(:proposal) { create :proposal, component: component, users: [author], created_at: Time.current }
let(:proposal) { create :extended_proposal, component: component, users: [author], created_at: Time.current }
let(:original_proposal) do
original_component = create(:extended_proposal_component, organization: organization, participatory_space: component.participatory_space)
create(:extended_proposal, component: original_component)
Expand Down Expand Up @@ -260,7 +260,7 @@ module Proposals
let(:user) { create :user, organization: organization }
let(:space) { component.participatory_space }
let!(:valuator_role) { create :participatory_process_user_role, role: :valuator, user: user, participatory_process: space }
let(:assigned_proposal) { create :proposal, component: component }
let(:assigned_proposal) { create :extended_proposal, component: component }
let!(:assignment) { create :valuation_assignment, proposal: assigned_proposal, valuator_role: valuator_role }

it "only returns the assigned proposals for the given space" do
Expand Down

0 comments on commit c1977b5

Please sign in to comment.