Skip to content

Instantly share code, notes, and snippets.

@shilovk
Created September 22, 2020 15:13
Show Gist options
  • Save shilovk/440c6893e991fe5e4a8926cc354c5b1a to your computer and use it in GitHub Desktop.
Save shilovk/440c6893e991fe5e4a8926cc354c5b1a to your computer and use it in GitHub Desktop.
def time_valid?(time = Time.current)
return true unless self.notify_on_time
Time.current >= 8 && Time.current <= 18
end
decribe '#time_valid?' do
let(:user) { create(:user) }
let(:user_with_time) { create(:user, :notify_on_time) }
it 'Time is valid for user, that can get notiies on all time' do
expect(user.time_valid?).to be true
end
it 'Time is valid for user_with_time, that can get notiies only through 8-18' do
expect(user_with_time.time_valid?(8)).to be true
expect(user_with_time.time_valid?(12)).to be true
expect(user_with_time.time_valid?(18)).to be true
end
it 'Time is not valid for user_with_time, that can get notiies only through 8-18' do
expect(user_with_time.time_valid?(7)).to be false
expect(user_with_time.time_valid?(20)).to be false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment