Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 6, 2023
1 parent fbc6220 commit 0168b90
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 384 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jobs:
- "spec/proposals/presenters"
- "spec/proposals/queries"
- "spec/proposals/services"
- "spec/proposals/system"
- "spec/proposals/system/admin"
- "spec/proposals/system/ammendable"
- "spec/proposals/system/*.rb"
- "spec/proposals/types"
- "spec/sortitions"
- "spec/system"
Expand Down
2 changes: 2 additions & 0 deletions lib/decidim/custom_proposal_states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module Decidim
module CustomProposalStates
module Overrides
autoload :Proposal, "decidim/custom_proposal_states/overrides/proposal"
autoload :ImportProposalsToBudgets, "decidim/custom_proposal_states/overrides/import_proposals_to_budgets"
autoload :ImportProposalsToElections, "decidim/custom_proposal_states/overrides/import_proposals_to_elections"
end

def self.create_default_states!(component, admin_user, with_traceability: true)
Expand Down
8 changes: 8 additions & 0 deletions lib/decidim/custom_proposal_states/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class Engine < ::Rails::Engine
initializer "decidim_custom_proposal_states.action_controller" do |_app|
Rails.application.reloader.to_prepare do
Decidim::Proposals::Proposal.prepend Decidim::CustomProposalStates::Overrides::Proposal

if Decidim.module_installed?("budgets")
Decidim::Budgets::Admin::ImportProposalsToBudgets.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToBudgets
end

if Decidim.module_installed?("elections")
Decidim::Elections::Admin::ImportProposalsToElections.prepend Decidim::CustomProposalStates::Overrides::ImportProposalsToElections
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true
module Decidim
module CustomProposalStates
module Overrides
module ImportProposalsToBudgets
def self.prepended(base)
base.class_eval do
def all_proposals
Decidim::Proposals::Proposal.where(component: origin_component).only_status(:accepted)
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true
module Decidim
module CustomProposalStates
module Overrides
module ImportProposalsToElections

def self.prepended(base)
base.class_eval do
def proposals
@proposals ||= if @form.import_all_accepted_proposals?
Decidim::Proposals::Proposal.where(component: origin_component).only_status(:accepted)
else
Decidim::Proposals::Proposal.where(component: origin_component)
end
end
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/decidim/custom_proposal_states/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,34 @@ def generate_state_title(token)

trait :evaluating do
state { :evaluating }
answered_at { Time.current }
state_published_at { Time.current }
end
trait :accepted do
state { :accepted }
answered_at { Time.current }
state_published_at { Time.current }
end
trait :rejected do
state { :rejected }
answered_at { Time.current }
state_published_at { Time.current }
end
trait :withdrawn do
state { :withdrawn }
end
trait :with_answer do
state { :accepted }
answer { generate_localized_title }
answered_at { Time.current }
state_published_at { Time.current }
end

trait :accepted_not_published do
state { :accepted }
answered_at { Time.current }
state_published_at { nil }
answer { generate_localized_title }
end
end

Expand Down
227 changes: 0 additions & 227 deletions spec/budgets/admin_manages_projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,231 +47,4 @@
end
end
end

describe "admin form" do
before do
within ".process-content" do
page.find(".button--title.new").click
end
end

it_behaves_like "having a rich text editor", "new_project", "full"

it "displays the proposals picker" do
expect(page).to have_content("Choose proposals")
end

context "when proposal linking is disabled" do
before do
allow(Decidim::Budgets).to receive(:enable_proposal_linking).and_return(false)

# Reload the page with the updated settings
visit current_path
end

it "does not display the proposal picker" do
expect(page).not_to have_content "Choose proposals"
end
end
end

it "updates a project" do
within find("tr", text: translated(project.title)) do
click_link "Edit"
end

within ".edit_project" do
fill_in_i18n(
:project_title,
"#project-title-tabs",
en: "My new title",
es: "Mi nuevo título",
ca: "El meu nou títol"
)

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("My new title")
end
end

context "when previewing projects" do
it "allows the user to preview the project" do
within find("tr", text: translated(project.title)) do
klass = "action-icon--preview"
href = resource_locator([project.budget, project]).path
target = "blank"

expect(page).to have_selector(
:xpath,
"//a[contains(@class,'#{klass}')][@href='#{href}'][@target='#{target}']"
)
end
end
end

context "when seeing finished and pending votes" do
let!(:project) { create(:project, budget_amount: 70_000_000, budget: budget) }

let!(:finished_orders) do
orders = create_list(:order, 10, budget: budget)
orders.each do |order|
order.update!(line_items: [create(:line_item, project: project, order: order)])
order.reload
order.update!(checked_out_at: Time.zone.today)
end
end

let!(:pending_orders) do
create_list(:order, 5, budget: budget, checked_out_at: nil)
end

it "shows the order count" do
visit current_path
expect(page).to have_content("Finished votes: \n10")
expect(page).to have_content("Pending votes: \n5")
end
end

it "creates a new project", :slow do
find(".card-title a.button.new").click

within ".new_project" do
fill_in_i18n(
:project_title,
"#project-title-tabs",
en: "My project",
es: "Mi proyecto",
ca: "El meu projecte"
)
fill_in_i18n_editor(
:project_description,
"#project-description-tabs",
en: "A longer description",
es: "Descripción más larga",
ca: "Descripció més llarga"
)
fill_in :project_budget_amount, with: 22_000_000

scope_pick select_data_picker(:project_decidim_scope_id), scope
select translated(category.name), from: :project_decidim_category_id

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("My project")
end
end

context "when deleting a project" do
let!(:project2) { create(:project, budget: budget) }

before do
visit current_path
end

it "deletes a project" do
within find("tr", text: translated(project2.title)) do
accept_confirm { click_link "Delete" }
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_no_content(translated(project2.title))
end
end
end

context "when having existing proposals" do
let!(:proposal_component) { create(:extended_proposal_component, participatory_space: participatory_space) }
let!(:proposals) { create_list :extended_proposal, 5, component: proposal_component, skip_injection: true }

it "updates a project" do
within find("tr", text: translated(project.title)) do
click_link "Edit"
end

within ".edit_project" do
fill_in_i18n(
:project_title,
"#project-title-tabs",
en: "My new title",
es: "Mi nuevo título",
ca: "El meu nou títol"
)

proposals_pick(select_data_picker(:project_proposals, multiple: true), proposals.last(2))

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("My new title")
end
end

it "removes proposals from project", :slow do
project.link_resources(proposals, "included_proposals")
not_removed_projects_title = project.linked_resources(:proposals, "included_proposals").first.title
expect(project.linked_resources(:proposals, "included_proposals").count).to eq(5)

within find("tr", text: translated(project.title)) do
click_link "Edit"
end

within ".edit_project" do
proposals_remove(select_data_picker(:project_proposals, multiple: true), proposals.last(4))

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")
expect(project.linked_resources(:proposals, "included_proposals").count).to eq(1)
expect(project.linked_resources(:proposals, "included_proposals").first.title).to eq(not_removed_projects_title)
end

it "creates a new project", :slow do
find(".card-title a.button.new").click

within ".new_project" do
fill_in_i18n(
:project_title,
"#project-title-tabs",
en: "My project",
es: "Mi project",
ca: "El meu project"
)
fill_in_i18n_editor(
:project_description,
"#project-description-tabs",
en: "A longer description",
es: "Descripción más larga",
ca: "Descripció més llarga"
)
fill_in :project_budget_amount, with: 22_000_000

proposals_pick(select_data_picker(:project_proposals, multiple: true), proposals.first(2))
scope_pick(select_data_picker(:project_decidim_scope_id), scope)
select translated(category.name), from: :project_decidim_category_id

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("My project")
end
end
end
end
Loading

0 comments on commit 0168b90

Please sign in to comment.