* First draft - all the big changes * Changing some more references to 'internal' * Relocate internal request tests to admin * Relocate internal system tests to admin * Fix trailing space * Test fix * Move queries from internal to admin * Docs updates * Rename internal stimuls controllers to admin (plus docs) * Rename admin layout * Fix routing after rebase * Fixes for latest added admin interfaces * Serviceworker ignore paths
57 lines
1.7 KiB
Ruby
57 lines
1.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "admin/organizations", type: :request do
|
|
let(:admin) { create(:user, :super_admin) }
|
|
let(:organization) { Organization.first }
|
|
|
|
before do
|
|
create_list :organization, 5
|
|
sign_in(admin)
|
|
end
|
|
|
|
describe "GETS /admin/organizations" do
|
|
let(:organizations) { Organization.pluck(:name).map { |n| CGI.escapeHTML(n) } }
|
|
let(:another_organization) { create(:organization, name: "T-800") }
|
|
|
|
it "lists all organizations" do
|
|
get "/admin/organizations"
|
|
expect(response.body).to include(*organizations)
|
|
end
|
|
|
|
it "allows searching" do
|
|
get "/admin/organizations?search=#{organization.name}"
|
|
expect(response.body).to include(CGI.escapeHTML(organization.name))
|
|
expect(response.body).not_to include(CGI.escapeHTML(another_organization.name))
|
|
end
|
|
end
|
|
|
|
describe "GET /admin/orgnaizations/:id" do
|
|
it "renders the correct organization" do
|
|
get "/admin/organizations/#{organization.id}"
|
|
expect(response.body).to include(CGI.escapeHTML(organization.name))
|
|
end
|
|
end
|
|
|
|
describe "PATCH /admin" do
|
|
let(:organization) { create(:organization) }
|
|
|
|
it "adds credits to an organization" do
|
|
params = { credits: 1, credit_action: :add }
|
|
|
|
expect do
|
|
patch update_org_credits_admin_organization_path(organization),
|
|
params: params
|
|
end.to change { organization.reload.unspent_credits_count }.by(1)
|
|
end
|
|
|
|
it "removes credits to an organization" do
|
|
Credit.add_to(organization, 1)
|
|
params = { credits: 1, credit_action: :remove }
|
|
|
|
expect do
|
|
patch update_org_credits_admin_organization_path(organization),
|
|
params: params
|
|
end.to change { organization.reload.unspent_credits_count }.by(-1)
|
|
end
|
|
end
|
|
end
|