/
gift_spec.rb
42 lines (35 loc) · 1.47 KB
/
gift_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rails_helper'
describe Gift, type: :model do
let(:gift) { create :gift }
let(:contribution) { gift.contribution }
let(:user) { gift.user }
let(:date) { gift.date }
it { is_expected.to validate_presence_of(:user) }
it { is_expected.to validate_presence_of(:contribution) }
it { is_expected.to validate_presence_of(:date) }
it { is_expected.to validate_inclusion_of(:date).in_array(Gift.giftable_dates).with_message('your gift should be for the month of December.') }
describe '#find' do
subject { described_class.find(user, Time.zone.now.to_date) }
it { is_expected.to eq gift }
end
it 'raises a validation error when a gift has already been given for the current day' do
expect do
user.gifts.create!(contribution: create(:contribution), date: date)
end.to raise_error ActiveRecord::RecordInvalid, 'Validation failed: Date you only need one gift per day. Save it for tomorrow!'
end
it "raises a validation error if the pull request has already been gifted" do
expect do
user.gifts.create!(contribution: contribution, date: date + 1.day)
end.to raise_error ActiveRecord::RecordInvalid, 'Validation failed: Contribution you can only gift each contribution once!'
end
describe '.date' do
subject { gift.date }
it 'should default to Gift.default_date' do
is_expected.to eq Gift.default_date
end
end
describe '.to_param' do
subject { gift.to_param }
it { is_expected.to eq gift.date.to_s }
end
end