Removed non-deterministic test, corrected typo

This commit is contained in:
redfast00 2018-12-30 20:01:57 +01:00
parent 05c83fb5cc
commit 2e3ee95de8
No known key found for this signature in database
GPG Key ID: 5946E0E34FD0553C
2 changed files with 5 additions and 13 deletions

View File

@ -47,12 +47,12 @@ class User < ActiveRecord::Base
.distinct
.pluck(:created_at)
frequency = (last_datetimes.map(&:to_time).map(&:to_i).sum / (num_orders * 10))
bonus = self.rich_privilige / 1.936
bonus = self.rich_privilege / 1.936
self.frecency = frequency * bonus
self.save
end
def rich_privilige
def rich_privilege
Math.atan(self.balance / 10) + (Math::PI / 2)
end

View File

@ -144,21 +144,13 @@ describe User do
end
it 'should be recalculated on creating an order' do
expect(@user.frecency).to eq 0
create :order, user: @user
expect(@user.frecency).to_not eq 0
end
it 'should be valid' do
dates = [Date.today.to_time, Date.yesterday.to_time]
dates.each do |date|
create :order, user: @user, created_at: date
end
@user.reload
num_orders = Rails.application.config.frecency_num_orders
# On Travis the result is 10025938 cause floating points
expect(@user.frecency).to be_within(50).of(10025915)
end
# TODO: add a test to check if the frecency is correct. Note that
# frecency currently changes over time
end
end