Add basic invitations
This commit is contained in:
13
spec/fixtures/invitations.yml
vendored
Normal file
13
spec/fixtures/invitations.yml
vendored
Normal 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
|
||||
15
spec/helpers/invitations_helper_spec.rb
Normal file
15
spec/helpers/invitations_helper_spec.rb
Normal 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
|
||||
22
spec/models/invitation_spec.rb
Normal file
22
spec/models/invitation_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user