Merge branch 'master' of github.com:ZeusWPI/Tab
This commit is contained in:
commit
a868cadd26
2 changed files with 14 additions and 1 deletions
|
@ -10,7 +10,14 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Client < ActiveRecord::Base
|
class Client < ActiveRecord::Base
|
||||||
|
before_create :generate_key
|
||||||
|
|
||||||
def transactions
|
def transactions
|
||||||
Transaction.where(origin: name)
|
Transaction.where(origin: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def generate_key
|
||||||
|
self.key = SecureRandom.base64(16) unless self.key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,5 +12,11 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Client, type: :model do
|
RSpec.describe Client, type: :model do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
it "should have a valid factory" do
|
||||||
|
expect(create(:client)).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should generate a key" do
|
||||||
|
expect(create(:client).key).to be_present
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue