System tests are used to test the application from the user's point of view. To test for specific exceptions, particularly regarding authorization permissions, controller tests fit better. Another option would be to test the page displayed shows a certain text, like "Internal server error". I'm choosing controller tests because they're faster and we're basically testing the same scenario many times and we've already got a test checking what happens when users access a page raising an exception.
55 lines
1.8 KiB
Ruby
55 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Admin::BudgetHeadingsController, :admin do
|
|
context "processes disabled" do
|
|
it "raises feature disabled for budgets" do
|
|
Setting["process.budgets"] = nil
|
|
group = create(:budget_group)
|
|
|
|
expect do
|
|
get :index, params: { budget_id: group.budget.id, group_id: group.id }
|
|
end.to raise_exception(FeatureFlags::FeatureDisabled)
|
|
end
|
|
end
|
|
|
|
describe "GET edit" do
|
|
let(:heading) { create(:budget_heading) }
|
|
|
|
it "raises an error if budget slug is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: "wrong_budget", group_id: heading.group.id, id: heading.id }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "raises an error if budget id is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: 0, group_id: heading.group.id, id: heading.id }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "raises an error if group slug is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: heading.budget.id, group_id: "wrong group", id: heading.id }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "raises an error if group id is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: heading.budget.id, group_id: 0, id: heading.id }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "raises an error if heading slug is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: heading.budget.id, group_id: heading.group.id, id: "wrong heading" }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
it "raises an error if heading id is not found" do
|
|
expect do
|
|
get :edit, params: { budget_id: heading.budget.id, group_id: heading.group.id, id: 0 }
|
|
end.to raise_error ActiveRecord::RecordNotFound
|
|
end
|
|
end
|
|
end
|