Add basic invitations

This commit is contained in:
2020-12-02 15:22:58 +01:00
parent 18df8fe449
commit d7fbda0855
12 changed files with 152 additions and 4 deletions

13
spec/fixtures/invitations.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
token: fedcba654321
user_id: 1
invited_user_id: nil
used_at: nil
two:
token: abcdef123456
user_id: 1
invited_user_id: nil
used_at: nil

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the InvitationsHelper. For example:
#
# describe InvitationsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe InvitationsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@@ -0,0 +1,22 @@
require 'rails_helper'
RSpec.describe Invitation, type: :model do
let(:user) { build :user }
describe "tokens" do
it "requires a user" do
expect { Invitation.create! }.to raise_error(ActiveRecord::RecordInvalid)
end
it "generates a random token when created" do
invitation = Invitation.new(user: user)
invitation.save!
token = invitation.token
expect(token).to be_a(String)
expect(token.length).to eq(16)
invitation_2 = Invitation.create(user: user)
expect(token).not_to eq(invitation_2.token)
end
end
end