Move system specs to subheader component specs
As the are much faster. Keep a system spec to check the component is called from the view.
This commit is contained in:
committed by
taitus
parent
822140a147
commit
26d14cbd04
104
spec/components/budgets/subheader_component_spec.rb
Normal file
104
spec/components/budgets/subheader_component_spec.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Budgets::SubheaderComponent, type: :component do
|
||||
it "shows budget current phase name" do
|
||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
||||
budget = create(:budget, :informing)
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
within(".budget-subheader") do
|
||||
expect(page).to have_content "CURRENT PHASE"
|
||||
expect(page).to have_content "Information"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when budget is accepting" do
|
||||
let(:budget) { create(:budget, :accepting) }
|
||||
|
||||
it "and user is level_two_or_three_verified shows a link to create a new investment" do
|
||||
allow(controller).to receive(:current_user).and_return(create(:user, :level_two))
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).to have_link "Create a budget investment"
|
||||
|
||||
(Budget::Phase::PHASE_KINDS - ["accepting"]).each do |phase|
|
||||
budget.update!(phase: phase)
|
||||
budget.reload
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).not_to have_link "Create a budget investment"
|
||||
end
|
||||
end
|
||||
|
||||
it "and user is not verified shows a link to account verification" do
|
||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).to have_content "To create a new budget investment"
|
||||
expect(page).to have_link "verify your account"
|
||||
|
||||
(Budget::Phase::PHASE_KINDS - ["accepting"]).each do |phase|
|
||||
budget.update!(phase: phase)
|
||||
budget.reload
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).not_to have_content "To create a new budget investment"
|
||||
expect(page).not_to have_link "verify your account"
|
||||
end
|
||||
end
|
||||
|
||||
it "and user is not logged in shows links to sign in and sign up" do
|
||||
allow(controller).to receive(:current_user).and_return(nil)
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).to have_content "To create a new budget investment you must"
|
||||
expect(page).to have_link "sign in"
|
||||
expect(page).to have_link "sign up"
|
||||
|
||||
(Budget::Phase::PHASE_KINDS - ["accepting"]).each do |phase|
|
||||
budget.update!(phase: phase)
|
||||
budget.reload
|
||||
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).not_to have_content "To create a new budget investment you must"
|
||||
expect(page).not_to have_link "sign in"
|
||||
expect(page).not_to have_link "sign up"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "See results link" do
|
||||
it "is showed when budget is finished and results are enabled for all users" do
|
||||
budget = create(:budget, :finished)
|
||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).to have_link "See results"
|
||||
|
||||
allow(controller).to receive(:current_user).and_return(create(:administrator).user)
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).to have_link "See results"
|
||||
end
|
||||
|
||||
it "is not showed when budget is finished or results are disabled for all users" do
|
||||
budget = create(:budget, :balloting, results_enabled: true)
|
||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).not_to have_link "See results"
|
||||
|
||||
allow(controller).to receive(:current_user).and_return(create(:administrator).user)
|
||||
render_inline Budgets::SubheaderComponent.new(budget)
|
||||
|
||||
expect(page).not_to have_link "See results"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,17 +22,6 @@ describe "Budgets" do
|
||||
let!(:heading1) { create(:budget_heading, group: group1) }
|
||||
let!(:heading2) { create(:budget_heading, group: group2) }
|
||||
|
||||
scenario "Show normal index with links in informing phase" do
|
||||
budget.update!(phase: "informing")
|
||||
|
||||
visit budgets_path
|
||||
|
||||
within(".budget-subheader") do
|
||||
expect(page).to have_content "CURRENT PHASE"
|
||||
expect(page).to have_content "Information"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Show normal index with links publishing prices" do
|
||||
budget.update!(phase: "publishing_prices")
|
||||
|
||||
@@ -137,15 +126,6 @@ describe "Budgets" do
|
||||
|
||||
expect(page).to have_content "There are no budgets"
|
||||
end
|
||||
|
||||
scenario "Accepting" do
|
||||
budget.update!(phase: "accepting")
|
||||
login_as(create(:user, :level_two))
|
||||
|
||||
visit budgets_path
|
||||
|
||||
expect(page).to have_link "Create a budget investment"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Index shows only published phases" do
|
||||
@@ -281,36 +261,14 @@ describe "Budgets" do
|
||||
expect(page).not_to have_css("#budget_heading_#{heading4.id}")
|
||||
end
|
||||
|
||||
scenario "See results button is showed if the budget has finished for all users" do
|
||||
scenario "See results button is showed if the budget has finished" do
|
||||
user = create(:user)
|
||||
admin = create(:administrator)
|
||||
budget = create(:budget, :finished)
|
||||
|
||||
login_as(user)
|
||||
visit budget_path(budget)
|
||||
|
||||
expect(page).to have_link "See results"
|
||||
|
||||
logout
|
||||
|
||||
login_as(admin.user)
|
||||
visit budget_path(budget)
|
||||
expect(page).to have_link "See results"
|
||||
end
|
||||
|
||||
scenario "See results button isn't showed if the budget hasn't finished for all users" do
|
||||
user = create(:user)
|
||||
admin = create(:administrator)
|
||||
budget = create(:budget, :balloting)
|
||||
|
||||
login_as(user)
|
||||
visit budget_path(budget)
|
||||
expect(page).not_to have_link "See results"
|
||||
|
||||
logout
|
||||
|
||||
login_as(admin.user)
|
||||
visit budget_path(budget)
|
||||
expect(page).not_to have_link "See results"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -328,34 +286,4 @@ describe "Budgets" do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Accepting" do
|
||||
before do
|
||||
budget.update(phase: "accepting")
|
||||
end
|
||||
|
||||
context "Permissions" do
|
||||
scenario "Verified user" do
|
||||
login_as(level_two_user)
|
||||
|
||||
visit budget_path(budget)
|
||||
expect(page).to have_link "Create a budget investment"
|
||||
end
|
||||
|
||||
scenario "Unverified user" do
|
||||
user = create(:user)
|
||||
login_as(user)
|
||||
|
||||
visit budget_path(budget)
|
||||
|
||||
expect(page).to have_content "To create a new budget investment verify your account."
|
||||
end
|
||||
|
||||
scenario "user not logged in" do
|
||||
visit budget_path(budget)
|
||||
|
||||
expect(page).to have_content "To create a new budget investment you must sign in or sign up"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user