docbrown/spec/requests/admin/invitations_spec.rb
Ridhwana 3a4da2dd5a
RFC 50: Remove hardcoded paths and use path_helpers instead (in the specs) (#13549)
* feat: update the paths in the spec files

* feat: update hardcoded paths with path helpers

* chore: update hardcoded paths to path helpers

* chore: hardcode describe blocks

* chore: oops

* feat: update some more hardcoded to use link_to's

* fix broken tests

* chore: admin_articles path

* chore: oops remove rails helper

* feat: add starting /

* chore: more pre slashes

* chore: add pre slashes

* chore: some small typos

* fix: oops
2021-04-28 21:32:51 +02:00

57 lines
1.6 KiB
Ruby

require "rails_helper"
RSpec.describe "/admin/invitations", type: :request do
let(:user) { create(:user) }
let(:admin) { create(:user, :super_admin) }
before do
sign_in(admin)
end
describe "GET /admin/invitations" do
it "renders to appropriate page" do
user.update_column(:registered, false)
get admin_invitations_path
expect(response.body).to include(user.username)
end
end
describe "GET /admin/invitations/new" do
it "renders to appropriate page" do
get new_admin_invitation_path
expect(response.body).to include("Email:")
end
end
describe "POST /admin/invitations" do
it "creates new invitation" do
post admin_invitations_path,
params: { user: { email: "hey#{rand(1000)}@email.co", name: "Roger #{rand(1000)}" } }
expect(User.last.registered).to be false
end
it "does not create an invitation if a user with that email exists" do
expect do
post admin_invitations_path,
params: { user: { email: admin.email, name: "Roger #{rand(1000)}" } }
end.not_to change { User.all.count }
expect(admin.reload.registered).to be true
expect(flash[:error].present?).to be true
end
end
describe "DELETE /admin/invitations" do
let!(:invitation) { create(:user, registered: false) }
before do
sign_in admin
end
it "deletes the invitation" do
expect do
delete admin_invitation_path(invitation.id)
end.to change { User.all.count }.by(-1)
expect(response.body).to redirect_to "/admin/invitations"
end
end
end